Compare commits
4 Commits
3c2ecc72ae
...
6f9ee34a94
Author | SHA1 | Date | |
---|---|---|---|
6f9ee34a94 | |||
3198a02081 | |||
6593f087c4 | |||
8b5704f397 |
67
update
67
update
@ -1,36 +1,29 @@
|
|||||||
#!/usr/bin/bash
|
#!/usr/bin/bash
|
||||||
|
|
||||||
VERSION="2.1.1"
|
VERSION="3.0.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
|
||||||
|
IRED='\033[0;91m' # Red
|
||||||
NO_COLOR="\033[0m" # Text Reset
|
NO_COLOR="\033[0m" # Text Reset
|
||||||
TMP="/tmp/update"
|
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
|
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 || exit 1
|
source "$HOME"/.config/update.conf || echo -e "${IRED}No config found${NO_COLOR}" || exit 1
|
||||||
|
|
||||||
if [ ! -d $BACKUP_LOCATION ]; then
|
check_for_valid_backup_location() {
|
||||||
echo -e "${IYELLOW}Backup location doesn't exist${NO_COLOR}"
|
if [ ! -d $1 ]; then
|
||||||
|
echo -e "${IYELLOW}$1 doesn't exist${NO_COLOR}"
|
||||||
read -p "Do you want to create the path and continue? [y/N]" input
|
read -p "Do you want to create the path and continue? [y/N]" input
|
||||||
case $input in
|
case $input in
|
||||||
[Yy]) mkdir --parents "$BACKUP_LOCATION" ;;
|
[Yy]) mkdir --parents "$1" ;;
|
||||||
[Nn]) exit 0;;
|
[Nn]) exit 0;;
|
||||||
* ) exit 0 ;;
|
* ) exit 0 ;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
if [ $SECONDARY_BACKUP_LOCATION ]; then
|
[[ $BACKUP_LOCATION ]] && check_for_valid_backup_location "$BACKUP_LOCATION" || echo -e "${IRED}No BACKUP_LOCATION specified${NO_COLOR}" || exit 1
|
||||||
if [ ! -d $SECONDARY_BACKUP_LOCATION ]; then
|
[[ $SECONDARY_BACKUP_LOCATION ]] && check_for_valid_backup_location "$SECONDARY_BACKUP_LOCATION"
|
||||||
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
|
|
||||||
fi
|
|
||||||
|
|
||||||
trap interrupt_function INT
|
trap interrupt_function INT
|
||||||
|
|
||||||
@ -44,18 +37,10 @@ interrupt_function() {
|
|||||||
|
|
||||||
help() {
|
help() {
|
||||||
echo "Usage: update [OPTION]"
|
echo "Usage: update [OPTION]"
|
||||||
echo
|
|
||||||
echo "options:"
|
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 "--help displays this message"
|
||||||
echo "--preview shows a preview of pkg's and flatpaks which can be updated"
|
echo "--preview shows a preview of pkg's and flatpaks which can be updated"
|
||||||
echo "--version prints out the version number"
|
echo "--version prints out the version number"
|
||||||
echo "--backup just does the before-backup without updating"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lock_pacman_db() {
|
lock_pacman_db() {
|
||||||
@ -124,12 +109,6 @@ if [[ ${1:0:2} == \-\- ]]; then
|
|||||||
[[ -x /usr/bin/flatpak ]] && flatpak remote-ls --updates ;;
|
[[ -x /usr/bin/flatpak ]] && flatpak remote-ls --updates ;;
|
||||||
version)
|
version)
|
||||||
echo "$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;;
|
help; exit 1;;
|
||||||
esac
|
esac
|
||||||
@ -137,29 +116,5 @@ if [[ ${1:0:2} == \-\- ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
before_backup && echo -e "${IGREEN}pre-backup complete${NO_COLOR}"
|
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}"
|
after_backup && echo -e "${IGREEN}after-backup complete${NO_COLOR}"
|
||||||
$FINAL_COMMAND && exit 0
|
|
||||||
|
@ -8,4 +8,4 @@ BACKUP_LOCATION=~
|
|||||||
PACMAN_WRAPPER=yay
|
PACMAN_WRAPPER=yay
|
||||||
|
|
||||||
# how many different backups to keep
|
# how many different backups to keep
|
||||||
BACKUP_AMOUNT=2
|
BACKUP_AMOUNT=10
|
||||||
|
Loading…
Reference in New Issue
Block a user