switch from sudo to su

and moved some stuff around
This commit is contained in:
AustrianToast 2024-07-13 01:04:31 +02:00
parent fe9d5936e7
commit c28fbf309e
Signed by: AustrianToast
GPG Key ID: 378A29F999424B1C

26
update
View File

@ -22,16 +22,25 @@ check_for_valid_backup_location() {
fi fi
} }
[[ $BACKUP_LOCATION ]] && check_for_valid_backup_location "$BACKUP_LOCATION" || echo -e "${IRED}No BACKUP_LOCATION specified${NO_COLOR}" || exit 1 if [ $BACKUP_LOCATION ]; then
check_for_valid_backup_location "$BACKUP_LOCATION"
else
echo -e "${IRED}No BACKUP_LOCATION in $HOME/.config/update.conf specified${NO_COLOR}"
exit 1
fi
[[ $SECONDARY_BACKUP_LOCATION ]] && check_for_valid_backup_location "$SECONDARY_BACKUP_LOCATION" [[ $SECONDARY_BACKUP_LOCATION ]] && check_for_valid_backup_location "$SECONDARY_BACKUP_LOCATION"
trap interrupt_function INT 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 --force /var/lib/pacman/db.lck > /dev/null 2>&1 if [ -f /var/lib/pacman/db.lck ]; then
rm --recursive --force "$TMP" > /dev/null 2>&1 echo -e "${IYELLOW}Trying to unlock the pacman db. Please enter your password.${NO_COLOR}"
rm --force "$BACKUP_LOCATION"/before-backup_"$DATE".tar.zst.new "$BACKUP_LOCATION"/after-backup_"$DATE".tar.zst.new su --command="rm --force /var/lib/pacman/db.lck" > /dev/null 2>&1
fi
[[ -d $TMP ]] && rm --recursive --force "$TMP"
[[ -f "$BACKUP_LOCATION"/before-backup_"$DATE".tar.zst.new ]] && rm --force "$BACKUP_LOCATION"/before-backup_"$DATE".tar.zst.new
[[ -f "$BACKUP_LOCATION"/after-backup_"$DATE".tar.zst.new ]] && rm --force "$BACKUP_LOCATION"/after-backup_"$DATE".tar.zst.new
exit 1 exit 1
} }
@ -49,7 +58,9 @@ lock_pacman_db() {
echo -e "${IYELLOW}->${NO_COLOR} there might be another instance of pacman running. exiting..." echo -e "${IYELLOW}->${NO_COLOR} there might be another instance of pacman running. exiting..."
exit 1 exit 1
fi fi
sudo touch /var/lib/pacman/db.lck
echo -e "${IYELLOW}Trying to lock the pacman db. Please enter your password.${NO_COLOR}"
su --command="touch /var/lib/pacman/db.lck"
} }
delete_oldest_backup() { delete_oldest_backup() {
@ -70,7 +81,8 @@ before_backup() {
mv "$TMP"/before-backup_"$DATE".tar.zst.new "$BACKUP_LOCATION" mv "$TMP"/before-backup_"$DATE".tar.zst.new "$BACKUP_LOCATION"
[[ $SECONDARY_BACKUP_LOCATION ]] && mv "$TMP"/before-backup_"$DATE".tar.zst.new "$SECONDARY_BACKUP_LOCATION" [[ $SECONDARY_BACKUP_LOCATION ]] && mv "$TMP"/before-backup_"$DATE".tar.zst.new "$SECONDARY_BACKUP_LOCATION"
sudo rm --force /var/lib/pacman/db.lck echo -e "${IYELLOW}Trying to unlock the pacman db. Please enter your password.${NO_COLOR}"
su --command="rm --force /var/lib/pacman/db.lck"
} }
after_backup() { after_backup() {
@ -115,6 +127,6 @@ if [[ ${1:0:2} == \-\- ]]; then
exit 0 exit 0
fi fi
before_backup && echo -e "${IGREEN}pre-backup complete${NO_COLOR}" before_backup && echo -e "${IGREEN}before-backup complete${NO_COLOR}"
update update
after_backup && echo -e "${IGREEN}after-backup complete${NO_COLOR}" after_backup && echo -e "${IGREEN}after-backup complete${NO_COLOR}"