Made flatpak optional and some code cleanup #11
2
makefile
2
makefile
@ -1,4 +1,4 @@
|
|||||||
VER = "v1.5"
|
VER = "v1.6"
|
||||||
|
|
||||||
install:
|
install:
|
||||||
@echo "==> Installing update $(VER) into /usr/local/bin"
|
@echo "==> Installing update $(VER) into /usr/local/bin"
|
||||||
|
26
update
26
update
@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# updates using a pacman-wrapper and flatpak-update with flags
|
# updates using a pacman-wrapper and flatpak-update with flags
|
||||||
# version 1.5
|
# version 1.6
|
||||||
|
|
||||||
source "$HOME"/.config/update.conf
|
source "$HOME"/.config/update.conf
|
||||||
|
|
||||||
@ -9,10 +9,10 @@ IGREEN="\033[0;92m" # Intense Green
|
|||||||
IYELLOW="\033[0;93m" # Intense Red
|
IYELLOW="\033[0;93m" # Intense Red
|
||||||
NC="\033[0m" # Text Reset
|
NC="\033[0m" # Text Reset
|
||||||
TMP="/tmp/backup"
|
TMP="/tmp/backup"
|
||||||
DATE="$(date +%s)"
|
DATE="$(date +"%Y-%m-%d %H:%M:%S")"
|
||||||
PRE_BACKUP_AMOUNT="$(ls -Ub "$BACKUP_LOCATION"/ | grep -c ^before-backup)"
|
PRE_BACKUP_AMOUNT="$(ls -Ub "$BACKUP_LOCATION"/ | grep -c ^before-backup)"
|
||||||
|
POST_BACKUP_AMOUNT="$(ls -Ub "$BACKUP_LOCATION"/ | grep -c ^after-backup)"
|
||||||
|
|
||||||
# output if wrong flag is used
|
|
||||||
Help() {
|
Help() {
|
||||||
echo "Usage: update [OPTION]"
|
echo "Usage: update [OPTION]"
|
||||||
echo
|
echo
|
||||||
@ -27,37 +27,37 @@ Help() {
|
|||||||
echo "-P, --preview shows a preview of which pkg's will be updates"
|
echo "-P, --preview shows a preview of which pkg's will be updates"
|
||||||
}
|
}
|
||||||
|
|
||||||
# creates package lists, moves them into a tar, adds some other files and adds the pacman database
|
|
||||||
# it then rsyncs the tar to the backup location
|
|
||||||
before_backup() {
|
before_backup() {
|
||||||
#if [[ $PRE_BACKUP_AMOUNT > $BACKUP_AMOUNT ]]; then
|
if [[ $PRE_BACKUP_AMOUNT > $BACKUP_AMOUNT ]]; then
|
||||||
# echo "yay"
|
OLDEST_FILE="$(ls -t "$BACKUP_LOCATION" | grep before-backup | tail -1)"
|
||||||
#fi
|
rm "$BACKUP_LOCATION"/"$OLDEST_FILE"
|
||||||
|
fi
|
||||||
[[ ! -d /tmp/backup ]] && mkdir /tmp/backup
|
[[ ! -d /tmp/backup ]] && mkdir /tmp/backup
|
||||||
pacman -Q > "$TMP"/pacman-pre.txt
|
pacman -Q > "$TMP"/pacman-pre.txt
|
||||||
flatpak list > "$TMP"/flatpak-pre.txt
|
flatpak list > "$TMP"/flatpak-pre.txt
|
||||||
sudo touch /var/lib/pacman/db.lck
|
sudo touch /var/lib/pacman/db.lck
|
||||||
tar -cJf "$TMP"/before-backup_"$DATE".tar.xz.new "$TMP"/pacman-pre.txt "$TMP"/flatpak-pre.txt /var/lib/pacman/local &> /dev/null
|
tar -cJf "$TMP"/before-backup_"$DATE".tar.xz.new "$TMP"/pacman-pre.txt "$TMP"/flatpak-pre.txt /var/lib/pacman/local &> /dev/null
|
||||||
sudo rm /var/lib/pacman/db.lck
|
sudo rm /var/lib/pacman/db.lck
|
||||||
rsync "$TMP"/before-backup_"$DATE".tar.xz.new "$BACKUP_LOCATION"
|
cp "$TMP"/before-backup_"$DATE".tar.xz.new "$BACKUP_LOCATION"
|
||||||
rename before-backup_"$DATE".tar.xz.new before-backup_"$DATE".tar.xz "$BACKUP_LOCATION"/before-backup_"$DATE".tar.xz.new
|
rename before-backup_"$DATE".tar.xz.new before-backup_"$DATE".tar.xz "$BACKUP_LOCATION"/before-backup_"$DATE".tar.xz.new
|
||||||
}
|
}
|
||||||
|
|
||||||
# moves the package lists into a tar, it then rsyncs the tar to the backup location
|
|
||||||
after_backup() {
|
after_backup() {
|
||||||
|
if [[ $POST_BACKUP_AMOUNT > $BACKUP_AMOUNT ]]; then
|
||||||
|
OLDEST_FILE="$(ls -t "$BACKUP_LOCATION" | grep after-backup | tail -1)"
|
||||||
|
rm "$BACKUP_LOCATION"/"$OLDEST_FILE"
|
||||||
|
|||||||
|
fi
|
||||||
tar -cJf "$TMP"/after-backup_"$DATE".tar.xz.new "$TMP"/pacman-after.txt "$TMP"/flatpak-after.txt &> /dev/null
|
tar -cJf "$TMP"/after-backup_"$DATE".tar.xz.new "$TMP"/pacman-after.txt "$TMP"/flatpak-after.txt &> /dev/null
|
||||||
rsync "$TMP"/after-backup_"$DATE".tar.xz.new "$BACKUP_LOCATION"
|
cp "$TMP"/after-backup_"$DATE".tar.xz.new "$BACKUP_LOCATION"
|
||||||
rename after-backup_"$DATE".tar.xz.new after-backup_"$DATE".tar.xz "$BACKUP_LOCATION"/after-backup_"$DATE".tar.xz.new
|
rename after-backup_"$DATE".tar.xz.new after-backup_"$DATE".tar.xz "$BACKUP_LOCATION"/after-backup_"$DATE".tar.xz.new
|
||||||
rm -r /tmp/backup
|
rm -r /tmp/backup
|
||||||
}
|
}
|
||||||
|
|
||||||
# updates using a pacman-wrapper
|
|
||||||
update_with_pacman_wrapper() {
|
update_with_pacman_wrapper() {
|
||||||
"$PACMAN_WRAPPER"
|
"$PACMAN_WRAPPER"
|
||||||
pacman -Q > "$TMP"/pacman-after.txt
|
pacman -Q > "$TMP"/pacman-after.txt
|
||||||
}
|
}
|
||||||
|
|
||||||
# updates using flatpak-update
|
|
||||||
update_with_flatpak() {
|
update_with_flatpak() {
|
||||||
flatpak update -u --noninteractive
|
flatpak update -u --noninteractive
|
||||||
flatpak list > "$TMP"/flatpak-after.txt
|
flatpak list > "$TMP"/flatpak-after.txt
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
BACKUP_LOCATION=~/
|
BACKUP_LOCATION=~/
|
||||||
|
|
||||||
# use this pacman-wrapper
|
# use this pacman-wrapper
|
||||||
PACMAN_WRAPPER=paru
|
PACMAN_WRAPPER=yay
|
||||||
|
|
||||||
# how many different backups to keep
|
# how many different backups to keep
|
||||||
BACKUP_AMOUNT=2
|
BACKUP_AMOUNT=2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user
Creates an error message when executing it because the directory cannot exist beforehand.
Error was addressed. Ready to merge.