Compare commits

...

5 Commits

Author SHA1 Message Date
e4e6f51bdb
fix indentation 2024-07-07 01:31:29 +02:00
0db312e8a0
now supports secondary backup 2024-07-07 01:30:36 +02:00
2fff3ce2a2
better backup location checks 2024-07-07 01:17:06 +02:00
b7a2dc89be
add secondary backup location 2024-07-07 01:16:00 +02:00
afab665ca6
switch to makefile
and more changes
2024-07-07 01:15:10 +02:00
3 changed files with 51 additions and 28 deletions

View File

@ -1,14 +1,10 @@
# Update
Update script written in Bash for Arch Linux only. Keeps all your pacman and aur packages as well as your flatpaks up to date with one simple script. It also backups a list of all your pacman and aur packages and flatpaks.
Update script written in Bash for Arch Linux only. Keeps all your official, aur packages and your flatpaks up to date with one simple script. It also backups a list of all your installed packages and flatpaks.
## Requirements
Here is what is required.
```bash
pacman -S just
```
It also technically requires sudo, but if you use something else, then just create a softlink for this script to work.<br/>
It requires sudo, but if you use something else, then just create a softlink for this script to work.
Doing that would look like this.
```bash
ln -s /usr/bin/your_program /usr/bin/sudo
@ -20,10 +16,10 @@ ln -s /usr/bin/your_program /usr/bin/sudo
git clone https://gitea.hopeless-cloud.xyz/AustrianToast/update.git && cd update
```
Before installing, please edit the config and configure it to your liking.<br/>
Before installing, please edit the config and configure it to your liking.
Then install using
```bash
just install
make
```
## Usage
@ -44,6 +40,5 @@ no flag same as -p
--backup just does the before-backup without updating
```
## Contributing
## Contributing
Contributions are always welcome!

59
update
View File

@ -1,9 +1,6 @@
#!/usr/bin/bash
source "$HOME"/.config/update.conf || exit 1
[[ ! -d $BACKUP_LOCATION ]] && mkdir --parents "$BACKUP_LOCATION"
VERSION="2.1.0"
VERSION="2.1.1"
IGREEN="\033[0;92m" # Intense Green
IYELLOW="\033[0;93m" # Intense Yellow
NO_COLOR="\033[0m" # Text Reset
@ -11,6 +8,30 @@ 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 || exit 1
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 "$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
fi
trap interrupt_function INT
interrupt_function() {
@ -22,19 +43,19 @@ 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"
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() {
@ -62,6 +83,7 @@ before_backup() {
tar --create --zstd --file "$TMP"/before-backup_"$DATE".tar.zst.new "$TMP"/before-backup_"$DATE" /var/lib/pacman/local > /dev/null 2>&1 # for some reason it needs the output suppresion
mv "$TMP"/before-backup_"$DATE".tar.zst.new "$BACKUP_LOCATION"
[[ $SECONDARY_BACKUP_LOCATION ]] && mv "$TMP"/before-backup_"$DATE".tar.zst.new "$SECONDARY_BACKUP_LOCATION"
sudo rm --force /var/lib/pacman/db.lck
}
@ -72,11 +94,14 @@ after_backup() {
tar --create --zstd --file "$TMP"/after-backup_"$DATE".tar.zst.new "$TMP"/after-backup_"$DATE" > /dev/null 2>&1
mv "$TMP"/after-backup_"$DATE".tar.zst.new "$BACKUP_LOCATION"
[[ $SECONDARY_BACKUP_LOCATION ]] && mv "$TMP"/before-backup_"$DATE".tar.zst.new "$SECONDARY_BACKUP_LOCATION"
delete_oldest_backup after-backup
mv "$BACKUP_LOCATION"/after-backup_"$DATE".tar.zst.new "$BACKUP_LOCATION"/after-backup_"$DATE".tar.zst
[[ $SECONDARY_BACKUP_LOCATION ]] && mv "$SECONDARY_BACKUP_LOCATION"/after-backup_"$DATE".tar.zst.new "$SECONDARY_BACKUP_LOCATION"/after-backup_"$DATE".tar.zst
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"
}

View File

@ -1,6 +1,9 @@
# Backup to this folder
# backup to this folder
BACKUP_LOCATION=~/
# optional secondary backup loaction
#SECONDARY_BACKUP_LOCATION=~/
# use this pacman-wrapper
PACMAN_WRAPPER=yay