-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaur.sh
executable file
·221 lines (165 loc) · 5.19 KB
/
aur.sh
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/env bash
#
# A simple script in bash to interact
# with the Arch User Repository (AUR).
#
# usage: aur {option} [package]
# options:
# -S, --sync install selected package from AUR
# -Su, --update update installed packages from AUR
# -Sy, --refresh check for new package versions in AUR
# -Sw, --download clone repository files from AUR only
# -Ss, --search search for packages matching name
# -Sc, -Scc, --clean remove uninstalled packages
# -R, --remove remove a package and delete files
# -Q, -Qq, --query check local installed packages
# -F, --find find and list packages in AUR
# -w, --web open AUR package page on web browser
#
# Requires "package-query" from AUR:
# https://aur.archlinux.org/packages/package-query/
#
# To install it, run:
# $ ./aur.sh package-query
# define user settings
DIR="/home/$USER/.aur/" # default path for cloning scripts
# define vars
ARG="$1" # argument to execute
PKG="$2" # package from AUR
# define functions
function help {
head -n 17 "$0" | tail -n 12 | sed 's/# //'; }
function sync {
if [[ "$PKG" != "" ]]; then
cd "$DIR"
[[ -d "$PKG" ]] &&
cd "$PKG" &&
git pull
[[ ! -d "$PKG" ]] &&
download
[[ -d "$PKG" ]] &&
cd "$PKG"
makepkg -siCcfr --needed --asdeps
else echo 'error: no target specified (use -h for help)'; fi; }
function download {
if [[ "$PKG" = "" ]]; then
echo 'error: no target specified (use -h for help)'; exit 1
elif [[ -d "$PKG" ]]; then
echo "$PKG folder already exists."; exit 1
else # download and check
git clone "https://aur.archlinux.org/${PKG}.git"
[[ "$(ls -1a "$PKG" | wc -l)" = 3 ]] &&
rm -r "$PKG"; fi; }
function refresh {
echo ":: Checking AUR for updated packages..."
package-query -Au; }
function update {
cd "$DIR"
echo ":: Starting AUR packages upgrade..."
package-query -Au | tee "$DIR/.aur"
sed -i 's:aur/::;s: .*::' "$DIR/.aur"
[[ "$(cat "$DIR/.aur")" = "" ]] &&
echo " there is nothing to do" &&
exit 1
[[ "$UPDATE" = "" ]] &&
printf "\nUpdate $(wc -l "$DIR/.aur" | cut -c1) packages? [Y/n] " &&
read UPDATE
if [[ "${UPDATE,,}" = y ]]; then
while read PKG; do
echo -e "\nUpdating ${PKG}..."
[[ -d "$PKG" ]] &&
cd "$PKG" &&
git pull
[[ ! -d "$PKG" ]] &&
download
[[ -d "$PKG" ]] &&
cd "$PKG"
makepkg -siCcfr --noconfirm --needed --asdeps
cd ..
done < "$DIR/.aur"
rm -f "$DIR/.aur"; fi; }
function remove {
cd "$DIR"
[[ -d "$PKG" ]] &&
rm -rf "$PKG"; }
function clean {
[[ "$ARG" = "-Scc" ]] &&
CLEAN_ALL=true ||
echo -e "Packages to keep:\n All locally installed packages"
[[ -d "$DIR" ]] &&
cd "$DIR" &&
echo -e "\nCache directory (AUR): $DIR"
printf ":: Do you want to remove $([[ $CLEAN_ALL = true ]] && echo 'ALL' || echo 'all other') files from cache? [Y/n] " &&
read CLEAN
if [[ "${CLEAN,,}" = y ]]; then
echo "removing $( [[ $CLEAN_ALL = true ]] && echo all||echo old ) packages from cache..."
packages="$(package-query -Q | grep 'local/' | grep "$PKG" | sed 's:local/::' | sort)"
for i in *; do
[[ ! "$packages" = *"$i"* || $CLEAN_ALL = true ]] &&
rm -rf "$i"; done; fi; }
function query {
package-query -Q | grep 'local/' \
| sed 's:local/::' \
| sort \
| ( [[ "$ARG" = "-Qq" || "${PKG:0:2}" = "-q" ]] && sed 's/ .*//' || cat ); }
function search {
package-query -As --nameonly "$PKG"; }
function find {
RES=$(curl -s "https://aur.archlinux.org/rpc/?v=5&type=search&arg=$PKG")
ERR=$(echo "$RES" | jq -r '.error')
WIDTH=$(stty size | cut -d ' ' -f 2)
if [[ "$ERR" != "null" ]]; then
echo $ERR
exit 1
else echo "$RES" | jq -r '.results | .[] | .Name + "|" +
.Version + "|" +
.Description' |
column -t -s '|' |
cut -c 1-${WIDTH} |
sort; fi; }
function web {
URL="https://aur.archlinux.org/packages/$PKG"
xdg-open "$URL"; }
function as_root {
if [[ ! $EUID -ne 0 && ! "$*" = *'--root' ]]; then
echo -e "error: root privileges detected\nrun as '--root' to explicity bypass this warning" 1>&2
exit 1; fi; }
# execute
mkdir -p "$DIR"
case "$ARG" in
-S|--sync)
as_root
sync
;;
-Su|--update)
as_root
update
;;
-Sy|--refresh)
refresh
;;
-Ss|--search)
search
;;
-Sc|-Scc|--clean)
clean
;;
-Sw|--download)
download
;;
-R|--remove)
remove
;;
-Q|-Qq|--query)
query
;;
-F|--find)
find
;;
-w|--web)
web
;;
*) # default
help
;;
esac # finishes