From e4874bc7981e6f3a360971e96a403e8a2c28a1c8 Mon Sep 17 00:00:00 2001 From: jwy Date: Fri, 31 May 2024 14:11:21 -0400 Subject: [PATCH] Fixed update script to account for dynamic hosts (from perspective of a host in flakes) --- dots/config/bspwm/scripts/Updates | 54 ++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/dots/config/bspwm/scripts/Updates b/dots/config/bspwm/scripts/Updates index 5d93c617c..988d22deb 100755 --- a/dots/config/bspwm/scripts/Updates +++ b/dots/config/bspwm/scripts/Updates @@ -5,32 +5,45 @@ HOST=$(hostname -s) PROJECT_DIR=~/jwy-gh0stzk-dotfiles +pre_call() { + cd $PROJECT_DIR || exit + sed -i "/^\s*host[[:space:]]*=[[:space:]]*\"/s/\"\(.*\)\"/\"$HOST\"/" ./flake.nix +} + +post_call() { + git restore ./flake.nix +} + get_total_updates() { - #nhstring="Closure size: 2048 -> 2048 (0 paths added, 0 paths removed, delta +0, disk usage +0B)." - #Since update checker command takes time to run, show 0 as default until command finishes - echo "0" - nhstring=$(nh os switch -n --hostname "$HOST" $PROJECT_DIR 2>/dev/null | rg Closure) - num_of_updates=${nhstring##*delta} - num_of_updates=${num_of_updates%,*} - num_of_updates=${num_of_updates##*+} - num_of_updates=${num_of_updates##*-} - - echo "$num_of_updates" + pre_call + #nhstring="Closure size: 2048 -> 2048 (0 paths added, 0 paths removed, delta +0, disk usage +0B)." + #Since update checker command takes time to run, show 0 as default until command finishes + echo "0" + nhstring=$(nh os switch -n --hostname "$HOST" $PROJECT_DIR 2>/dev/null | rg Closure) + num_of_updates=${nhstring##*delta} + num_of_updates=${num_of_updates%,*} + num_of_updates=${num_of_updates##*+} + num_of_updates=${num_of_updates##*-} + + echo "$num_of_updates" + post_call } print_updates() { - print_updates=$(get_total_updates) - - if [[ "$print_updates" -gt 0 ]]; then - echo -e "\033[1m\033[33mThere are $print_updates updates available:\033[0m\n" - nh os switch -n --hostname $HOST $PROJECT_DIR - else - echo -e "\033[1m\033[32mYour system is already updated!\033[0m" - fi + print_updates=$(get_total_updates) + + if [[ "$print_updates" -gt 0 ]]; then + echo -e "\033[1m\033[33mThere are $print_updates updates available:\033[0m\n" + nh os switch -n --hostname $HOST $PROJECT_DIR + else + echo -e "\033[1m\033[32mYour system is already updated!\033[0m" + fi } update_system() { - nh os switch -a --hostname $HOST $PROJECT_DIR + pre_call + nh os switch -a --hostname "$HOST" $PROJECT_DIR + post_call } case "$1" in @@ -44,3 +57,6 @@ Options: --print-updates Print the number of available package to update. --update-system Update your system including the AUR packages.\n" esac + + +