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 1/2] 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.45.2 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 2/2] 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.45.2