forked from vbatts/slackware-container
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_paths.sh
executable file
·120 lines (103 loc) · 2.85 KB
/
get_paths.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
#!/bin/bash
# _is_sourced tests whether this script is being source, or executed directly
_is_sourced() {
# https://unix.stackexchange.com/a/215279
# thanks @tianon
[ "${FUNCNAME[${#FUNCNAME[@]} - 1]}" == 'source' ]
}
_usage() {
echo "... just read the code"
}
_release_base() {
echo "${1}" | cut -d - -f 1
}
_fetch_file_list() {
local mirror="${1}"
local release="${2}"
local directory="${3}"
local ret
curl -sSL "${mirror}/${release}/${directory}/FILE_LIST"
ret=$?
if [ $ret -ne 0 ] ; then
return $ret
fi
}
_sections_from_file_list() {
local file_list="${1}"
local ret
grep '/tagfile$' "${file_list}" | awk '{ print $8 }' | sed -e 's|./\([[:alpha:]]*\)/tagfile$|\1|g'
ret=$?
if [ $ret -ne 0 ] ; then
return $ret
fi
}
_fetch_tagfile() {
local mirror="${1}"
local release="${2}"
local section="${3}"
local ret
curl -sSL "${mirror}/${release}/$(_release_base "${release}")/${section}/tagfile"
ret=$?
if [ $ret -ne 0 ] ; then
return $ret
fi
}
main() {
local mirror
local release
local tmp_file_list
local ret
mirror="${MIRROR:-http://slackware.osuosl.org}"
release="${RELEASE:-slackware64-current}"
while getopts ":hm:r:tpe" opts ; do
case "${opts}" in
m)
mirror="${OPTARG}"
;;
r)
release="${OPTARG}"
;;
t)
fetch_tagfiles=1
;;
p)
fetch_patches=1
;;
e)
fetch_extra=1
;;
*)
_usage
exit 1
;;
esac
done
shift $((OPTIND-1))
tmp_dir="$(mktemp -d)"
tmp_file_list="${tmp_dir}/FILE_LIST"
if [ -n "${fetch_patches}" ] ; then
_fetch_file_list "${mirror}" "${release}" "patches" >> "${tmp_file_list}"
elif [ -n "${fetch_extra}" ] ; then
_fetch_file_list "${mirror}" "${release}" "extra" >> "${tmp_file_list}"
else
_fetch_file_list "${mirror}" "${release}" "$(_release_base "${release}")" > "${tmp_file_list}"
fi
ret=$?
if [ $ret -ne 0 ] ; then
echo "ERROR fetching FILE_LIST" >&2
exit $ret
fi
if [ -n "${fetch_tagfiles}" ] ; then
for section in $(_sections_from_file_list "${tmp_file_list}") ; do
mkdir -p "${tmp_dir}/${section}"
_fetch_tagfile "${mirror}" "${release}" "${section}" > "${tmp_dir}/${section}/tagfile"
if [ $ret -ne 0 ] ; then
echo "ERROR fetching ${section}/tagfile" >&2
exit $ret
fi
done
fi
grep '\.t.z$' "${tmp_file_list}" | awk '{ print $8 }' | sed -e 's|\./\(.*\.t.z\)$|\1|g'
}
_is_sourced || main "${@}"
# vim:set shiftwidth=4 softtabstop=4 expandtab: