- skips if version is installed - moved command setup to function
This commit is contained in:
parent
d626c5f110
commit
b6d1948c4b
3
TODO.txt
3
TODO.txt
@ -1,3 +0,0 @@
|
|||||||
Comments are left in code using TODO# to track possible implementation location.
|
|
||||||
|
|
||||||
TODO1. check current installed version to see if it matches requested install version, only error if they don't match
|
|
59
install.sh
59
install.sh
@ -1,5 +1,24 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
#installs any commands set in the command input value
|
||||||
|
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 |
|
||||||
|
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}"
|
||||||
|
else
|
||||||
|
echo "FATAL: Unable to install ${i} with go"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#start script
|
||||||
echo "Starting Golang install"
|
echo "Starting Golang install"
|
||||||
|
|
||||||
#validate version and architecture
|
#validate version and architecture
|
||||||
@ -30,23 +49,24 @@ echo "Checking if go is already installed"
|
|||||||
# -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
|
||||||
GO_CHECK=$(command -v go)
|
GO_CHECK=$(command -v go)
|
||||||
if [[ "$GO_CHECK" ]]; then
|
if [[ "$GO_CHECK" ]]; then
|
||||||
#if purge flag is set remove old go files
|
#if the version of go matches the requested version, skip
|
||||||
if [[ "$GO_INSTALL_PURGE" == "yes" ]]; then
|
GVC=$(go version)
|
||||||
|
if [[ "$GVC" == "go version go${DL_VERSION} linux/${DL_ARCH}" ]]; then
|
||||||
|
echo "Go ${DL_VERSION} already installed, skipping!"
|
||||||
|
installCommands
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
#if the purge flag is not set and version does not match, exit
|
||||||
|
if [[ "$GO_INSTALL_PURGE" != "yes" ]]; then
|
||||||
|
echo "FATAL: The wrong version of Go is already installed, set purge to 'yes' if you wish to update installed version"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
echo "Removing old go versions"
|
echo "Removing old go versions"
|
||||||
sudo rm -r /usr/bin/go
|
sudo rm -r /usr/bin/go
|
||||||
sudo rm -r /usr/bin/gofmt
|
sudo rm -r /usr/bin/gofmt
|
||||||
else
|
|
||||||
#TODO1: if installed version matches requested version we can consider the job successful
|
|
||||||
#go version go1.23.0 linux/amd64
|
|
||||||
GVC=$(go version)
|
|
||||||
if [[ "$GVC" == "go version go${DL_VERSION} linux/${DL_ARCH}" ]]; then
|
|
||||||
echo "Requested Go version already installed, skipping."
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
echo "FATAL: Go is already installed, set purge to 'yes' if you wish to update installed version"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Ready for install"
|
echo "Ready for install"
|
||||||
|
|
||||||
echo "Downloading go files for ${DL_VERSION}/${DL_ARCH}"
|
echo "Downloading go files for ${DL_VERSION}/${DL_ARCH}"
|
||||||
@ -88,17 +108,4 @@ GP=$(go env GOPATH)/bin
|
|||||||
export PATH=$PATH:$GP
|
export PATH=$PATH:$GP
|
||||||
echo "$GP" >> "$GITHUB_PATH"
|
echo "$GP" >> "$GITHUB_PATH"
|
||||||
|
|
||||||
#if commands input is set pull the input and install them all using 'go install'
|
installCommands
|
||||||
if [[ "$GO_INSTALL_COMMANDS" != "." ]]; then # "." is used as a default
|
|
||||||
#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}"
|
|
||||||
else
|
|
||||||
echo "FATAL: Unable to install ${i} with go"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
Loading…
x
Reference in New Issue
Block a user