|
11 | 11 | #
|
12 | 12 | # Will install gvm in `<app-sys-root>/gvm` and add `/etc/profile.d/gvm.sh`.
|
13 | 13 |
|
| 14 | +declare -r _GVM_ROOT="$APPS_HOME/gvm" |
| 15 | +declare -r _GVM_VERSION='34b56311e1e3add4b8f7ce3eeadd23f19c627328' |
14 | 16 | declare -r _GVM_PROFILE="$APPS_HOME/etc/profile.d/gvm.sh"
|
15 | 17 | declare -r _GVM_INSTALLER_URL='https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer'
|
| 18 | +declare -r _GVM_BOOTSTRAP_VERSION='release-branch.go1.4' |
16 | 19 |
|
17 | 20 | _install_gvm() {
|
18 |
| - local app_sys_root="$1" |
19 |
| - local gvm_dir="$app_sys_root/gvm" |
20 |
| - local gvm_version="$2" |
21 |
| - |
22 | 21 | if [[ -f "$_GVM_PROFILE" ]]; then
|
23 | 22 | return
|
24 | 23 | fi
|
25 | 24 |
|
26 | 25 | curl -L -O "$_GVM_INSTALLER_URL"
|
27 |
| - GVM_NO_UPDATE_PROFILE=true bash ./gvm-installer "$gvm_version" "$app_sys_root" |
| 26 | + GVM_NO_UPDATE_PROFILE=true bash ./gvm-installer "$_GVM_VERSION" "$APPS_HOME" |
28 | 27 | rm ./gvm-installer
|
29 |
| - echo ". '$gvm_dir/scripts/gvm'" >>"$_GVM_PROFILE" |
| 28 | + echo ". '$_GVM_ROOT/scripts/gvm'" >>"$_GVM_PROFILE" |
30 | 29 | chmod +x "$_GVM_PROFILE"
|
31 | 30 | }
|
32 | 31 |
|
33 |
| -_install_go() { |
34 |
| - local app_sys_root="$1" |
35 |
| - local go_version="$2" |
36 |
| - local gvm_version="$3" |
| 32 | +_prepare_go_repo_for_bootstrap() { |
| 33 | + local repo_url='https://go.googlesource.com/go' |
| 34 | + local repo_path="$_GVM_ROOT/archive/go" |
| 35 | + local version="$_GVM_BOOTSTRAP_VERSION" |
| 36 | + local orig_pwd="$PWD" |
37 | 37 |
|
38 |
| - if [[ -z "$go_version" ]]; then |
39 |
| - return |
| 38 | + printf 'Preparing %s to build %s\n' "$repo_path" "$version" |
| 39 | + |
| 40 | + if [[ ! -d "$repo_path" ]] && ! git clone "$repo_url" "$repo_path"; then |
| 41 | + printf 'Failed to clone %s into %s\n' "$repo_url" "$repo_path" >&2 |
| 42 | + exit 1 |
| 43 | + elif ! cd "$repo_path" >/dev/null; then |
| 44 | + printf 'Failed to change into repo directory %s\n' "$repo_path" >&2 |
| 45 | + exit 1 |
| 46 | + elif ! git fetch origin "$version"; then |
| 47 | + printf 'Failed to fetch bootstrap branch %s\n' "$version" >&2 |
| 48 | + exit 1 |
| 49 | + elif ! git checkout "$version"; then |
| 50 | + printf 'Failed to checkout bootstrap branch %s\n' "$version" >&2 |
| 51 | + exit 1 |
| 52 | + elif ! cd "$orig_pwd" >/dev/null; then |
| 53 | + printf 'Failed to change directory back to %s\n' "$orig_pwd" >&2 |
| 54 | + exit 1 |
40 | 55 | fi
|
| 56 | +} |
41 | 57 |
|
42 |
| - _install_gvm "$app_sys_root" "$gvm_version" |
| 58 | +_install_go() { |
| 59 | + _install_gvm |
43 | 60 | . "$_GVM_PROFILE"
|
44 |
| - gvm install go1.4.3 |
45 |
| - gvm use go1.4.3 |
46 |
| - gvm install $go_version |
47 |
| - gvm use $go_version --default |
48 |
| - gvm uninstall go1.4.3 |
| 61 | + |
| 62 | + if [[ -f "$_GVM_ROOT/gos/$GO_VERSION/bin/go" ]]; then |
| 63 | + printf 'Go version %s already installed\n' "$GO_VERSION" |
| 64 | + return |
| 65 | + elif ! _prepare_go_repo_for_bootstrap; then |
| 66 | + return 1 |
| 67 | + elif ! gvm install "$_GVM_BOOTSTRAP_VERSION"; then |
| 68 | + return 1 |
| 69 | + elif ! gvm use "$_GVM_BOOTSTRAP_VERSION"; then |
| 70 | + return 1 |
| 71 | + elif ! GOROOT_BOOTSTRAP="$_GVM_ROOT/gos/$_GVM_BOOTSTRAP_VERSION" \ |
| 72 | + gvm install "$GO_VERSION"; then |
| 73 | + return 1 |
| 74 | + elif ! gvm use "$GO_VERSION" --default; then |
| 75 | + return 1 |
| 76 | + fi |
| 77 | + gvm uninstall "$_GVM_BOOTSTRAP_VERSION" |
49 | 78 | }
|
50 | 79 |
|
51 | 80 | _install_go "$@"
|
0 commit comments