Compare commits
No commits in common. "91eb6be7c63e4af051ad7d8f239a1cb6ab52fb9a" and "fe9d5936e7d01a9872fd550cb03e45f479cf90fd" have entirely different histories.
91eb6be7c6
...
fe9d5936e7
36
update
36
update
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
VERSION="3.1"
|
||||
VERSION="3.0.0"
|
||||
IGREEN="\033[0;92m" # Intense Green
|
||||
IYELLOW="\033[0;93m" # Intense Yellow
|
||||
IRED='\033[0;91m' # Red
|
||||
@ -22,25 +22,16 @@ check_for_valid_backup_location() {
|
||||
fi
|
||||
}
|
||||
|
||||
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
|
||||
[[ $BACKUP_LOCATION ]] && check_for_valid_backup_location "$BACKUP_LOCATION" || echo -e "${IRED}No BACKUP_LOCATION specified${NO_COLOR}" || exit 1
|
||||
[[ $SECONDARY_BACKUP_LOCATION ]] && check_for_valid_backup_location "$SECONDARY_BACKUP_LOCATION"
|
||||
|
||||
trap interrupt_function INT
|
||||
|
||||
interrupt_function() {
|
||||
echo "Interrupt has been detected"
|
||||
if [ -f /var/lib/pacman/db.lck ]; then
|
||||
echo -e "${IYELLOW}Trying to unlock the pacman db. Please enter your password.${NO_COLOR}"
|
||||
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
|
||||
[[ -f /var/lib/pacman/db.lck ]] && sudo rm --force /var/lib/pacman/db.lck > /dev/null 2>&1
|
||||
rm --recursive --force "$TMP" > /dev/null 2>&1
|
||||
rm --force "$BACKUP_LOCATION"/before-backup_"$DATE".tar.zst.new "$BACKUP_LOCATION"/after-backup_"$DATE".tar.zst.new
|
||||
exit 1
|
||||
}
|
||||
|
||||
@ -58,14 +49,7 @@ lock_pacman_db() {
|
||||
echo -e "${IYELLOW}->${NO_COLOR} there might be another instance of pacman running. exiting..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${IYELLOW}Trying to lock the pacman db. Please enter your password.${NO_COLOR}"
|
||||
su --command="touch /var/lib/pacman/db.lck"
|
||||
}
|
||||
|
||||
unlock_pacman_db() {
|
||||
echo -e "${IYELLOW}Trying to unlock the pacman db. Please enter your password.${NO_COLOR}"
|
||||
su --command="rm --force /var/lib/pacman/db.lck"
|
||||
sudo touch /var/lib/pacman/db.lck
|
||||
}
|
||||
|
||||
delete_oldest_backup() {
|
||||
@ -76,7 +60,6 @@ delete_oldest_backup() {
|
||||
|
||||
before_backup() {
|
||||
lock_pacman_db
|
||||
|
||||
[[ -d $TMP ]] && rm --recursive --force "$TMP"
|
||||
mkdir --parents "$TMP"/before-backup_"$DATE" "$TMP"/after-backup_"$DATE"
|
||||
|
||||
@ -87,12 +70,10 @@ before_backup() {
|
||||
mv "$TMP"/before-backup_"$DATE".tar.zst.new "$BACKUP_LOCATION"
|
||||
[[ $SECONDARY_BACKUP_LOCATION ]] && mv "$TMP"/before-backup_"$DATE".tar.zst.new "$SECONDARY_BACKUP_LOCATION"
|
||||
|
||||
unlock_pacman_db
|
||||
sudo rm --force /var/lib/pacman/db.lck
|
||||
}
|
||||
|
||||
after_backup() {
|
||||
lock_pacman_db
|
||||
|
||||
pacman --verbose --query > "$TMP"/after-backup_"$DATE"/pacman-after.txt
|
||||
[[ -x /usr/bin/flatpak ]] && flatpak list --all --show-details > "$TMP"/after-backup_"$DATE"/flatpak-after.txt
|
||||
tar --create --zstd --file "$TMP"/after-backup_"$DATE".tar.zst.new "$TMP"/after-backup_"$DATE" > /dev/null 2>&1
|
||||
@ -107,7 +88,6 @@ after_backup() {
|
||||
mv "$BACKUP_LOCATION"/before-backup_"$DATE".tar.zst.new "$BACKUP_LOCATION"/before-backup_"$DATE".tar.zst
|
||||
[[ $SECONDARY_BACKUP_LOCATION ]] && mv "$SECONDARY_BACKUP_LOCATION"/before-backup_"$DATE".tar.zst.new "$SECONDARY_BACKUP_LOCATION"/before-backup_"$DATE".tar.zst
|
||||
|
||||
unlock_pacman_db
|
||||
rm --recursive --force "$TMP"
|
||||
}
|
||||
|
||||
@ -135,6 +115,6 @@ if [[ ${1:0:2} == \-\- ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
before_backup && echo -e "${IGREEN}before-backup complete${NO_COLOR}"
|
||||
before_backup && echo -e "${IGREEN}pre-backup complete${NO_COLOR}"
|
||||
update
|
||||
after_backup && echo -e "${IGREEN}after-backup complete${NO_COLOR}"
|
||||
|
Loading…
Reference in New Issue
Block a user