-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpacget
executable file
·292 lines (261 loc) · 9.41 KB
/
pacget
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
#!/bin/bash
# ##############################################################################
# ################################ pacget #####################################
# ##############################################################################
# Copyright (c) 2017 Md. Jahidul Hamid
#
# -----------------------------------------------------------------------------
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * The names of its contributors may not be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# Disclaimer:
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# ##############################################################################
version=1.1.2
pkgname=pacget
txtrst='\\e[0m' # Text Reset
bldcyn='\\e[1;36m' # Cyan
bldgrn='\\e[1;32m' # Green
bldblu='\\e[1;34m' # Blue
bldwht='\\e[1;37m' # White
bldpur='\\e[1;35m' # Purple
bldylw='\\e[1;33m' # Yellow
third_bracket_color=$bldcyn
good_version_color=$bldgrn
bracket_text=$bldblu
package_name_color=$bldwht
repo_name_color=$bldpur
end_color=$txtrst
num_color=$bldylw
help="
#################################### $pkgname ####################################
############################ A wrapper around pacaur ###########################
################################################################################
Usage:
$pkgname [operation] [options] [target/s] #1
$pkgname [packages_to_install] #2
All options work the same way as pacaur except the following:
-s <search_term> : Search arch repo and AUR and do interactive install
-Ss <search_term> : Search arch repo and AUR and do interactive install
-Fs <file_name> : Search for containing file and do interactive install
-cs <search_term> : Same as -s with compact output
All other options are forwarded to pacaur.
################################################################################
"
msg_out(){
printf "%b\n" "*** $*" #> /dev/stdout
}
_star_s(){
if [ "$1" = '' ]; then
title='**********'
else
title=" ($1) "
fi
local s="************************$title*****************************"
printf "\n\n\n%b\n" "*** $s"
}
_star_e(){
local s='***************************************************************'
printf "%b\n" "*** $s"
}
err_out(){
printf "%b\n" "\nE: $*" >&2
}
wrn_out(){
printf "%b\n" "\nW: $*" >&2
}
err_exit(){
err_out "$*"
exit 1
}
empty_var_exit(){
# $1 -> msg
# $2 -> var
if [ "$2" = '' ]; then
err_exit "$1"
fi
}
chkroot(){
if [ "$(id -u)" != "0" ]; then
err_out "root access required."
exit 1
fi
}
chknorm(){
if [ "$(id -u)" = "0" ]; then
wrn_out "Running as root not recommended. May produce some problems. Better run as a normal user."
return 1
fi
}
chkcmd(){
if command -v "$1" >/dev/null 2>&1; then
return 0
else
return 1
fi
}
declare -a args
declare -a pargs
search=false
search_term=
compact_mode=false
PARGS=' --noconfirm --noedit -e --edit -q --quiet --devel --foreign --ignore --needed --rebuild --silent ' # must start and end with a space
while [ $# -gt 0 ]
do
i=$1
j=$2
if [[ "$i" = -h ]] || [[ "$i" = --help ]]; then
args+=("$i")
printf "%s\n" "$help"
elif [[ "$i" = -v ]] || [[ "$i" = --version ]]; then
args+=("$i")
msg_out "pacget version: $version"
msg_out "pacaur version: $(pacaur -v)"
msg_out "pacman version: $(pacman --version)"
exit 1
elif [[ "$i" = -s ]] || [[ "$i" = --search ]]; then
empty_var_exit "Search term not specified" "$j"
search_term=$2
search=true
args+=("$i" "$j")
shift
elif [[ "$i" =~ ^-S(.*)s(.*)$ ]]; then
empty_var_exit "Search term not specified" "$j"
search_term=$j
search=true
pacman_S='set'
args+=("$i")
elif [[ "$i" =~ ^-([^-]*)S(.*)$ ]]; then
pacman_S='set'
args+=("$i")
elif [[ "$i" =~ ^-F(.*)s(.*)$ ]]; then
empty_var_exit "Search term not specified" "$j"
search_term=$j
search=true
pacman_F='set'
args+=("$i")
elif [[ "$i" =~ ^-([^-]*)F(.*)$ ]]; then
pacman_F='set'
args+=("$i")
elif [[ "$i" = -a ]] || [[ "$i" = --aur ]]; then
aur_only='set'
args+=("$i")
elif [[ "$i" = -c ]] || [[ "$i" = --compact ]]; then
compact_mode=true
elif [[ "$i" = -cs ]]; then
compact_mode=true
empty_var_exit "Search term not specified" "$j"
search_term=$2
search=true
args+=(-s "$j")
shift
elif [[ "$PARGS" = *"$i"* ]]; then
pargs+=("$i")
else
args+=("$i")
fi
shift
done
search_results=
if $search; then
if [[ "$pacman_S" != set ]] && [[ "$pacman_F" != set ]] && [[ "$aur_only" != set ]]; then
search_results=$(pacman -Ss "$search_term")
fi
search_results+=$'\n'"$(pacaur "${args[@]}")"
fi
if $search; then
if ! $compact_mode; then
raw_indexed_search_results=$(echo "$search_results"$'\n' | awk 'BEGIN {a=0} /^[a-zA-Z0-9_.-]+\// {a++; print "\n" a,$0; next;} {print $0;}' |sed -zr 's/\n([^0-9])/\x0\1/g' |sort -n -r | tr '\0' '\n')
else
raw_indexed_search_results=$(echo "$search_results" | awk 'BEGIN {a=0} /^[a-zA-Z0-9_.-]+\// {a++; print "\n" a,$0; next;} {print $0;}' |sed -zr 's/\n([^0-9])/\x0\1/g' |sort -n -r | tr -s '\0' '\n')
fi
search_results=$(
echo "$raw_indexed_search_results" |
sed -r \
-e "s#^([0-9]+[[:blank:]]+[^[:blank:]/]+/[^[:blank:]]+[*[:blank:]]*[^][]*)(\[[^][]+\])#\1$third_bracket_color\2$end_color #" \
-e "s#^([0-9]+[[:blank:]]+[^[:blank:]/]+/[^[:blank:]]+[*[:blank:]]*[^()]*)(\([^()]+\))#\1$bracket_text\2$end_color #" \
-e "s#^([0-9]+[[:blank:]]+[^[:blank:]/]+/[^[:blank:]]+[*[:blank:]]*)([^[:blank:]]+)#\1$good_version_color\2$end_color #" \
-e "s#^([0-9]+[[:blank:]]+[^[:blank:]/]+/)([^[:blank:]]+)[*[:blank:]]*#\1$package_name_color\2$end_color #" \
-e "s#^([0-9]+[[:blank:]]+)([^[:blank:]/]+)/#\1$repo_name_color\2$end_color/#" \
-e "s#^([0-9]+)[[:blank:]]+#$num_color\1$end_color #" \
)
printf "%b\n" "$search_results"
if [[ "$search_results" != '' ]]; then
if $compact_mode; then
msg=
else
msg=$'\n'$'\n'
fi
msg+="$bldylw==>$txtrst ${bldwht}Enter n° of packages to be installed$txtrst
$bldylw==>$txtrst ${bldwht}(e.g., 1 2 3 or 1,2,3 or 1-3 or 3-1)$txtrst
$bldylw==>$txtrst ${bldwht}------------------------------------$txtrst
$bldylw==>$txtrst "
msg=$(printf "%b\n" "$msg" | sed -r -e "s#.+#$bldwht&$end_color#")
printf "%b" "$msg"
read -re inp
declare -a arr
packs=
packns=
arr=($(echo "$inp" |tr ',' '\n')) # word splitting occurs and splits the numbers according to whitespaces.
for p in "${arr[@]}"; do
if [[ "$p" =~ ^[0-9]+$ ]]; then
packns+="|$p"
elif [[ "$p" =~ ^([0-9]+)[[:blank:]]*-[[:blank:]]*([0-9]+) ]]; then
if [ ${BASH_REMATCH[1]} -gt ${BASH_REMATCH[2]} ]; then
lc=${BASH_REMATCH[2]}
uc=${BASH_REMATCH[1]}
else
lc=${BASH_REMATCH[1]}
uc=${BASH_REMATCH[2]}
fi
for i in $(seq $lc $uc); do
packns+="|$i"
done
else
err_exit "Invalid range or sequence: $p"
fi
done
if [[ "$packns" != '' ]]; then
packs+=" $(echo "$raw_indexed_search_results" | sed -r -n -e "s#^(${packns#|})[[:blank:]]+[^/]+/([^[:blank:]]+).*#\2#p")"
fi
if [[ "$packs" != '' ]]; then
pacaur "${pargs[@]}" -S $packs
fi
fi
else
# see if any options are passed
for p in "${args[@]}"; do
if [[ "$p" =~ ^-(.*)$ ]]; then
option_passed='set'
break
fi
done
if [[ "$option_passed" = set ]]; then
pacaur "${pargs[@]}" "${args[@]}"
else
# If no option is passed, all will be taken as package names
pacaur "${pargs[@]}" -S "${args[@]}"
fi
fi