-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
static-get
executable file
·648 lines (586 loc) · 25.8 KB
/
static-get
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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
#!/bin/sh
#description: get static linux binaries from s.minos.io and mirrors
#usage: static-get package
#example: static-get git
#git-1.8.2.1-3.tar.gz:sha512sum
VERSION="2020.02.11-00:21"
LATEST_URI_BASENAME="https://raw.githubusercontent.com/minos-org/minos-static/master"
_usage() {
printf "%b\\n" "Usage: ${progname} [OPTION]... PACKAGE ..."
printf "%b\\n" "Retrieve static linux binaries from s.minos.io and mirrors."
printf "\\n"
printf "%b\\n" " -d, --download [dir] write in the specified directory"
printf "%b\\n" " -o, --output [file] write to file"
printf "%b\\n" " -s, --search [pattern] search packages by pattern"
printf "%b\\n" " -x, --extract extract after download"
printf "%b\\n" " -i, --install install after download"
printf "%b\\n" " -p, --prefix [dir] specifies an install location for the package"
printf "%b\\n" " -n, --dry-run perform a trial run with no changes made"
printf "%b\\n" " -c, --clean-cache remove temporal files"
printf "%b\\n" " -r, --remove removes an installed package"
printf "\\n"
printf "%b\\n" " -m, --mirror [s.minos.io] set mirror"
printf "%b\\n" " -a, --arch [x86_64|i686] set architecture"
printf "%b\\n" " -f, --format [gz|bz2|xz] set compress format"
printf "%b\\n" " -k, --checksum [sha512|md5] set checksum"
printf "%b\\n" " -t, --distro [all|bifrost|morpheus|rlsd2|misc] set distro"
printf "\\n"
printf "%b\\n" " -U, --update update this program to latest version"
printf "%s\\n" " -V, --version display version"
printf "%b\\n" " -v, --verbose turn on verbose mode"
printf "%b\\n" " -q, --quiet suppress non-error messages"
printf "%b\\n" " -h, --help show this message and exit"
}
_basename() {
[ -z "${1}" ] && return 1 || _basename__name="${1}"
[ -z "${2}" ] || _basename__suffix="${2}"
case "${_basename__name}" in
/*|*/*) _basename__name="${_basename__name##*/}"
esac
if [ -n "${_basename__suffix}" ] && [ "${#_basename__name}" -gt "${#2}" ]; then
_basename__name="${_basename__name%$_basename__suffix}"
fi
printf "%s\\n" "${_basename__name}"
}
_die() {
[ -z "${1}" ] || printf "%s\\n" "${*}" >&2
_usage >&2; exit 1
}
_update() {
_u__current_file="$(cd "$(dirname "${0}")" && pwd)/${progname}"
_u__current_version_long="$(awk -F\" \
'/VERSION=/{print $2;exit}' "${_u__current_file}" 2>/dev/null)"
_u__current_version="$(printf "%s\\n" "${_u__current_version_long}" | \
awk '{gsub(/[\.:]/,"");gsub(/-/,"");print;exit}' 2>/dev/null)"
[ -z "${_u__current_version}" ] && printf "%s\\n%s\\n%s\\n" \
"ERROR: Failed to detect current version, please update manually" \
"${progname} = ${_u__current_file}" \
"${progname} version = ${_u__current_version}" >&2 && return 1
command -v "wget" >/dev/null 2>&1 || command -v "curl" >/dev/null 2>&1 || \
{ printf "%s\\n" "ERROR: Install either 'wget' or 'curl' to upgrade" >&2; return 1; }
_u__url="${LATEST_URI_BASENAME}/${progname}"
_u__tmpfile="/tmp/${progname}.${$}.update"
_u__error_msg="$(wget -q -O- --no-check-certificate "${_u__url}" \
> "${_u__tmpfile}" 2>&1 || curl -L -s "${_u__url}" \
> "${_u__tmpfile}" 2>&1)" || { printf "%s\\n%s\\n" \
"ERROR: Failed to fetch update, please try later or update manually" \
"${_u__error_msg}" >&2; return 1; }
_u__update_version_long="$(awk -F\" \
'/VERSION=/{print $2;exit}' "${_u__tmpfile}" 2>/dev/null)"
_u__update_version="$(printf "%s\\n" "${_u__update_version_long}" | awk \
'{gsub(/[\.:]/,"");gsub(/-/,"");print;exit}' 2>/dev/null)"
[ -n "${_u__update_version}" ] || _u__update_version="0"
if [ "${_u__current_version}" -lt "${_u__update_version}" ]; then
printf "%s %s\\n" "Updating from version" \
"${_u__current_version_long} to ${_u__update_version_long} ..."
chmod +x "${_u__tmpfile}"
if ! mv -f "${_u__tmpfile}" "${_u__current_file}" 2>/dev/null; then
printf "%s\\n" "ERROR: no write permissions on ${_u__current_file}" >&2
printf "%s\\n" "INFO : trying with sudo ..." >&2
if command -v "sudo" >/dev/null 2>&1; then
sudo mv "${_u__tmpfile}" "${_u__current_file}" || return 1
else
printf "%s\\n" "ERROR: sudo isn't available, exiting ..." >&2
rm -rf "${_u__tmpfile}"
return 1
fi
fi
printf "%s\\n" "${progname} is up-to-date (${_u__update_version_long})"
return 0
fi
printf "%s\\n" "${progname} is up-to-date (${_u__current_version_long})"
rm -rf "${_u__tmpfile}"
}
_show_version() {
printf "%s\\n" "${progname} ${VERSION}"
}
_mkdir_p() { #portable mkdir -p
[ -n "${1}" ] || return 1
for _mkdir_p__dir in "${@}"; do
[ -d "${_mkdir_p__dir}" ] && continue
_mkdir_p__IFS="${IFS}"
IFS="/"
#shellcheck disable=SC2086
set -- ${_mkdir_p__dir}
IFS="${_mkdir_p__IFS}"
(
case "${_mkdir_p__dir}" in
/*) cd / || return; shift ;;
esac
for _mkdir_p__subdir in "${@}"; do
[ -z "${_mkdir_p__subdir}" ] && continue
if [ -d "${_mkdir_p__subdir}" ] || mkdir "${_mkdir_p__subdir}"; then
if cd "${_mkdir_p__subdir}"; then
:
else
printf "%s\\n" "_mkdir_p: Can't enter ${_mkdir_p__subdir} while creating ${_mkdir_p__dir}"
return 1
fi
else
return 1
fi
done
)
done
}
_verbose() {
[ -z "${1}" ] && return 1
[ -n "${verbose}" ] && printf "%s\\n" "${*}" || :
}
_cat() {
[ -z "${1}" ] && return 1
[ -z "${global_output}" ] && output_fname="$(_basename "${1}")" || {
[ -z "${output_counter}" ] && output_counter="0"
}
if [ -z "${global_output}" ]; then
cat "${1}" > "${directory}/${output_fname}"
else
case "${output_fname}" in
-) cat "${1}"; return 0 ;;
*\{#\}*) output_counter="$((output_counter + 1))"
cat "${1}" >> "${directory}/$(printf "%s\\n" "${output_fname}" | \
sed "s:{#}:${output_counter}:")"
;;
*) cat "${1}" >> "${directory}/${output_fname}" ;;
esac
fi
printf "%s\\n" "${directory}/${output_fname}" | sed 's:\./::' | sed "s:{#}:${output_counter}:"
}
_uniq_id_mirror() {
printf "%s\\n" "${1%/}" | sed 's|/|##|g'
}
_fetch() {
case "${#}" in
1) $retriever_bin "${1}" ;;
2)
case "${retriever_bin}" in
wget*) $retriever_bin -O "${2}" "${1}" >/dev/null || \
$retriever_bin -O "${2}" "http://${1}" >/dev/null ;;
curl*) ${retriever_bin% -O} -o "${2}" "${1}" >/dev/null ;;
*) return 1 ;;
esac
;;
*) return 1 ;;
esac
}
_get_available_distros() {
#$1 => mirror, eg: s.minos.io|s.minos.io/archive
[ -z "${1}" ] && return 1
[ -z "${uniq_id_mirror}" ] && uniq_id_mirror="$(_uniq_id_mirror "${1}")"
_mkdir_p "${tmpcache}.${uniq_id_mirror}"
if [ ! -f "${tmpcache}.${uniq_id_mirror}/index.html" ]; then
cd "${tmpcache}.${uniq_id_mirror}" || return
_fetch "${1}" index.html
fi
awk -F'"' '/href/ {if ($2 != "../" && $2 != "robots.txt") {sub(/\//,"",$2);print $2}}' \
"${tmpcache}.${uniq_id_mirror}/index.html" 2>/dev/null
}
_get_available_archs() {
#$1 => mirror, eg: s.minos.io|s.minos.io/archive
#$2 => distro, eg: bifrost
[ -z "${2}" ] && return 1
[ -z "${uniq_id_mirror}" ] && uniq_id_mirror="$(_uniq_id_mirror "${1}")"
_mkdir_p "${tmpcache}.${uniq_id_mirror}/${2}"
if [ ! -f "${tmpcache}.${uniq_id_mirror}/${2}/index.html" ]; then
cd "${tmpcache}.${uniq_id_mirror}/${2}" || return
_fetch "${1}/${2}" index.html
fi
awk -F'"' '/href/ {if ($2 != "../") {sub(/\//,"",$2);print $2}}' \
"${tmpcache}.${uniq_id_mirror}/${2}/index.html" 2>/dev/null | \
grep -v "lock" | grep -v "archive/"
}
_get_package_indexes() {
#$1 => mirror, eg: s.minos.io|s.minos.io/archive
[ -z "${1}" ] && return 1
[ -z "${available_distros}" ] && available_distros="$(_get_available_distros "${1}")"
[ -z "${uniq_id_mirror}" ] && uniq_id_mirror="$(_uniq_id_mirror "${1}")"
for gdistro in ${available_distros}; do
available_arch="$(_get_available_archs "${1}" "${gdistro}")"
for garch in ${available_arch}; do
_mkdir_p "${tmpcache}.${uniq_id_mirror}/${gdistro}/${garch}"
if [ ! -f "${tmpcache}.${uniq_id_mirror}/${gdistro}/${garch}/${checksum}sum.txt" ]; then
(
cd "${tmpcache}.${uniq_id_mirror}/${gdistro}/${garch}" || return
if _fetch "${1}/${gdistro}/${garch}/${checksum}sum.tar.${compress_format}"; then
${compress_bin} < "${checksum}sum.tar.${compress_format}" | tar -xf -
elif _fetch "${1}/${gdistro}/${garch}/${checksum}sum.txt"; then
:
else
head -3 "${checksum}sum.tar.${compress_format}" >&2
fi
)
fi
done
done
}
_set_defaults() {
[ -z "${mirror}" ] && mirror="s.minos.io/archive"
[ -z "${uniq_id_mirror}" ] && uniq_id_mirror="$(_uniq_id_mirror "${mirror}")"
[ -z "${distro}" ] && distro="all"
[ -z "${arch}" ] && arch="$(uname -m)"
[ -z "${directory}" ] && directory="."
[ X"${output_fname}" = X"-" ] && directory="."
if [ -z "${dry_run}" ]; then
_mkdir_p "${directory}" || { printf "%s\\n" "unable to create ${directory}, exiting"; exit 1; }
fi
case "${arch}" in
x86|386|486|586|i86|32) arch="i686" ;;
amd64|64) arch="x86_64" ;;
i686|x86_64) : ;;
*) _verbose "${arch} is not a valid architecture, using system default: $(uname -m)"; arch="$(uname -m)" ;;
esac
case "${compress_format}" in
gz) compress_bin="zcat" ;;
bz2) compress_bin="bzcat" ;;
xz) compress_bin="xzcat" ;;
*) if command -v "xzcat" >/dev/null 2>&1; then
compress_format="xz"
compress_bin="xzcat"
elif command -v "xz" >/dev/null 2>&1; then
compress_format="xz"
compress_bin="xz -cd"
elif command -v "bzcat" >/dev/null 2>&1; then
compress_format="bz2"
compress_bin="bzcat"
elif command -v "bzip2" >/dev/null 2>&1; then
compress_format="bz2"
compress_bin="bzip2 -cd"
elif command -v "zcat" >/dev/null 2>&1; then
compress_format="gz"
compress_bin="zcat"
elif command -v "gzip" >/dev/null 2>&1; then
compress_format="gz"
compress_bin="gzip -cd"
else
printf "%s\\n" "install either 'gzip', 'bzip2' or 'xz' to run this program" >&2
exit 1
fi
;;
esac
case "${checksum}" in
sha512) checksum_bin="shasum -a 512" ;;
md5) checksum_bin="md5sum" ;;
*) if command -v "shasum" >/dev/null 2>&1; then
checksum="sha512"
checksum_bin="shasum -a 512"
elif command -v "md5sum" >/dev/null 2>&1; then
checksum="md5"
checksum_bin="md5sum"
else
printf "%s\\n" "install either 'md5sum' or 'shasum' to run this program" >&2
exit 1
fi
;;
esac
if command -v "wget" >/dev/null 2>&1; then
retriever_bin="wget -q"
elif command -v "curl" >/dev/null 2>&1; then
retriever_bin="curl -L -s -O"
elif command -v "fetch" >/dev/null 2>&1; then
retriever_bin="fetch"
else
printf "%s\\n" "install either 'wget', 'curl' or 'fetch' to run this program" >&2
exit 1
fi
available_distros="$(_get_available_distros "${mirror}")"
if [ -z "${available_distros}" ]; then
printf "%s\\n" "no available packages at ${mirror}, it may be an incorrect url or could be down temporarily" >&2
exit 1
fi
}
_static_search() {
#$1 => search pattern
[ -z "${1}" ] && return 1
_set_defaults
_get_package_indexes "${mirror}"
_ssearch__sanitazed_pattern="$(printf "%s\\n" "${1}" | \
tr -cd 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.-')"
[ X"${distro}" = X"all" ] && distro=""
_ssearch__result="$(find "${tmpcache}.${uniq_id_mirror}"/ -name "${checksum}sum.txt" | \
grep -- "${distro}" | xargs grep -- "${_ssearch__sanitazed_pattern}" | grep -- "${arch}" | \
grep -- "tar.${compress_format}" | sed "s:${tmpcache}.::g;s:##:/:g;s:/${checksum}sum.txt\:: :g")"
if [ -n "${_ssearch__result}" ]; then
if [ "${verbose}" ]; then
printf "%s\\n" "${_ssearch__result}" | awk '{printf "%s %s %s\n", $3, $2, $1}' | \
grep -- "${1}" | awk '{printf "%s:%s:%s\n", $3, $1, $2}'
else
printf "%s\\n" "${_ssearch__result}" | awk '{printf "%s:%s\n", $3, $2}' | \
grep -- "${1}" | cat
fi
else
return 1
fi
}
_extract() {
_mkdir_p "${directory}/${_sget__bfile%%.tar*}"
(cd "${directory}/${_sget__bfile%%.tar*}" && \
${compress_bin} < "../${_sget__bfile}" | tar -xf -)
[ "${1}" ] && printf "%s\\n" "${directory}/${_sget__bfile%%.tar*}/" | sed 's:\./::'
}
_static_get() {
[ -z "${1}" ] && return 1 || _set_defaults
for package in "${@}"; do
#extra_params="-m ${mirror} -a ${arch} -f ${compress_format} -c ${checksum} -t ${distro}"
#_sget__file="$("${0}" ${extra_params} -v -n -s "^${package}" | sort -nr |head -1)"
_sget__file="$(verbose=1 dry_run=1 _static_search "^${package}" | sort -nr |head -1)"
[ -z "${_sget__file}" ] && _verbose "No matches for '${package}', skipping..." && continue
[ -z "${uniq_id_mirror}" ] && uniq_id_mirror="$(_uniq_id_mirror "${mirror}")"
_sget__hash="${_sget__file##*:}"
_sget__file="${_sget__file%:$_sget__hash}" #remove hash
_sget__file="$(printf "%s\\n" "${_sget__file}" | tr ':' '/')"
_sget__bfile="$(_basename "${_sget__file}")"
for i in 1 2; do #download on first run, write/extract on second
if [ "${dry_run}" ]; then
if [ "${output_fname}" ]; then
case "${output_fname}" in
*\{#\}*) [ -z "${output_counter}" ] && output_counter="0"
output_counter="$((output_counter + 1))"
;;
esac
printf "%s\\n" "${directory}/${output_fname}" | sed 's:\./::' | sed "s:{#}:${output_counter}:"
else
printf "%s\\n" "${directory}/${_sget__bfile}" | sed 's:\./::'
[ "${extract}" ] && printf "%s\\n" "${directory}/${_sget__bfile%%.tar*}/" | sed 's:\./::'
fi
break
fi
if [ -f "${tmpcache}.${uniq_id_mirror}/${_sget__bfile}" ]; then
_sget__hash_new="$($checksum_bin "${tmpcache}.${uniq_id_mirror}/${_sget__bfile}" | awk '{print $1}')"
_sget__bfile_sub1="$(printf "%s\\n" "${_sget__bfile}" | cut -d "-" -f 1)"
if [ "${remove}" ]; then
if [ -e ~/.static-get/"${_sget__bfile_sub1}" ]; then
if [ -w ~/.static-get/"${_sget__bfile_sub1}" ]; then
while read -r line; do
rm -rf "${line}"
done < ~/.static-get/"${_sget__bfile_sub1}"
rm ~/.static-get/"${_sget__bfile_sub1}"
elif command -v "sudo" >/dev/null 2>&1; then
while read -r line; do
sudo rm -rf "${line}"
done < ~/.static-get/"${_sget__bfile_sub1}"
sudo rm ~/.static-get/"${_sget__bfile_sub1}"
else
printf "%s\\n" "ERROR: sudo isn't available, exiting ..." >&2
fi
elif [ "${i}" = "1" ]; then
printf "ERROR: package %s could not be removed.\\n" "${_sget__bfile_sub1}" >&2
fi
elif [ "${_sget__hash}" = "${_sget__hash_new}" ]; then
_cat "${tmpcache}.${uniq_id_mirror}/${_sget__bfile}"
# Install the package
if [ "${install}" ]; then
_extract "${extract}"
_mkdir_p ~/.static-get
if [ -w "${prefix}/" ]; then
cd "${_sget__bfile%%.tar*}" && \
cp -vr -- * "${prefix}/" | cut -d "'" -f 4 > ~/.static-get/"${_sget__bfile_sub1}" || return 1
elif command -v "sudo" >/dev/null 2>&1; then
cd "${_sget__bfile%%.tar*}" && \
sudo cp -vr -- * "${prefix}/" | cut -d "'" -f 4 > ~/.static-get/"${_sget__bfile_sub1}" || return 1
else
printf "%s\\n" "ERROR: sudo isn't available, exiting ..." >&2
fi
if ! [ "${extract}" ]; then
cd "../" && rm -rf "${_sget__bfile%%.tar*}"
fi
elif [ "${extract}" ]; then
_extract "${extract}"
fi
break
else
printf "'%s' doesn't match hashsum => '%s', clean the cache (%s) and try again\\n" \
"${directory}/${_sget__bfile}" "${_sget__hash}" \
"$(_usage | awk '/remove temporal/ {sub(/,/, ""); print $1 "|" $2}')" | sed 's:\./::'
rm -f "${tmpcache}.${uniq_id_mirror}/${_sget__bfile}"
fi
else
(cd "${tmpcache}.${uniq_id_mirror}/" && _fetch "${_sget__file}")
fi
done
done
}
progname="$(_basename "${0}")"
tmpcache="/tmp/static-get"
if [ ! -t 0 ]; then
#there is input comming from pipe or file, add it to the end of $@
#shellcheck disable=SC2046
set -- "${@}" $(cat)
fi
[ "${#}" -eq "0" ] && _die
for arg in "${@}"; do #parse options
case "${arg}" in
-h|--help) _usage; exit ;;
-U|--update) _update; exit "${?}" ;;
-V|--version) _show_version; exit "${?}" ;;
-q|--quiet) quiet="1"; shift ;;
-v|--verbose) verbose="1"; shift ;;
-x|--extract) extract="1"; shift ;;
-i|--install) install="1"; shift ;;
-r|--remove) remove="1"; shift ;;
-n|--dry-run) dry_run="1"; shift ;;
'-p'|'--prefix'|-p*|--prefix*)
case "${arg}" in
'-p'|'--prefix')
if [ "${#}" -gt "1" ]; then
case "${2}" in
'-') : ;; #special stdout character
-*) printf "Option '%s' requires a parameter %s\\n" "${arg}" "${2}";;
'.') prefix="${PWD}" ; shift; shift; break ;;
'..')prefix="${PWD}/../" ; shift; shift; break ;;
esac
shift; prefix="${1}"; [ "${1}" ] && shift
else
prefix="${PWD}"
fi
;;
-p*) prefix="${1#-p}"; shift ;;
--prefix*) prefix="${1#--prefix}"; shift ;;
esac
;;
'-d'|'--download'|-d*|--download*)
case "${arg}" in
'-d'|'--download')
if [ "${#}" -gt "1" ]; then
case "${2}" in
-*) _die "Option '${arg}' requires a parameter";;
esac
shift; directory="${1}"; [ "${1}" ] && shift
else
_die "Option '${arg}' requires a parameter"
fi
;;
-d*) directory="${1#-d}"; shift ;;
--download*) directory="${1#--download}"; shift ;;
esac
;;
'-o'|'--output'|-o*|--output*)
case "${arg}" in
'-o'|'--output')
if [ "${#}" -gt "1" ]; then
case "${2}" in
'-') : ;; #special stdout character
-*) _die "Option '${arg}' requires a parameter" ;;
esac
shift; output_fname="${1}"; global_output="1"; [ "${1}" ] && shift
else
_die "Option '${arg}' requires a parameter"
fi
;;
-o*) output_fname="${1#-o}"; shift; global_output="1" ;;
--output*) output_fname="${1#--output}"; shift; global_output="1" ;;
esac
;;
'-s'|'--search'|-s*|--search*)
case "${arg}" in
'-s'|'--search')
if [ "${#}" -gt "1" ]; then
case "${1}" in
-*) shift; for opt in "${@}"; do
#last parameter as search regex
search_pattern="${opt}"
done
;;
*) shift; search_pattern="${1}"
[ "${1}" ] && shift ;;
esac
else
search_pattern="."
fi
;;
-s*) search_pattern="${1#-s}"; shift ;;
--search*) search_pattern="${1#--search}"; shift ;;
esac
;;
'-a'|'--arch'|-a*|--arch*)
case "${arg}" in
'-a'|'--arch')
if [ "${#}" -gt "1" ]; then
case "${2}" in
-*) _die "Option '${arg}' requires a parameter" ;;
esac
shift; arch="${1}"; [ "${1}" ] && shift
else
_die "Option '${arg}' requires a parameter"
fi
;;
-a*) arch="${1#-a}"; shift ;;
--arch*) arch="${1#--arch}"; shift ;;
esac
;;
'-m'|'--mirror'|-m*|--mirror*)
case "${arg}" in
'-m'|'--mirror')
if [ "${#}" -gt "1" ]; then
case "${2}" in
-*) _die "Option '${arg}' requires a parameter" ;;
esac
shift; mirror="${1}"; [ "${1}" ] && shift
else
_die "Option '${arg}' requires a parameter"
fi
;;
-m*) mirror="${1#-m}"; shift ;;
--mirror*) mirror="${1#--mirror}"; shift ;;
esac
;;
'-k'|'--checksum'|-k*|--checksum*)
case "${arg}" in
'-k'|'--checksum')
if [ "${#}" -gt "1" ]; then
case "${2}" in
-*) _die "Option '${arg}' requires a parameter" ;;
esac
shift; checksum="${1}"; [ "${1}" ] && shift
else
_die "Option '${arg}' requires a parameter"
fi
;;
-k*) checksum="${1#-k}"; shift ;;
--checksum*) checksum="${1#--checksum}"; shift ;;
esac
;;
'-t'|'--distro'|-t*|--distro*)
case "${arg}" in
'-t'|'--distro')
if [ "${#}" -gt "1" ]; then
case "${2}" in
-*) _die "Option '${arg}' requires a parameter" ;;
esac
shift; distro="${1}"; [ "${1}" ] && shift
else
_die "Option '${arg}' requires a parameter"
fi
;;
-t*) distro="${1#-t}"; shift ;;
--distro*) distro="${1#--distro}"; shift ;;
esac
;;
'-f'|'--format'|-f*|--format*)
case "${arg}" in
'-f'|'--format')
if [ "${#}" -gt "1" ]; then
case "${2}" in
-*) _die "Option '${arg}' requires a parameter" ;;
esac
shift; compress_format="${1}"; [ "${1}" ] && shift
else
_die "Option '${arg}' requires a parameter"
fi
;;
-f*) compress_format="${1#-f}"; shift ;;
--format*) compress_format="${1#--format}"; shift ;;
esac
;;
-c|--clean-cache) rm -rf "${tmpcache}".* && \
[ -z "${quiet}" ] && printf "%s\\n" "Cache cleared successfully"
exit ;;
'-') : ;; #special stdout character
-*) _die "${progname}: unrecognized option '${arg}'" >&2 ;;
esac
done
if [ -z "${search_pattern}" ]; then
[ "${#}" -eq "0" ] && _die "${progname}: missing arguments"
_static_get "${@}"
else
_static_search "${search_pattern}"
fi