diff --git a/README.md b/README.md index c0e12ab..ce9d9ab 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Additional options can be specified when installing Go: -pb, --with-protobuf Install Go protocol buffers. -b, --with-build-tools Install package build tools. -B, --binary Only install from binary. + --preferbinary Attempt a binary install, falling back to source. -h, --help Display this message. List Go Versions diff --git a/scripts/install b/scripts/install index 3d07522..719bd62 100755 --- a/scripts/install +++ b/scripts/install @@ -38,6 +38,9 @@ read_command_line() { -B|--binary) INSTALL_SOURCE="binary" ;; + --prefer-binary) + INSTALL_SOURCE="preferbinary" + ;; -h|--help) show_usage exit 0 @@ -258,47 +261,57 @@ install_goprotobuf() { fi } -main() { - trap 'display_fatal "Canceled!"' INT - read_command_line "$@" - [[ "$VERSION" == "" ]] && display_fatal "No version specified" - - if [[ "x$INSTALL_SOURCE" != "xbinary" ]]; then - download_source - check_tag - if [[ "$?" == "1" ]]; then - update_source - check_tag || display_fatal "Unrecognized Go version" - fi - if [[ "$GO_NAME" == "" ]]; then - GO_NAME=$version - fi - install_go - else - if [[ "$GO_NAME" == "" ]]; then - GO_NAME=$VERSION - fi - install_go_binary +install_from_source() { + download_source + check_tag + if [[ "$?" == "1" ]]; then + update_source + check_tag || display_fatal "Unrecognized Go version" fi + if [[ "$GO_NAME" == "" ]]; then + GO_NAME=$version + fi + install_go GVM_GOINSTALL="goinstall" which goinstall &> /dev/null || GVM_GOINSTALL="go get" - if [[ "x$INSTALL_SOURCE" != "xbinary" ]]; then - x="$(hg tags -R "$GO_CACHE_PATH")"; echo "${x#*b0819469a6df}" | $GREP_PATH "$version " &> /dev/null - if [[ "$?" == "1" ]]; then - if [[ "$INSTALL_BUILD_TOOLS" == "true" ]]; then - install_gb || display_warning "Failed to install gb" - install_gpkg || display_warning "Failed to install gpkg" - fi - if [[ "$INSTALL_PB" == "true" ]]; then - install_goprotobuf - fi + x="$(hg tags -R "$GO_CACHE_PATH")"; echo "${x#*b0819469a6df}" | $GREP_PATH "$version " &> /dev/null + if [[ "$?" == "1" ]]; then + if [[ "$INSTALL_BUILD_TOOLS" == "true" ]]; then + install_gb || display_warning "Failed to install gb" + install_gpkg || display_warning "Failed to install gpkg" + fi + if [[ "$INSTALL_PB" == "true" ]]; then + install_goprotobuf fi fi cd "$GO_INSTALL_ROOT" && find . > manifest } +main() { + trap 'display_fatal "Canceled!"' INT + read_command_line "$@" + [[ "$VERSION" == "" ]] && display_fatal "No version specified" + + if [[ "$GO_NAME" == "" ]]; then + GO_NAME=$VERSION + fi + + if [[ "x$INSTALL_SOURCE" == "xbinary" ]]; then + install_go_binary + elif [[ "x$INSTALL_SOURCE" == "xpreferbinary" ]]; then + install_go_binary || { + display_message "Falling back to source installation of $GO_NAME" + install_from_source + } + else + install_from_source + fi + + cd "$GO_INSTALL_ROOT" && find . > manifest +} + main "$@" diff --git a/tests/scenario/gvm_install_1.2.2_preferbinary_comment_test.sh b/tests/scenario/gvm_install_1.2.2_preferbinary_comment_test.sh new file mode 100644 index 0000000..ce6cbc2 --- /dev/null +++ b/tests/scenario/gvm_install_1.2.2_preferbinary_comment_test.sh @@ -0,0 +1 @@ +gvm install go1.2 --preferbinary #status=0