fix(scripts): improve offline resilience and restore missing update scripts
All checks were successful
Check / eval-and-lint (push) Successful in 7m5s

This commit is contained in:
Bernardo Magri
2026-06-01 20:07:08 +01:00
parent 6ed2ca3d78
commit 1e6becd42d
6 changed files with 67 additions and 12 deletions

View File

@@ -0,0 +1,32 @@
#!/usr/bin/env bash
# Nomarchy Full Update Script
# 1. Syncs the local repository (if applicable)
# 2. Performs a full system update (NixOS + Home Manager)
set -e
# Detect the repository location
if [ -f "/etc/nixos/flake.nix" ]; then
REPO_DIR="/etc/nixos"
elif [ -f "/etc/nomarchy/flake.nix" ]; then
REPO_DIR="/etc/nomarchy"
else
echo "Error: Nomarchy flake repository not found in /etc/nixos or /etc/nomarchy."
exit 1
fi
echo "--- Starting Nomarchy Full Update ---"
# 1. Sync repository if it's a git repo
if [ -d "$REPO_DIR/.git" ]; then
echo "Syncing repository from remote..."
if ! git -C "$REPO_DIR" pull --ff-only; then
echo "Warning: git pull failed. Proceeding with local configuration."
fi
fi
# 2. System update
nomarchy-sys-update
echo "--- Nomarchy Full Update Complete ---"

View File

@@ -16,18 +16,14 @@ if [ -z "$REPO_DIR" ]; then
exit 0
fi
# We use a simple logic: Check for flake updates periodically.
# Since this is run by Waybar, we should be careful with performance.
# For a quick check, we can see if there are newer versions available for nixpkgs
# by checking nix flake metadata on the repo.
# Fast-fail if offline to avoid expensive nix commands.
if ! ping -c 1 -W 2 1.1.1.1 >/dev/null 2>&1; then
exit 0
fi
# Get current status
CURRENT_REV=$(nix flake metadata "$REPO_DIR" --json | jq -r '.lock.nodes.root.inputs.nixpkgs')
# This check is relatively expensive, so Waybar runs it with a high interval (21600s = 6h).
# Just return an icon if we are in a system that can be updated.
# In a real implementation, we could compare local flake.lock vs upstream if it's a git repo.
# For now, we'll return the update icon to show it's active.
echo ""

View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
# Nomarchy Time Sync Script
# Force sync system time using systemd-timesyncd
set -e
echo "Syncing system time..."
if ! sudo systemctl restart systemd-timesyncd; then
echo "Error: Failed to restart systemd-timesyncd. Check internet connection."
exit 1
fi
# Wait a moment for sync
sleep 2
echo "Current time: $(date)"
echo "Time sync complete."

View File

@@ -13,9 +13,15 @@ fi
# Use ix.io as the default pastebin
if [[ -n $1 ]]; then
url=$(curl -F "f:1=@$1" ix.io)
# --connect-timeout 5: fail fast if ix.io is unreachable
url=$(curl -s --connect-timeout 5 -F "f:1=@$1" ix.io || echo "OFFLINE")
else
url=$(curl -F "f:1=@-" ix.io)
url=$(curl -s --connect-timeout 5 -F "f:1=@-" ix.io || echo "OFFLINE")
fi
if [[ "$url" == "OFFLINE" ]]; then
echo "Error: Could not upload log. Check your internet connection."
exit 1
fi
echo "Log uploaded to: $url"