removed mkbackup script, refactored all script files to use pkgs.writeShellApplication rather than pkgs.writeShellScriptBin

This commit is contained in:
pagedmov
2024-11-06 18:17:29 -05:00
parent ad22e5a0b1
commit a53bae9870
18 changed files with 497 additions and 416 deletions

View File

@@ -1,41 +1,52 @@
{
self,
pkgs,
pkgs
}:
pkgs.writeShellScriptBin "garbage-collect" ''
#!/run/current-system/sw/bin/bash
pkgs.writeShellApplication {
name = "garbage-collect";
runtimeInputs = with pkgs; [
bash
coreutils
gnugrep
bc
alsa-utils
findutils
nix
];
text = ''
#!/run/current-system/sw/bin/bash
echo "This will delete all unused paths in the nix store and delete any files in the gtrash folder."
echo -e "\033[1;4;38;2;243;139;168mThis process is irreversible.\033[0m Are you sure?"
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "Sweeping system..."; scheck && runbg aplay "$HOME/assets/sound/sys/collectgarbage.wav"; break;;
No ) echo "Canceling garbage collection."; return;;
esac
done
echo "This will delete all unused paths in the nix store and delete any files in the gtrash folder."
echo -e "\033[1;4;38;2;243;139;168mThis process is irreversible.\033[0m Are you sure?"
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "Sweeping system..."; scheck && runbg aplay "$HOME/assets/sound/sys/collectgarbage.wav"; break;;
No ) echo "Canceling garbage collection."; return;;
esac
done
output=$(nix-collect-garbage | tee /dev/tty)
nix_freed=$(echo "$output" | grep -oP '\d+(\.\d+)? MiB freed' | cut -d' ' -f1)
output=$(nix-collect-garbage | tee /dev/tty)
nix_freed=$(echo "$output" | grep -oP '\d+(\.\d+)? MiB freed' | cut -d' ' -f1)
# Get the size of the trash folder before deleting
if [ "$(ls -A ~/.local/share/Trash/files/ 2>/dev/null)" ]; then
rm_freed=$(du -sm ~/.local/share/Trash/files | awk '{print $1}')
/run/current-system/sw/bin/rm -rfv ~/.local/share/Trash/files/* # Verbose output
mkdir -p ~/.local/share/Trash/files
else
rm_freed="0"
fi
# Get the size of the trash folder before deleting
if [ "$(ls -A ~/.local/share/Trash/files/ 2>/dev/null)" ]; then
rm_freed=$(du -sm ~/.local/share/Trash/files | awk '{print $1}')
/run/current-system/sw/bin/rm -rfv ~/.local/share/Trash/files/* # Verbose output
mkdir -p ~/.local/share/Trash/files
else
rm_freed="0"
fi
total_freed=$(echo "$nix_freed + $rm_freed" | bc)
total_freed=$(echo "$nix_freed + $rm_freed" | bc)
units=("MB" "GB" "TB" "PB")
divisions=0
while [ "$(echo "$total_freed >= 1024.0" | bc -l)" -eq 1 ]; do
total_freed=$(echo "scale=2; $total_freed / 1024" | bc -l)
divisions=$((divisions + 1))
done
units=("MB" "GB" "TB" "PB")
divisions=0
while [ "$(echo "$total_freed >= 1024.0" | bc -l)" -eq 1 ]; do
total_freed=$(echo "scale=2; $total_freed / 1024" | bc -l)
divisions=$((divisions + 1))
done
echo -e "System cleaning complete, freed \033[1;4;38;2;166;227;161m$total_freed ''${units[$divisions]}\033[0m in total"
echo -e "System cleaning complete, freed \033[1;4;38;2;166;227;161m$total_freed ''${units[$divisions]}\033[0m in total"
scheck && runbg aplay "$HOME/assets/sound/sys/rm.wav"
''
scheck && runbg aplay "$HOME/assets/sound/sys/rm.wav"
'';
}

View File

@@ -1,9 +1,11 @@
{
self,
pkgs,
pkgs
}:
pkgs.writeShellScriptBin "nsp" ''
#!/run/current-system/sw/bin/bash
pkgs.writeShellApplication {
name = "nsp";
text = ''
#!/run/current-system/sw/bin/bash
nix-shell -p "$@" --run zsh
''
nix-shell -p "$@" --run zsh
'';
}

View File

@@ -3,16 +3,16 @@
self,
pkgs,
}:
pkgs.writeShellScriptBin "rebuild" ''
#!/run/current-system/sw/bin/bash
scheck && runbg aplay ${self}/assets/sound/nixswitch-start.wav
set -e
nh os switch -H ${host} $HOME/.sysflake
sudo nixos-rebuild switch --flake "$HOME/.sysflake#${host}"
if [ $? -eq 0 ]; then
scheck && runbg aplay ${self}/assets/sound/update.wav
else
scheck && runbg aplay ${self}/assets/sound/error.wav
fi
''
pkgs.writeShellApplication {
name = "rebuild";
text = ''
scheck && runbg aplay ${self}/assets/sound/nixswitch-start.wav
set -e
nh os switch -H ${host} "$HOME"/.sysflake
if sudo nixos-rebuild switch --flake "$HOME/.sysflake#${host}"; then
scheck && runbg aplay ${self}/assets/sound/update.wav
else
scheck && runbg aplay ${self}/assets/sound/error.wav
fi
'';
}