diff --git a/install.sh b/install.sh index 5059345..1a002c1 100755 --- a/install.sh +++ b/install.sh @@ -1,15 +1,17 @@ #!/bin/bash -#installs any commands set in the command input value +## +# installs commands using "go install" if any are set in the commands input +## function installCommands { - #if commands input is set pull the input and install them all using 'go install' - if [[ "$GO_INSTALL_COMMANDS" != "." ]]; then # "." is used as a default - #allows for multiple cmds using | + # "." is used as a default, meaning no commands were added + if [[ "$GO_INSTALL_COMMANDS" != "." ]]; then + #splitting into an array allows for multiple cmds using | INPUT_ARR=( $GO_INSTALL_COMMANDS ) for i in "${INPUT_ARR[@]}"; do echo "Installing go command from ${i}" if go install ${i}; then - echo "Command setup for ${i}" + echo "Installed ${i}" else echo "FATAL: Unable to install ${i} with go" exit 1 @@ -18,11 +20,13 @@ function installCommands { fi } +## +# fix version ensures we have a patch level version on our go version string from the go.mod file +## function fixVersion { DL_VSPL=( $DL_VERSION_RAW ) DL_VERSION="${DL_VSPL[1]}" - #ensure we have patch-level version, if not add 0 for stable releases # -P uses perl syntax DL_VERSION_PAD_CHECK="$(grep "^go [0-9]+.[0-9]+.[0-9]+" go.mod -P)" if [[ -z "$DL_VERSION_PAD_CHECK" ]]; then @@ -31,10 +35,12 @@ function fixVersion { fi } -#start script +#start + echo "Parsing go version" #check install version field first if [[ -z $GO_INSTALL_VERSION ]]; then + echo "No version input found, checking go.mod files" # -P uses perl syntax DL_VERSION_RAW="$(grep "^go [0-9]+.[0-9]+" go.mod -P)" if [[ -z "$DL_VERSION_RAW" ]]; then @@ -44,31 +50,22 @@ if [[ -z $GO_INSTALL_VERSION ]]; then fixVersion fi else + echo "Version input found" DL_VERSION=$GO_INSTALL_VERSION fi - echo "Found go version: ${DL_VERSION}" DL_ARCH=$GO_INSTALL_ARCH - -#ensure we have patch-level version, if not add 0 for stable releases -# -P uses perl syntax -# DL_VERSION_PAD_CHECK="$(grep "^go [0-9]+.[0-9]+.[0-9]+" go.mod -P)" -# if [[ -z "$DL_VERSION_PAD_CHECK" ]]; then -# DL_VERSION="$DL_VERSION"".0" -# echo "Fixing version number to ${DL_VERSION}" -# fi - echo "Checking if go is already installed" #check if go is already present before starting install process and delete files if purge input is set -# -v writes string that indicates command or command path to output, prevents command not found error +# -v writes string that indicates command or command path to output, prevents command not found error if go isn't installed GO_CHECK=$(command -v go) if [[ "$GO_CHECK" ]]; then #if the version of go matches the requested version, skip GVC=$(go version) if [[ "$GVC" == "go version go${DL_VERSION} linux/${DL_ARCH}" ]]; then - echo "Go ${DL_VERSION} already installed, skipping!" + echo "Go ${DL_VERSION} already installed, skipping go setup" installCommands exit 0 fi @@ -83,11 +80,11 @@ if [[ "$GO_CHECK" ]]; then fi fi -echo "Ready for install" - +echo "Ready to install" echo "Downloading go files for ${DL_VERSION}/${DL_ARCH}" PATH_FOR_FILES=/usr/local/go PATH_FOR_TAR=/usr/local +#creating our files with proper file perms sudo mkdir -v -m 0777 -p "$PATH_FOR_FILES" #wget @@ -100,12 +97,13 @@ sudo mkdir -v -m 0777 -p "$PATH_FOR_FILES" # - extract from pipe as a file # -C change to GOPATH directory if sudo wget -qO- "https://golang.org/dl/go${DL_VERSION}.linux-${DL_ARCH}.tar.gz" | sudo tar -zxf - -C "$PATH_FOR_TAR"; then - echo "Files downloaded" + echo "Files downloaded successfully" else echo "FATAL: Unable to download and extract files" + exit 1 fi -echo "Setting path for go command" +echo "Adding go to path" export PATH=$PATH:$PATH_FOR_FILES/bin echo "$PATH_FOR_FILES/bin" >> "$GITHUB_PATH" #set action path too