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 1/9] 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 +} 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 2/9] 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 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 3/9] 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 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 4/9] 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;; ?) 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 5/9] 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 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 6/9] 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! 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 7/9] 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;; ?) 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 8/9] 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." 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 9/9] 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