92 lines
3.2 KiB
Bash
92 lines
3.2 KiB
Bash
#!/bin/bash
|
|
|
|
# updates using a pacman-wrapper and flatpak-update with flags
|
|
# version 1.4
|
|
|
|
IGREEN="\033[0;92m" # Intense Green
|
|
IYELLOW="\033[0;93m" # Intense Red
|
|
NC="\033[0m" # Text Reset
|
|
TMP="/tmp/backup"
|
|
|
|
source "${HOME}"/.config/update.conf
|
|
|
|
# output if wrong flag is used
|
|
Help() {
|
|
echo "Usage: update [OPTION]"
|
|
echo
|
|
echo "options:"
|
|
echo "no flag same as -a"
|
|
echo "-f updates using flatpak update only"
|
|
echo "-p updates using a pacman-wrapper only"
|
|
echo "-a updates using flatpak update and a pacman-wrapper"
|
|
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 tar, adds some other files and adds the pacman database
|
|
# it then rsyncs the tar to the backup location
|
|
before_backup() {
|
|
[[ ! -d /tmp/backup ]] && mkdir /tmp/backup
|
|
pacman -Q > "${TMP}"/pacman-pre.txt
|
|
flatpak list > "${TMP}"/flatpak-pre.txt
|
|
sudo touch /var/lib/pacman/db.lck
|
|
tar -cJf "${TMP}"/before-backup.tar.xz.new "${TMP}"/pacman-pre.txt "${TMP}"/flatpak-pre.txt /var/lib/pacman/local &> /dev/null
|
|
sudo rm /var/lib/pacman/db.lck
|
|
rsync "${TMP}"/before-backup.tar.xz.new "${backup_location}"
|
|
rename before-backup.tar.xz.new before-backup.tar.xz "${backup_location}"/before-backup.tar.xz.new
|
|
}
|
|
|
|
# moves the package lists into a tar, it then rsyncs the tar to the backup location
|
|
after_backup() {
|
|
tar -cJf "${TMP}"/after-backup.tar.xz.new "${TMP}"/pacman-after.txt "${TMP}"/flatpak-after.txt &> /dev/null
|
|
rsync "${TMP}"/after-backup.tar.xz.new "${backup_location}"
|
|
rename after-backup.tar.xz.new after-backup.tar.xz "${backup_location}"/after-backup.tar.xz.new
|
|
rm -r /tmp/backup
|
|
}
|
|
|
|
# updates using a pacman-wrapper
|
|
update_with_pacman_wrapper() {
|
|
"${pacman_wrapper}"
|
|
pacman -Q > "${TMP}"/pacman-after.txt
|
|
}
|
|
|
|
# updates using flatpak-update
|
|
update_with_flatpak() {
|
|
flatpak update -u --noninteractive
|
|
flatpak list > "${TMP}"/flatpak-after.txt
|
|
}
|
|
|
|
[[ $1 = --help ]] && Help && exit 0;
|
|
|
|
while [ -f /var/lib/pacman/db.lck ]; do {
|
|
echo -e "${IYELLOW}->${NC} /var/lib/pacman/db.lck exists"
|
|
echo -e "${IYELLOW}->${NC} there might be an instance of pacman running. exiting..."
|
|
exit 1
|
|
}
|
|
done
|
|
|
|
before_backup && echo -e "${IGREEN}pre-backup complete${NC}"
|
|
|
|
[[ -z $1 ]] && update_with_pacman_wrapper && update_with_flatpak;
|
|
while getopts 'fpagr' OPTIONS; do
|
|
case "$OPTIONS" in
|
|
f)
|
|
update_with_flatpak ;;
|
|
p)
|
|
update_with_pacman_wrapper ;;
|
|
a)
|
|
update_with_pacman_wrapper; update_with_flatpak ;;
|
|
g)
|
|
[[ $1 = -g ]] && update_with_pacman_wrapper && update_with_flatpak;
|
|
after_backup && echo -e "${IGREEN}after-backup complete${NC}" && sleep 3s && shutdown now ;;
|
|
r)
|
|
[[ $1 = -r ]] && update_with_pacman_wrapper && 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}"
|