doing stuff

This commit is contained in:
AustrianToast 2024-01-02 16:32:56 +01:00
parent 92669692f6
commit 355abbf36b
No known key found for this signature in database
GPG Key ID: 8086574D3AAF2453

33
update
View File

@ -3,7 +3,7 @@
source "$HOME"/.config/update.conf || exit 1 source "$HOME"/.config/update.conf || exit 1
[[ ! -d $BACKUP_LOCATION ]] && mkdir --parents "$BACKUP_LOCATION" [[ ! -d $BACKUP_LOCATION ]] && mkdir --parents "$BACKUP_LOCATION"
VERSION="2.0.9" VERSION="2.1.0"
IGREEN="\033[0;92m" # Intense Green IGREEN="\033[0;92m" # Intense Green
IYELLOW="\033[0;93m" # Intense Yellow IYELLOW="\033[0;93m" # Intense Yellow
NO_COLOR="\033[0m" # Text Reset NO_COLOR="\033[0m" # Text Reset
@ -15,8 +15,8 @@ trap interrupt_function INT
interrupt_function() { interrupt_function() {
echo "Interrupt has been detected" echo "Interrupt has been detected"
[[ -f /var/lib/pacman/db.lck ]] && sudo rm /var/lib/pacman/db.lck > /dev/null 2>&1 [[ -f /var/lib/pacman/db.lck ]] && sudo rm /var/lib/pacman/db.lck
rm --recursive "$TMP" > /dev/null 2>&1 rm --recursive "$TMP"
exit 1 exit 1
} }
@ -24,7 +24,7 @@ help() {
echo "Usage: update [OPTION]" echo "Usage: update [OPTION]"
echo echo
echo "options:" echo "options:"
echo "no flag same as -p" echo "no option same as -p"
echo "-f updates using flatpak update only" echo "-f updates using flatpak update only"
echo "-p updates using a pacman-wrapper only" echo "-p updates using a pacman-wrapper only"
echo "-a updates using flatpak update and a pacman-wrapper" echo "-a updates using flatpak update and a pacman-wrapper"
@ -58,7 +58,7 @@ before_backup() {
[[ -d $TMP ]] && rm -r "$TMP" [[ -d $TMP ]] && rm -r "$TMP"
mkdir --parents "$TMP"/before-backup_"$DATE" "$TMP"/after-backup_"$DATE" mkdir --parents "$TMP"/before-backup_"$DATE" "$TMP"/after-backup_"$DATE"
pacman -Q > "$TMP"/before-backup_"$DATE"/pacman-before.txt 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 [[ -x /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 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 sudo rm /var/lib/pacman/db.lck
mv "$TMP"/before-backup_"$DATE".tar.xz.new "$BACKUP_LOCATION" mv "$TMP"/before-backup_"$DATE".tar.xz.new "$BACKUP_LOCATION"
@ -79,8 +79,10 @@ update_with_pacman_wrapper() {
} }
update_with_flatpak() { update_with_flatpak() {
flatpak update --assumeyes if [[ -x /usr/bin/flatpak ]]; then
flatpak list --all --show-details > "$TMP"/after-backup_"$DATE"/flatpak-after.txt flatpak update --assumeyes
flatpak list --all --show-details > "$TMP"/after-backup_"$DATE"/flatpak-after.txt
fi
} }
if [[ ${1:0:2} = -- ]]; then if [[ ${1:0:2} = -- ]]; then
@ -89,9 +91,10 @@ if [[ ${1:0:2} = -- ]]; then
help ;; help ;;
preview) preview)
"$PACMAN_WRAPPER" -Sy "$PACMAN_WRAPPER" -Sy
"$PACMAN_WRAPPER" -Qu ;; "$PACMAN_WRAPPER" -Qu
[[ -x /usr/bin/flatpak ]] && flatpak remote-ls --updates ;;
version) version)
echo "$VERSON" ;; echo "$VERSION" ;;
backup) backup)
before_backup before_backup
rm --recursive "$TMP" ;; rm --recursive "$TMP" ;;
@ -103,7 +106,9 @@ fi
before_backup && echo -e "${IGREEN}pre-backup complete${NO_COLOR}" before_backup && echo -e "${IGREEN}pre-backup complete${NO_COLOR}"
[[ $1 ]] || update_with_pacman_wrapper if [[ -z $1 ]]; then
update_with_pacman_wrapper; update_with_flatpak
fi
while getopts 'fpagr' OPTIONS; do while getopts 'fpagr' OPTIONS; do
case $OPTIONS in case $OPTIONS in
f) f)
@ -113,10 +118,14 @@ while getopts 'fpagr' OPTIONS; do
a) a)
update_with_pacman_wrapper; update_with_flatpak ;; update_with_pacman_wrapper; update_with_flatpak ;;
g) g)
[[ $1 = -g ]] && update_with_pacman_wrapper if [ "$1" == "-g" ]; then
update_with_pacman_wrapper; update_with_flatpak
fi
FINAL_COMMAND="systemctl --check-inhibitors=yes poweroff" ;; FINAL_COMMAND="systemctl --check-inhibitors=yes poweroff" ;;
r) r)
[[ $1 = -r ]] && update_with_pacman_wrapper if [ "$1" == "-r" ]; then
update_with_pacman_wrapper; update_with_flatpak
fi
FINAL_COMMAND="systemctl --check-inhibitors=yes reboot" ;; FINAL_COMMAND="systemctl --check-inhibitors=yes reboot" ;;
?) ?)
help; exit 1;; help; exit 1;;