Compare commits
No commits in common. "6f9ee34a945450bf80fbca48b5c43ae665225e30" and "3c2ecc72ae77d3cf3e4c856e7b1119c3945283fa" have entirely different histories.
6f9ee34a94
...
3c2ecc72ae
69
update
69
update
@ -1,29 +1,36 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
VERSION="3.0.0"
|
||||
VERSION="2.1.1"
|
||||
IGREEN="\033[0;92m" # Intense Green
|
||||
IYELLOW="\033[0;93m" # Intense Yellow
|
||||
IRED='\033[0;91m' # Red
|
||||
NO_COLOR="\033[0m" # Text Reset
|
||||
TMP="/tmp/update"
|
||||
DATE="$(date +"%Y-%m-%dT%H:%M:%S%:z")" # RFC 3339 date-time https://datatracker.ietf.org/doc/html/rfc3339#section-5.6
|
||||
FINAL_COMMAND="true"
|
||||
|
||||
source "$HOME"/.config/update.conf || echo -e "${IRED}No config found${NO_COLOR}" || exit 1
|
||||
source "$HOME"/.config/update.conf || exit 1
|
||||
|
||||
check_for_valid_backup_location() {
|
||||
if [ ! -d $1 ]; then
|
||||
echo -e "${IYELLOW}$1 doesn't exist${NO_COLOR}"
|
||||
if [ ! -d $BACKUP_LOCATION ]; then
|
||||
echo -e "${IYELLOW}Backup location doesn't exist${NO_COLOR}"
|
||||
read -p "Do you want to create the path and continue? [y/N]" input
|
||||
case $input in
|
||||
[Yy]) mkdir --parents "$1" ;;
|
||||
[Yy]) mkdir --parents "$BACKUP_LOCATION" ;;
|
||||
[Nn]) exit 0;;
|
||||
* ) exit 0 ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ $SECONDARY_BACKUP_LOCATION ]; then
|
||||
if [ ! -d $SECONDARY_BACKUP_LOCATION ]; then
|
||||
echo -e "${IYELLOW}Secondary Backup location doesn't exist${NO_COLOR}"
|
||||
read -p "Do you want to create the path and continue? [y/N]" input
|
||||
case $input in
|
||||
[Yy]) mkdir --parents "$SECONDARY_BACKUP_LOCATION" ;;
|
||||
[Nn]) exit 0;;
|
||||
* ) exit 0 ;;
|
||||
esac
|
||||
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"
|
||||
fi
|
||||
|
||||
trap interrupt_function INT
|
||||
|
||||
@ -37,10 +44,18 @@ interrupt_function() {
|
||||
|
||||
help() {
|
||||
echo "Usage: update [OPTION]"
|
||||
echo
|
||||
echo "options:"
|
||||
echo "no option 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"
|
||||
echo "-g shutdowns the computer afterwards"
|
||||
echo "-r reboots the computer afterwards"
|
||||
echo "--help displays this message"
|
||||
echo "--preview shows a preview of pkg's and flatpaks which can be updated"
|
||||
echo "--version prints out the version number"
|
||||
echo "--backup just does the before-backup without updating"
|
||||
}
|
||||
|
||||
lock_pacman_db() {
|
||||
@ -109,6 +124,12 @@ if [[ ${1:0:2} == \-\- ]]; then
|
||||
[[ -x /usr/bin/flatpak ]] && flatpak remote-ls --updates ;;
|
||||
version)
|
||||
echo "$VERSION" ;;
|
||||
backup)
|
||||
before_backup
|
||||
delete_oldest_backup before-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
|
||||
rm --recursive --force "$TMP" ;;
|
||||
?)
|
||||
help; exit 1;;
|
||||
esac
|
||||
@ -116,5 +137,29 @@ if [[ ${1:0:2} == \-\- ]]; then
|
||||
fi
|
||||
|
||||
before_backup && echo -e "${IGREEN}pre-backup complete${NO_COLOR}"
|
||||
update
|
||||
|
||||
[[ -z $1 ]] && update
|
||||
while getopts 'fpagr' OPTIONS; do
|
||||
case $OPTIONS in
|
||||
f)
|
||||
if [[ -x /usr/bin/flatpak ]]; then
|
||||
flatpak update --assumeyes
|
||||
flatpak list --all --show-details > "$TMP"/after-backup_"$DATE"/flatpak-after.txt
|
||||
fi ;;
|
||||
p)
|
||||
"$PACMAN_WRAPPER" ;;
|
||||
a)
|
||||
update ;;
|
||||
g)
|
||||
[[ $1 == \-\g ]] && update
|
||||
FINAL_COMMAND="systemctl --check-inhibitors=yes poweroff" ;;
|
||||
r)
|
||||
[[ $1 == \-\r ]] && update
|
||||
FINAL_COMMAND="systemctl --check-inhibitors=yes reboot" ;;
|
||||
?)
|
||||
help; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
after_backup && echo -e "${IGREEN}after-backup complete${NO_COLOR}"
|
||||
$FINAL_COMMAND && exit 0
|
||||
|
@ -8,4 +8,4 @@ BACKUP_LOCATION=~
|
||||
PACMAN_WRAPPER=yay
|
||||
|
||||
# how many different backups to keep
|
||||
BACKUP_AMOUNT=10
|
||||
BACKUP_AMOUNT=2
|
||||
|
Loading…
Reference in New Issue
Block a user