move lang from install to it's own folder

master
David Kebler 2023-03-08 08:30:25 -08:00
parent 95beb818d0
commit ed853fdf99
9 changed files with 148 additions and 30 deletions

View File

@ -1,8 +0,0 @@
# --- Go Language Environment BEGIN ---
export GOROOT=/opt/go
export PATH=$PATH:/opt/go/bin
export GOPATH=/opt/go/apps
export PATH=$PATH:/opt/go/apps/bin
# --- Go Language Environment END ---

View File

@ -1,22 +0,0 @@
#!/bin/bash
declare dir="$(dirname $(realpath "${BASH_SOURCE:-$0}"))"
# todo call distro specific install
echo updating...
sudo apt-get update >/dev/null 2>&1
echo installing pip and venv for python3
sudo apt-get install python3-pip python3-venv -y >/dev/null
echo loading $dir/python.lib
source $dir/python.lib
echo available alias for pip use with sudo for libraries
alias | grep spip
mkdir -p /opt/python/apps/bin
echo always use pip with sudo for libraries, for apps use pipx
sudo -H python3 -m pip install pipx >/dev/null 2>&1
BASH_SHELL_HOST=${BASH_SHELL_HOST:-$(dirname $BASH_SHELL_BASE)/$(hostname)}
mkdir -p $BASH_SHELL_HOST/load
cp $dir/python.lib $BASH_SHELL_HOST/load/
echo installed pipx version $(pipx --version) at $(which pipx)
echo installing pypi apps to
env | grep PIP
echo available alias
alias | grep pipx

148
lang/go/go.inst Executable file
View File

@ -0,0 +1,148 @@
#!/bin/bash
go_install () {
local latest_url="https://go.dev/VERSION?m=text"
## START INSTALL
module_load host-utils
PLATFORM=$(get_platform)
if [ -z "$PLATFORM" ]; then
echo "Your operating system is not supported by this install script."
return 1
fi
local goroot
local force
declare OPTION
declare OPTARG
declare OPTIND
while getopts 'fr:' OPTION; do
# echo $OPTION $OPTARG
case "$OPTION" in
f)
force=true
;;
r)
goroot=$OPTARG
;;
*)
echo unknown option $OPTION
;;
esac
done
shift $(( OPTIND - 1 ))
if [[ $GOROOT ]]; then
goroot=$GOROOT
else
[[ ! $goroot ]] && goroot="$HOME/.go"
fi
[[ $GOPATH ]] && gopath=$GOROOT || gopath=$goroot/apps
goenv=(
"\n"
"# ======= GO LANGUAGE ENVIRONMENT ===========\n"
'export GOROOT='"$goroot"'\n'
'export PATH=$PATH:'"$goroot"'/bin\n'
'export GOPATH='"$gopath"'\n'
'export PATH=$PATH:'"$gopath"'/bin\n'
"# ======= GO LANGUAGE ENVIRONMENT ==========="
"\n")
module_load confirm
echo go install and environment will be
printf "${goenv[*]}\n"
confirm Do you want to continue || return 1
VERSION=$(curl -s $latest_url | sed 's/^go//')
if [[ $(which go) ]]; then
INSTALLED_VERSION=$(echo $(go version)| awk '{print $3}' | cut -c 3-)
# INSTALLED_VERSION=1.15.2 # this is for testing upgrade, comment out for production
echo installed: $INSTALLED_VERSION available: $VERSION
if [ "$INSTALLED_VERSION" == "$VERSION" ]; then
if [[ ! $force ]]; then
echo Installed Version $INSTALLED_VERSION is current nothing to do, exiting
echo use -r flag to force reinstall
return 2
fi
fi
confirm Do you want to upgrade || return 1
fi
echo installing version $VERSION ......
PACKAGE_NAME="go$VERSION.$PLATFORM.tar.gz"
TEMP_DIRECTORY=$(mktemp -d)
URL=https://go.dev/dl/go$VERSION.$PLATFORM.tar.gz
echo "Downloading $URL ..."
if which wget 2>/dev/null; then
wget $URL -O "$TEMP_DIRECTORY/go.tar.gz"
else
curl -o "$TEMP_DIRECTORY/go.tar.gz" $URL
fi
if [ $? -ne 0 ]; then
echo "Download failed! Exiting."
return 1
fi
echo "Extracting File..."
if ! mkdir -p "$goroot"; then
echo unable to make directory $goroot with current user $user; aborting
return 3
fi
tar -C "$goroot" --strip-components=1 -xzf "$TEMP_DIRECTORY/go.tar.gz"
echo done installing go binary and support files
rm -rf $TEMP_DIRECTORY
echo making go workspace directories
mkdir -p "${gopath}/"{src,pkg,bin}
# TODO set correct permission if all have access
echo "Setting up GO environment..."
if [[ -d $BASH_SHELL_HOST ]] && [[ ! $goroot == "$HOME/.go" ]]; then
echo saving environment to $BASH_SHELL_HOST/load/go.env
# confirm Do you want to continue || return 1
printf "${goenv[*]}\n" > $BASH_SHELL_HOST/load/go.env
else
if [[ -d $BASH_SHELL_USER_DIR ]] && [[ $goroot == "$HOME/.go" ]]; then
echo saving environment to $BASH_SHELL_USER_DIR/load/go.env
# confirm Do you want to continue || return 1
printf "${goenv[*]}\n" > $BASH_SHELL_USER_DIR/load/go.env
else
echo appending environment block to $HOME/.bashrc
# confirm Do you want to continue || return 1
printf "${goenv[*]}\n" >> $HOME/.bashrc
cat $HOME/.bashrc
fi
fi
echo -e "\nGo $VERSION was installed into $goroot.\n(re)start a new shell for environment to take effect"
return 0
}
# go_uninstall () {
# }
# go_upgrade () {
# }
(return 0 2>/dev/null) || go_install $@