From fe80b5ba14b86d7614f6829fd3f3170cd4e11796 Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Sun, 29 Oct 2023 00:17:28 +0200 Subject: [PATCH 1/6] small refactor --- README.md | 23 +++++++++++++++-------- makefile | 10 ---------- update | 25 +++++++++++++------------ 3 files changed, 28 insertions(+), 30 deletions(-) delete mode 100644 makefile diff --git a/README.md b/README.md index 2a30ce7..6923317 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,28 @@ # 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. +Update script written in bash for Arch Linux only. 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 and aur packages and flatpaks. + +## Requirements + +Here is what is required. +```bash +pacman -S just +``` +It also technically requires sudo, but if you use something else, then just have create softlink for this script to work.
+Doing that looks like this. +```bash +ln -s /usr/bin/your_program /usr/bin/sudo +``` ## Installation ```bash -git clone https://github.com/AustrianToast/update.git && cd update +git clone https://gitea.hopeless-cloud.xyz/AustrianToast/update.git && cd update ``` -Before installing, please edit the config and configure it to your liking. - +Before installing, please edit the config and configure it to your liking.
Then install using ```bash -make install -``` -or -```bash just install ``` diff --git a/makefile b/makefile deleted file mode 100644 index fe06a04..0000000 --- a/makefile +++ /dev/null @@ -1,10 +0,0 @@ -install: - @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 from /usr/local/bin" - @sudo rm /usr/local/bin/update ${HOME}/.config/update.conf - @echo "==> Finished." diff --git a/update b/update index dfd1290..b1fa1c2 100644 --- a/update +++ b/update @@ -2,23 +2,24 @@ # updates using a pacman-wrapper and flatpak-update with flags -source "$HOME"/.config/update.conf +source "$HOME"/.config/update.conf || exit 1 +[[ ! -d $BACKUP_LOCATION ]] && mkdir --parents $BACKUP_LOCATION -VER="2.0.7" +VER="2.0.8" IGREEN="\033[0;92m" # Intense Green IYELLOW="\033[0;93m" # Intense Yellow 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)" +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 interrupt_function() { echo "Interrupt has been detected" - sudo rm /var/lib/pacman/db.lck > /dev/null 2>&1 + [[ -f /var/lib/pacman/db.lck ]] && sudo rm /var/lib/pacman/db.lck > /dev/null 2>&1 rm -r "$TMP" > /dev/null 2>&1 exit 1 } @@ -40,11 +41,10 @@ Help() { } check_for_dblck() { - if [ -f /var/lib/pacman/db.lck ]; then { + 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 - } fi } @@ -60,7 +60,7 @@ before_backup() { delete_oldest_backup $PRE_BACKUP_AMOUNT 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 + pacman -Q > "$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 @@ -79,7 +79,7 @@ after_backup() { update_with_pacman_wrapper() { "$PACMAN_WRAPPER" - pacman -Qq > "$TMP"/after-backup_"$DATE"/pacman-after.txt + pacman -Q > "$TMP"/after-backup_"$DATE"/pacman-after.txt } update_with_flatpak() { @@ -92,7 +92,8 @@ if [[ ${1:0:2} = -- ]]; then help) Help ;; preview) - sudo pacman -Sy > /dev/null 2>&1 && sudo pacman -Qu ;; + "$PACMAN_WRAPPER" -Sy > /dev/null 2>&1 + "$PACMAN_WRAPPER" -Qu ;; version) echo "$VER" ;; backup) @@ -116,10 +117,10 @@ while getopts 'fpagr' OPTIONS; do update_with_pacman_wrapper; update_with_flatpak ;; g) [[ $1 = -g ]] && update_with_pacman_wrapper - FINAL_COMMAND="shutdown now" ;; + FINAL_COMMAND="systemctl poweroff" ;; r) [[ $1 = -r ]] && update_with_pacman_wrapper - FINAL_COMMAND="reboot" ;; + FINAL_COMMAND="systemctl reboot" ;; ?) Help && exit 1;; esac -- 2.45.2 From b41e4963782287b19eb225c72f8b94483a35af5f Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Sun, 29 Oct 2023 00:18:31 +0200 Subject: [PATCH 2/6] fix README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6923317..28abaf5 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Here is what is required. ```bash pacman -S just ``` -It also technically requires sudo, but if you use something else, then just have create softlink for this script to work.
+It also technically requires sudo, but if you use something else, then just create a softlink for this script to work.
Doing that looks like this. ```bash ln -s /usr/bin/your_program /usr/bin/sudo -- 2.45.2 From 97a0d2cd9c57d2a7f81279fa1e1081b321608930 Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Sun, 29 Oct 2023 00:21:01 +0200 Subject: [PATCH 3/6] another tiny fix --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 28abaf5..6109cf8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Update -Update script written in bash for Arch Linux only. 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 and aur packages and flatpaks. +Update script written in Bash for Arch Linux only. 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 and aur packages and flatpaks. ## Requirements @@ -9,7 +9,7 @@ Here is what is required. pacman -S just ``` It also technically requires sudo, but if you use something else, then just create a softlink for this script to work.
-Doing that looks like this. +Doing that would look like this. ```bash ln -s /usr/bin/your_program /usr/bin/sudo ``` -- 2.45.2 From 1d4feed7e5bbd6a0cc7406c18f3a2da04f6de3e8 Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Thu, 30 Nov 2023 23:43:32 +0100 Subject: [PATCH 4/6] refactoring --- README.md | 2 +- update | 83 +++++++++++++++++++++++++++---------------------------- 2 files changed, 41 insertions(+), 44 deletions(-) mode change 100644 => 100755 update diff --git a/README.md b/README.md index 6109cf8..2853db8 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,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 pre-backup without updating +--backup just does the before-backup without updating ``` ## Contributing diff --git a/update b/update old mode 100644 new mode 100755 index b1fa1c2..ce6f8f9 --- a/update +++ b/update @@ -1,18 +1,14 @@ #!/usr/bin/bash -# updates using a pacman-wrapper and flatpak-update with flags - source "$HOME"/.config/update.conf || exit 1 -[[ ! -d $BACKUP_LOCATION ]] && mkdir --parents $BACKUP_LOCATION +[[ ! -d $BACKUP_LOCATION ]] && mkdir --parents "$BACKUP_LOCATION" -VER="2.0.8" +VERSION="2.0.9" IGREEN="\033[0;92m" # Intense Green IYELLOW="\033[0;93m" # Intense Yellow -NC="\033[0m" # Text Reset +NO_COLOR="\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)" +DATE="$(date +"%Y-%m-%dT%H:%M:%S%:z")" # RFC 3339 date-time FINAL_COMMAND="" trap interrupt_function INT @@ -20,11 +16,11 @@ trap interrupt_function INT interrupt_function() { echo "Interrupt has been detected" [[ -f /var/lib/pacman/db.lck ]] && sudo rm /var/lib/pacman/db.lck > /dev/null 2>&1 - rm -r "$TMP" > /dev/null 2>&1 + rm --recursive "$TMP" > /dev/null 2>&1 exit 1 } -Help() { +help() { echo "Usage: update [OPTION]" echo echo "options:" @@ -37,44 +33,44 @@ 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 pre-backup without updating" + echo "--backup just does the before-backup without updating" } -check_for_dblck() { +lock_pacman_db() { 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..." + echo -e "${IYELLOW}->${NO_COLOR} /var/lib/pacman/db.lck exists" + echo -e "${IYELLOW}->${NO_COLOR} there might be another instance of pacman running. exiting..." exit 1 fi + sudo touch /var/lib/pacman/db.lck } delete_oldest_backup() { - if [[ $1 -ge $BACKUP_AMOUNT ]]; then - OLDEST_FILE="$(ls -t "$BACKUP_LOCATION" | grep $2 | tail -1)" + if [[ $(ls -Ub "$BACKUP_LOCATION" | grep -c $1) -ge $BACKUP_AMOUNT ]]; then + OLDEST_FILE="$(ls -rt1 $BACKUP_LOCATION | grep $1 | head -1)" # sorts by time (oldes first) and gets the first item rm "$BACKUP_LOCATION"/"$OLDEST_FILE" fi } before_backup() { - check_for_dblck - delete_oldest_backup $PRE_BACKUP_AMOUNT before-backup - 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 - [[ -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 + lock_pacman_db + delete_oldest_backup before-backup + [[ -d $TMP ]] && rm -r "$TMP" + mkdir --parents "$TMP"/before-backup_"$DATE" "$TMP"/after-backup_"$DATE" + pacman -Q > "$TMP"/before-backup_"$DATE"/pacman-before.txt + [[ -f /usr/bin/flatpak ]] && flatpak list --all --show-details > "$TMP"/before-backup_"$DATE"/flatpak-before.txt + tar --create --xz --file "$TMP"/before-backup_"$DATE".tar.xz.new "$TMP"/before-backup_"$DATE" /var/lib/pacman/local > /dev/null 2>&1 # for some reason it needs the output suppresion 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 > /dev/null 2>&1 + mv "$TMP"/before-backup_"$DATE".tar.xz.new "$BACKUP_LOCATION" + mv "$BACKUP_LOCATION"/before-backup_"$DATE".tar.xz.new "$BACKUP_LOCATION"/before-backup_"$DATE".tar.xz } 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 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 + delete_oldest_backup after-backup + tar --create --xz --file "$TMP"/after-backup_"$DATE".tar.xz.new "$TMP"/after-backup_"$DATE" > /dev/null 2>&1 + mv "$TMP"/after-backup_"$DATE".tar.xz.new "$BACKUP_LOCATION" + mv "$BACKUP_LOCATION"/after-backup_"$DATE".tar.xz.new "$BACKUP_LOCATION"/after-backup_"$DATE".tar.xz + rm --recursive "$TMP" } update_with_pacman_wrapper() { @@ -83,28 +79,29 @@ update_with_pacman_wrapper() { } update_with_flatpak() { - flatpak update -u --noninteractive - flatpak list > "$TMP"/after-backup_"$DATE"/flatpak-after.txt + flatpak update --assumeyes + flatpak list --all --show-details > "$TMP"/after-backup_"$DATE"/flatpak-after.txt } if [[ ${1:0:2} = -- ]]; then case "${1:2}" in help) - Help ;; + help ;; preview) - "$PACMAN_WRAPPER" -Sy > /dev/null 2>&1 + "$PACMAN_WRAPPER" -Sy "$PACMAN_WRAPPER" -Qu ;; version) - echo "$VER" ;; + echo "$VERSON" ;; backup) - before_backup ;; + before_backup + rm --recursive "$TMP" ;; ?) - Help && exit 1;; + help; exit 1;; esac exit 0 fi -before_backup && echo -e "${IGREEN}pre-backup complete${NC}" +before_backup && echo -e "${IGREEN}pre-backup complete${NO_COLOR}" [[ $1 ]] || update_with_pacman_wrapper while getopts 'fpagr' OPTIONS; do @@ -117,14 +114,14 @@ while getopts 'fpagr' OPTIONS; do update_with_pacman_wrapper; update_with_flatpak ;; g) [[ $1 = -g ]] && update_with_pacman_wrapper - FINAL_COMMAND="systemctl poweroff" ;; + FINAL_COMMAND="systemctl --check-inhibitors=yes poweroff" ;; r) [[ $1 = -r ]] && update_with_pacman_wrapper - FINAL_COMMAND="systemctl reboot" ;; + FINAL_COMMAND="systemctl --check-inhibitors=yes reboot" ;; ?) - Help && exit 1;; + help; exit 1;; esac done -after_backup && echo -e "${IGREEN}after-backup complete${NC}" +after_backup && echo -e "${IGREEN}after-backup complete${NO_COLOR}" $FINAL_COMMAND; exit 0 -- 2.45.2 From 0032f6f4c245b2079ca793301441c5dc867d8e35 Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Thu, 30 Nov 2023 23:51:24 +0100 Subject: [PATCH 5/6] tiny change --- update | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/update b/update index ce6f8f9..fb2381c 100755 --- a/update +++ b/update @@ -8,7 +8,7 @@ IGREEN="\033[0;92m" # Intense Green IYELLOW="\033[0;93m" # Intense Yellow NO_COLOR="\033[0m" # Text Reset TMP="/tmp/update" -DATE="$(date +"%Y-%m-%dT%H:%M:%S%:z")" # RFC 3339 date-time +DATE="$(date +"%Y-%m-%dT%H:%M:%S%:z")" # RFC 3339 date-time https://datatracker.ietf.org/doc/html/rfc3339#section-5.6 FINAL_COMMAND="" trap interrupt_function INT @@ -124,4 +124,4 @@ while getopts 'fpagr' OPTIONS; do done after_backup && echo -e "${IGREEN}after-backup complete${NO_COLOR}" -$FINAL_COMMAND; exit 0 +$FINAL_COMMAND; exit -- 2.45.2 From 2950e116543decc1486f1945b535e41838ce362d Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Thu, 30 Nov 2023 23:55:22 +0100 Subject: [PATCH 6/6] small change no longer overwrites an existing config --- justfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/justfile b/justfile index fe06a04..0c34d80 100644 --- a/justfile +++ b/justfile @@ -1,7 +1,7 @@ install: @echo "==> Installing update into /usr/local/bin" @sudo install -Dm755 update /usr/local/bin/update - @cp update.conf ${HOME}/.config/ + @[[ -f ${HOME}/.config/update.conf ]] || cp update.conf ${HOME}/.config/ @echo "==> Finished." uninstall: -- 2.45.2