From 70889fd9fc2ba21febd747ffda38ff455a1e89f6 Mon Sep 17 00:00:00 2001 From: ark-lamp-umbrella Date: Thu, 28 Mar 2024 21:41:56 -0700 Subject: [PATCH] Add hash checks --- .gitignore | 1 + scripts/export.fish | 53 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a47f7e0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/temp/ \ No newline at end of file diff --git a/scripts/export.fish b/scripts/export.fish index 3c45b5a..6dd0fb3 100644 --- a/scripts/export.fish +++ b/scripts/export.fish @@ -2,19 +2,44 @@ source scripts/shared.fish +mkdir -p "temp" + +set dircontent $(find "nixos" -type f | sort -z) + +for i in $dircontent + if [ $i != "" ] + echo "[INFO] Hashing $i" + set ihash "$(sha1sum $i)" + echo "$ihash" >> "temp/directorylisthashed.txt" + end +end + if fish_is_root_user echo "[ERROR] Running with root permissions is not supported" + exit 0 else - read -sP "[INPUT] Root password: " rpass - echo "$rpass" | sudo -S echo "[INFO] Obtaining admin permissions" - sudo cp -r "nixos/" "/etc/" - read -P "[INPUT] Trigger rebuild Y/n: " rebuild - if [ "$rebuild" = "" ] - set rebuild "y" - end - set rebuild "$(string lower $rebuild)" - if [ "$rebuild" = "y" ] - sudo nixos-rebuild switch &> /dev/null + set hash1 "$(cat temp/directorylisthashed.txt)" + set hash1 $(string split " " $hash1) + set hash1 $hash1[1] + set hash2 "$(cat temp/directorylisthashedprevious.txt)" + set hash2 $(string split " " $hash2) + set hash2 $hash2[1] + if [ "$hash1" != "$hash2" ] + read -sP "[INPUT] Root password: " rpass + if [ "$rpass" = "" ] + echo "[ERROR] Failed to get root password" + exit 0 + end + echo "$rpass" | sudo -S echo "[INFO] Obtaining admin permissions" + sudo cp -r "nixos/" "/etc/" + read -P "[INPUT] Trigger rebuild Y/n: " rebuild + if [ "$rebuild" = "" ] + set rebuild "y" + end + set rebuild "$(string lower $rebuild)" + if [ "$rebuild" = "y" ] + sudo nixos-rebuild switch &> /dev/null + end end read -P "[INPUT] Git update Y/n: " gitpush if [ "$gitpush" = "" ] @@ -24,10 +49,12 @@ else if [ "$gitpush" = "y" ] read -P "[INPUT] Commit message: " cmessage echo "[INFO] Adding to git" - git add . + git add . --quiet echo "[INFO] Creating commit with message $cmessage" - git commit -m "$cmessage" + git commit -m "$cmessage" --quiet echo "[INFO] Pushing to external repository" git push --quiet end -end \ No newline at end of file +end + +cp "temp/directorylisthashed.txt" "temp/directorylisthashedprevious.txt" \ No newline at end of file