#!/usr/bin/env bash # # Author: Georg Voell - georg.voell@standby.cloud # Version: @(#)install-scripts 3.3.0 19.01.2026 (c)2026 Standby.cloud # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ # # This script can be used free of charge. Use it as is or customize as needed. It is not guaranteed to be # error free and you will not be reimbursed for any damage it may cause. # #@ This script downloads useful UNIX scripts and installs them. #@ If scripts are already installed, it tries to update them. #@ #@Usage: install-scripts [action] #@ Action: optional #@ check : Check if scripts are installed and if there is a newer version available. #@ download : Just download the scripts - don't install them. #@ basic : Just install basic scripts (subset of all available scripts e.g. errormsg and confirm). #@ management: Install basic scripts and management scripts (subset of all available scripts e.g. key-management). #@ remove : Removes all installed scripts. # # Exit codes: # 01: Unknown or wrong parameter. # 02: Unknown OS. # 03: Need root privileges. # 04: **curl** not found. This script needs **curl** to perform. # 05: Error while downloading. # 06: Downloaded file corrupted. # # Supported platforms: # # Darwin (Mac OS X), SunOS (Solaris), Linux (OEL, Red Hat, CentOS, Ubuntu) # # Usage: # # # Install for all users # curl -skL https://standby.cloud/download/beta/install-scripts | sudo bash # # # Install for one user # curl -skL https://standby.cloud/download/beta/install-scripts | bash # # # Dont't install - just download all scripts (beta version) # curl -skL https://standby.cloud/download/beta/install-scripts | bash -s download # # # Install just basic scripts # curl -skL https://standby.cloud/download/beta/install-scripts | sudo bash -s basic # # # Install just management scripts # curl -skL https://standby.cloud/download/beta/install-scripts | sudo bash -s management # # ToDo: # - Local install with download # # Update history: # # V 3.0.0 18.04.2020 New version # V 3.0.1 16.09.2020 Use new download URL: https://standby.cloud/download # V 3.0.2 18.09.2020 Set PATH for login_shell corrected # V 3.0.3 30.09.2020 Beta Test included # V 3.0.4 09.10.2020 Download / Delete obsolete script # V 3.1.0 05.06.2023 New copyright # V 3.2.0 11.09.2024 New minor version: Install basic scripts # V 3.2.1 17.01.2025 Update MANPATH # V 3.2.2 08.08.2025 Download from Objectstorage # V 3.3.0 19.01.2026 Revised with support of Claude Code # # Get the REALUSER if [[ "$REALUSER" = "" ]]; then export USER=$(whoami) # Current user export OS=$(uname -s) # Infos about the host os (e.g. Darwin, SunOS, Linux) # Try to get HOME if it is not set if [[ "$HOME" = "" || "$HOME" = "/" ]]; then export HOME=$(eval echo ~${USER}) if [[ "$HOME" = "" ]]; then export HOME="/" fi fi # Check if re run with 'sudo' if [[ "$SUDO_USER" != "" ]]; then export REALUSER="$SUDO_USER" export REALGROUP=$(id -gn $SUDO_USER) export REALHOME=$(eval echo ~${SUDO_USER}) export HOME=$(eval echo ~${USER}) else export REALUSER="$USER" export REALGROUP=$(id -gn $USER) export REALHOME="$HOME" fi fi ### #myinfo="/tmp/myinfo.txt" #echo "REALUSER: '$REALUSER'." > $myinfo #echo "REALGROUP: '$REALGROUP'." >> $myinfo #echo "REALHOME: '$REALHOME'." >> $myinfo #echo "HOME: '$HOME'." >> $myinfo #echo "SUDO_USER: '$SUDO_USER'." >> $myinfo #echo "USER: '$USER'." >> $myinfo #echo "HOME: '$HOME'." >> $myinfo #echo "OS: '$OS'." >> $myinfo # Define helpful alias shopt -s expand_aliases unalias -a if [[ "$OS" = "SunOS" ]]; then # If we are runnung on Solaris, tail had to be handled different if [[ -x "/usr/gnu/bin/tail" ]]; then alias tailfromline2="/usr/gnu/bin/tail -n +2" alias taillastline="/usr/gnu/bin/tail -n 1" else alias tailfromline2="/usr/bin/tail +2" alias taillastline="/usr/bin/tail -1" fi else alias tailfromline2="tail -n +2" alias taillastline="tail -n 1" fi # Define WORKPATH if [[ "$WORKPATH" = "" ]]; then stdpath="/usr/local/sbin:/usr/local/bin:/usr/gnu/bin:/sbin:/bin:/usr/sbin:/usr/bin" if [[ "$HOME" = "/" ]]; then export WORKPATH="${stdpath}:$PATH" else if [[ "$REALHOME" != "$HOME" ]]; then export WORKPATH="${HOME}/.local/bin:${HOME}/bin:${REALHOME}/.local/bin:${REALHOME}/bin:${stdpath}:$PATH" else export WORKPATH="${REALHOME}/.local/bin:${REALHOME}/bin:${stdpath}:$PATH" fi fi fi # Saving original PATH if [[ "$SUDO_USER" != "" ]]; then # This script started using sudo USERENV=$(su - "$SUDO_USER" -c 'env') ORGPATH=$(echo "$USERENV" | grep '^PATH=' | cut -d '=' -f2) USERSHELL=$(echo "$USERENV" | grep '^SHELL=' | cut -d '=' -f2) MAN_PATH=$(echo "$USERENV" | grep '^MANPATH=' | cut -d '=' -f2) LIB_PATH=$(echo "$USERENV" | grep '^LD_LIBRARY_PATH=' | cut -d '=' -f2) # ORGPATH=$(sudo -Hiu "$SUDO_USER" env | grep '^PATH=' | cut -d '=' -f2) # USERSHELL=$(sudo -Hiu "$SUDO_USER" env | grep '^SHELL=' | cut -d '=' -f2) else ORGPATH="$PATH" USERSHELL="$SHELL" MAN_PATH="$MANPATH" LIB_PATH="$LD_LIBRARY_PATH" # ORGPATH=$(env | grep '^PATH=' | cut -d '=' -f2) # USERSHELL=$(env | grep '^SHELL=' | cut -d '=' -f2) fi ### #echo "USERENV: '$USERENV'." >> $myinfo #echo "ORGPATH: '$ORGPATH'." >> $myinfo #echo "USERSHELL: '$USERSHELL'." >> $myinfo #echo "LIB_PATH: '$LIB_PATH'." >> $myinfo if [[ "$USERSHELL" != "" ]]; then USERSHELL=$(basename "$USERSHELL") case "$USERSHELL" in bash) USTYPE="sh" if [[ -r "${REALHOME}/.bash_profile" ]]; then LOGIN_PROFILE="${REALHOME}/.bash_profile" else LOGIN_PROFILE="${REALHOME}/.profile" fi PROFILE="${REALHOME}/.bashrc" ;; sh | ksh | mksh) USTYPE="sh" LOGIN_PROFILE="${REALHOME}/.profile" PROFILE="" ;; csh | tcsh) USTYPE="csh" LOGIN_PROFILE="${REALHOME}/.profile" if [[ -r "${REALHOME}/.tcshrc" ]]; then PROFILE="${REALHOME}/.tcshrc" else PROFILE="${REALHOME}/.cshrc" fi ;; *) USTYPE="" LOGIN_PROFILE="" PROFILE="" ;; esac fi # Set PATH to something useful PATH="$WORKPATH" ### #echo "USTYPE: '$USTYPE'." >> $myinfo #echo "LOGIN_PROFILE: '$LOGIN_PROFILE'." >> $myinfo #echo "PROFILE: '$PROFILE'." >> $myinfo #echo "WORKPATH: '$WORKPATH'." >> $myinfo function ToLower { # Combine all arguments into a single string local s="$*" # If no arguments, then check for pipe if [[ -z "$s" ]]; then # If input comes from a pipe or file, use STDIN mode if [[ ! -t 0 ]]; then # Read all STDIN in one go and convert echo "Oh No" tr '[:upper:]' '[:lower:]' return fi else # Use bash built-in expansion when possible (faster) if [[ "${BASH_VERSINFO[0]:-0}" -ge 4 ]]; then printf '%s' "${s,,}" else printf '%s' "$s" | tr '[:upper:]' '[:lower:]' fi fi } function StripComment { local file="$*" if [[ ! -z "$file" ]]; then if [[ -s $file ]]; then sed -E 's/([[:space:]]|^)\#.*$//' "$file" fi else # If input comes from a pipe or file, use STDIN mode if [[ ! -t 0 ]]; then # Read all STDIN in one go and convert # remove '#' that is preceded by space or start-of-line; keep URLs (simple heuristic) # $SED -E 's/([[:space:]]|^)\#.*$//' sed -E 's/([[:space:]]|^)\#.*$//' fi fi } function Cleanup { # Delete working directory and exit if [[ "$param" != "download" && "$wdir" != "" ]]; then rm -fR $wdir 2>/dev/null fi filecheck -rm "$scratchfile" } function errormsg { normal='\033[0m' redcol='\033[0;91m' # Highlighted red number=${1} # Error Number errmsg=${2} # Error Message errrsn=${3} # Error Reason if [[ "$errrsn" = "" ]]; then printf "${redcol}ERROR(%02d): ${errmsg}${normal}\n" $number > /dev/stderr else printf "${redcol}ERROR(%02d): ${errmsg} (${errrsn})${normal}\n" $number > /dev/stderr fi } function filecheck { option=${1} filnam=${2} case "$option" in -x) if [[ -f "$filnam" && -x "$filnam" ]]; then # We have to check if it is a file first - otherwise it may is a directory dname=$(dirname "$filnam") if [[ "$dname" = "." ]]; then dname=$(pwd) bname=$(basename "$filnam") echo "${dname}/$bname" else echo "$filnam" fi else # '2>/dev/null' needed for Linux, sed needed for Solaris 10 resstr=$(command -v "$filnam" 2>/dev/null) if [[ "$resstr" != "" ]]; then echo "$resstr" fi fi ;; -z) if [[ -f "$filnam" ]]; then unzip=$(command -v unzip 2>/dev/null) if [[ "$unzip" != "" ]]; then $unzip -t "$filnam" >/dev/null 2>&1 stat=$? if (( stat == 0 )); then echo "$filnam" fi fi fi ;; -s) if [[ -f "$filnam" ]]; then fresult=$(cat "$filnam" | wc -c) if (( fresult > 0 )); then echo "$filnam" fi fi ;; -sl) if [[ -f "$filnam" ]]; then fresult=$(cat "$filnam" | wc -l) if (( fresult > 1 )); then echo "$filnam" fi fi ;; -rm) if [[ -f "$filnam" ]]; then rm -f "$filnam" fi ;; *) echo "Invalid option '$option'." exit 1 ;; esac } # Update mandb with new manuals function UpdateWhatis { # Create mandb case "$OS" in Darwin) makewhatis=$(filecheck -x "/usr/libexec/makewhatis") if [[ "$makewhatis" != "" ]]; then filecheck -rm "${manfolder}/whatis" $makewhatis "${manfolder}" > /dev/null 2>&1 fi ;; Linux) mandb=$(filecheck -x mandb) if [[ "$mandb" != "" ]]; then $mandb "${manfolder}" > /dev/null 2>&1 fi ;; SunOS) catman=$(filecheck -x catman) if [[ "$catman" != "" ]]; then $catman -M "${manfolder}" > /dev/null 2>&1 fi ;; esac if [[ "$needchown" = true ]]; then chown -fR ${REALUSER}:$REALGROUP $manfolder fi } function UpdateProfile { local profilefile=${1} local infotext=${2} local grepres="" local oldpath="" local oldmanpath="" local pathchanged=false local manchanged=false local libchanged=false if [[ -r "$profilefile" ]]; then grepres=$(grep '\> $profilefile else echo 'setenv PATH "$HOME/.local/bin:$HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"' >> $profilefile fi fi else if [[ "$oldpath" != "$HOME/.local/bin:$HOME/bin:/usr/local/bin:$ORGPATH" ]]; then pathchanged=true if [[ "$USTYPE" = "sh" ]]; then echo 'export PATH="$HOME/.local/bin:$HOME/bin:/usr/local/bin:$PATH"' >> $profilefile else echo 'setenv PATH "$HOME/.local/bin:$HOME/bin:/usr/local/bin:$PATH"' >> $profilefile fi fi fi if [[ "$MAN_PATH" = "" ]]; then if [[ "$oldmanpath" != "$HOME/.local/share/man:/usr/local/share/man:/usr/share/man" ]]; then manchanged=true if [[ "$USTYPE" = "sh" ]]; then echo 'export MANPATH="$HOME/.local/share/man:/usr/local/share/man:/usr/share/man"' >> $profilefile else echo 'setenv MANPATH "$HOME/.local/share/man:/usr/local/share/man:/usr/share/man"' >> $profilefile fi fi else if [[ "$oldmanpath" != "$HOME/.local/share/man:/usr/local/share/man:$MAN_PATH" ]]; then manchanged=true if [[ "$USTYPE" = "sh" ]]; then echo 'export MANPATH="$HOME/.local/share/man:/usr/local/share/man:$MANPATH"' >> $profilefile else echo 'setenv MANPATH "$HOME/.local/share/man:/usr/local/share/man:$MANPATH"' >> $profilefile fi fi fi # V 3.2.2 result=$(cat $profilefile | grep '^export LD_LIBRARY_PATH=') if [[ "$userhome" = "${REALHOME}/.local" && "$result" = "" ]]; then libchanged=true if [[ "$LIB_PATH" = "" ]]; then if [[ "$USTYPE" = "sh" ]]; then echo 'export LD_LIBRARY_PATH="$HOME/.local/lib"' >> $profilefile else echo 'setenv LD_LIBRARY_PATH "$HOME/.local/lib"' >> $profilefile fi else if [[ "$USTYPE" = "sh" ]]; then echo 'export LD_LIBRARY_PATH="$HOME/.local/lib:$LD_LIBRARY_PATH"' >> $profilefile else echo 'setenv LD_LIBRARY_PATH "$HOME/.local/lib:$LD_LIBRARY_PATH"' >> $profilefile fi fi fi if [[ "$pathchanged" = "true" || "$manchanged" = "true" || "$libchanged" = "true" ]]; then if [[ "$infotext" != "" ]]; then printf "\n%s.\n" "$infotext" else printf "\n" fi if [[ "$pathchanged" = "true" ]]; then echo "Expanded PATH." fi if [[ "$manchanged" = "true" ]]; then echo "Expanded MANPATH." fi if [[ "$libchanged" = "true" ]]; then echo "Extended LD_LIBRARY_PATH." fi echo "To use the new variables, execute 'source $profilefile' in shell or re-login." fi } # Check if this script was called direct or whithin a pipe script=${0} # Name of this script progstr=$(basename "$script") # Basename of the script progdir=$(dirname "$script") # Dirname of the script if [[ "$progstr" = "bash" ]]; then progstr="install-scripts" # Need a name for logfiles or scratchfile # script=$(filecheck -x $progstr) # Location of the script fi # Repository where we load scripts from storageurl="https://objectstorage.eu-frankfurt-1.oraclecloud.com/n/frcc4jd4wdkp/b/download/o" downloadurl="https://standby.cloud/download" scriptsurl="${downloadurl}/beta" havebeta=$(basename "$scriptsurl") # Define default variables exitcode=0 # Default exit code firsttime=false # If script is called the first time, set this to true needchown=false # Need to change filerights # showhelp=false # false = don't show help / true = show help # showversion=false # false = don't show version / true = show version errstr="" # Default error message pid="$$" # Get the process id from current shell tmpdir="/tmp" # Temporary directory timestamp=$(date '+%y%m%d%H%M%S') # Extension String with current date and time scratchfile="${tmpdir}/${progstr}.${timestamp}.${pid}.tmp" # Temporary file toolsname="tools" # Unused scriptsname="scripts" templatesname="templates" # Unused setupname="lib.bash" # Check where the scripts are set up / installed # Check if we laready installed the scripts result=$(filecheck -x /usr/local/bin/$setupname) if [[ "$result" != "" ]]; then userhome="/usr/local" if [[ "$USER" != "root" ]]; then exitcode=3 errormsg $exitcode "Root privileges needed to alter scripts." exit $exitcode fi else result=$(filecheck -x ${REALHOME}/.local/bin/$setupname) if [[ "$result" != "" ]]; then userhome="${REALHOME}/.local" if [[ "$USER" = "root" ]]; then needchown=true fi else # We install the first time firsttime=true if [[ "$USER" = "root" ]]; then userhome="/usr/local" else userhome="${REALHOME}/.local" fi fi fi binfolder="${userhome}/bin" libfolder="${userhome}/lib" # lib64 manfolder="${userhome}/share/man" infofolder="${userhome}/share/info" appfolder="${userhome}/share/applications" templatesfolder="${userhome}/share/$templatesname" scriptsfile="${infofolder}/installed-${scriptsname}.txt" manfile="${infofolder}/installed-manuals.txt" manfile2="${infofolder}/installed-cmd-manuals.txt" templatesfile="${infofolder}/installed-${templatesname}.txt" sshdfolder="/etc/ssh" getauthkeys="get-authkeys" curdate=$(date "+%Y-%m-%d %T") # For use in logfiles, etc. wdir="${tmpdir}/$scriptsname" # That where the scripts are downloaded to cdir=$(pwd) # Current working directory if [[ "$1" != "" ]]; then param="$(ToLower "$1")" # First papameter fi # Script only works on UNIX like systems if [[ "$OS" != "Linux" && "$OS" != "SunOS" && "$OS" != "Darwin" ]]; then exitcode=2 errormsg $exitcode "This script only works UNIX like systems." exit $exitcode fi # Check if we have curl and gzip available curl=$(filecheck -x curl) gzip=$(filecheck -x gzip) ### ToDo: Test if we really need to unzip man pages on Solaris myip="" if [[ "$curl" = "" ]]; then exitcode=4 errormsg $exitcode "No 'curl' in PATH '$PATH'. Please install first e.g. 'sudo yum -y install curl'." exit $exitcode else # Check if we have internet access # $curl -k -L -m 10 -s $downloadurl >/dev/null 2>&1 $curl -skL -m 5 -s ${downloadurl}/lists/${scriptsname}.txt >/dev/null 2>&1 status=$? if (( status != 0 )); then downloadurl="$storageurl" scriptsurl="${downloadurl}/beta" # Check if we have service gateway access $curl -skL -m 5 -s ${downloadurl}/lists/${scriptsname}.txt >/dev/null 2>&1 status=$? fi if (( status == 0 )); then # Display the result printf "\n$progstr\n" myip="unknown" # Create working directory and sub directory if it does not exists if [[ ! -d ${wdir}/$scriptsname ]]; then mkdir -p ${wdir}/$scriptsname fi else # No internet access? Check for local install # echo "Local install" exitcode=5 errormsg $exitcode "No Internet Access." exit $exitcode fi fi if [[ "$param" = "" ]]; then if [[ "$firsttime" = true ]]; then param="install" else param="update" fi else if [[ "$param" != "check" && "$param" != "download" && "$param" != "remove" && "$param" != "basic" && "$param" != "management" ]]; then exitcode=1 errormsg $exitcode "Unknown parameter '$param'." exit $exitcode fi fi if [[ "$param" != "download" ]]; then # We create some folder if they don't exist for destfolder in $binfolder ${manfolder}/man1 $infofolder; do if [[ ! -d "$destfolder" ]]; then mkdir -m 0755 -p "$destfolder" printf "Created folder '$destfolder'.\n" fi done fi # Add bin to path if it is not already in path (only the first call) if [[ "$firsttime" = true ]]; then if [[ "$OCI_CLI_CLOUD_SHELL" = "True" ]]; then profilefile="$PROFILE" else profilefile="$LOGIN_PROFILE" fi if [[ -r "$profilefile" ]]; then # Save old profile cp -f "$profilefile" "${profilefile}.old" UpdateProfile "$profilefile" "Old profile '$profilefile' was saved to '${profilefile}.old'" if [[ "$SUDO_USER" != "" ]]; then chown ${REALUSER}:$REALGROUP "$profilefile" "${profilefile}.old" fi else # Create profile if [[ "$USTYPE" != "" ]]; then touch "$profilefile" stat=$? if (( stat == 0 )); then UpdateProfile "$profilefile" "New profile '$profilefile' was created" if [[ "$SUDO_USER" != "" ]]; then chown ${REALUSER}:$REALGROUP "$profilefile" fi else printf "\nCould not create '$profilefile'. Please expand PATH in your profile with '$binfolder'.\n" fi else printf "\nPlease expand PATH in your profile with '$binfolder'.\n" fi fi # # Check if PYTHONWARNINGS is set # pythonopt=$(grep "PYTHONWARNINGS" "$profilefile") # if [ "$pythonopt" = "" ]; then # if [ "$USTYPE" = "sh" ]; then # echo 'export PYTHONWARNINGS="ignore"' >> $profilefile # else # echo 'setenv PYTHONWARNINGS "ignore"' >> $profilefile # fi # # printf "\nPYTHONWARNINGS will be ignored.\n" # fi fi # Display the os name printf "\n%9s: %s\n" "Action" "$param" printf "%9s: %s\n" "OS" "$OS" printf "%9s: %s\n" "User" "$USER" if [[ "$SUDO_USER" != "" ]]; then printf "%9s: %s\n" "Real User" "$SUDO_USER" printf "%9s: %s\n" "Mode" "All-user-installation" else printf "%9s: %s\n" "Mode" "Single-user-installation" fi if [[ "$param" != "download" ]]; then printf "%9s: %s\n" "User bin" "$binfolder" printf "%9s: %s\n" "Man pages" "$manfolder" printf "%9s: %s\n" "Origin" "$scriptsurl" else printf "%9s: %s\n" "Download" "$wdir" fi if [[ "$param" = "check" ]]; then if [[ "$firsttime" = true ]]; then printf "\nScripts are not yet installed, but could be installed on this platform.\n" exit $exitcode fi fi # Print new line printf "\n" # Download filelist if [[ "$myip" != "" ]]; then rfile="${scriptsname}.txt" if [[ "$havebeta" = "latest" ]]; then # Download stable version dfile="$rfile" else # Download Beta Test version dfile="beta.txt" fi $curl -k -s -m 10 "${downloadurl}/lists/$dfile" -o "${wdir}/$rfile" status=$? if (( status != 0 )); then exitcode=5 errormsg $exitcode "Could not download filelist '$dfile'." "CURL could not establish a connection to server" filecheck -rm "${wdir}/${rfile}" exit $exitcode else if [[ -f ${wdir}/$rfile ]]; then cmd="$(cat ${wdir}/$rfile | head -n 1 | cut -d$'\t' -f1)" if [[ "$cmd" != "cmd" ]]; then exitcode=6 errormsg $exitcode "Corrupt filelist '$dfile'." "Download not successful" filecheck -rm "${wdir}/${rfile}" exit $exitcode fi fi fi fi # Deinstall previously installed scripts and manuals if [[ "$param" != "download" ]]; then if [[ -f "${wdir}/${scriptsname}.txt" ]]; then if [[ -f $scriptsfile ]]; then while IFS=$'\t' read -r sname svers; do # Browse through all installed scripts if [[ "$sname" != "" && "$svers" != "" ]]; then cmd=$(basename "$sname") if [[ "$cmd" != "" ]]; then grepres=$(grep "^$cmd " "${wdir}/${scriptsname}.txt") if [[ "$grepres" = "" || "$param" = "remove" ]]; then # Script not found in download list or needs to be removed printf "%s\t%s\n" "$cmd" "$sname" >> "$scratchfile" fi fi fi done < <(tailfromline2 $scriptsfile | StripComment) fi if [[ -f "$scratchfile" ]]; then if [[ "$param" = "check" ]]; then printf "Obsolete scripts:\n\n" else printf "Deleting prviously installed scripts and manuals:\n\n" fi while IFS=$'\t' read -r cmd sname; do if [[ -f "$sname" ]]; then # Script exists - check if it has a version instvers=$(head -n 10 $sname | grep '^# Version: @(#' | cut -d' ' -f4) if [[ "$param" = "check" ]]; then if [[ "$instvers" = "" ]]; then instvers="modified" fi printf "Script %s obsolete. Version: %s\n" "$sname" "$instvers" else if [[ "$instvers" != "" ]]; then echo "Deleting script '$cmd'." filecheck -rm "$sname" if [[ -f "$manfile" ]]; then mname=$(grep "/${cmd}.1" "$manfile" | cut -d$'\t' -f1) if [[ -f "$mname" ]]; then echo "Deleting manual '$cmd'." filecheck -rm "$mname" fi fi else echo "Script '$cmd' not deleted. Modified version found." fi fi fi done < "$scratchfile" if [[ "$param" != "remove" ]]; then printf "\n" filecheck -rm "$scratchfile" else filecheck -rm $scriptsfile filecheck -rm $manfile Cleanup exit $exitcode fi fi fi fi if [[ "$param" != "remove" ]]; then # Install every script in filelist if [[ -f ${wdir}/${scriptsname}.txt ]]; then if [[ "$param" != "check" && "$param" != "download" ]]; then # Create an empty list of installed scripts echo "script version" > $scriptsfile echo "man1 version" > $manfile fi while IFS=$'\t' read -r cmd svers basic; do if [[ "$cmd" != "" && "$svers" != "" ]]; then if [[ "$param" = "basic" || "$param" = "management" ]]; then ok=$basic if [[ "$ok" = false && "$param" = "management" ]]; then result=$(echo "$cmd" | grep '\-management$') if [[ "$result" != "" ]]; then ok=true fi fi else ok=true fi if [[ "$param" != "check" ]]; then # We can only download something if we have an internet connection if [[ "$myip" != "" && "$ok" = true ]]; then # Download the script if [[ "$param" = "download" ]]; then echo "Downloading script: '$cmd'." fi # $curl -s -m 10 "${downloadurl}/${scriptsname}/${cmd}/${svers}/${cmd}" -o "${wdir}/${scriptsname}/${cmd}-$svers" $curl -k -s -m 20 "${scriptsurl}/${cmd}" -o "${wdir}/${scriptsname}/${cmd}-$svers" status=$? if (( status != 0 )); then echo "Could not download script '$cmd'." filecheck -rm "${wdir}/${scriptsname}/${cmd}-$svers" else if [[ -r "${wdir}/${scriptsname}/${cmd}-$svers" ]]; then grepres=$(grep '^' "${wdir}/${scriptsname}/${cmd}-$svers") if [[ "$grepres" != "" ]]; then echo "Corrupt script '$cmd'." filecheck -rm "${wdir}/${scriptsname}/${cmd}-$svers" fi fi fi # Download man1 page if we could download the script if [[ "$havebeta" = "latest" ]]; then if [[ -f "${wdir}/${scriptsname}/${cmd}-$svers" && "$cmd" != "lib.bash" ]]; then if [[ "$downloadurl" = "$storageurl" ]]; then $curl -k -s -m 20 "${downloadurl}/man/${cmd}.1" -o "${wdir}/${scriptsname}/${cmd}-$svers-man1" status=$? else $curl -k -s -m 20 "${downloadurl}/man/${cmd}/${svers}/${cmd}.1" -o "${wdir}/${scriptsname}/${cmd}-$svers-man1" status=$? fi # Delete the file if it is HTML or if we got an error if [[ -r "${wdir}/${scriptsname}/${cmd}-$svers-man1" ]]; then grepres=$(grep '^' "${wdir}/${scriptsname}/${cmd}-$svers-man1") if [[ $status -ne 0 || "$grepres" != "" ]]; then filecheck -rm "${wdir}/${scriptsname}/${cmd}-$svers-man1" fi fi fi fi fi fi tool="${binfolder}/$cmd" if [[ -f "$tool" ]]; then # Tool already exists - check if it has a version instvers=$(head -n 10 $tool | grep '^# Version: @(#' | cut -d' ' -f4) else tool="" instvers="" fi if [[ "$param" = "check" ]]; then if [[ "$tool" != "" ]]; then if [[ "$instvers" = "" ]]; then instvers="modified" fi if [[ "$instvers" != "modified" && "$instvers" != "$svers" ]]; then printf "Script %s/%s installed. Version: %s (newer version %s available)\n" "$binfolder" "$cmd" "$instvers" "$svers" else printf "Script %s/%s installed. Version: %s\n" "$binfolder" "$cmd" "$instvers" fi fi fi if [[ "$param" != "check" && "$param" != "download" ]]; then if [[ -f "${wdir}/${scriptsname}/${cmd}-$svers" ]]; then # Install the script if [[ "$tool" = "" || "$instvers" != "" ]]; then if [[ "$tool" = "" ]]; then printf "Installing script '$cmd': " else printf "Updating script '$cmd': " fi cp -f "${wdir}/${scriptsname}/${cmd}-$svers" "${binfolder}/$cmd" chmod 755 "${binfolder}/$cmd" # if [ "${cmd:0:4}" != "lib." ]; then # chmod 755 "${binfolder}/$cmd" # fi if [[ "$needchown" = true ]]; then chown ${REALUSER}:$REALGROUP "${binfolder}/$cmd" fi echo "${binfolder}/$cmd installed. Version: '$svers'." # Write entry to list of installed scripts echo "${binfolder}/$cmd $svers" >> $scriptsfile # Copy man page if it exists if [[ -f "${wdir}/${scriptsname}/${cmd}-$svers-man1" ]]; then filecheck -rm "${manfolder}/man1/${cmd}.1.gz" cp "${wdir}/${scriptsname}/${cmd}-$svers-man1" "${manfolder}/man1/${cmd}.1" if [[ "$gzip" != "" && "$OS" != "SunOS" ]]; then $gzip "${manfolder}/man1/${cmd}.1" chmod 644 "${manfolder}/man1/${cmd}.1.gz" if [[ "$needchown" = true ]]; then chown ${REALUSER}:$REALGROUP "${binfolder}/$cmd" fi echo "${manfolder}/man1/${cmd}.1.gz $svers" >> $manfile else chmod 644 "${manfolder}/man1/${cmd}.1" if [[ "$needchown" = true ]]; then chown ${REALUSER}:$REALGROUP "${binfolder}/$cmd" fi # echo "${manfolder}/man1/${cmd}.1 installed. Version: '$svers'." # Write entry to list of installed man pages echo "${manfolder}/man1/${cmd}.1 $svers" >> $manfile fi fi else echo "Script '$cmd' not installed. Modified version found at '$tool'." fi fi fi fi done < <(tailfromline2 "${wdir}/${scriptsname}.txt" | StripComment) # Download the install script if [[ "$param" = "download" ]]; then if [[ "$myip" != "" ]]; then for cmd in install-scripts install-tools get-authkeys; do echo "Downloading script: '$cmd'." $curl -k -s -m 20 "${scriptsurl}/${cmd}" -o "${wdir}/${cmd}" status=$? if (( status != 0 )); then echo "Could not download script '$cmd'." filecheck -rm "${wdir}/${cmd}" else if [[ -r "${wdir}/${cmd}" ]]; then grepres=$(grep '^' "${wdir}/${cmd}") if [[ "$grepres" != "" ]]; then echo "Corrupt script '$cmd'." filecheck -rm "${wdir}/${cmd}" else chmod 755 "${wdir}/${cmd}" fi fi fi done fi else if [[ "$param" != "check" ]]; then if [[ "$needchown" = true ]]; then chown ${REALUSER}:$REALGROUP $scriptsfile chown ${REALUSER}:$REALGROUP $manfile fi # Create mandb UpdateWhatis fi fi fi fi # Cleanup and exit Cleanup exit $exitcode