1+ #! /bin/sh
2+ set -e
3+ # Code generated by godownloader. DO NOT EDIT.
4+ #
5+
6+ usage () {
7+ this=$1
8+ cat << EOF
9+ $this : download go binaries for matthewmueller/joy
10+
11+ Usage: $this [-b] bindir [version]
12+ -b sets bindir or installation directory, default "/usr/local/bin"
13+ [version] is a version number from
14+ https://github.com/matthewmueller/joy/releases
15+ If version is missing, then an attempt to find the latest will be found.
16+
17+ EOF
18+ exit 2
19+ }
20+
21+ parse_args () {
22+ # BINDIR is /usr/local/bin unless set be ENV
23+ # over-ridden by flag below
24+
25+ BINDIR=${BINDIR:-/ usr/ local/ bin}
26+ while getopts " b:h?" arg; do
27+ case " $arg " in
28+ b) BINDIR=" $OPTARG " ;;
29+ h | \? ) usage " $0 " ;;
30+ esac
31+ done
32+ shift $(( OPTIND - 1 ))
33+ VERSION=$1
34+ }
35+ # this function wraps all the destructive operations
36+ # if a curl|bash cuts off the end of the script due to
37+ # network, either nothing will happen or will syntax error
38+ # out preventing half-done work
39+ execute () {
40+ TMPDIR=$( mktmpdir)
41+ echo " $PREFIX : downloading ${TARBALL_URL} "
42+ http_download " ${TMPDIR} /${TARBALL} " " ${TARBALL_URL} "
43+
44+ echo " $PREFIX : verifying checksums"
45+ http_download " ${TMPDIR} /${CHECKSUM} " " ${CHECKSUM_URL} "
46+ hash_sha256_verify " ${TMPDIR} /${TARBALL} " " ${TMPDIR} /${CHECKSUM} "
47+
48+ (cd " ${TMPDIR} " && untar " ${TARBALL} " )
49+ install -d " ${BINDIR} "
50+ install " ${TMPDIR} /${BINARY} " " ${BINDIR} /"
51+ echo " $PREFIX : installed as ${BINDIR} /${BINARY} "
52+ }
53+ is_supported_platform () {
54+ platform=$1
55+ found=1
56+ case " $platform " in
57+ darwin/amd64) found=0 ;;
58+ darwin/386) found=0 ;;
59+ linux/amd64) found=0 ;;
60+ linux/386) found=0 ;;
61+ windows/amd64) found=0 ;;
62+ windows/386) found=0 ;;
63+ freebsd/amd64) found=0 ;;
64+ freebsd/386) found=0 ;;
65+ netbsd/amd64) found=0 ;;
66+ netbsd/386) found=0 ;;
67+ openbsd/amd64) found=0 ;;
68+ openbsd/386) found=0 ;;
69+ esac
70+ return $found
71+ }
72+ check_platform () {
73+ if is_supported_platform " $PLATFORM " ; then
74+ # optional logging goes here
75+ true
76+ else
77+ echo " ${PREFIX} : platform $PLATFORM is not supported. Make sure this script is up-to-date and file request at https://github.com/${PREFIX} /issues/new"
78+ exit 1
79+ fi
80+ }
81+ adjust_version () {
82+ if [ -z " ${VERSION} " ]; then
83+ echo " $PREFIX : checking GitHub for latest version"
84+ VERSION=$( github_last_release " $OWNER /$REPO " )
85+ fi
86+ # if version starts with 'v', remove it
87+ VERSION=${VERSION# v}
88+ }
89+ adjust_format () {
90+ # change format (tar.gz or zip) based on ARCH
91+ true
92+ }
93+ adjust_os () {
94+ # adjust archive name based on OS
95+ true
96+ }
97+ adjust_arch () {
98+ # adjust archive name based on ARCH
99+ true
100+ }
101+
102+ cat /dev/null << EOF
103+ ------------------------------------------------------------------------
104+ https://github.com/client9/shlib - portable posix shell functions
105+ Public domain - http://unlicense.org
106+ https://github.com/client9/shlib/blob/master/LICENSE.md
107+ but credit (and pull requests) appreciated.
108+ ------------------------------------------------------------------------
109+ EOF
110+ is_command () {
111+ command -v " $1 " > /dev/null
112+ }
113+ uname_os () {
114+ os=$( uname -s | tr ' [:upper:]' ' [:lower:]' )
115+ echo " $os "
116+ }
117+ uname_arch () {
118+ arch=$( uname -m)
119+ case $arch in
120+ x86_64) arch=" amd64" ;;
121+ x86) arch=" 386" ;;
122+ i686) arch=" 386" ;;
123+ i386) arch=" 386" ;;
124+ aarch64) arch=" arm64" ;;
125+ armv5* ) arch=" arm5" ;;
126+ armv6* ) arch=" arm6" ;;
127+ armv7* ) arch=" arm7" ;;
128+ esac
129+ echo ${arch}
130+ }
131+ uname_os_check () {
132+ os=$( uname_os)
133+ case " $os " in
134+ darwin) return 0 ;;
135+ dragonfly) return 0 ;;
136+ freebsd) return 0 ;;
137+ linux) return 0 ;;
138+ android) return 0 ;;
139+ nacl) return 0 ;;
140+ netbsd) return 0 ;;
141+ openbsd) return 0 ;;
142+ plan9) return 0 ;;
143+ solaris) return 0 ;;
144+ windows) return 0 ;;
145+ esac
146+ echo " $0 : uname_os_check: internal error '$( uname -s) ' got converted to '$os ' which is not a GOOS value. Please file bug at https://github.com/client9/shlib"
147+ return 1
148+ }
149+ uname_arch_check () {
150+ arch=$( uname_arch)
151+ case " $arch " in
152+ 386) return 0 ;;
153+ amd64) return 0 ;;
154+ arm64) return 0 ;;
155+ armv5) return 0 ;;
156+ armv6) return 0 ;;
157+ armv7) return 0 ;;
158+ ppc64) return 0 ;;
159+ ppc64le) return 0 ;;
160+ mips) return 0 ;;
161+ mipsle) return 0 ;;
162+ mips64) return 0 ;;
163+ mips64le) return 0 ;;
164+ s390x) return 0 ;;
165+ amd64p32) return 0 ;;
166+ esac
167+ echo " $0 : uname_arch_check: internal error '$( uname -m) ' got converted to '$arch ' which is not a GOARCH value. Please file bug report at https://github.com/client9/shlib"
168+ return 1
169+ }
170+ untar () {
171+ tarball=$1
172+ case " ${tarball} " in
173+ * .tar.gz | * .tgz) tar -xzf " ${tarball} " ;;
174+ * .tar) tar -xf " ${tarball} " ;;
175+ * .zip) unzip " ${tarball} " ;;
176+ * )
177+ echo " Unknown archive format for ${tarball} "
178+ return 1
179+ ;;
180+ esac
181+ }
182+ mktmpdir () {
183+ test -z " $TMPDIR " && TMPDIR=" $( mktemp -d) "
184+ mkdir -p " ${TMPDIR} "
185+ echo " ${TMPDIR} "
186+ }
187+ http_download () {
188+ local_file=$1
189+ source_url=$2
190+ header=$3
191+ headerflag=' '
192+ destflag=' '
193+ if is_command curl; then
194+ cmd=' curl --fail -sSL'
195+ destflag=' -o'
196+ headerflag=' -H'
197+ elif is_command wget; then
198+ cmd=' wget -q'
199+ destflag=' -O'
200+ headerflag=' --header'
201+ else
202+ echo " http_download: unable to find wget or curl"
203+ return 1
204+ fi
205+ if [ -z " $header " ]; then
206+ echo " $cmd " $destflag " $local_file " " $source_url "
207+ $cmd $destflag " $local_file " " $source_url "
208+ else
209+ echo " $cmd "
210+ $cmd $headerflag " $header " $destflag " $local_file " " $source_url "
211+ fi
212+ }
213+ github_api () {
214+ local_file=$1
215+ source_url=$2
216+ header=" "
217+ case " $source_url " in
218+ https://api.github.com* )
219+ test -z " $GITHUB_TOKEN " || header=" Authorization: token $GITHUB_TOKEN "
220+ ;;
221+ esac
222+ http_download " $local_file " " $source_url " " $header "
223+ }
224+ github_last_release () {
225+ owner_repo=$1
226+ giturl=" https://api.github.com/repos/${owner_repo} /releases/latest"
227+ html=$( github_api - " $giturl " )
228+ version=$( echo " $html " | tr ' ,' ' \n' | grep -m 1 " \" tag_name\" :" | cut -f4 -d' "' )
229+ test -z " $version " && return 1
230+ echo " $version "
231+ }
232+ hash_sha256 () {
233+ TARGET=${1:-/ dev/ stdin}
234+ if is_command gsha256sum; then
235+ hash=$( gsha256sum " $TARGET " ) || return 1
236+ echo " $hash " | cut -d ' ' -f 1
237+ elif is_command sha256sum; then
238+ hash=$( sha256sum " $TARGET " ) || return 1
239+ echo " $hash " | cut -d ' ' -f 1
240+ elif is_command shasum; then
241+ hash=$( shasum -a 256 " $TARGET " 2> /dev/null) || return 1
242+ echo " $hash " | cut -d ' ' -f 1
243+ elif is_command openssl; then
244+ hash=$( openssl -dst openssl dgst -sha256 " $TARGET " ) || return 1
245+ echo " $hash " | cut -d ' ' -f a
246+ else
247+ echo " hash_sha256: unable to find command to compute sha-256 hash"
248+ return 1
249+ fi
250+ }
251+ hash_sha256_verify () {
252+ TARGET=$1
253+ checksums=$2
254+ if [ -z " $checksums " ]; then
255+ echo " hash_sha256_verify: checksum file not specified in arg2"
256+ return 1
257+ fi
258+ BASENAME=${TARGET##*/ }
259+ want=$( grep " ${BASENAME} " " ${checksums} " 2> /dev/null | tr ' \t' ' ' | cut -d ' ' -f 1)
260+ if [ -z " $want " ]; then
261+ echo " hash_sha256_verify: unable to find checksum for '${TARGET} ' in '${checksums} '"
262+ return 1
263+ fi
264+ got=$( hash_sha256 " $TARGET " )
265+ if [ " $want " != " $got " ]; then
266+ echo " hash_sha256_verify: checksum for '$TARGET ' did not verify ${want} vs $got "
267+ return 1
268+ fi
269+ }
270+ cat /dev/null << EOF
271+ ------------------------------------------------------------------------
272+ End of functions from https://github.com/client9/shlib
273+ ------------------------------------------------------------------------
274+ EOF
275+
276+ OWNER=matthewmueller
277+ REPO=joy
278+ BINARY=joy
279+ FORMAT=tar.gz
280+ OS=$( uname_os)
281+ ARCH=$( uname_arch)
282+ PREFIX=" $OWNER /$REPO "
283+ PLATFORM=" ${OS} /${ARCH} "
284+ GITHUB_DOWNLOAD=https://github.com/${OWNER} /${REPO} /releases/download
285+
286+ uname_os_check " $OS "
287+ uname_arch_check " $ARCH "
288+
289+ parse_args " $@ "
290+
291+ check_platform
292+
293+ adjust_version
294+
295+ adjust_format
296+
297+ adjust_os
298+
299+ adjust_arch
300+
301+ echo " $PREFIX : found version ${VERSION} for ${OS} /${ARCH} "
302+
303+ NAME=${BINARY} _${VERSION} _${OS} _${ARCH}
304+ TARBALL=${NAME} .${FORMAT}
305+ TARBALL_URL=${GITHUB_DOWNLOAD} /v${VERSION} /${TARBALL}
306+ CHECKSUM=${BINARY} _${VERSION} _checksums.txt
307+ CHECKSUM_URL=${GITHUB_DOWNLOAD} /v${VERSION} /${CHECKSUM}
308+
309+ # Adjust binary name if windows
310+ if [ " $OS " = " windows" ]; then
311+ BINARY=" ${BINARY} .exe"
312+ fi
313+
314+ execute
0 commit comments