Made flatpak optional and some code cleanup #11

Merged
AustrianToast merged 6 commits from dev into main 2023-03-09 00:19:25 +01:00
4 changed files with 44 additions and 26 deletions
Showing only changes of commit 041a3d623c - Show all commits

View File

@ -13,6 +13,9 @@ Before installing, please edit the config and configure it to your liking.
```bash ```bash
make install make install
``` ```
You will likely have to
## Usage ## Usage
``` ```
@ -25,6 +28,8 @@ no flag same as -a
-a updates using flatpak update and a pacman-wrapper -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) -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) -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 ## Contributing

View File

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

52
update
View File

@ -1,14 +1,16 @@
#!/bin/bash #!/bin/bash
# updates using a pacman-wrapper and flatpak-update with flags # updates using a pacman-wrapper and flatpak-update with flags
# version 1.4 # version 1.5
IGREEN="\033[0;92m" # Intense Green source "$HOME"/.config/update.conf
IYELLOW="\033[0;93m" # Intense Red
NC="\033[0m" # Text Reset IGREEN="\033[0;92m" # Intense Green
IYELLOW="\033[0;93m" # Intense Red
NC="\033[0m" # Text Reset
TMP="/tmp/backup" TMP="/tmp/backup"
DATE="$(date +%s)"
source "${HOME}"/.config/update.conf PRE_BACKUP_AMOUNT="$(ls -Ub "$BACKUP_LOCATION"/ | grep -c ^before-backup)"
# output if wrong flag is used # output if wrong flag is used
Help() { Help() {
@ -21,46 +23,52 @@ Help() {
echo "-a updates using flatpak update and a pacman-wrapper" 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 "-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 "-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 # 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 # it then rsyncs the tar to the backup location
before_backup() { before_backup() {
#if [[ $PRE_BACKUP_AMOUNT > $BACKUP_AMOUNT ]]; then
# echo "yay"
#fi
[[ ! -d /tmp/backup ]] && mkdir /tmp/backup [[ ! -d /tmp/backup ]] && mkdir /tmp/backup
pacman -Q > "${TMP}"/pacman-pre.txt pacman -Q > "$TMP"/pacman-pre.txt
flatpak list > "${TMP}"/flatpak-pre.txt flatpak list > "$TMP"/flatpak-pre.txt
sudo touch /var/lib/pacman/db.lck 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 sudo rm /var/lib/pacman/db.lck
rsync "${TMP}"/before-backup.tar.xz.new "${backup_location}" rsync "$TMP"/before-backup_"$DATE".tar.xz.new "$BACKUP_LOCATION"
rename before-backup.tar.xz.new before-backup.tar.xz "${backup_location}"/before-backup.tar.xz.new 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 # moves the package lists into a tar, it then rsyncs the tar to the backup location
after_backup() { after_backup() {
tar -cJf "${TMP}"/after-backup.tar.xz.new "${TMP}"/pacman-after.txt "${TMP}"/flatpak-after.txt &> /dev/null tar -cJf "$TMP"/after-backup_"$DATE".tar.xz.new "$TMP"/pacman-after.txt "$TMP"/flatpak-after.txt &> /dev/null
FUH22860 commented 2023-03-09 00:16:19 +01:00 (Migrated from github.com)
Review

Creates an error message when executing it because the directory cannot exist beforehand.

Creates an error message when executing it because the directory cannot exist beforehand.
FUH22860 commented 2023-03-09 00:18:06 +01:00 (Migrated from github.com)
Review

Error was addressed. Ready to merge.

Error was addressed. Ready to merge.
rsync "${TMP}"/after-backup.tar.xz.new "${backup_location}" rsync "$TMP"/after-backup_"$DATE".tar.xz.new "$BACKUP_LOCATION"
rename after-backup.tar.xz.new after-backup.tar.xz "${backup_location}"/after-backup.tar.xz.new rename after-backup_"$DATE".tar.xz.new after-backup_"$DATE".tar.xz "$BACKUP_LOCATION"/after-backup_"$DATE".tar.xz.new
rm -r /tmp/backup rm -r /tmp/backup
} }
# updates using a pacman-wrapper # updates using a pacman-wrapper
update_with_pacman_wrapper() { update_with_pacman_wrapper() {
"${pacman_wrapper}" "$PACMAN_WRAPPER"
pacman -Q > "${TMP}"/pacman-after.txt pacman -Q > "$TMP"/pacman-after.txt
} }
# updates using flatpak-update # updates using flatpak-update
update_with_flatpak() { update_with_flatpak() {
flatpak update -u --noninteractive 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 { while [ -f /var/lib/pacman/db.lck ]; do {
echo -e "${IYELLOW}->${NC} /var/lib/pacman/db.lck exists" 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 exit 1
} }
done done
@ -78,10 +86,12 @@ while getopts 'fpagr' OPTIONS; do
update_with_pacman_wrapper; update_with_flatpak ;; update_with_pacman_wrapper; update_with_flatpak ;;
g) g)
[[ $1 = -g ]] && update_with_pacman_wrapper && update_with_flatpak; [[ $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) r)
[[ $1 = -r ]] && update_with_pacman_wrapper && update_with_flatpak; [[ $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 Help
exit 1;; exit 1;;

View File

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