forked from Sakurasaki-Hiro/pacup
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pacup
executable file
·144 lines (125 loc) · 3.18 KB
/
pacup
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
function usage() {
cat <<EOM
Usage: $(basename "$0") [OPTION]...
-p Run Pacman only
-h Show help
EOM
}
while (($#>0)); do
case $1 in
p|-p|--pacman)
PACUP_MOD="pacman"
;;
h|-h|--help)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
shift
done
function PACUP_PACMAN() {
echo -e "Updating Pacman packages..."
if [[ "$(whoami)" != "root" && $(command -v checkupdates) ]]; then
checkupdates > /dev/null
if [ $? == 0 ]; then
sudo pacman -Syu
else
echo "No Pacman updates available."
fi
else
sudo pacman -Syu
fi
}
function PACUP_ORPHAN() {
echo -e "\nChecking for orphaned packages..."
pkgs="$(pacman -Qtdq)"
if [[ ! -z "$pkgs" ]]
then
echo -e "The following packages are installed but not required (anymore):\n$pkgs\n"
read -p "Do you want to (r)emove, mark them as (e)xplicit or (i)gnore? [r|e|I] " choice
case "$choice" in
r|R ) echo -e "Removing orphaned packages\n" && sudo pacman -Rns $(pacman -Qtdq);;
e|E ) echo -e "Marking orphaned packages as explicit\n" && sudo pacman -D --asexplicit $pkgs;;
* ) echo "No orphaned packages removed";;
esac
else
echo "No orphaned packages."
fi
}
function PACUP_SYS() {
if [ $(command -v snap) ]; then
echo -e "\nUpdating Snap packages..."
pkgs="$(sudo snap refresh --list)"
if [[ ! -z "$pkgs" ]]; then
sudo snap refresh
else
echo "No updates available."
fi
fi
if [ $(command -v flatpak) ]; then
echo -e "\nUpdating Flatpak packages..."
system_pkgs="$(flatpak remote-ls --updates)"
user_pkgs="$(flatpak remote-ls --user --updates)"
all_pkgs="$system_pkgs$user_pkgs"
# Check if there are any updates available
if [[ ! -z "$all_pkgs" ]]; then
sudo flatpak update --noninteractive --assumeyes
flatpak update --user --noninteractive --assumeyes
else
echo "No Flatpak updates available."
fi
fi
}
function PACUP_AUR_ROOT() {
if [ "$(whoami)" == "root" ]; then
echo -e "\nBecause you are running as root, the AUR operation is skipped."
echo -e "\nDone!"
exit 0
fi
PACUP_AUR
}
function PACUP_AUR() {
yay_available=$(command -v yay)
paru_available=$(command -v paru)
pacaur_available=$(command -v pacaur)
pikaur_available=$(command -v pikaur)
aura_available=$(command -v yay)
if [[ $yay_available || $paru_available || $pacaur_available || $pikaur_available || $aura_available ]]; then
echo -e "\nUpdating AUR packages..."
if [ $yay_available ]; then
yay -Sayu
elif [ $paru_available ]; then
paru -Sayu
elif [ $pacaur_available ]; then
pacaur -Sayu
elif [ $pikaur_available ]; then
pikaur -Sayu
elif [ $aura_available ]; then
aura -Au
fi
fi
}
if [ "$PACUP_MOD" == "pacman" ]; then
sudo echo -n
if [ $? != 0 ]; then
echo -e "\nPacman command requires root privileges.\nPlease try again.\n"
sudo echo -n
if [ $? != 0 ]; then
echo -e "\nExecution terminated because privilege elevation failed."
exit 1
fi
fi
PACUP_PACMAN
exit 0
fi
PACUP_PACMAN
PACUP_SYS
PACUP_AUR_ROOT
PACUP_ORPHAN
echo -e "\nDone!"
exit 0