Add hash checks

This commit is contained in:
ark-lamp-umbrella 2024-03-28 21:41:56 -07:00
parent 5b1eb5782b
commit 70889fd9fc
Signed by: ark-lamp-umbrella
GPG Key ID: 15E48F7B97025652
2 changed files with 41 additions and 13 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/temp/

View File

@ -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
end
cp "temp/directorylisthashed.txt" "temp/directorylisthashedprevious.txt"