9175d0cd00c5496e9cad49abb2fcfdf11efab699
[buildscripts] / go
1 #!/bin/bash
2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
4
5 # usage: no args, run to install latest go.
6
7 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
8
9 shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4
10 source /a/bin/errhandle/err
11
12 m() { printf "$pre %s\n" "$*"; "$@"; }
13 e() { printf "$pre %s\n" "$*"; }
14 err() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $0: $*" >&2; }
15
16 m cd /a/opt/go.git
17 m git fetch
18 vers=($(git tag | sort -Vr | grep -E '^go[0-9.]+$' | head))
19
20 ver=${vers[0]}
21 dl() {
22 arch=$(dpkg --print-architecture)
23 f=${ver}.linux-${arch}.tar.gz
24
25 if [[ -e $f ]]; then
26 timestamp=$(stat -c %Y $f)
27 else
28 timestamp=0
29 fi
30 m wget -N https://dl.google.com/go/$f || ret=$?
31 }
32 dl
33 # 8 is return code for 404. for a new release, they might not have a binary out yet
34 if [[ $ret == 8 ]]; then
35 ver=${vers[1]}
36 dl
37 fi
38
39 new_timestamp=$(stat -c %Y $f)
40 if [[ $timestamp != $new_timestamp || ! -e /usr/local/go/bin/go ]]; then
41 m sudo rm -rf /usr/local/go
42 m sudo tar -C /usr/local -xzf $f
43 fi
44
45 shopt -s nullglob
46 for x in go*.tar.gz; do
47 if [[ $x == $f ]]; then continue; fi
48 rm -fv $x
49 done
50
51 go get -u mvdan.cc/fdroidcl