-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebdown
More file actions
executable file
·65 lines (55 loc) · 1.27 KB
/
debdown
File metadata and controls
executable file
·65 lines (55 loc) · 1.27 KB
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
#!/bin/sh
myname="${0##*/}"
# usage: check_cmd command
# returns 1 if command exists
check_cmd_exist(){
[ "$(command -v "$1" 2>/dev/null)" ] && printf '1\n'
}
can_dld=$(check_cmd_exist "dld")
show_help () {
printf 'Usage: %s < package(s) >\n' "${myname}"
printf '\tDownload .deb archive for the input package\n'
printf '%s\n' "Options"
printf ' %s' "-h, --help, help"
printf ' %s\n' "show this help."
}
deb_url () {
url=$(apt-get install --reinstall --print-uris -qq "$1" | cut -d"'" -f2 | grep "/${1}_")
printf '%s\n' "$url"
}
deb_down () {
PKG="$1"
url=$(deb_url "$PKG")
printf '%s\n\t%s\n\n' "${myname}: downloading '$PKG' from url:" "'$url'"
if [ "$can_dld" = 1 ]; then
dld "$url"
else
wget "$url"
fi
}
########
# main #
########
if [ "${#}" -eq 0 ]; then
show_help
else
arguments=""
while [ "${#}" -gt 0 ]; do
case "$1" in
help|-h|--help)
show_help
exit 0
;;
*)
arguments="$arguments $1"
;;
esac
shift
done
# we do want word splitting here
# shellcheck disable=SC2086
set -- $arguments
for arg in "$@"; do
deb_down "$arg"
done
fi