60 lines
1.7 KiB
Fish
60 lines
1.7 KiB
Fish
#!/usr/bin/env fish
|
|
|
|
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
|
|
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" = "" ]
|
|
set gitpush "y"
|
|
end
|
|
set gitpush "$(string lower $gitpush)"
|
|
if [ "$gitpush" = "y" ]
|
|
read -P "[INPUT] Commit message: " cmessage
|
|
echo "[INFO] Adding to git"
|
|
git add . --quiet
|
|
echo "[INFO] Creating commit with message $cmessage"
|
|
git commit -m "$cmessage" --quiet
|
|
echo "[INFO] Pushing to external repository"
|
|
git push --quiet
|
|
end
|
|
end
|
|
|
|
cp "temp/directorylisthashed.txt" "temp/directorylisthashedprevious.txt" |