Feature/preview #9

Merged
AustrianToast merged 7 commits from feature/preview into dev 2023-02-13 19:46:57 +01:00
4 changed files with 44 additions and 26 deletions

View File

@ -13,6 +13,9 @@ Before installing, please edit the config and configure it to your liking.
```bash
make install
```
You will likely have to
## Usage
```
@ -25,6 +28,8 @@ no flag same as -a
-a updates using flatpak update and a pacman-wrapper
-g shutdowns the computer afterwards (needs to be the last or only option to work properly)
-r reboots the computer afterwards (needs to be the last or only option to work properly)
--help displays this message
-P, --preview shows a preview of which pkg's will be updates
```
## Contributing

View File

@ -1,12 +1,12 @@
VER = "v1.4"
VER = "v1.5"
install:
@echo "==> Installing update $(VER)..."
@echo "==> Installing update $(VER) into /usr/local/bin"
@sudo install -Dm755 update /usr/local/bin/update
@cp update.conf ${HOME}/.config/
@echo "==> Finished."
uninstall:
@echo "==> Uninstalling update $(VER)..."
@echo "==> Uninstalling update $(VER) from /usr/local/bin"
@sudo rm /usr/local/bin/update ${HOME}/.config/update.conf
@echo "==> Finished."

52
update
View File

@ -1,14 +1,16 @@
#!/bin/bash
# updates using a pacman-wrapper and flatpak-update with flags
# version 1.4
# version 1.5
IGREEN="\033[0;92m" # Intense Green
IYELLOW="\033[0;93m" # Intense Red
NC="\033[0m" # Text Reset
source "$HOME"/.config/update.conf
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
DATE="$(date +%s)"
PRE_BACKUP_AMOUNT="$(ls -Ub "$BACKUP_LOCATION"/ | grep -c ^before-backup)"
# output if wrong flag is used
Help() {
@ -21,46 +23,52 @@ Help() {
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)"
echo "--help displays this message"
echo "-P, --preview shows a preview of which pkg's will be updates"
}
# 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() {
#if [[ $PRE_BACKUP_AMOUNT > $BACKUP_AMOUNT ]]; then
# echo "yay"
#fi
[[ ! -d /tmp/backup ]] && mkdir /tmp/backup
pacman -Q > "${TMP}"/pacman-pre.txt
flatpak list > "${TMP}"/flatpak-pre.txt
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
tar -cJf "$TMP"/before-backup_"$DATE".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
rsync "$TMP"/before-backup_"$DATE".tar.xz.new "$BACKUP_LOCATION"
rename before-backup_"$DATE".tar.xz.new before-backup_"$DATE".tar.xz "$BACKUP_LOCATION"/before-backup_"$DATE".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
tar -cJf "$TMP"/after-backup_"$DATE".tar.xz.new "$TMP"/pacman-after.txt "$TMP"/flatpak-after.txt &> /dev/null
rsync "$TMP"/after-backup_"$DATE".tar.xz.new "$BACKUP_LOCATION"
rename after-backup_"$DATE".tar.xz.new after-backup_"$DATE".tar.xz "$BACKUP_LOCATION"/after-backup_"$DATE".tar.xz.new
rm -r /tmp/backup
}
# updates using a pacman-wrapper
update_with_pacman_wrapper() {
"${pacman_wrapper}"
pacman -Q > "${TMP}"/pacman-after.txt
"$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
flatpak list > "$TMP"/flatpak-after.txt
}
[[ $1 = --help ]] && Help && exit 0;
[[ $1 = --help ]] && Help && exit 0
[[ $1 = --preview || $1 = -P ]] && sudo pacman -Sy &> /dev/null && sudo pacman -Qu && 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..."
echo -e "${IYELLOW}->${NC} there might be another instance of pacman running. exiting..."
exit 1
}
done
@ -78,10 +86,12 @@ while getopts 'fpagr' OPTIONS; do
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 ;;
after_backup && echo -e "${IGREEN}after-backup complete${NC}" && sleep 3s && shutdown now
exit 0;;
r)
[[ $1 = -r ]] && update_with_pacman_wrapper && update_with_flatpak;
after_backup && echo -e "${IGREEN}after-backup complete${NC}" && sleep 3s && reboot ;;
after_backup && echo -e "${IGREEN}after-backup complete${NC}" && sleep 3s && reboot
exit 0;;
?)
Help
exit 1;;

View File

@ -1,5 +1,8 @@
# Backup to this folder
backup_location=~/
BACKUP_LOCATION=~/
# use this pacman-wrapper
pacman_wrapper=paru
PACMAN_WRAPPER=paru
# how many different backups to keep
BACKUP_AMOUNT=2