-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-system.sh
More file actions
executable file
·70 lines (53 loc) · 2.35 KB
/
update-system.sh
File metadata and controls
executable file
·70 lines (53 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
! [[ -x "$(command -v checkupdates)" ]] && echo "required package pacman-contrib is not installed" && exit 1
# save current week day
day=$(date '+%u')
echo "Checking for updates ..."
upgradable=$(checkupdates | wc -l)
packages() {
if [[ "$upgradable" -eq 0 ]]; then echo "There are currently no package updates."; return
else echo "$upgradable updates available." && read -rp "update the system? (y/N) " choice_update; fi
if [[ ${choice_update,,} != 'y' ]]; then return; fi
# update system if user chooses to
echo "It's $(date +"%A"), time to update"
# use paru to upgrade packages if paru is installed
if [ -x "$(command -v paru)" ]; then echo "Updating Packages ..." && paru -Syu;
# use yay to upgrade packages if yay is installed
elif [ -x "$(command -v yay)" ]; then echo "Updating Packages ..." && yay -Syu;
# use pamac to upgrade packages if pamac is installed
elif [ -x "$(command -v pamac)" ]; then echo "Updating Packages ..." && sudo pamac update -a;
# use trizen to upgrade packages if trizen is installed
elif [ -x "$(command -v trizen)" ]; then echo "Updating Packages ..." && trizen -Syu;
# use pacman to upgrade packages
else echo "Updating Packages ..." && sudo pacman -Syu; fi
# update flatpaks if flatpak is installed
[ -x "$(command -v flatpak)" ] && echo "Updating Flatpaks" && flatpak update
# update snaps if snap is installed
[ -x "$(command -v snap)" ] && echo "Updating Snaps" && sudo snap refresh
}
cache() {
# clear packages if paccache is installed
[ -x "$(command -v paccache)" ] && paccache -d || return
read -rp 'Clean pacman cache? (y/N) ' choice_cache
[[ ${choice_cache,,} == 'y' ]] && sudo paccache -r
# checks if orphan packages exists
if [[ "$(pacman -Qtdq | wc -l)" -eq 0 ]]; then echo "No orphans packages were found";
else
read -rp 'Want to remove orphaned packages? (y/N) ' choice_orphend
[[ ${choice_orphend,,} == 'y' ]] && sudo pacman -Rsn "$(pacman -Qtdq)"
fi
}
# if today is Friday then update
# if not just cache the updates
if [ "$day" == 5 ];
then
packages
cache
else
# just downloads packages
# it doesn't install them
[[ -x "$(command -v pacman)" ]] && [[ "$upgradable" -gt 0 ]] && (
echo "packages are being downloaded"
sudo pacman -Syuw --needed --noconfirm
)
fi