Skip to content

Commit

Permalink
Fixed update script to account for dynamic hosts (from perspective of a
Browse files Browse the repository at this point in the history
host in flakes)
  • Loading branch information
jwyuen committed May 31, 2024
1 parent d0ceeae commit e4874bc
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions dots/config/bspwm/scripts/Updates
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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



0 comments on commit e4874bc

Please sign in to comment.