X-Git-Url: https://git.josue.xyz/?a=blobdiff_plain;f=golang%2Finstall.bash;h=fa97d207800cb9846adbfdf263fe06efe005ee1d;hb=969df21e47c4d8312925638739a23eef0c349e1c;hp=59ca0f4df08321a2c951a7bb9f464f79912e77e6;hpb=aca704f2d3b6f2ad94aa9e440e7dc9050821be5d;p=webi-installers%2F.git diff --git a/golang/install.bash b/golang/install.bash index 59ca0f4..fa97d20 100644 --- a/golang/install.bash +++ b/golang/install.bash @@ -10,7 +10,6 @@ # mkdir -p hello/ # pushd hello/ # ``` -#
# # ```bash # cat << EOF >> main.go @@ -25,7 +24,6 @@ # } # EOF # ``` -#
# # ```bash # go fmt ./... @@ -37,67 +35,94 @@ set -e set -u -################### -# Install go # -################### +GOBIN="${HOME}/go" +GOBIN_REAL="${HOME}/.local/opt/go-bin-v${WEBI_VERSION}" -new_go_home="${HOME}/.local/opt/go-v${WEBI_VERSION}" -new_go="${HOME}/.local/opt/go-v${WEBI_VERSION}/bin/go" +# The package is 'golang', but the command is 'go' +pkg_cmd_name="go" -# Test for existing version -set +e -cur_go="$(command -v go)" -set -e -if [ -n "$cur_go" ]; then - cur_ver=$(go version | cut -d' ' -f3 | sed 's:go::') - if [ "$cur_ver" == "$(echo $WEBI_VERSION | sed 's:\.0::g')" ]; then - echo "go v$WEBI_VERSION already installed at $cur_go" - exit 0 - elif [ "$cur_go" != "$new_go" ]; then - echo "WARN: possible conflict with go v$WEBI_VERSION at $cur_go" - fi -fi - - -# Note: this file is `source`d by the true installer and hence will have the webi functions - -# because we created releases.js we can use webi_download() -# downloads go to ~/Downloads -webi_download - -# because this is tar or zip, we can webi_extract() -# extracts to the WEBI_TMP directory, raw (no --strip-prefix) -webi_extract - -pushd "$WEBI_TMP" 2>&1 >/dev/null - echo Installing go v${WEBI_VERSION} as "$new_go" - - # simpler for single-binary commands - #mv ./example*/bin/example "$HOME/.local/bin" - - # best for packages and toolchains - rm -rf "$new_go_home" - if [ -n "$(command -v rsync 2>/dev/null | grep rsync)" ]; then - rsync -Krl ./go*/ "$new_go_home/" 2>/dev/null - else - cp -Hr ./go*/* "$new_go_home/" 2>/dev/null - cp -Hr ./go*/.* "$new_go_home/" 2>/dev/null - fi +# NOTE: pkg_* variables can be defined here +# pkg_cmd_name +# pkg_src, pkg_src_bin, pkg_src_cmd +# pkg_dst, pkg_dst_bin, pkg_dst_cmd +# +# Their defaults are defined in webi/template.bash at https://github.com/webinstall/packages + +pkg_get_current_version() { + # 'go version' has output in this format: + # go version go1.14.2 darwin/amd64 + # This trims it down to just the version number: + # 1.14.2 + echo "$(go version 2>/dev/null | head -n 1 | cut -d' ' -f3 | sed 's:go::')" +} + +pkg_format_cmd_version() { + # 'go v1.14.0' will be 'go1.14' + my_version=$(echo "$1" | sed 's:\.0::g') + echo "${pkg_cmd_name}${my_version}" +} + +pkg_link_src_dst() { + # 'pkg_dst' will default to $HOME/.local/opt/go + # 'pkg_src' will be the installed version, such as to $HOME/.local/opt/go-v1.14.2 + rm -rf "$pkg_dst" + ln -s "$pkg_src" "$pkg_dst" + + # Go has a special $GOBIN + + # 'GOBIN' is set above to "${HOME}/go" + # 'GOBIN_REAL' will be "${HOME}/.local/opt/go-bin-v${WEBI_VERSION}" + rm -rf "$GOBIN" + mkdir -p "$GOBIN_REAL/bin" + ln -s "$GOBIN_REAL" "$GOBIN" +} + +pkg_pre_install() { + # web_* are defined in webi/template.bash at https://github.com/webinstall/packages + + # multiple versions may be installed + # if one already matches, it will simply be re-linked + webi_check + + # the download is quite large - hopefully you have wget installed + # will go to ~/Downloads by default + webi_download + + # Multiple formats are supported: .xz, .tar.*, and .zip + # will be extracted to $WEBI_TMP + webi_extract +} + +pkg_install() { + pushd "$WEBI_TMP" 2>&1 >/dev/null + + # remove the versioned folder, just in case it's there with junk + rm -rf "$pkg_src" + + # rename the entire extracted folder to the new location + # (this will be "$HOME/.local/opt/go-v$WEBI_VERSION" by default) + mv ./"$pkg_cmd_name"* "$pkg_src" + + popd 2>&1 >/dev/null +} + +pkg_post_install() { + pkg_link_src_dst + + # web_path_add is defined in webi/template.bash at https://github.com/webinstall/packages + # Updates PATH with + # "$HOME/.local/opt/go" + webi_path_add "$pkg_dst_bin" + webi_path_add "$GOBIN/bin" # Install x go - $new_go_home/bin/go get golang.org/x/tools/cmd/goimports > /dev/null 2>/dev/null - $new_go_home/bin/go get golang.org/x/tools/cmd/gorename > /dev/null 2>/dev/null - $new_go_home/bin/go get golang.org/x/tools/cmd/gotype > /dev/null 2>/dev/null - $new_go_home/bin/go get golang.org/x/tools/cmd/stringer > /dev/null 2>/dev/null -popd 2>&1 >/dev/null - -################### -# Update PATH # -################### - -# TODO get better output from pathman / output the path to add as return to webi bootstrap -webi_path_add "$new_go_home/bin" -webi_path_add "$HOME/go/bin" - -echo "Installed 'go' (and go tools)" -echo "" + echo "Installing go extended tools (goimports, gorename, etc)" + "$pkg_dst_cmd" get golang.org/x/tools/cmd/goimports > /dev/null 2>/dev/null + "$pkg_dst_cmd" get golang.org/x/tools/cmd/gorename > /dev/null 2>/dev/null + "$pkg_dst_cmd" get golang.org/x/tools/cmd/gotype > /dev/null 2>/dev/null + "$pkg_dst_cmd" get golang.org/x/tools/cmd/stringer > /dev/null 2>/dev/null +} + +pkg_post_install_message() { + echo "Installed 'go' (and go tools)" +}