update/update
René Fuhry 78d0a8b6a4
changes in the backup functions
They now create .new files, rsync them and then rename them to remove the .new
2022-12-25 05:25:34 +01:00

87 lines
3.2 KiB
Bash

#!/bin/bash
# shellcheck source=/dev/null
# updates via an aur-helper and flatpak with flags
# version 0.7
# add options to change aur-helper in the config
# maybe make a first time setup, which asks for backup_location and aur_helper, maybe even if you wanna opt-in to non-interactive flatpak-update (maybe a flag?)
IGreen="\033[0;92m" # Green
NC="\033[0m" # Text Reset
source ~/.config/update.conf
# output if wrong flag is used
Help() {
echo "updates via an aur-helper and flatpak with flags"
echo
echo "Usage: update [OPTION]"
echo
echo "options:"
echo "no flag same as -a"
echo "-f updates using flatpak update only"
echo "-y updates using an aur-helper only"
echo "-a updates using flatpak update and an aur-helper"
echo "-g shutdowns the computer afterwards (needs to be the last or only option to work properly)"
echo "-r reboots the computer afterwards (needs to be the last or only option to work properly)"
}
# creates package lists, moves them into a zip, adds some other files to the zip and backups the pacman database in the form of a tar
# it then rsyncs the zip and the tar to the backup location
before_backup() {
paclog-pkglist > ~/pacman-pre.txt
flatpak list > ~/flatpak-pre.txt
zip --quiet --move ~/before_backup.zip.new ~/pacman-pre.txt ~/flatpak-pre.txt
zip --quiet --grow ~/before_backup.zip.new /etc/fstab /etc/makepkg.conf
tar -cJf ~/pacman_database.tar.xz.new /var/lib/pacman/local &> /dev/null
rsync --remove-source-files ~/before_backup.zip.new ~/pacman_database.tar.xz.new "$backup_location"
rename before_backup.zip.new before_backup.zip "$backup_location"/before_backup.zip.new
rename pacman_database.tar.xz.new pacman_database.tar.xz "$backup_location"/pacman_database.tar.xz.new
}
# moves the package lists into a zip, it then rsyncs the zip to the backup location
after_backup() {
zip --quiet --move ~/after_backup.zip.new ~/pacman-after.txt ~/flatpak-after.txt
rsync --remove-source-files ~/after_backup.zip.new "$backup_location"
rename after_backup.zip.new after_backup.zip "$backup_location"/after_backup.zip.new
}
# updates using aur-helper
update_with_aur_helper() {
"$aur_helper"
paclog-pkglist > ~/pacman-after.txt
}
# updates using flatpak update
update_with_flatpak() {
flatpak update -u --noninteractive
flatpak list > ~/flatpak-after.txt
}
before_backup && echo -e "${IGreen} pre-backup complete ${NC}"
[[ -z $1 ]] && update_with_aur_helper && update_with_flatpak;
while getopts 'fyagr' OPTION; do
case "$OPTION" in
f)
update_with_flatpak ;;
y)
update_with_aur_helper ;;
a)
update_with_aur_helper; update_with_flatpak ;;
g)
[[ $1 = -g ]] && update_with_aur_helper && update_with_flatpak;
after_backup && echo -e "${IGreen} after-backup complete ${NC}" && sleep 3s && shutdown now ;;
r)
[[ $1 = -r ]] && update_with_aur_helper && update_with_flatpak;
after_backup && echo -e "${IGreen} after-backup complete ${NC}" && sleep 3s && reboot ;;
?)
Help
exit 1;;
esac
done
after_backup && echo -e "${IGreen} after-backup complete ${NC}"