/
aurtool
executable file
·406 lines (385 loc) · 12.9 KB
/
aurtool
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
#!/usr/bin/env bash
#
# Aurtool V1.0.1
#
# Maintainer: Eris Nihila (M1ndFlay3r)
# sp0t1fyfr33tr1alabus3@outlook.com
#
# This software comes with absolutely NO WARRANTY, expressed or implied. Any and all use of this software is entirely
# at your own risk. By using this software you agree to release and forever discharge the developer from all manner of actions,
# cause of action, debts, accounts, bonds, contracts, claims and demands for or by any reason of damage, loss (including data loss)
# or injury to person or property that has been or may be sustained as a result of your usage of this software.
#
# This software is shipped under the GNU General Public License and is provided "as is", with no explicit or implied expectation or
# obligation to provide support, development, or otherwise unspecified services of any kind. Furthermore, the developer reserves the
# right to cease development at any time for any reason, with no obligation to provide reason(s) for cessation.
#
#
#
### initialization steps
###
OP=$1
OPINPUT="${@:2}"
USR="$(whoami)"
STARTDIR=$(pwd)
PATH=$STARTDIR/${BASH_SOURCE%/*}:$PATH
LIBDEFLOC=/usr/include/libaurtool
if [ -f "$LIBDEFLOC" ]; then
source /usr/include/libaurtool
else
source ${BASH_SOURCE%/*}/resources/libaurtool
fi
GOAHEAD="0"
if [ -z "$NCHECKALL" ]; then
NCHECKALL="0"
fi
###
###
### env normalization
###
PATH=/usr/bin:$PATH
if which gcc &> /dev/null; then
CC='gcc'
CXX='g++'
fi
### check run conditions
###
if [ "$USR" == root ]; then
ctext red std "Error: aurtool cannot be run as root!"
exit 13
fi
VALID=("-S" "-Sy" "-Syu" "-Ss" "--help" "-Syyu" "-Sss" "--version" "-SS" "-R")
if [ ! -z "$OP" ]; then
if ! isvalidoperation "$1" ${VALID[@]}; then
ctext red nnl "Error: "
ctext magenta nnl "$1"
ctext red std ": Invalid command!"
ctext cyan std "Do aurtool --help for help page"
exit 22
fi
else
ctext red std "Error: aurtool requires input!"
ctext cyan std "Do aurtool --help for help page"
exit 22
fi
if ! which package-query &> /dev/null; then
if [ -z "$PKGQUERYINS" ]; then
PKGQUERYINS="0"
fi
if [ ! $PKGQUERYINS == 1 ]; then
ctext magenta std "Error: package-query not found in PATH!"
if ! isyes "$(ctext cyan nnl "Install it now? (Y/n)")"; then
exit 65
else
PKGQUERYINS="1" NCHECKALL="1" aurtool -SS package-query
fi
fi
fi
function OPERROR {
if [ -z "$OPINPUT" ]; then
ctext red std "Error: $OP requires additional input."
ctext cyan std "Do aurtool --help for help page"
exit 22
fi
}
if [ -z "$SILENT" ]; then
SILENT=0
elif [ $SILENT = 1 ]; then
NODEL=1
NCHECKALL=1
fi
###
### Script functionality begins here.
### Yes, I wrote the functions as if statements.
### No, it does not have any effects on functionality.
### No, I don't know why I did that. I was high. Get off my back.
###
if [ "$OP" == -Sss ]; then
OPERROR
package-query -A -s ${@:2}
fi
if [ "$OP" == -Ss ]; then
OPERROR
ctext cyan std "---------"
ctext cyan std " Non-AUR "
ctext cyan std "---------"
pacsearch ${@:2}
ctext cyan std "---------"
ctext cyan std " AUR "
ctext cyan std "---------"
package-query -A -s ${@:2}
fi
if [ "$OP" == -SS ]; then
OPERROR
if [ $NCHECKALL == 0 ]; then
echo " "
for dD in ${@:2}; do
ctext blue nnl " $dD"
done
echo " "
echo " "
if isyes "$(ctext cyan nnl "Install these packages? (Y/n)")"; then
GOAHEAD="1"
else
GOAHEAD="0"
fi
else
GOAHEAD="1"
NCHECKALL="0"
fi
if [ $GOAHEAD == "1" ]; then
for b in ${@:2}; do
cd $HOME
mkdir .aurtool
cd .aurtool
if [ $b == dxvk-mingw-git ]; then
b="dxvk-git"
elif [ $b == openrazer-daemon ] || [ $b == openrazer-driver-dkms ] || [ $b == openrazer-meta ] || [ $b == python-openrazer ]; then
b="openrazer"
fi
git clone http://aur.archlinux.org/$b.git
cd $b
PKGB=./PKGBUILD
if [ ! -f $PKGB ]; then
ctext red std "Error: package does not exist by the name $b!"
ctext magenta std "Aborting"
cd $HOME
exit 6
fi
#
# Yes, this is a pointless function that uses up 3 lines unnecessarily. The script didn't behave properly without it. Bash has moods, and Brian Fox hates us all.
#
function PKGBUILD {
if DEFINVERT="1" isyes "$(ctext cyan nnl "Would you like to edit the PKGBUILD? (y/N)")"; then
BINDIRS=(
'/bin/'
'/sbin/'
'/usr/bin/'
'/usr/sbin/'
'/usr/local/bin/'
'/usr/local/sbin/'
)
TEHNEWSFLAG="0"
TAHNOOSFLABG="0"
unset KNOWNEDITDIR
for i in ${BINDIRS[@]}; do
if ls -a $i/nano &> /dev/null; then
TEHNEWSFLAG=1
KNOWNEDITDIR="$i/nano"
break
elif ls -a $i/nvim &> /dev/null; then
TAHNOOSFLABG=1
KNOWNEDITDIR="$i/nvim"
break
elif ls -a $i/vim &> /dev/null; then
TAHNOOSFLABG=1
KNOWNEDITDIR="$i/vim"
break
elif ls -a $i/vi &> /dev/null; then
TAHNOOSFLABG=1
KNOWNEDITDIR="$i/vi"
break
fi
done
if [ -z "$KNOWNEDITDIR" ]; then
if which nano &> /dev/null; then
KNOWNEDITDIR="$(which nano)"
elif which nvim &> /dev/null; then
KNOWNEDITDIR="$(which nvim)"
elif which vim &> /dev/null; then
KNOWNEDITDIR="$(which vim)"
elif which vi &> /dev/null; then
KNOWNEDITDIR="$(which vi)"
fi
fi
if [ ! -z "$KNOWNEDITDIR" ]; then
eval $KNOWNEDITDIR ./PKGBUILD
elif ls -a /home/$USER/.aurtool_edit_command &> /dev/null; then
KNOWNEDITDIR="$(cat /home/$USER/.aurtool_edit_command)"
eval $KNOWNEDITDIR ./PKGBUILD
else
ctext magenta std "No suitable text editor found!"
ctext cyan nnl "If one is present on the system, enter its command now (eg: nano, vim, emacs, etc). Otherwise leave blank to skip PKGBUILD editing: "
read PKGEDIT
if [ -z "$PKGEDIT" ]; then
PKGEDIT="true"
ctext magenta std "Editor does not exist! skipping PKGBUILD editing for this session"
fi
if [ -v $PKGEDIT ]; then
$PKGEDIT ./PKGBUILD
fi
fi
fi
}
PKGBUILD
unset makedepends
unset optdepends
unset depends
source ./PKGBUILD
uDEPS=(${makedepends[@]} ${depends[@]})
for i in ${uDEPS[@]}; do
i=${i%=*}
i=${i%>*}
i=${i%<*}
DEPS=(${DEPS[@]} $i)
done
for i in ${DEPS[@]}; do
if ! pacman -Ql $i &> /dev/null; then
ctext cyan std "Trying to install $i with pacman (dependency)"
if ! sudo pacman -S --noconfirm --needed $i; then
ctext magenta std "Installing $i with pacman failed"
ctext cyan std "Trying to install $i from AUR"
if ! NODEL="1" NCHECKALL="1" aurtool -SS $i; then
ctext red std "FATAL: Unable to install dependency $i!"
cd $HOME
exit 65
fi
fi
fi
done
if ! makepkg -csi || false; then
ctext red std "Error! Aborting"
cd $HOME
exit 131
fi
cd $HOME/.aurtool
done
if [ -z "$NODEL" ]; then
NODEL="0"
fi
if [ ! "$NODEL" == 1 ]; then
if isyes "$(ctext cyan nnl "Build files and / or built packages are stored in .aurtool in your home directory. Would you like to delete them? (Y/n)")"; then
echo "Cleaning up.."
cd $HOME
rm -rf $HOME/.aurtool
fi
fi
else
echo "Aborting"
cd $HOME
exit 125
fi
fi
if [ "$OP" == -Syy ]; then
UPD=$(package-query -A -u)
if [ -z "$UPD" ]; then
ctext cyan std "No AUR package updates available"
exit 0
else
echo " "
ctext blue std "$UPD"
echo " "
fi
fi
if [ "$OP" == -Syyu ]; then
UPD=$(package-query -A -u | grep -oP "aur/\K[^ ]*")
if [ -z "$UPD" ]; then
echo " there is nothing to do"
exit 0
fi
echo " "
for vV in $UPD; do
ctext blue nnl " $vV"
done
echo " "
echo " "
if isyes "$(ctext cyan nnl "Update these AUR packages? (Y/n)")"; then
for i in $UPD; do
if [ $SILENT != 1 ]; then
NCHECKALL="1" aurtool -SS $i
else
NCHECKALL="1" NODEL="1" SILENT="1" aurtool -SS $i
fi
done
else
echo "Aborting"
cd $HOME
exit 125
fi
fi
if [ "$OP" == -Syu ]; then
ctext cyan std "Updating non-AUR packages..."
sudo pacman -Syu
ctext cyan std "Updating AUR packages..."
if [ $SILENT == 1 ]; then
SILENT=1 aurtool -Syyu
else
aurtool -Syyu
fi
fi
if [ "$OP" == -S ]; then
OPERROR
echo " "
for dD in ${@:2}; do
ctext blue nnl " $dD"
done
echo " "
echo " "
if isyes "$(ctext cyan nnl "Install these packages? (Y/n)")"; then
for m in ${@:2}; do
ctext cyan std "Trying to install $m using pacman..."
if ! sudo pacman -S --needed --noconfirm $m; then
ctext magenta std "Installing $m using pacman failed!"
ctext cyan std "Trying to install $m using AUR..."
if [ $SILENT != 1 ]; then
NCHECKALL="1" aurtool -SS $m
else
NODEL=1 NCHECKALL="1" SILENT=1 aurtool -SS $m
fi
fi
done
else
echo "Aborting"
cd $HOME
exit 125
fi
fi
if [ "$OP" == -R ]; then
OPERROR
echo " "
for dD in ${@:2}; do
ctext blue nnl " $dD"
done
echo " "
echo " "
if isyes "$(ctext cyan nnl "Remove these packages? (Y/n)")"; then
for u in ${@:2}; do
sudo pacman -R --noconfirm $u
done
else
ctext magenta std "Aborting"
cd $HOME
exit 125
fi
fi
if [ "$OP" == --version ]; then
ctext green std "aurtool V1.0 RC2"
fi
if [ "$OP" == --help ]; then
ctext white std " $(tput bold)--------------------------------------------------------------------------------------"
ctext green std " $(tput bold) aurtool $(ctext white)-$(ctext cyan) minimal AUR package management system "
ctext white std " $(tput bold)--------------------------------------------------------------------------------------"
ctext green std " $(tput bold)options$(ctext white): "
ctext white std " $(tput bold)-------- "
ctext cyan std " $(tput bold)$(ctext magenta)-SS $(ctext white) - install an AUR package (or update a single AUR package). "
ctext cyan std " $(tput bold)$(ctext magenta)-S $(ctext white) - install a package, trying pacman first, and AUR if pacman fails "
ctext cyan std " $(tput bold)$(ctext magenta)-Sy $(ctext white) - check for updates to installed AUR packages "
ctext cyan std " $(tput bold)$(ctext magenta)-Syyu $(ctext white) - install all available updates to AUR packages "
ctext cyan std " $(tput bold)$(ctext magenta)-Syu $(ctext white) - install all available updates to both AUR and non-AUR packages "
ctext cyan std " $(tput bold)$(ctext magenta)-Sss $(ctext white) - search the AUR for a package by name "
ctext cyan std " $(tput bold)$(ctext magenta)-Ss $(ctext white) - search both repositories and AUR for package by name "
ctext cyan std " $(tput bold)$(ctext magenta)-R $(ctext white) - remove a package "
ctext cyan std " $(tput bold)$(ctext magenta)--help $(ctext white) - display this help dialog "
ctext cyan std " $(tput bold)$(ctext magenta)--version $(ctext white) - display aurtool version info "
echo ""
ctext white std " $(tput bold)--------------------------------------------------------------------------------------"
ctext green std " $(tput bold) environment flags "
echo ""
ctext cyan std " $(tput bold) $(ctext yellow)NCHECKALL=1 $(ctext white)-$(ctext cyan) disable PKGBUILD edit prompt and \"are you sure\" prompts "
ctext cyan std " $(tput bold) $(ctext yellow) NODEL=1 $(ctext white)-$(ctext cyan) disable prompting user to delete built package after installation "
ctext cyan std " $(tput bold) $(ctext yellow) SILENT=1 $(ctext white)-$(ctext cyan) enable both of the above "
echo ""
ctext blue std " $(tput bold) $(ctext green)ex$(ctext white) -$(ctext blue) SILENT=1 aurtool -S wine-staging-git "
ctext white std " $(tput bold)--------------------------------------------------------------------------------------"
fi
###