added first draft of golang installer
This commit is contained in:
parent
b3613062c6
commit
306e13dfba
1 changed files with 172 additions and 0 deletions
172
extras/golang.install
Normal file
172
extras/golang.install
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
#/bin/bash
|
||||
# golang Bootstrap installer script
|
||||
|
||||
# Bash expansions to get the name and location of this script when run
|
||||
scriptname="${BASH_SOURCE[0]##*/}"
|
||||
rundir="${BASH_SOURCE[0]%/*}"
|
||||
sys_arch=$(uname -m)
|
||||
|
||||
golang_bashrc="# Golang system path setup
|
||||
export PATH=\$PATH:/usr/local/go/bin
|
||||
"
|
||||
|
||||
# Source PRbL Functions locally or retrieve from online
|
||||
if [ ! -z $prbl_functions ] ; then
|
||||
source $prbl_functions
|
||||
else
|
||||
source <(curl -ks 'https://raw.githubusercontent.com/pyr0ball/PRbL/master/functions')
|
||||
fi
|
||||
|
||||
logfile="${rundir}/${pretty_date}_${scriptname}.log"
|
||||
installdir="$HOME/devl"
|
||||
|
||||
# Dependencies
|
||||
sys_packages=(
|
||||
cmake
|
||||
libunwind-dev
|
||||
libgtk3-dev
|
||||
libgmp3-dev
|
||||
)
|
||||
|
||||
pip_packages=()
|
||||
|
||||
repo_packages=()
|
||||
|
||||
codedog_bashrc="# CodeDog system path setup
|
||||
export PATH=\"\$PATH:\$HOME/devl/CodeDog\"
|
||||
"
|
||||
|
||||
strip-html-tags() {
|
||||
local input="$1"
|
||||
local stripped=$(echo "$input" | sed 's/<[^>]*>//g')
|
||||
echo "$stripped"
|
||||
}
|
||||
|
||||
# Functions
|
||||
check-deps(){
|
||||
# Iterate through the list of required packages and check if installed
|
||||
for pkg in ${packages[@]} ; do
|
||||
local _pkg=$(dpkg -l $pkg 2>&1 >/dev/null ; echo $?)
|
||||
# If not installed, add it to the list of missing bins
|
||||
if [[ $_pkg != 0 ]] ; then
|
||||
bins_missing+=($pkg)
|
||||
fi
|
||||
done
|
||||
# Count the number of entries in bins_missing
|
||||
local _bins_missing=${#bins_missing[@]}
|
||||
# If higher than 0, return a fail (1)
|
||||
if [[ $_bins_missing != 0 ]] ; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
install-deps(){
|
||||
logger echo "Installing packages $sys_packages"
|
||||
run "for $_package in $sys_packages ; do sudo apt-get install -y $_package ; done"
|
||||
if [ -f ${rundir}/requirements.txt ] ; then
|
||||
pip install -y ${rundir}/requirements.txt
|
||||
else
|
||||
if [ ! -z $pip_packages ] ; then
|
||||
pip install -y ${pip_packages[@]}
|
||||
fi
|
||||
fi
|
||||
# Sets dependency installed flag to true
|
||||
depsinstalled=true
|
||||
}
|
||||
|
||||
dry-run-report(){
|
||||
box-rounded
|
||||
boxborder "${grn}Dry-run Report:${dfl}"
|
||||
box-norm
|
||||
boxborder \
|
||||
"bins_missing= " \
|
||||
"${bins_missing[@]}" \
|
||||
"backup_files= " \
|
||||
"${backup_files[@]}" \
|
||||
"installed_files= " \
|
||||
"${installed_files[@]}" \
|
||||
"installed_dirs= " \
|
||||
"${installed_dirs[@]}"
|
||||
}
|
||||
|
||||
install(){
|
||||
local _golang_html=$(curl -ks "https://go.dev/dl/" | grep linux-amd64 | grep 1.19 | head -n 1)
|
||||
local golang_current=$(strip-html-tags "$_golang_html")
|
||||
export tmp_dir=`mktemp -d /tmp/selfextract.XXXXXX`
|
||||
run wget "https://go.dev/dl/${golang_current}" -O $tmp_dir/$golang_current
|
||||
run sudo rm -rf /usr/local/go
|
||||
run tar -C /usr/local -xzf $tmp_dir/$golang_current
|
||||
if [ ! -f $HOME/.bashrc.d/11-golang.bashrc ] ; then
|
||||
run echo -e "$codedog_bashrc" >> $HOME/.bashrc.d/11-golang.bashrc && \
|
||||
boxborder ".bashrc.d/11-golang.bashrc installed..."
|
||||
fi
|
||||
export PATH=$PATH:/usr/local/go/bin
|
||||
if [ ! -f /usr/bin/go ] ; then
|
||||
run sudo ln -s /usr/bin/go /usr/local/go/bin/go && \
|
||||
boxborder "golang symlink created at /usr/bin/go"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function for displaying the usage of this script
|
||||
usage(){
|
||||
boxborder \
|
||||
"${lbl}Usage:${dfl}" \
|
||||
"${lyl}./$scriptname ${bld}[args]${dfl}" \
|
||||
"$(boxseparator)" \
|
||||
"[args:]" \
|
||||
" -i [--install]" \
|
||||
" -d [--dependencies]" \
|
||||
" -D [--dry-run]" \
|
||||
" -r [--remove]" \
|
||||
" -f [--force]" \
|
||||
" -F [--force-remove]" \
|
||||
" -u [--update]" \
|
||||
" -h [--help]"
|
||||
}
|
||||
|
||||
case $1 in
|
||||
-i | --install)
|
||||
install && success " [${lbl}Slip${gry}Stream ${lyl}Installed${dfl}]"
|
||||
;;
|
||||
-r | --remove)
|
||||
remove && success " [${lbl}Slip${gry}Stream ${lyl}Removed${dfl}]"
|
||||
;;
|
||||
-d | --dependencies)
|
||||
install-deps && success "${lbl}Slip${gry}Stream ${dfl} Dependencies installed!"
|
||||
;;
|
||||
-D | --dry-run)
|
||||
export dry_run=true
|
||||
install
|
||||
dry-run-report
|
||||
usage
|
||||
unset dry_run
|
||||
success "${lbl}Slip${gry}Stream ${lyl}Installer Dry-Run Complete!${dfl}"
|
||||
;;
|
||||
-u | --update)
|
||||
export update_run=true
|
||||
update && unset update_run && success " [${lbl}Slip${gry}Stream ${lyl}Updated${dfl}]"
|
||||
;;
|
||||
-f | --force)
|
||||
remove-arbitrary
|
||||
install && success " [${lbl}Slip${blu}Stream ${lyl}Installed${dfl}]"
|
||||
;;
|
||||
-F | --force-remove)
|
||||
remove-arbitrary && success " [${lbl}Slip${gry}Stream ${lyl}Force-Removed${dfl}]"
|
||||
;;
|
||||
-h | --help)
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
warn "Invalid argument $@"
|
||||
usage
|
||||
#exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
#------------------------------------------------------#
|
||||
# Script begins here
|
||||
#------------------------------------------------------#
|
||||
|
||||
#install
|
||||
Loading…
Reference in a new issue