From 3143cbae765c2c29110db950370636ec154a79ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Sat, 21 Jan 2023 03:01:48 +0100 Subject: [PATCH 01/40] Moved something to somewhere... goodnight... * added help long option * Add files via upload --- makefile | 4 ++-- update | 46 +++++++++++++++++++++++----------------------- update.conf | 2 +- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/makefile b/makefile index 34d238c..22b4740 100644 --- a/makefile +++ b/makefile @@ -1,10 +1,10 @@ install: - @echo "==> Installing update v0.4..." + @echo "==> Installing update v1.0..." @sudo install -Dm755 update /usr/local/bin/update @cp update.conf ${HOME}/.config/ @echo "==> Finished." uninstall: - @echo "==> Uninstalling update v0.4..." + @echo "==> Uninstalling update v1.0..." @sudo rm /usr/local/bin/update ${HOME}/.config/update.conf @echo "==> Finished." diff --git a/update b/update index c9dcd9c..222604a 100644 --- a/update +++ b/update @@ -1,16 +1,13 @@ #!/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?) - +# version 1.0 IGreen="\033[0;92m" # Green NC="\033[0m" # Text Reset +dir="$pwd" + source ~/.config/update.conf # output if wrong flag is used @@ -31,36 +28,39 @@ Help() { # 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 + 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 + 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 + paclog-pkglist > pacman-after.txt } # updates using flatpak update update_with_flatpak() { flatpak update -u --noninteractive - flatpak list > ~/flatpak-after.txt + flatpak list > flatpak-after.txt } -before_backup && echo -e "${IGreen} pre-backup complete ${NC}" +[[ $1 = --help ]] && Help && exit 0; + +[[ ! -d /tmp/backup ]] && mkdir /tmp/backup; +cd /tmp/backup && before_backup && echo -e "${IGreen} pre-backup complete ${NC}" [[ -z $1 ]] && update_with_aur_helper && update_with_flatpak; while getopts 'fyagr' OPTION; do @@ -73,14 +73,14 @@ while getopts 'fyagr' OPTION; do 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 ;; + after_backup && cd "$dir"; 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 ;; + after_backup && cd "$dir"; echo -e "${IGreen} after-backup complete ${NC}" && sleep 3s && reboot ;; ?) Help exit 1;; esac done -after_backup && echo -e "${IGreen} after-backup complete ${NC}" +after_backup && cd "$dir"; rm -r /tmp/backup; echo -e "${IGreen} after-backup complete ${NC}" diff --git a/update.conf b/update.conf index b9d5b66..53e4090 100644 --- a/update.conf +++ b/update.conf @@ -2,4 +2,4 @@ backup_location=~/ # use this aur-helper -aur_helper=yay +aur_helper=paru -- 2.49.0 From 3465d2c3e4d729542d875df1a726885738f661ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Sat, 21 Jan 2023 03:35:48 +0100 Subject: [PATCH 02/40] perfect... --- README.md | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0b78264..8275367 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,41 @@ -# update +# Update -This is an update script written in bash which updates all your pacman and aur packages as well as your flatpaks. -It also backups a list of all your pkg's and flatpaks, your fstab and the makepkg.conf to the location that you specify in the config. +Update script written in bash for Arch. Keeps all your pacman and aur packages as well as your flatpaks up to date with one simple script. It also backups a list of all your pacman/aur pkg's and flatpaks. As well as your fstab and the makepkg.conf to the location that you specify in the config. +## Dependencies + +Needed dependencies + +```bash + pacman -S zip pacutils +``` +## Installation + +```bash +git clone https://github.com/AustrianToast/update.git && cd update +``` + +Before installing, please edit the config and configure it to your liking. + +```bash +make install +``` +## Usage + +``` +Usage: update [OPTION] + +options: +no flag same as -a +-f updates using flatpak update only +-y updates using an aur-helper only +-a updates using flatpak update and an aur-helper +-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) +``` +## Roadmap + +- Publish to the aur +- First time setup +## Contributing + +Contributions are always welcome! \ No newline at end of file -- 2.49.0 From ceb94c21fc24a4e90fc869db43c75242b7ae7f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Sat, 21 Jan 2023 23:10:18 +0100 Subject: [PATCH 03/40] Improvements --- makefile | 6 ++++-- update | 47 +++++++++++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/makefile b/makefile index 22b4740..aef8943 100644 --- a/makefile +++ b/makefile @@ -1,10 +1,12 @@ +VER = "v1.1" + install: - @echo "==> Installing update v1.0..." + @echo "==> Installing update $(VER)..." @sudo install -Dm755 update /usr/local/bin/update @cp update.conf ${HOME}/.config/ @echo "==> Finished." uninstall: - @echo "==> Uninstalling update v1.0..." + @echo "==> Uninstalling update $(VER)..." @sudo rm /usr/local/bin/update ${HOME}/.config/update.conf @echo "==> Finished." diff --git a/update b/update index 222604a..38a2121 100644 --- a/update +++ b/update @@ -1,28 +1,26 @@ #!/bin/bash # updates via an aur-helper and flatpak with flags -# version 1.0 +# version 1.1 IGreen="\033[0;92m" # Green NC="\033[0m" # Text Reset -dir="$pwd" +DIR="$(pwd)" -source ~/.config/update.conf +source "${HOME}"/.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)" + 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 @@ -33,21 +31,21 @@ before_backup() { 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 + 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 + 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" + "${aur_helper}" paclog-pkglist > pacman-after.txt } @@ -59,12 +57,17 @@ update_with_flatpak() { [[ $1 = --help ]] && Help && exit 0; +while [ -f /var/lib/pacman/db.lck ]; do { + sleep 1s +} +done + [[ ! -d /tmp/backup ]] && mkdir /tmp/backup; cd /tmp/backup && 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 +while getopts 'fyagr' OPTIONS; do + case "$OPTIONS" in f) update_with_flatpak ;; y) @@ -73,14 +76,14 @@ while getopts 'fyagr' OPTION; do update_with_aur_helper; update_with_flatpak ;; g) [[ $1 = -g ]] && update_with_aur_helper && update_with_flatpak; - after_backup && cd "$dir"; echo -e "${IGreen} after-backup complete ${NC}" && sleep 3s && shutdown now ;; + after_backup && cd "${DIR}" || return; echo -e "${IGreen} after-backup complete ${NC}" && sleep 3s && shutdown now ;; r) [[ $1 = -r ]] && update_with_aur_helper && update_with_flatpak; - after_backup && cd "$dir"; echo -e "${IGreen} after-backup complete ${NC}" && sleep 3s && reboot ;; + after_backup && cd "${DIR}" || return; echo -e "${IGreen} after-backup complete ${NC}" && sleep 3s && reboot ;; ?) Help exit 1;; esac done -after_backup && cd "$dir"; rm -r /tmp/backup; echo -e "${IGreen} after-backup complete ${NC}" +after_backup && cd "${DIR}" || return; rm -r /tmp/backup; echo -e "${IGreen} after-backup complete ${NC}" -- 2.49.0 From 2aca92f351b6259d393959c9f5e9f75299e679f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Sat, 28 Jan 2023 01:54:33 +0100 Subject: [PATCH 04/40] removed pacutils dependency the script now uses pacman's build in flag to output all pkg's (even looks the same) --- README.md | 2 +- makefile | 2 +- update | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8275367..33ee849 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Update script written in bash for Arch. Keeps all your pacman and aur packages a Needed dependencies ```bash - pacman -S zip pacutils + pacman -S zip ``` ## Installation diff --git a/makefile b/makefile index aef8943..c2ffd5c 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -VER = "v1.1" +VER = "v1.2" install: @echo "==> Installing update $(VER)..." diff --git a/update b/update index 38a2121..3519d0a 100644 --- a/update +++ b/update @@ -1,7 +1,7 @@ #!/bin/bash # updates via an aur-helper and flatpak with flags -# version 1.1 +# version 1.2 IGreen="\033[0;92m" # Green NC="\033[0m" # Text Reset @@ -26,7 +26,7 @@ Help() { # 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 + pacman -Q > 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 @@ -46,7 +46,7 @@ after_backup() { # updates using aur-helper update_with_aur_helper() { "${aur_helper}" - paclog-pkglist > pacman-after.txt + pacman -Q > pacman-after.txt } # updates using flatpak update -- 2.49.0 From 2a00f56fc636c899f32c0418a5f93406d1635b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Tue, 31 Jan 2023 00:29:35 +0100 Subject: [PATCH 05/40] betterer code --- README.md | 18 +++++-------- makefile | 2 +- update | 73 +++++++++++++++++++++++++---------------------------- update.conf | 4 +-- 4 files changed, 44 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 33ee849..4af4d5d 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,7 @@ # Update Update script written in bash for Arch. Keeps all your pacman and aur packages as well as your flatpaks up to date with one simple script. It also backups a list of all your pacman/aur pkg's and flatpaks. As well as your fstab and the makepkg.conf to the location that you specify in the config. -## Dependencies -Needed dependencies - -```bash - pacman -S zip -``` ## Installation ```bash @@ -25,12 +19,12 @@ make install Usage: update [OPTION] options: -no flag same as -a --f updates using flatpak update only --y updates using an aur-helper only --a updates using flatpak update and an aur-helper --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) +no flag same as -a +-f updates using flatpak update only +-p updates using a pacman-wrapper only +-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) ``` ## Roadmap diff --git a/makefile b/makefile index c2ffd5c..d456093 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -VER = "v1.2" +VER = "v1.3" install: @echo "==> Installing update $(VER)..." diff --git a/update b/update index 3519d0a..9f9043d 100644 --- a/update +++ b/update @@ -1,12 +1,11 @@ #!/bin/bash -# updates via an aur-helper and flatpak with flags -# version 1.2 +# updates using a pacman-wrapper and flatpak-update with flags +# version 1.3 IGreen="\033[0;92m" # Green NC="\033[0m" # Text Reset - -DIR="$(pwd)" +TMP="/tmp/backup" source "${HOME}"/.config/update.conf @@ -17,42 +16,41 @@ Help() { 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 "-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 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 +# 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() { - pacman -Q > 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 + [[ ! -d /tmp/backup ]] && mkdir /tmp/backup + pacman -Q > "${TMP}"/pacman-pre.txt + flatpak list > "${TMP}"/flatpak-pre.txt + tar -cJf "${TMP}"/before-backup.tar.xz.new "${TMP}"/pacman-pre.txt "${TMP}"/flatpak-pre.txt /var/lib/pacman/local &> /dev/null + 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 zip, it then rsyncs the zip to the backup location +# moves the package lists into a tar, it then rsyncs the tar 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 + 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 aur-helper -update_with_aur_helper() { - "${aur_helper}" - pacman -Q > pacman-after.txt +# updates using a pacman-wrapper +update_with_pacman_wrapper() { + "${pacman_wrapper}" + pacman -Q > "${TMP}"/pacman-after.txt } -# updates using flatpak update +# updates using flatpak-update update_with_flatpak() { flatpak update -u --noninteractive - flatpak list > flatpak-after.txt + flatpak list > "${TMP}"/flatpak-after.txt } [[ $1 = --help ]] && Help && exit 0; @@ -62,28 +60,27 @@ while [ -f /var/lib/pacman/db.lck ]; do { } done -[[ ! -d /tmp/backup ]] && mkdir /tmp/backup; -cd /tmp/backup && before_backup && echo -e "${IGreen} pre-backup complete ${NC}" +before_backup && echo -e "${IGreen} pre-backup complete ${NC}" -[[ -z $1 ]] && update_with_aur_helper && update_with_flatpak; -while getopts 'fyagr' OPTIONS; do +[[ -z $1 ]] && update_with_pacman_wrapper && update_with_flatpak; +while getopts 'fpagr' OPTIONS; do case "$OPTIONS" in f) update_with_flatpak ;; - y) - update_with_aur_helper ;; + p) + update_with_pacman_wrapper ;; a) - update_with_aur_helper; update_with_flatpak ;; + update_with_pacman_wrapper; update_with_flatpak ;; g) - [[ $1 = -g ]] && update_with_aur_helper && update_with_flatpak; - after_backup && cd "${DIR}" || return; echo -e "${IGreen} after-backup complete ${NC}" && sleep 3s && shutdown now ;; + [[ $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_aur_helper && update_with_flatpak; - after_backup && cd "${DIR}" || return; echo -e "${IGreen} after-backup complete ${NC}" && sleep 3s && reboot ;; + [[ $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 && cd "${DIR}" || return; rm -r /tmp/backup; echo -e "${IGreen} after-backup complete ${NC}" +after_backup && echo -e "${IGreen} after-backup complete ${NC}" diff --git a/update.conf b/update.conf index 53e4090..22a9b63 100644 --- a/update.conf +++ b/update.conf @@ -1,5 +1,5 @@ # Backup to this folder backup_location=~/ -# use this aur-helper -aur_helper=paru +# use this pacman-wrapper +pacman_wrapper=paru -- 2.49.0 From b92c888f42da75e44e6a5adf6aa9888b52074162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Wed, 1 Feb 2023 02:07:55 +0100 Subject: [PATCH 06/40] Continued development... --- update | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/update b/update index 9f9043d..499d5c3 100644 --- a/update +++ b/update @@ -1,9 +1,10 @@ #!/bin/bash # updates using a pacman-wrapper and flatpak-update with flags -# version 1.3 +# version 1.4 -IGreen="\033[0;92m" # Green +IGREEN="\033[0;92m" # Intense Green +IYELLOW="\033[0;93m" # Intense Red NC="\033[0m" # Text Reset TMP="/tmp/backup" @@ -26,9 +27,11 @@ Help() { # it then rsyncs the tar to the backup location before_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 + 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 } @@ -56,11 +59,13 @@ update_with_flatpak() { [[ $1 = --help ]] && Help && exit 0; while [ -f /var/lib/pacman/db.lck ]; do { - sleep 1s + 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}" +before_backup && echo -e "${IGREEN}pre-backup complete${NC}" [[ -z $1 ]] && update_with_pacman_wrapper && update_with_flatpak; while getopts 'fpagr' OPTIONS; do @@ -73,14 +78,14 @@ 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 ;; 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 ;; ?) Help exit 1;; esac done -after_backup && echo -e "${IGreen} after-backup complete ${NC}" +after_backup && echo -e "${IGREEN}after-backup complete${NC}" -- 2.49.0 From 97a72332690330f3d1070903f4f3f57c1c5d4b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Wed, 1 Feb 2023 02:08:37 +0100 Subject: [PATCH 07/40] version bump --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index d456093..ef4679b 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -VER = "v1.3" +VER = "v1.4" install: @echo "==> Installing update $(VER)..." -- 2.49.0 From 693282236b9d60442800a4614259d997a8b97c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Wed, 1 Feb 2023 02:10:05 +0100 Subject: [PATCH 08/40] nevermind -- 2.49.0 From 0b9443e4daedb82ce2662725e4aabe00ff7c8e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Wed, 1 Feb 2023 02:12:07 +0100 Subject: [PATCH 09/40] perfect... now dealing with the db.lck file --- makefile | 2 +- update | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/makefile b/makefile index d456093..ef4679b 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -VER = "v1.3" +VER = "v1.4" install: @echo "==> Installing update $(VER)..." diff --git a/update b/update index 9f9043d..499d5c3 100644 --- a/update +++ b/update @@ -1,9 +1,10 @@ #!/bin/bash # updates using a pacman-wrapper and flatpak-update with flags -# version 1.3 +# version 1.4 -IGreen="\033[0;92m" # Green +IGREEN="\033[0;92m" # Intense Green +IYELLOW="\033[0;93m" # Intense Red NC="\033[0m" # Text Reset TMP="/tmp/backup" @@ -26,9 +27,11 @@ Help() { # it then rsyncs the tar to the backup location before_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 + 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 } @@ -56,11 +59,13 @@ update_with_flatpak() { [[ $1 = --help ]] && Help && exit 0; while [ -f /var/lib/pacman/db.lck ]; do { - sleep 1s + 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}" +before_backup && echo -e "${IGREEN}pre-backup complete${NC}" [[ -z $1 ]] && update_with_pacman_wrapper && update_with_flatpak; while getopts 'fpagr' OPTIONS; do @@ -73,14 +78,14 @@ 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 ;; 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 ;; ?) Help exit 1;; esac done -after_backup && echo -e "${IGreen} after-backup complete ${NC}" +after_backup && echo -e "${IGREEN}after-backup complete${NC}" -- 2.49.0 From 175757c688de1ec2ab9a158cf9bee2074465eaec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Wed, 1 Feb 2023 02:12:58 +0100 Subject: [PATCH 10/40] better --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 4af4d5d..471b20e 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,7 @@ no flag same as -a -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) ``` -## Roadmap -- Publish to the aur -- First time setup ## Contributing Contributions are always welcome! \ No newline at end of file -- 2.49.0 From c32f402d3b53f6f416eb8b9d1df3a55c5b4e3c3c Mon Sep 17 00:00:00 2001 From: FUH22860 <101731147+FUH22860@users.noreply.github.com> Date: Fri, 3 Feb 2023 23:34:48 +0100 Subject: [PATCH 11/40] Add PKGBUILD --- PKGBUILD | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 PKGBUILD diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..1b4dabd --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,21 @@ +# Maintainer: AustrianToast +pkgname=update-git +pkgver=1.4 +pkgrel=1 +pkgdesc="Update script for Arch linux written in bash" +arch=('any') +url="https://github.com/AustrianToast/update" +license=('GPL3') +provides=(update) +depends=('bash') +makedepends=('git') +optdepends=('yay' 'paru' 'pacaur' 'pikaur' 'aura' 'flatpak') +home=${HOME} +backup=(${home#/}/.config/update.conf) +source=("$pkgname::git+https://github.com/AustrianToast/update.git") +md5sums=('SKIP') + +package() { + cd "$pkgname" + make install +} -- 2.49.0 From 041a3d623cdb1fa7c43029906dbe54365d08bbab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Thu, 9 Feb 2023 01:25:09 +0100 Subject: [PATCH 12/40] This is a basic implementation that works. --- README.md | 5 +++++ makefile | 6 +++--- update | 52 +++++++++++++++++++++++++++++++--------------------- update.conf | 7 +++++-- 4 files changed, 44 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 471b20e..0c8eb62 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/makefile b/makefile index ef4679b..a5f9cf1 100644 --- a/makefile +++ b/makefile @@ -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." diff --git a/update b/update index 499d5c3..c5601f8 100644 --- a/update +++ b/update @@ -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;; diff --git a/update.conf b/update.conf index 22a9b63..d42b061 100644 --- a/update.conf +++ b/update.conf @@ -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 -- 2.49.0 From 1dcd0684b7cf92733fa616a4b5ae46e4430d43c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Mon, 20 Feb 2023 22:47:43 +0100 Subject: [PATCH 13/40] I know what I am doing. Trust me. --- makefile | 2 +- update | 26 +++++++++++++------------- update.conf | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/makefile b/makefile index a5f9cf1..6055492 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -VER = "v1.5" +VER = "v1.6" install: @echo "==> Installing update $(VER) into /usr/local/bin" diff --git a/update b/update index c5601f8..8682c3e 100644 --- a/update +++ b/update @@ -1,7 +1,7 @@ #!/bin/bash # updates using a pacman-wrapper and flatpak-update with flags -# version 1.5 +# version 1.6 source "$HOME"/.config/update.conf @@ -9,10 +9,10 @@ IGREEN="\033[0;92m" # Intense Green IYELLOW="\033[0;93m" # Intense Red NC="\033[0m" # Text Reset TMP="/tmp/backup" -DATE="$(date +%s)" +DATE="$(date +"%Y-%m-%d %H:%M:%S")" PRE_BACKUP_AMOUNT="$(ls -Ub "$BACKUP_LOCATION"/ | grep -c ^before-backup)" +POST_BACKUP_AMOUNT="$(ls -Ub "$BACKUP_LOCATION"/ | grep -c ^after-backup)" -# output if wrong flag is used Help() { echo "Usage: update [OPTION]" echo @@ -27,37 +27,37 @@ Help() { 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 + if [[ $PRE_BACKUP_AMOUNT > $BACKUP_AMOUNT ]]; then + OLDEST_FILE="$(ls -t "$BACKUP_LOCATION" | grep before-backup | tail -1)" + rm "$BACKUP_LOCATION"/"$OLDEST_FILE" + fi [[ ! -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_"$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_"$DATE".tar.xz.new "$BACKUP_LOCATION" + cp "$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() { + if [[ $POST_BACKUP_AMOUNT > $BACKUP_AMOUNT ]]; then + OLDEST_FILE="$(ls -t "$BACKUP_LOCATION" | grep after-backup | tail -1)" + rm "$BACKUP_LOCATION"/"$OLDEST_FILE" + fi 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" + cp "$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 } -# updates using flatpak-update update_with_flatpak() { flatpak update -u --noninteractive flatpak list > "$TMP"/flatpak-after.txt diff --git a/update.conf b/update.conf index d42b061..8151e97 100644 --- a/update.conf +++ b/update.conf @@ -2,7 +2,7 @@ BACKUP_LOCATION=~/ # use this pacman-wrapper -PACMAN_WRAPPER=paru +PACMAN_WRAPPER=yay # how many different backups to keep BACKUP_AMOUNT=2 -- 2.49.0 From 19299264ab7be78bf9cd0e9021c702cd00ecc732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Thu, 9 Mar 2023 00:08:16 +0100 Subject: [PATCH 14/40] Made flatpak optional and code cleanup --- README.md | 2 +- makefile | 2 +- update | 29 +++++++++++++++-------------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0c8eb62..b254349 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ You will likely have to Usage: update [OPTION] options: -no flag same as -a +no flag same as -p -f updates using flatpak update only -p updates using a pacman-wrapper only -a updates using flatpak update and a pacman-wrapper diff --git a/makefile b/makefile index 6055492..cef642b 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -VER = "v1.6" +VER = "v1.7" install: @echo "==> Installing update $(VER) into /usr/local/bin" diff --git a/update b/update index 8682c3e..942f6a2 100644 --- a/update +++ b/update @@ -1,14 +1,14 @@ #!/bin/bash # updates using a pacman-wrapper and flatpak-update with flags -# version 1.6 +# version 1.7 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" +TMP="/tmp/update" DATE="$(date +"%Y-%m-%d %H:%M:%S")" PRE_BACKUP_AMOUNT="$(ls -Ub "$BACKUP_LOCATION"/ | grep -c ^before-backup)" POST_BACKUP_AMOUNT="$(ls -Ub "$BACKUP_LOCATION"/ | grep -c ^after-backup)" @@ -17,7 +17,7 @@ Help() { echo "Usage: update [OPTION]" echo echo "options:" - echo "no flag same as -a" + echo "no flag same as -p" 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" @@ -32,11 +32,12 @@ before_backup() { OLDEST_FILE="$(ls -t "$BACKUP_LOCATION" | grep before-backup | tail -1)" rm "$BACKUP_LOCATION"/"$OLDEST_FILE" fi - [[ ! -d /tmp/backup ]] && mkdir /tmp/backup - pacman -Q > "$TMP"/pacman-pre.txt - flatpak list > "$TMP"/flatpak-pre.txt + rm -r "$TMP" + mkdir "$TMP" && mkdir "$TMP"/before-backup_"$DATE" && mkdir "$TMP"/after-backup_"$DATE" + pacman -Q > "$TMP"/before-backup_"$DATE"/pacman-pre.txt + [[ -f /usr/bin/flatpak ]] && flatpak list > "$TMP"/before-backup_"$DATE"/flatpak-pre.txt sudo touch /var/lib/pacman/db.lck - tar -cJf "$TMP"/before-backup_"$DATE".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"/before-backup_"$DATE" /var/lib/pacman/local &> /dev/null sudo rm /var/lib/pacman/db.lck cp "$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 @@ -47,20 +48,20 @@ after_backup() { OLDEST_FILE="$(ls -t "$BACKUP_LOCATION" | grep after-backup | tail -1)" rm "$BACKUP_LOCATION"/"$OLDEST_FILE" fi - tar -cJf "$TMP"/after-backup_"$DATE".tar.xz.new "$TMP"/pacman-after.txt "$TMP"/flatpak-after.txt &> /dev/null + tar -cJf "$TMP"/after-backup_"$DATE".tar.xz.new "$TMP"/after-backup_"$DATE" &> /dev/null cp "$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 + rm -r "$TMP" } update_with_pacman_wrapper() { "$PACMAN_WRAPPER" - pacman -Q > "$TMP"/pacman-after.txt + pacman -Q > "$TMP"/after-backup_"$DATE"/pacman-after.txt } update_with_flatpak() { flatpak update -u --noninteractive - flatpak list > "$TMP"/flatpak-after.txt + flatpak list > "$TMP"/after-backup_"$DATE"/flatpak-after.txt } [[ $1 = --help ]] && Help && exit 0 @@ -75,7 +76,7 @@ done before_backup && echo -e "${IGREEN}pre-backup complete${NC}" -[[ -z $1 ]] && update_with_pacman_wrapper && update_with_flatpak; +[[ -z $1 ]] && update_with_pacman_wrapper; while getopts 'fpagr' OPTIONS; do case "$OPTIONS" in f) @@ -85,11 +86,11 @@ while getopts 'fpagr' OPTIONS; do a) update_with_pacman_wrapper; update_with_flatpak ;; 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 exit 0;; 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 exit 0;; ?) -- 2.49.0 From e3d725677188b7dd1a994b3aa62d9d31cdea0063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Thu, 9 Mar 2023 00:16:10 +0100 Subject: [PATCH 15/40] fixed issue with useless error msg --- update | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update b/update index 942f6a2..f4ed718 100644 --- a/update +++ b/update @@ -32,7 +32,7 @@ before_backup() { OLDEST_FILE="$(ls -t "$BACKUP_LOCATION" | grep before-backup | tail -1)" rm "$BACKUP_LOCATION"/"$OLDEST_FILE" fi - rm -r "$TMP" + rm -r "$TMP" &> /dev/null mkdir "$TMP" && mkdir "$TMP"/before-backup_"$DATE" && mkdir "$TMP"/after-backup_"$DATE" pacman -Q > "$TMP"/before-backup_"$DATE"/pacman-pre.txt [[ -f /usr/bin/flatpak ]] && flatpak list > "$TMP"/before-backup_"$DATE"/flatpak-pre.txt -- 2.49.0 From c7134e791972c5314b252b5be3289002f322ec92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Thu, 9 Mar 2023 00:19:24 +0100 Subject: [PATCH 16/40] Made flatpak optional and some code cleanup (#11) * Add PKGBUILD * This is a basic implementation that works. * I know what I am doing. Trust me. * Made flatpak optional and code cleanup * fixed issue with useless error msg --------- Co-authored-by: FUH22860 <101731147+FUH22860@users.noreply.github.com> --- PKGBUILD | 21 +++++++++++++++ README.md | 7 ++++- makefile | 6 ++--- update | 77 ++++++++++++++++++++++++++++++----------------------- update.conf | 7 +++-- 5 files changed, 79 insertions(+), 39 deletions(-) create mode 100644 PKGBUILD diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..1b4dabd --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,21 @@ +# Maintainer: AustrianToast +pkgname=update-git +pkgver=1.4 +pkgrel=1 +pkgdesc="Update script for Arch linux written in bash" +arch=('any') +url="https://github.com/AustrianToast/update" +license=('GPL3') +provides=(update) +depends=('bash') +makedepends=('git') +optdepends=('yay' 'paru' 'pacaur' 'pikaur' 'aura' 'flatpak') +home=${HOME} +backup=(${home#/}/.config/update.conf) +source=("$pkgname::git+https://github.com/AustrianToast/update.git") +md5sums=('SKIP') + +package() { + cd "$pkgname" + make install +} diff --git a/README.md b/README.md index 471b20e..b254349 100644 --- a/README.md +++ b/README.md @@ -13,18 +13,23 @@ Before installing, please edit the config and configure it to your liking. ```bash make install ``` + +You will likely have to + ## Usage ``` Usage: update [OPTION] options: -no flag same as -a +no flag same as -p -f updates using flatpak update only -p updates using a pacman-wrapper only -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 diff --git a/makefile b/makefile index ef4679b..cef642b 100644 --- a/makefile +++ b/makefile @@ -1,12 +1,12 @@ -VER = "v1.4" +VER = "v1.7" 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." diff --git a/update b/update index 499d5c3..f4ed718 100644 --- a/update +++ b/update @@ -1,73 +1,82 @@ #!/bin/bash # updates using a pacman-wrapper and flatpak-update with flags -# version 1.4 +# version 1.7 -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 -source "${HOME}"/.config/update.conf +IGREEN="\033[0;92m" # Intense Green +IYELLOW="\033[0;93m" # Intense Red +NC="\033[0m" # Text Reset +TMP="/tmp/update" +DATE="$(date +"%Y-%m-%d %H:%M:%S")" +PRE_BACKUP_AMOUNT="$(ls -Ub "$BACKUP_LOCATION"/ | grep -c ^before-backup)" +POST_BACKUP_AMOUNT="$(ls -Ub "$BACKUP_LOCATION"/ | grep -c ^after-backup)" -# output if wrong flag is used Help() { echo "Usage: update [OPTION]" echo echo "options:" - echo "no flag same as -a" + echo "no flag same as -p" 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)" + 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() { - [[ ! -d /tmp/backup ]] && mkdir /tmp/backup - pacman -Q > "${TMP}"/pacman-pre.txt - flatpak list > "${TMP}"/flatpak-pre.txt + if [[ $PRE_BACKUP_AMOUNT > $BACKUP_AMOUNT ]]; then + OLDEST_FILE="$(ls -t "$BACKUP_LOCATION" | grep before-backup | tail -1)" + rm "$BACKUP_LOCATION"/"$OLDEST_FILE" + fi + rm -r "$TMP" &> /dev/null + mkdir "$TMP" && mkdir "$TMP"/before-backup_"$DATE" && mkdir "$TMP"/after-backup_"$DATE" + pacman -Q > "$TMP"/before-backup_"$DATE"/pacman-pre.txt + [[ -f /usr/bin/flatpak ]] && flatpak list > "$TMP"/before-backup_"$DATE"/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"/before-backup_"$DATE" /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 + cp "$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 - rm -r /tmp/backup + if [[ $POST_BACKUP_AMOUNT > $BACKUP_AMOUNT ]]; then + OLDEST_FILE="$(ls -t "$BACKUP_LOCATION" | grep after-backup | tail -1)" + rm "$BACKUP_LOCATION"/"$OLDEST_FILE" + fi + tar -cJf "$TMP"/after-backup_"$DATE".tar.xz.new "$TMP"/after-backup_"$DATE" &> /dev/null + cp "$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" } -# updates using a pacman-wrapper update_with_pacman_wrapper() { - "${pacman_wrapper}" - pacman -Q > "${TMP}"/pacman-after.txt + "$PACMAN_WRAPPER" + pacman -Q > "$TMP"/after-backup_"$DATE"/pacman-after.txt } -# updates using flatpak-update update_with_flatpak() { flatpak update -u --noninteractive - flatpak list > "${TMP}"/flatpak-after.txt + flatpak list > "$TMP"/after-backup_"$DATE"/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 before_backup && echo -e "${IGREEN}pre-backup complete${NC}" -[[ -z $1 ]] && update_with_pacman_wrapper && update_with_flatpak; +[[ -z $1 ]] && update_with_pacman_wrapper; while getopts 'fpagr' OPTIONS; do case "$OPTIONS" in f) @@ -77,11 +86,13 @@ while getopts 'fpagr' OPTIONS; do 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 ;; + [[ $1 = -g ]] && update_with_pacman_wrapper; update_with_flatpak + 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 ;; + [[ $1 = -r ]] && update_with_pacman_wrapper; update_with_flatpak + after_backup && echo -e "${IGREEN}after-backup complete${NC}" && sleep 3s && reboot + exit 0;; ?) Help exit 1;; diff --git a/update.conf b/update.conf index 22a9b63..8151e97 100644 --- a/update.conf +++ b/update.conf @@ -1,5 +1,8 @@ # Backup to this folder -backup_location=~/ +BACKUP_LOCATION=~/ # use this pacman-wrapper -pacman_wrapper=paru +PACMAN_WRAPPER=yay + +# how many different backups to keep +BACKUP_AMOUNT=2 -- 2.49.0 From b0d9c41348d79bdaea9326ac24f8dc7a296e2787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Thu, 9 Mar 2023 00:27:01 +0100 Subject: [PATCH 17/40] removed line --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index b254349..86b0e96 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,6 @@ Before installing, please edit the config and configure it to your liking. make install ``` -You will likely have to - ## Usage ``` @@ -34,4 +32,4 @@ no flag same as -p ## Contributing -Contributions are always welcome! \ No newline at end of file +Contributions are always welcome! -- 2.49.0 From d916c2d0e6fb2b6f24000e39bcaf9a655b001c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Thu, 9 Mar 2023 15:53:59 +0100 Subject: [PATCH 18/40] fixed options flatpak was not completly optional, but now should be fixed --- update | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/update b/update index f4ed718..3dc6ec1 100644 --- a/update +++ b/update @@ -86,11 +86,11 @@ while getopts 'fpagr' OPTIONS; do a) update_with_pacman_wrapper; update_with_flatpak ;; g) - [[ $1 = -g ]] && update_with_pacman_wrapper; update_with_flatpak + [[ $1 = -g ]] && update_with_pacman_wrapper 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 + [[ $1 = -r ]] && update_with_pacman_wrapper after_backup && echo -e "${IGREEN}after-backup complete${NC}" && sleep 3s && reboot exit 0;; ?) -- 2.49.0 From 994130d7dfd31a84e4bbaad8f9180c9a74dd3ef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Wed, 29 Mar 2023 15:27:54 +0200 Subject: [PATCH 19/40] Created justfile In the name of inclusivity --- justfile | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 justfile diff --git a/justfile b/justfile new file mode 100644 index 0000000..f3a4963 --- /dev/null +++ b/justfile @@ -0,0 +1,12 @@ +VER := "v1.7" + +install: + @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}} from /usr/local/bin" + @sudo rm /usr/local/bin/update ${HOME}/.config/update.conf + @echo "==> Finished." -- 2.49.0 From dc9b90846781f9b5d57d55da95c07cf06f0577de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Wed, 29 Mar 2023 15:30:05 +0200 Subject: [PATCH 20/40] updated README added section for installation using the justfile --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 86b0e96..b46b856 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,14 @@ git clone https://github.com/AustrianToast/update.git && cd update Before installing, please edit the config and configure it to your liking. +Then install using ```bash make install ``` +or +```bash +just install +``` ## Usage -- 2.49.0 From 634154128983be1db0d373406f3d99e1a302283a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Fri, 31 Mar 2023 01:09:02 +0200 Subject: [PATCH 21/40] Useless --- PKGBUILD | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 PKGBUILD diff --git a/PKGBUILD b/PKGBUILD deleted file mode 100644 index 1b4dabd..0000000 --- a/PKGBUILD +++ /dev/null @@ -1,21 +0,0 @@ -# Maintainer: AustrianToast -pkgname=update-git -pkgver=1.4 -pkgrel=1 -pkgdesc="Update script for Arch linux written in bash" -arch=('any') -url="https://github.com/AustrianToast/update" -license=('GPL3') -provides=(update) -depends=('bash') -makedepends=('git') -optdepends=('yay' 'paru' 'pacaur' 'pikaur' 'aura' 'flatpak') -home=${HOME} -backup=(${home#/}/.config/update.conf) -source=("$pkgname::git+https://github.com/AustrianToast/update.git") -md5sums=('SKIP') - -package() { - cd "$pkgname" - make install -} -- 2.49.0 From dd7cc6202754ccbf2ed70effeb135766b41569be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Fri, 31 Mar 2023 01:10:49 +0200 Subject: [PATCH 22/40] Code cleanup Improved Code by using extraction and I reduced the amount of redundant code --- update | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/update b/update index 3dc6ec1..2ca99e8 100644 --- a/update +++ b/update @@ -1,7 +1,7 @@ #!/bin/bash # updates using a pacman-wrapper and flatpak-update with flags -# version 1.7 +# version 1.8 source "$HOME"/.config/update.conf @@ -24,14 +24,28 @@ Help() { 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" + echo "-P, --preview shows a preview of which pkg's can be updated" +} + +check_for_dblck() { + 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 another instance of pacman running. exiting..." + exit 1 + } + done +} + +delete_oldest_backup() { + if [[ $1 > $BACKUP_AMOUNT ]]; then + OLDEST_FILE="$(ls -t "$BACKUP_LOCATION" | grep $2 | tail -1)" + rm "$BACKUP_LOCATION"/"$OLDEST_FILE" + fi } before_backup() { - if [[ $PRE_BACKUP_AMOUNT > $BACKUP_AMOUNT ]]; then - OLDEST_FILE="$(ls -t "$BACKUP_LOCATION" | grep before-backup | tail -1)" - rm "$BACKUP_LOCATION"/"$OLDEST_FILE" - fi + check_for_dblck + delete_oldest_backup $PRE_BACKUP_AMOUNT before-backup rm -r "$TMP" &> /dev/null mkdir "$TMP" && mkdir "$TMP"/before-backup_"$DATE" && mkdir "$TMP"/after-backup_"$DATE" pacman -Q > "$TMP"/before-backup_"$DATE"/pacman-pre.txt @@ -44,10 +58,7 @@ before_backup() { } after_backup() { - if [[ $POST_BACKUP_AMOUNT > $BACKUP_AMOUNT ]]; then - OLDEST_FILE="$(ls -t "$BACKUP_LOCATION" | grep after-backup | tail -1)" - rm "$BACKUP_LOCATION"/"$OLDEST_FILE" - fi + delete_oldest_backup $POST_BACKUP_AMOUNT after-backup tar -cJf "$TMP"/after-backup_"$DATE".tar.xz.new "$TMP"/after-backup_"$DATE" &> /dev/null cp "$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 @@ -55,8 +66,10 @@ after_backup() { } update_with_pacman_wrapper() { + before_backup && echo -e "${IGREEN}pre-backup complete${NC}" "$PACMAN_WRAPPER" pacman -Q > "$TMP"/after-backup_"$DATE"/pacman-after.txt + after_backup && echo -e "${IGREEN}after-backup complete${NC}" } update_with_flatpak() { @@ -67,15 +80,6 @@ update_with_flatpak() { [[ $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 another instance of pacman running. exiting..." - exit 1 -} -done - -before_backup && echo -e "${IGREEN}pre-backup complete${NC}" - [[ -z $1 ]] && update_with_pacman_wrapper; while getopts 'fpagr' OPTIONS; do case "$OPTIONS" in @@ -84,19 +88,15 @@ while getopts 'fpagr' OPTIONS; do p) update_with_pacman_wrapper ;; a) - update_with_pacman_wrapper; update_with_flatpak ;; + update_with_flatpak; update_with_pacman_wrapper ;; g) [[ $1 = -g ]] && update_with_pacman_wrapper - after_backup && echo -e "${IGREEN}after-backup complete${NC}" && sleep 3s && shutdown now - exit 0;; + sleep 3s && shutdown now && exit 0;; r) [[ $1 = -r ]] && update_with_pacman_wrapper - after_backup && echo -e "${IGREEN}after-backup complete${NC}" && sleep 3s && reboot - exit 0;; + sleep 3s && reboot && exit 0;; ?) Help exit 1;; esac done - -after_backup && echo -e "${IGREEN}after-backup complete${NC}" -- 2.49.0 From e4e0047d4f7520cd95a8188a243463a09696d517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Fri, 31 Mar 2023 01:11:06 +0200 Subject: [PATCH 23/40] Version bump --- justfile | 2 +- makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/justfile b/justfile index f3a4963..f3277d7 100644 --- a/justfile +++ b/justfile @@ -1,4 +1,4 @@ -VER := "v1.7" +VER := "v1.8" install: @echo "==> Installing update {{VER}} into /usr/local/bin" diff --git a/makefile b/makefile index cef642b..a54130b 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -VER = "v1.7" +VER = "v1.8" install: @echo "==> Installing update $(VER) into /usr/local/bin" -- 2.49.0 From e5559ed6c14b570187542c6702a70f644b37548c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Fri, 31 Mar 2023 13:20:47 +0200 Subject: [PATCH 24/40] Complete rewrite of argument parsing Now it is easier to add long and short options. I added two functions, one after everything is done and another which is executed in case of an interrupt. --- update | 81 ++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 25 deletions(-) diff --git a/update b/update index 2ca99e8..b20d5db 100644 --- a/update +++ b/update @@ -1,10 +1,10 @@ -#!/bin/bash +#!/usr/bin/bash # updates using a pacman-wrapper and flatpak-update with flags -# version 1.8 source "$HOME"/.config/update.conf +VER="1.9" IGREEN="\033[0;92m" # Intense Green IYELLOW="\033[0;93m" # Intense Red NC="\033[0m" # Text Reset @@ -12,6 +12,9 @@ TMP="/tmp/update" DATE="$(date +"%Y-%m-%d %H:%M:%S")" PRE_BACKUP_AMOUNT="$(ls -Ub "$BACKUP_LOCATION"/ | grep -c ^before-backup)" POST_BACKUP_AMOUNT="$(ls -Ub "$BACKUP_LOCATION"/ | grep -c ^after-backup)" +FINAL_COMMAND="" + +trap interrupt_function INT Help() { echo "Usage: update [OPTION]" @@ -21,8 +24,8 @@ Help() { 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)" + echo "-g shutdowns the computer afterwards" + echo "-r reboots the computer afterwards" echo "--help displays this message" echo "-P, --preview shows a preview of which pkg's can be updated" } @@ -62,7 +65,6 @@ after_backup() { tar -cJf "$TMP"/after-backup_"$DATE".tar.xz.new "$TMP"/after-backup_"$DATE" &> /dev/null cp "$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" } update_with_pacman_wrapper() { @@ -77,26 +79,55 @@ update_with_flatpak() { flatpak list > "$TMP"/after-backup_"$DATE"/flatpak-after.txt } -[[ $1 = --help ]] && Help && exit 0 -[[ $1 = --preview || $1 = -P ]] && sudo pacman -Sy &> /dev/null && sudo pacman -Qu && exit 0 +interrupt_function() { + echo "Interrupt has been detected" + sudo rm /var/lib/pacman/db.lck &> /dev/null + rm -r "$TMP" &> /dev/null + exit 1 +} -[[ -z $1 ]] && update_with_pacman_wrapper; -while getopts 'fpagr' OPTIONS; do - case "$OPTIONS" in - f) - update_with_flatpak ;; - p) - update_with_pacman_wrapper ;; - a) - update_with_flatpak; update_with_pacman_wrapper ;; - g) - [[ $1 = -g ]] && update_with_pacman_wrapper - sleep 3s && shutdown now && exit 0;; - r) - [[ $1 = -r ]] && update_with_pacman_wrapper - sleep 3s && reboot && exit 0;; +final() { + rm -r "$TMP" &> /dev/null + [[ $FINAL_COMMAND ]] && sleep 3s && $FINAL_COMMAND && exit 0 +} + +[[ $1 ]] || update_with_pacman_wrapper +if [[ ${1:0:2} = -- ]]; then + case "${1:2}" in + help) + Help && exit 0;; + preview) + sudo pacman -Sy &> /dev/null && sudo pacman -Qu && exit 0;; + version) + echo "$VER" && exit 0;; ?) - Help - exit 1;; + Help && exit 1;; esac -done +else + while getopts 'fpagr' OPTIONS; do + case $OPTIONS in + P) + sudo pacman -Sy &> /dev/null && sudo pacman -Qu && exit 0;; + f) + update_with_flatpak;; + p) + update_with_pacman_wrapper ;; + a) + update_with_flatpak; update_with_pacman_wrapper ;; + g) + [[ $1 = -g ]] && update_with_pacman_wrapper + FINAL_COMMAND="shutdown now" ;; + r) + [[ $1 = -r ]] && update_with_pacman_wrapper + FINAL_COMMAND="reboot" ;; + h) + Help && exit 0;; + V) + echo "$VER" && exit 0;; + ?) + Help && exit 1;; + esac + done +fi + +final \ No newline at end of file -- 2.49.0 From 9b66f59fc27835716d48493cb66974b87a0a0987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Fri, 31 Mar 2023 13:21:06 +0200 Subject: [PATCH 25/40] Version bump --- justfile | 2 +- makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/justfile b/justfile index f3277d7..dcbead8 100644 --- a/justfile +++ b/justfile @@ -1,4 +1,4 @@ -VER := "v1.8" +VER := "v1.9" install: @echo "==> Installing update {{VER}} into /usr/local/bin" diff --git a/makefile b/makefile index a54130b..582e772 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -VER = "v1.8" +VER = "v1.9" install: @echo "==> Installing update $(VER) into /usr/local/bin" -- 2.49.0 From b587f13ed2f91fff6c992ccc8ec6a58a775b5516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Mon, 3 Apr 2023 19:18:43 +0200 Subject: [PATCH 26/40] Should work properly now --- update | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/update b/update index b20d5db..7ee05b6 100644 --- a/update +++ b/update @@ -4,7 +4,7 @@ source "$HOME"/.config/update.conf -VER="1.9" +VER="2.0.0" IGREEN="\033[0;92m" # Intense Green IYELLOW="\033[0;93m" # Intense Red NC="\033[0m" # Text Reset @@ -27,11 +27,12 @@ Help() { echo "-g shutdowns the computer afterwards" echo "-r reboots the computer afterwards" echo "--help displays this message" - echo "-P, --preview shows a preview of which pkg's can be updated" + echo "--preview shows a preview of which pkg's can be updated" + echo "--version prints out the version number" } check_for_dblck() { - while [ -f /var/lib/pacman/db.lck ]; do { + if [ -f /var/lib/pacman/db.lck ]; do { echo -e "${IYELLOW}->${NC} /var/lib/pacman/db.lck exists" echo -e "${IYELLOW}->${NC} there might be another instance of pacman running. exiting..." exit 1 @@ -65,13 +66,12 @@ after_backup() { tar -cJf "$TMP"/after-backup_"$DATE".tar.xz.new "$TMP"/after-backup_"$DATE" &> /dev/null cp "$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 + [[ $FINAL_COMMAND ]] && sleep 3s && $FINAL_COMMAND && exit 0 } update_with_pacman_wrapper() { - before_backup && echo -e "${IGREEN}pre-backup complete${NC}" "$PACMAN_WRAPPER" pacman -Q > "$TMP"/after-backup_"$DATE"/pacman-after.txt - after_backup && echo -e "${IGREEN}after-backup complete${NC}" } update_with_flatpak() { @@ -86,12 +86,7 @@ interrupt_function() { exit 1 } -final() { - rm -r "$TMP" &> /dev/null - [[ $FINAL_COMMAND ]] && sleep 3s && $FINAL_COMMAND && exit 0 -} - -[[ $1 ]] || update_with_pacman_wrapper +[[ $1 ]] || before_backup && echo -e "${IGREEN}pre-backup complete${NC}" && update_with_pacman_wrapper if [[ ${1:0:2} = -- ]]; then case "${1:2}" in help) @@ -104,30 +99,26 @@ if [[ ${1:0:2} = -- ]]; then Help && exit 1;; esac else + before_backup && echo -e "${IGREEN}pre-backup complete${NC}" + while getopts 'fpagr' OPTIONS; do case $OPTIONS in - P) - sudo pacman -Sy &> /dev/null && sudo pacman -Qu && exit 0;; f) update_with_flatpak;; p) update_with_pacman_wrapper ;; a) - update_with_flatpak; update_with_pacman_wrapper ;; + update_with_pacman_wrapper; update_with_flatpak ;; g) [[ $1 = -g ]] && update_with_pacman_wrapper FINAL_COMMAND="shutdown now" ;; r) [[ $1 = -r ]] && update_with_pacman_wrapper FINAL_COMMAND="reboot" ;; - h) - Help && exit 0;; - V) - echo "$VER" && exit 0;; ?) Help && exit 1;; esac done fi -final \ No newline at end of file +after_backup && echo -e "${IGREEN}after-backup complete${NC}" -- 2.49.0 From 032bed15c6c5504bb0bbdccc7f05f2d674c75b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Mon, 3 Apr 2023 19:19:05 +0200 Subject: [PATCH 27/40] Version Bump --- justfile | 2 +- makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/justfile b/justfile index dcbead8..e501af1 100644 --- a/justfile +++ b/justfile @@ -1,4 +1,4 @@ -VER := "v1.9" +VER := "v2.0.0" install: @echo "==> Installing update {{VER}} into /usr/local/bin" diff --git a/makefile b/makefile index 582e772..1ce2f53 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -VER = "v1.9" +VER = "v2.0.0" install: @echo "==> Installing update $(VER) into /usr/local/bin" -- 2.49.0 From b380df76ca581059ad41175bf26835d02c3cd4ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Mon, 3 Apr 2023 19:38:53 +0200 Subject: [PATCH 28/40] removed line --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 39b7d80..b46b856 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,6 @@ or ```bash just install ``` -======= ## Usage -- 2.49.0 From 3a976e50b5748f3284391baf6b75dc481cd3c498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Mon, 3 Apr 2023 20:02:41 +0200 Subject: [PATCH 29/40] I am stupid --- justfile | 2 +- makefile | 2 +- update | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/justfile b/justfile index e501af1..0fd9996 100644 --- a/justfile +++ b/justfile @@ -1,4 +1,4 @@ -VER := "v2.0.0" +VER := "v2.0.1" install: @echo "==> Installing update {{VER}} into /usr/local/bin" diff --git a/makefile b/makefile index 1ce2f53..cd50cc1 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -VER = "v2.0.0" +VER = "v2.0.1" install: @echo "==> Installing update $(VER) into /usr/local/bin" diff --git a/update b/update index 7ee05b6..512d529 100644 --- a/update +++ b/update @@ -4,7 +4,7 @@ source "$HOME"/.config/update.conf -VER="2.0.0" +VER="2.0.1" IGREEN="\033[0;92m" # Intense Green IYELLOW="\033[0;93m" # Intense Red NC="\033[0m" # Text Reset @@ -32,12 +32,12 @@ Help() { } check_for_dblck() { - if [ -f /var/lib/pacman/db.lck ]; do { + if [ -f /var/lib/pacman/db.lck ]; then { echo -e "${IYELLOW}->${NC} /var/lib/pacman/db.lck exists" echo -e "${IYELLOW}->${NC} there might be another instance of pacman running. exiting..." exit 1 } - done + fi } delete_oldest_backup() { @@ -86,7 +86,7 @@ interrupt_function() { exit 1 } -[[ $1 ]] || before_backup && echo -e "${IGREEN}pre-backup complete${NC}" && update_with_pacman_wrapper +[[ -z $1 ]] && before_backup && echo -e "${IGREEN}pre-backup complete${NC}" && update_with_pacman_wrapper if [[ ${1:0:2} = -- ]]; then case "${1:2}" in help) -- 2.49.0 From 792504c4fcad7913e0456ff01354048f76dc643b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Mon, 3 Apr 2023 23:53:36 +0200 Subject: [PATCH 30/40] Minor code improvement --- update | 66 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/update b/update index 512d529..4976e18 100644 --- a/update +++ b/update @@ -4,7 +4,7 @@ source "$HOME"/.config/update.conf -VER="2.0.1" +VER="2.0.2" IGREEN="\033[0;92m" # Intense Green IYELLOW="\033[0;93m" # Intense Red NC="\033[0m" # Text Reset @@ -16,6 +16,13 @@ FINAL_COMMAND="" trap interrupt_function INT +interrupt_function() { + echo "Interrupt has been detected" + sudo rm /var/lib/pacman/db.lck &> /dev/null + rm -r "$TMP" &> /dev/null + exit 1 +} + Help() { echo "Usage: update [OPTION]" echo @@ -79,46 +86,41 @@ update_with_flatpak() { flatpak list > "$TMP"/after-backup_"$DATE"/flatpak-after.txt } -interrupt_function() { - echo "Interrupt has been detected" - sudo rm /var/lib/pacman/db.lck &> /dev/null - rm -r "$TMP" &> /dev/null - exit 1 -} - [[ -z $1 ]] && before_backup && echo -e "${IGREEN}pre-backup complete${NC}" && update_with_pacman_wrapper + if [[ ${1:0:2} = -- ]]; then case "${1:2}" in help) - Help && exit 0;; + Help ;; preview) - sudo pacman -Sy &> /dev/null && sudo pacman -Qu && exit 0;; + sudo pacman -Sy &> /dev/null && sudo pacman -Qu ;; version) - echo "$VER" && exit 0;; + echo "$VER" ;; ?) Help && exit 1;; esac -else - before_backup && echo -e "${IGREEN}pre-backup complete${NC}" - - 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 - FINAL_COMMAND="shutdown now" ;; - r) - [[ $1 = -r ]] && update_with_pacman_wrapper - FINAL_COMMAND="reboot" ;; - ?) - Help && exit 1;; - esac - done + exit 0 fi +before_backup && echo -e "${IGREEN}pre-backup complete${NC}" + +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 + FINAL_COMMAND="shutdown now" ;; + r) + [[ $1 = -r ]] && update_with_pacman_wrapper + FINAL_COMMAND="reboot" ;; + ?) + Help && exit 1;; + esac +done + after_backup && echo -e "${IGREEN}after-backup complete${NC}" -- 2.49.0 From 832237903a5f27f68ac4ac8799330a9b39878718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Mon, 3 Apr 2023 23:54:11 +0200 Subject: [PATCH 31/40] Removed version variable It was too stupid to maintain --- justfile | 6 ++---- makefile | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/justfile b/justfile index 0fd9996..fe06a04 100644 --- a/justfile +++ b/justfile @@ -1,12 +1,10 @@ -VER := "v2.0.1" - install: - @echo "==> Installing update {{VER}} into /usr/local/bin" + @echo "==> Installing update into /usr/local/bin" @sudo install -Dm755 update /usr/local/bin/update @cp update.conf ${HOME}/.config/ @echo "==> Finished." uninstall: - @echo "==> Uninstalling update {{VER}} from /usr/local/bin" + @echo "==> Uninstalling update from /usr/local/bin" @sudo rm /usr/local/bin/update ${HOME}/.config/update.conf @echo "==> Finished." diff --git a/makefile b/makefile index cd50cc1..fe06a04 100644 --- a/makefile +++ b/makefile @@ -1,12 +1,10 @@ -VER = "v2.0.1" - install: - @echo "==> Installing update $(VER) into /usr/local/bin" + @echo "==> Installing update into /usr/local/bin" @sudo install -Dm755 update /usr/local/bin/update @cp update.conf ${HOME}/.config/ @echo "==> Finished." uninstall: - @echo "==> Uninstalling update $(VER) from /usr/local/bin" + @echo "==> Uninstalling update from /usr/local/bin" @sudo rm /usr/local/bin/update ${HOME}/.config/update.conf @echo "==> Finished." -- 2.49.0 From 9c92ced4bb94155acc10c452d4af1c05e7d19e3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Tue, 4 Apr 2023 10:36:58 +0200 Subject: [PATCH 32/40] Fixed Issue with after_backup not completing --- update | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/update b/update index 4976e18..379f507 100644 --- a/update +++ b/update @@ -4,7 +4,7 @@ source "$HOME"/.config/update.conf -VER="2.0.2" +VER="2.0.3" IGREEN="\033[0;92m" # Intense Green IYELLOW="\033[0;93m" # Intense Red NC="\033[0m" # Text Reset @@ -73,7 +73,7 @@ after_backup() { tar -cJf "$TMP"/after-backup_"$DATE".tar.xz.new "$TMP"/after-backup_"$DATE" &> /dev/null cp "$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 - [[ $FINAL_COMMAND ]] && sleep 3s && $FINAL_COMMAND && exit 0 + $FINAL_COMMAND } update_with_pacman_wrapper() { @@ -86,8 +86,6 @@ update_with_flatpak() { flatpak list > "$TMP"/after-backup_"$DATE"/flatpak-after.txt } -[[ -z $1 ]] && before_backup && echo -e "${IGREEN}pre-backup complete${NC}" && update_with_pacman_wrapper - if [[ ${1:0:2} = -- ]]; then case "${1:2}" in help) @@ -104,10 +102,11 @@ fi before_backup && echo -e "${IGREEN}pre-backup complete${NC}" +[[ $1 ]] || update_with_pacman_wrapper while getopts 'fpagr' OPTIONS; do case $OPTIONS in f) - update_with_flatpak;; + update_with_flatpak ;; p) update_with_pacman_wrapper ;; a) -- 2.49.0 From 67b3caff370473b6d094587987e6539857dc4d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Tue, 4 Apr 2023 10:38:20 +0200 Subject: [PATCH 33/40] Added new option --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b46b856..9e665ff 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,11 @@ no flag same as -p -f updates using flatpak update only -p updates using a pacman-wrapper only -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) +-g shutdowns the computer afterwards +-r reboots the computer afterwards --help displays this message --P, --preview shows a preview of which pkg's will be updates +--preview shows a preview of which pkg's will be updates +--version prints out the version number ``` ## Contributing -- 2.49.0 From ca33ad9f9358e715bb56201e382afb15a53475f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Tue, 4 Apr 2023 10:38:52 +0200 Subject: [PATCH 34/40] formating --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e665ff..28d5bae 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ no flag same as -p -g shutdowns the computer afterwards -r reboots the computer afterwards --help displays this message ---preview shows a preview of which pkg's will be updates +--preview shows a preview of which pkg's will be updates --version prints out the version number ``` -- 2.49.0 From 244e150d8e2291e0cb0ab12d6dc1c7088a2e374e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Fri, 7 Apr 2023 00:48:40 +0200 Subject: [PATCH 35/40] small fix Moved FINAL_COMMAND to after the after_backup --- update | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/update b/update index 379f507..1c65044 100644 --- a/update +++ b/update @@ -4,7 +4,7 @@ source "$HOME"/.config/update.conf -VER="2.0.3" +VER="2.0.4" IGREEN="\033[0;92m" # Intense Green IYELLOW="\033[0;93m" # Intense Red NC="\033[0m" # Text Reset @@ -73,7 +73,6 @@ after_backup() { tar -cJf "$TMP"/after-backup_"$DATE".tar.xz.new "$TMP"/after-backup_"$DATE" &> /dev/null cp "$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 - $FINAL_COMMAND } update_with_pacman_wrapper() { @@ -123,3 +122,4 @@ while getopts 'fpagr' OPTIONS; do done after_backup && echo -e "${IGREEN}after-backup complete${NC}" +$FINAL_COMMAND; exit 0 -- 2.49.0 From 37f244606d859d475b2afc1c5c45d19155511970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Sat, 13 May 2023 00:21:37 +0200 Subject: [PATCH 36/40] slight improvements made it so that the pacman/aur list can be fed into pacman in order to reinstall everything improved hiding output od certain cmd's --- update | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/update b/update index 1c65044..3de16b9 100644 --- a/update +++ b/update @@ -4,7 +4,7 @@ source "$HOME"/.config/update.conf -VER="2.0.4" +VER="2.0.5" IGREEN="\033[0;92m" # Intense Green IYELLOW="\033[0;93m" # Intense Red NC="\033[0m" # Text Reset @@ -18,8 +18,8 @@ trap interrupt_function INT interrupt_function() { echo "Interrupt has been detected" - sudo rm /var/lib/pacman/db.lck &> /dev/null - rm -r "$TMP" &> /dev/null + sudo rm /var/lib/pacman/db.lck > /dev/null 2>&1 + rm -r "$TMP" > /dev/null 2>&1 exit 1 } @@ -57,27 +57,27 @@ delete_oldest_backup() { before_backup() { check_for_dblck delete_oldest_backup $PRE_BACKUP_AMOUNT before-backup - rm -r "$TMP" &> /dev/null + rm -r "$TMP" > /dev/null 2>&1 mkdir "$TMP" && mkdir "$TMP"/before-backup_"$DATE" && mkdir "$TMP"/after-backup_"$DATE" - pacman -Q > "$TMP"/before-backup_"$DATE"/pacman-pre.txt + pacman -Qq > "$TMP"/before-backup_"$DATE"/pacman-pre.txt [[ -f /usr/bin/flatpak ]] && flatpak list > "$TMP"/before-backup_"$DATE"/flatpak-pre.txt sudo touch /var/lib/pacman/db.lck - tar -cJf "$TMP"/before-backup_"$DATE".tar.xz.new "$TMP"/before-backup_"$DATE" /var/lib/pacman/local &> /dev/null + tar -cJf "$TMP"/before-backup_"$DATE".tar.xz.new "$TMP"/before-backup_"$DATE" /var/lib/pacman/local > /dev/null 2>&1 sudo rm /var/lib/pacman/db.lck cp "$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 + rename before-backup_"$DATE".tar.xz.new before-backup_"$DATE".tar.xz "$BACKUP_LOCATION"/before-backup_"$DATE".tar.xz.new > /dev/null 2>&1 } after_backup() { delete_oldest_backup $POST_BACKUP_AMOUNT after-backup - tar -cJf "$TMP"/after-backup_"$DATE".tar.xz.new "$TMP"/after-backup_"$DATE" &> /dev/null + tar -cJf "$TMP"/after-backup_"$DATE".tar.xz.new "$TMP"/after-backup_"$DATE" > /dev/null 2>&1 cp "$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 } update_with_pacman_wrapper() { - "$PACMAN_WRAPPER" - pacman -Q > "$TMP"/after-backup_"$DATE"/pacman-after.txt + "$PACMAN_WRAPPER" + pacman -Qq > "$TMP"/after-backup_"$DATE"/pacman-after.txt } update_with_flatpak() { @@ -90,7 +90,7 @@ if [[ ${1:0:2} = -- ]]; then help) Help ;; preview) - sudo pacman -Sy &> /dev/null && sudo pacman -Qu ;; + sudo pacman -Sy > /dev/null 2>&1 && sudo pacman -Qu ;; version) echo "$VER" ;; ?) -- 2.49.0 From b555ce76446d0ebd35a0f749ca26334fe15709a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Tue, 23 May 2023 17:14:25 +0200 Subject: [PATCH 37/40] small change I recommend you clear your backup dir --- update | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/update b/update index 3de16b9..5ffa90a 100644 --- a/update +++ b/update @@ -4,7 +4,7 @@ source "$HOME"/.config/update.conf -VER="2.0.5" +VER="2.0.6" IGREEN="\033[0;92m" # Intense Green IYELLOW="\033[0;93m" # Intense Red NC="\033[0m" # Text Reset @@ -48,7 +48,7 @@ check_for_dblck() { } delete_oldest_backup() { - if [[ $1 > $BACKUP_AMOUNT ]]; then + if [[ $1 -ge $BACKUP_AMOUNT ]]; then OLDEST_FILE="$(ls -t "$BACKUP_LOCATION" | grep $2 | tail -1)" rm "$BACKUP_LOCATION"/"$OLDEST_FILE" fi -- 2.49.0 From b588b1ca787964394f8739f8ecdb114268daca6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Wed, 24 May 2023 11:50:10 +0200 Subject: [PATCH 38/40] new backup flag --- update | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/update b/update index 5ffa90a..8696d2d 100644 --- a/update +++ b/update @@ -4,9 +4,9 @@ source "$HOME"/.config/update.conf -VER="2.0.6" +VER="2.0.7" IGREEN="\033[0;92m" # Intense Green -IYELLOW="\033[0;93m" # Intense Red +IYELLOW="\033[0;93m" # Intense Yellow NC="\033[0m" # Text Reset TMP="/tmp/update" DATE="$(date +"%Y-%m-%d %H:%M:%S")" @@ -60,6 +60,7 @@ before_backup() { rm -r "$TMP" > /dev/null 2>&1 mkdir "$TMP" && mkdir "$TMP"/before-backup_"$DATE" && mkdir "$TMP"/after-backup_"$DATE" pacman -Qq > "$TMP"/before-backup_"$DATE"/pacman-pre.txt + [[ -f "$TMP"/before-backup_"$DATE"/pacman-pre.txt ]] || echo -e "$IYELLOW backup was unsuccessful" || exit 1 [[ -f /usr/bin/flatpak ]] && flatpak list > "$TMP"/before-backup_"$DATE"/flatpak-pre.txt sudo touch /var/lib/pacman/db.lck tar -cJf "$TMP"/before-backup_"$DATE".tar.xz.new "$TMP"/before-backup_"$DATE" /var/lib/pacman/local > /dev/null 2>&1 @@ -93,6 +94,8 @@ if [[ ${1:0:2} = -- ]]; then sudo pacman -Sy > /dev/null 2>&1 && sudo pacman -Qu ;; version) echo "$VER" ;; + backup) + before_backup ;; ?) Help && exit 1;; esac -- 2.49.0 From c355fe01d0bb0702de331596e3ed8774a8673e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Tue, 6 Jun 2023 23:42:26 +0200 Subject: [PATCH 39/40] I cringe at my own stupidity --- README.md | 1 + update | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 28d5bae..c207b25 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ no flag same as -p --help displays this message --preview shows a preview of which pkg's will be updates --version prints out the version number +--backup just does the before backup without updating ``` ## Contributing diff --git a/update b/update index 8696d2d..895696a 100644 --- a/update +++ b/update @@ -36,6 +36,7 @@ Help() { echo "--help displays this message" echo "--preview shows a preview of which pkg's can be updated" echo "--version prints out the version number" + echo "--backup just does the before backup without updating" } check_for_dblck() { -- 2.49.0 From dbafa1dde0830bfdd3d567addb3a86c0db1479c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Tue, 6 Jun 2023 23:43:39 +0200 Subject: [PATCH 40/40] Bruh --- README.md | 2 +- update | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c207b25..2a30ce7 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ no flag same as -p --help displays this message --preview shows a preview of which pkg's will be updates --version prints out the version number ---backup just does the before backup without updating +--backup just does the pre-backup without updating ``` ## Contributing diff --git a/update b/update index 895696a..dfd1290 100644 --- a/update +++ b/update @@ -36,7 +36,7 @@ Help() { echo "--help displays this message" echo "--preview shows a preview of which pkg's can be updated" echo "--version prints out the version number" - echo "--backup just does the before backup without updating" + echo "--backup just does the pre-backup without updating" } check_for_dblck() { -- 2.49.0