#!/usr/bin/env bash ############################################################ ### ### ### Someguy Scripts - (C) 2019 github.com/Someguy123 ### ### Released as open source under the GNU AGPL v3 ### ### Someguy Scripts Version: 2.6.0 ### ### ### ### github.com/Someguy123/someguy-scripts ### ### ### ### This minified script was compiled at: ### ### Mon Jun 14 06:57:25 UTC 2021 ### ### ### ############################################################ ############################################################ ### ### ### Someguy Scripts - (C) 2019 github.com/Someguy123 ### ### Released as open source under the GNU AGPL v3 ### ### Someguy Scripts Version: 2.6.0 ### ### ### ### github.com/Someguy123/someguy-scripts ### ### ### ### This minified script was compiled at: ### ### Mon Jun 14 06:57:25 UTC 2021 ### ### ### ############################################################ ### -------------------------------------- ### Someguy123/someguy-scripts/scripts/base.sh ### -------------------------------------- tee /tmp/findbin.py <<"EOF" #!/usr/bin/env python3 ################################################################################################################# # findbin.py - This is a dependency-free python3.x script, which is designed to work as a drop-in shim for # 'command', 'command -v', 'which', and 'whereis'. # # This script is part of Someguy's Scripts - a toolkit designed for provisioning *nix systems the way that # Someguy123 likes 'em :) # # Official Someguy's Scripts repo: https://github.com/Someguy123/someguy-scripts ################################################################################################################# _G='{}: {}: command not found' _F='command' _E='which' _D='utf-8' _C=None _B=True _A=False from pathlib import Path from os import getenv as env from typing import Union,Optional,List,Tuple,Dict import sys,os,subprocess,shlex def is_true(x):return str(x).lower()in['1','true','yes','t','y','tru','+'] RECURSE=is_true(env('PATH_RECURSE','0')) QUIET=is_true(env('QUIET','0')) DEBUG=is_true(env('DEBUG','0')) VERB_FLAG=_A PATH_DEFAULTS=is_true(env('PATH_DEFAULTS','1')) _PATH_DEFAULT_LIST='~/.local/bin:/snap/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin' PATH_DEFAULT_LIST=[Path(A.strip()).expanduser().resolve()for A in env('PATH_DEFAULT_LIST',_PATH_DEFAULT_LIST).split(':')] PATH=env('PATH',env('path',env('Path',''))).strip() PATH=[Path(A.strip()).expanduser().resolve()for A in PATH.split(':')] ERROR_CODE=127 def _add_paths(plist,pathz,expanduser=_B,resolve=_B): C=plist;B=pathz;B=list(B) for A in B:A=A if isinstance(A,Path)else Path(str(A));A=A.expanduser()if expanduser else A;A=A.resolve()if resolve else A;C.append(A) return C def add_paths(plist,*A,expanduser=_B,resolve=_B):return _add_paths(plist,A,expanduser=expanduser,resolve=resolve) def _debug(*A,file=sys.stderr,**B): if DEBUG:print(' [DEBUG] ',*A,file=file,**B) if PATH_DEFAULTS: for pd in PATH_DEFAULT_LIST: if pd not in PATH:PATH.append(pd) argx=list(sys.argv) self_cmd=argx.pop(0) self_bin=env('SELF_BIN',self_cmd.split('/')[-1]) binlist=[] '\nbinlist = list of binaries passed on the command line for us to try and find.\n' if self_bin==_E:ERROR_CODE=1 def is_exe(fpath): A=fpath try:return os.path.isfile(A)and os.access(A,os.X_OK) except (PermissionError,FileNotFoundError):return _A while len(argx)>0: a=argx.pop(0) if len(binlist)>0:binlist.append(str(a)) elif a in['-v','-V']:VERB_FLAG=_B elif a in['-r','-R']:RECURSE=_B elif a in['-q','-Q']:QUIET=_B elif a in['-vv','-VV','-dbg','-debug','--dbg','--debug']:DEBUG=_B elif len(binlist)==0 and a.startswith('-'):0 else:binlist.append(str(a)) SHOULD_EXEC=not VERB_FLAG and self_bin==_F matched_paths={} matched_bool={binlist[0]:_A}if SHOULD_EXEC else{A:_A for A in binlist} class IgnoreFile(Exception):0 def validate_file(file,multi=_A,known_paths=_C,fail=_B): C=fail;B=known_paths;A=file;A=A if isinstance(A,Path)else Path(A) try: if A.is_dir()or not A.is_file(): _debug("Path {} isn't a file - may be a folder or FIFO etc. - Skipping.".format(str(A))) if C:raise IgnoreFile return _A if not multi and B is not _C and str(A.name)in B: _debug('Binary name {name} has already been matched to a higher priority path: {mp}'.format(name=str(A.name),mp=B[str(A.name)])) if C:raise IgnoreFile return _A except (PermissionError,FileNotFoundError)as D: _debug("Got unexpected error while scanning path '{}'. Reason: {} {}".format(str(A),type(D),str(D))) if C:raise D return _A return _B def find_binaries(*F,force_tuple=_A,skip_none=_B,multi=_A,find_ext=_A,known_paths=_C,bin_bool=_C): O='*';H=multi;G=bin_bool;E=known_paths;F=list(F);B=[] for C in PATH: _debug('Searching for binaries in path {}.'.format(str(C))) if find_ext: for I in F: L='{}.*'.format(I);J=C.glob(I)if not RECURSE else C.rglob(I);M=C.glob(L)if not RECURSE else C.rglob(L) for D in J: if str(D)in B:continue if not validate_file(D,multi=H,known_paths=E,fail=_A):continue B.append(str(D)) for D in M: if str(D)in B:continue if not validate_file(D,multi=H,known_paths=E,fail=_A):continue B.append(str(D)) else: J=C.glob(O)if not RECURSE else C.rglob(O) for A in J: K=_C if not validate_file(A,multi=H,known_paths=E,fail=_A):continue if str(A.name)in F: _debug('Found binary in path {} which is present in binary list: {}'.format(str(C),str(A.name)));K=N=str(A) if E is not _C and str(A.name)not in E:E[str(A.name)]=N if G is not _C and(str(A.name)not in G or G[str(A.name)]==_A):G[str(A.name)]=_B if K is _C and skip_none:continue B.append(K) if not force_tuple and len(B)==1:return B[0] return tuple(B) if SHOULD_EXEC: mainbin=find_binaries(binlist[0],force_tuple=_B)[0];bin_args=binlist[1:] if mainbin is _C or mainbin=='':print(_G.format(self_cmd,binlist[0]),file=sys.stderr);sys.exit(127) fargs=[mainbin]+bin_args;_debug('Running command with subprocess.call: {}'.format(fargs));popx=subprocess.Popen(fargs,stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=subprocess.PIPE) if not sys.stdin.isatty(): rd=sys.stdin.read(128) while rd not in[_C,_A,b'','']:popx.stdin.write(rd.encode(_D));rd=sys.stdin.read(128) try:popx.stdin.flush() except Exception as e:_debug('Exception while flushing stdin: {} {}'.format(type(e),str(e))) try:popx.stdin.close() except Exception as e:_debug('Exception while closing stdin: {} {}'.format(type(e),str(e))) rd=popx.stdout.read(128) while rd not in[_C,_A,b'','']: sys.stdout.write(rd.decode(_D));rd=popx.stdout.read(128) try:sys.stdout.flush() except Exception as e:_debug('Exception while flushing sys.stdout: {} {}'.format(type(e),str(e))) try:popx.stdout.close() except Exception as e:_debug('Exception while closing popx stdout: {} {}'.format(type(e),str(e))) rd=popx.stderr.read(128) while rd not in[_C,_A,b'','']: sys.stderr.write(rd.decode(_D));rd=popx.stderr.read(128) try:sys.stderr.flush() except Exception as e:_debug('Exception while flushing stderr: {} {}'.format(type(e),str(e))) try:popx.stderr.close() except Exception as e:_debug('Exception while closing popx stderr: {} {}'.format(type(e),str(e))) code=popx.wait(60*60*2);sys.exit(code) if self_bin=='whereis': add_paths(PATH,*['/usr/share/man/man{}'.format(A)for A in range(1,9)],'/etc','/opt');RECURSE=_B for bl in binlist:flist=find_binaries(bl,force_tuple=_B,multi=_B,find_ext=_B);print('{}: {}'.format(bl,' '.join(flist))) sys.exit(0) find_binaries(*binlist,known_paths=matched_paths,bin_bool=matched_bool) if len(matched_paths)==0: if self_bin==_F:print(_G.format(self_cmd,binlist[0]),file=sys.stderr) elif self_bin==_E: if not QUIET:print('{}: command not found'.format(binlist[0])) else:print("{}: ERROR - Binary '{}' was not found in search path. command not found".format(self_cmd,binlist[0]),file=sys.stderr) sys.exit(ERROR_CODE) for bl in binlist: if bl in matched_paths: mt=matched_paths[bl] if not QUIET:print(str(mt)) _debug("Bin List item '{}' was matched to path: {}".format(bl,mt)) elif not QUIET and len(binlist)>1:print('-') _debug('Matched paths: {}'.format(matched_paths)) _debug('Matched bools: {}'.format(matched_bool)) sys.exit(0 if len(matched_bool)>=len(binlist)and all(list(matched_bool.values()))else 1) EOF export PATH="${HOME}/.local/bin:/snap/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:${PATH}" : ${XDEBUG="0"} export XDEBUG if (( XDEBUG )); then set -x fi find-cmd() { [[ -f "/usr/bin/$1" || -f "/bin/$1" || -f "/usr/sbin/$1" || -f "/sbin/$1" || -f "/usr/local/bin/$1" ]] } msg() { echo -e "$@" } msgerr() { >&2 msg "$@"; } _debug() { (( SG_DEBUG )) && msgerr "$@" || true; } instx() { local outx="/dev/stderr" needsudo=1 [[ "$1" == "-q" ]] && outx="/dev/null" && shift [[ "$1" == "-u" ]] && needsudo=0 && shift [[ "$1" == "-q" ]] && outx="/dev/null" && shift if (( needsudo )); then sg-sudo cp "$1" "$2" &> "$outx" sg-sudo chmod +x "$2" &> "$outx" else cp "$1" "$2" &> "$outx" chmod +x "$2" &> "$outx" fi } sgs_var_defaults() { : ${SKIP_CLONE='n'} # Do not git clone. Trust that LIB_DIR contains someguy-scripts already. : ${SKIP_LOCALE='n'} # Do not configure/generate locales : ${SKIP_INSTALL='n'} # Do not install packages listed in INSTALL_PKGS : ${SKIP_GLOBAL='n'} # Do not install configurations and zsh files globally : ${SKIP_HARDEN='n'} # Do not run server hardening : ${LIB_DIR="$(mktemp -d)"} # Destination to clone someguy-scripts into (or existing location of someguy-scripts if SKIP_CLONE) } SGBASE_LOADED='y' has_command() { command -v "$1" > /dev/null; } sg_has_binary() { local q="$1" wi if [[ -f "/usr/bin/findbin" ]]; then /usr/bin/findbin -q "$@" return $? elif [[ -f "/usr/local/bin/command" ]]; then /usr/local/bin/command "$@" &> /dev/null; return $? elif find-cmd command; then env -- command -v "$1" &> /dev/null; return $? elif [[ -f "/usr/local/bin/which" ]]; then /usr/local/bin/which "$@" &> /dev/null; return $? elif find-cmd which; then env -- which "$@" &> /dev/null; return $? elif find-cmd whereis; then wi="$(env -- whereis "$1" &> /dev/null)" [[ "$wi" != "${q}:" && "$wi" != "${q}: " && "$wi" != "${q}:\t" ]] return $? else command -v "$q" &> /dev/null; return $? fi } sg-has-binary() { sg_has_binary "$@"; } has_binary() { sg_has_binary "$@"; } has-binary() { sg_has_binary "$@"; } export -f has_binary sg_has_binary has-binary sg-has-binary sg-sudo() { if (( EUID == 0 )); then _debug "EUID is 0 (root). Using eval to evaluate the passed arguments directly: $*" while (( $# > 0 )); do if [[ "$1" == "sudo" || "$1" == "sg-sudo" ]]; then msgerr "Attempted to run sudo with sudo!!!!" return 2 fi [[ "$1" == "--" ]] && break if grep -Eq '^\-' <<< "$1"; then shift else break fi done _debug "Running env: $*" env -- "$@" return $? else if sg-has-binary sudo; then _debug "User is not root, but found sudo. Running sudo with args: $*" if [[ -f "/usr/bin/findbin" ]]; then local sdbin="$(/usr/bin/findbin sudo)" _debug "Found direct path to sudo binary using findbin: $sdbin" "$sdbin" -- "$@" return $? else _debug "findbin not available. Using env to run sudo: env sudo -- $*" env sudo -- "$@" return $? fi elif sg-has-binary su; then _debug "sudo not available but su is. using su: su -c \"$(printf '%q ' "$@")\"" while (( $# > 0 )); do if [[ "$1" == "sudo" || "$1" == "sg-sudo" ]]; then msgerr "Attempted to run sudo with sudo!!!!" return 2 fi [[ "$1" == "--" ]] && break if grep -Eq '^\-' <<< "$1"; then shift else break fi done su -c "$(printf '%q ' "$@")" return $? else msgerr " [!!!] ERROR: Neither sudo nor su are available, and you're not root. Cannot run: $*" return 9 fi fi } xsudo() { sg-sudo "$@"; } unalias sudo &> /dev/null unset sudo &> /dev/null sudo() { sg-sudo "$@"; } export -f sg-sudo xsudo sudo if find-cmd python3 && [[ -f /tmp/findbin.py ]]; then instx -q /tmp/findbin.py /usr/bin/findbin sg-sudo ln -s /usr/bin/findbin /usr/local/bin/findbin [[ ! -f /usr/local/bin/command ]] && sg-sudo ln -s /usr/bin/findbin /usr/local/bin/command [[ ! -f /usr/local/bin/which ]] && sg-sudo ln -s /usr/bin/findbin /usr/local/bin/which fi if ! find-cmd sudo && [ "$EUID" -eq 0 ]; then has_sudo() { return 0; } else has_sudo() { sudo -n ls > /dev/null; } fi OS="$(uname -s)" : ${BASE_OS=""} : ${BASE_PKG_MGR=""} : ${FB_PKG_MGR=""} if [[ -n "$BASE_PKG_MGR" ]]; then : ${PKG_UPDATE="$BASE_PKG_MGR update -y"} : ${PKG_INSTALL="$BASE_PKG_MGR install -y"} else PKG_UPDATE="" PKG_INSTALL="" fi PKG_MGR_UPDATED=0 : ${PKG_INSTALLED=""} if [[ -z "$PKG_INSTALL" || -z "$BASE_OS" ]]; then [[ -f /etc/debian_version ]] && BASE_OS="debian" sg-has-binary apt-get && sg-has-binary dpkg && BASE_OS="debian" [[ -f /etc/redhat-release ]] && BASE_OS="rhel" [[ -f /etc/oracle-release ]] && BASE_OS="rhel" { sg-has-binary yum || sg-has-binary dnf; } && BASE_OS="rhel" [[ -f "/etc/arch-release" ]] && sg-has-binary pacman && BASE_OS="arch" [[ -f "/etc/gentoo-release" ]] && sg-has-binary emerge && BASE_OS="gentoo" [[ -f "/etc/alpine-release" ]] && sg-has-binary apk && BASE_OS="alpine" fi if [[ -z "$PKG_INSTALL" || -z "$PKG_UPDATE" ]]; then case "$BASE_OS" in debian|deb|ubuntu|Ubuntu|ubu|mint|Mint|Kali|"Kali Linux"|"Linux Mint"|"Ubuntu Linux") BASE_PKG_MGR="apt-get" FB_PKG_MGR="apt" sg-has-binary "$BASE_PKG_MGR" || BASE_PKG_MGR="$FB_PKG_MGR" PKG_UPDATE="$BASE_PKG_MGR update -qy" PKG_INSTALL="$BASE_PKG_MGR install -qy" PKG_INSTALLED="dpkg -s" ;; rhel|rh|RHEL|RH|redhat|RedHat|oracle|Oracle|"Oracle Linux"fedora|centos|Fedora|CentOS|"RedHat Enterprise Linux") BASE_PKG_MGR="dnf" FB_PKG_MGR="yum" sg-has-binary "$BASE_PKG_MGR" || BASE_PKG_MGR="$FB_PKG_MGR" PKG_UPDATE="$BASE_PKG_MGR makecache -y" PKG_INSTALL="$BASE_PKG_MGR install -y" PKG_INSTALLED="rh-has-pkg" ;; arch|archlinux|Arch|ArchLinux|"Arch Linux"|"arch linux") BASE_PKG_MGR="pacman" PKG_UPDATE="$BASE_PKG_MGR -Sy" PKG_INSTALL="$BASE_PKG_MGR -S" PKG_INSTALLED="$BASE_PKG_MGR -Q" ;; alp|alpine|alpinelinux|"Alpine"|"Alpine Linux"|"alpine linux") BASE_PKG_MGR="apk" PKG_UPDATE="$BASE_PKG_MGR update" PKG_INSTALL="$BASE_PKG_MGR add -f" PKG_INSTALLED="apk-has-pkg" ;; gen|gentoo|Gentoo|"gentoo linux"|"Gentoo Linux") BASE_PKG_MGR="emerge" PKG_UPDATE="$BASE_PKG_MGR --sync" PKG_INSTALL="$BASE_PKG_MGR" PKG_INSTALLED="apk-has-pkg" ;; esac fi PKG_MGR_UPDATE="$PKG_UPDATE" PKG_MGR_INSTALL="$PKG_INSTALL" PKG_MGR_INSTALLED="$PKG_INSTALLED" export DEBIAN_FRONTEND=noninteractive rh-has-pkg() { rpm -qa | grep -qi "$1" } apk-has-pkg() { lct="$(apk version "$1" | wc -l)" (( lct >= 2 )) || false } is-rhel() { [[ "$BASE_OS" == "rhel" ]] || [[ -f /etc/redhat-release ]] || [[ -f /etc/oracle-release ]]; } has-rhel-equiv() { [[ -v RHEL_EQUIV[$1] ]]; } get-rhel-equiv() { local pname="$1" sedmatched=0 if grep -Eq -- '^python3\.' <<< "$pname"; then pname="$(sed -E 's/^python3\./python3/' <<< "$pname")" sedmatched=1 fi if grep -Eq -- '^(python3-venv|python3(\.[0-9]+)-venv)$' <<< "$pname"; then pname="$(sed -E 's/\-venv$/-virtualenv/' <<< "$pname")" sedmatched=1 fi if grep -Eq -- '-dev$' <<< "$pname"; then pname="$(sed -E 's/\-dev$/-devel/' <<< "$pname")" sedmatched=1 fi if (( sedmatched )); then _debug yellow " [get-rhel-equiv] sedmatched is true, djusted name: $pname" else _debug yellow " [get-rhel-equiv] sedmatched is false, finding equiv for: $pname" fi case "$pname" in dnsutils) echo "bind-utils";; iputils-ping) echo "iputils";; liblz4-tool) echo "lz4";; "build-essential") echo "gcc gcc-c++ make cmake automake autoconf bison libtool awk glibc-devel glibc-headers libcurl-devel";; thin-provisioning-tools) echo "lvm2";; *) echo "$pname";; esac } pkg-installed() { sg-sudo "$PKG_INSTALLED" "$@" &> /dev/null } install-pkg() { local pkglst pkglst=("$@") _debug yellow " [install-pkg] BASE_OS: '$BASE_OS' | BASE_PKG_MGR: $BASE_PKG_MGR | PKG_INSTALL: $PKG_INSTALL | PKG_UPDATE: $PKG_UPDATE | pkglst: ${pkglst[*]}" msg cyan " >>> Installing packages: ${pkglst[*]} ..." if [[ "$BASE_OS" == "debian" && "$APT_UPDATED" == "n" ]]; then _debug yellow " [install-pkg] Running debian package manager update command: sudo $BASE_PKG_MGR update -qy" msg bold blue " > Updating apt repository data, please wait..." sg-sudo "$BASE_PKG_MGR" update -qy &> /dev/null APT_UPDATED="y" PKG_MGR_UPDATED=1 elif (( PKG_MGR_UPDATED == 0 )) && [[ -n "$PKG_UPDATE" ]]; then _debug yellow " [install-pkg] Running OS '$BASE_OS' package manager update command: sudo $PKG_UPDATE" sg-sudo $PKG_UPDATE PKG_MGR_UPDATED=1 fi if is-rhel; then _new_pkgs=() for p in "${pkglst[@]}"; do _new_pkg=($(get-rhel-equiv "$p")) _debug yellow " --> Found Redhat-based equivalent package for '${p}'. Replacing package name with: ${_new_pkg[*]}" _new_pkgs+=("${_new_pkg[@]}") done pkglst=("${_new_pkgs[@]}") _debug yellow " ---> Updated package list is: ${_new_pkgs[*]}" fi if [[ -n "$PKG_INSTALLED" ]]; then _new_pkgs=() _debug yellow " ---> Stripping any packages that are already installed using command: $PKG_INSTALLED" for p in "${pkglst[@]}"; do pkg-installed "$p" && _debug yellow " ------> Package '$p' is already installed. removing from list." continue _debug yellow " ------> Package '$p' not installed. adding to list." _new_pkgs+=("$p") done pkglst=("${_new_pkgs[@]}") fi msg bold blue " > Installing various packages, please wait..." if [[ "$BASE_OS" == "debian" ]]; then _DEB_EX_ARGS=("-o" "Dpkg::Options::='--force-confold'" "-o" "Dpkg::Use-Pty=0" "--force-yes" "install" "-qq" "-y") _debug yellow " [install-pkg] OS appears to be debian, using $BASE_PKG_MGR - sudo $BASE_PKG_MGR ${_DEB_EX_ARGS[*]} ${pkglst[*]}" DEBIAN_FRONTEND=noninteractive sg-sudo "$BASE_PKG_MGR" "${_DEB_EX_ARGS[@]}" "${pkglst[@]}" &>/dev/null elif [[ -n "$PKG_INSTALL" ]]; then _debug yellow " [install-pkg] Running package manager install command: sudo $PKG_INSTALL ${pkglst[*]}" if ! sg-sudo $PKG_INSTALL "${pkglst[@]}" ; then if [[ -n "$PKG_INSTALLED" ]]; then _new_pkgs=() _debug yellow " ---> Stripping any packages that are already installed using command: $PKG_INSTALLED" for p in "${pkglst[@]}"; do pkg-installed "$p" && continue _new_pkgs+=("$p") done pkglst=("${_new_pkgs[@]}") fi for pk in "${pkglst[@]}"; do _debug yellow " [install-pkg] Installing individual package $pk - running package manager install command: sudo $PKG_INSTALL ${pk}" sg-sudo $PKG_INSTALL "$pk" done fi fi } pkg_not_found() { if (( $# < 2 )); then msg red "ERR: pkg_not_found requires 2 arguments (cmd) (package)" return 9 fi local cmd="$1" pkg="$2" _new_pkg="" _debug yellow " [pkg_not_found] Checking if we have binary: $cmd (pkg: ${pkg})" if ! sg-has-binary "$cmd"; then _debug yellow " [pkg_not_found] Got falsey from has_binary '$cmd'" msg yellow "WARNING: Command $cmd was not found. installing now..." install-pkg "$pkg" else _debug green " [pkg_not_found] We appear to already have the binary: '$cmd'" fi } pkg-not-found() { pkg_not_found "$@"; } autopkg() { local cmdlist missingpkgs missingpkgs=() cmdlist=("$@") for xc in "${cmdlist[@]}"; do if ! sg-has-binary "$xc"; then msg yellow "WARNING: Command $xc was not found. Adding to package installation queue ..." missingpkgs+=("$xc") else _debug green " [autopkg] We appear to already have the binary: '$xc'" fi done if (( ${#missingpkgs[@]} < 1 )); then _debug green " [autopkg] All commands passed to autopkg already seem to exist. Not installing package for any of these cmds: ${missingpkgs[*]}" else msg cyan " >>> Installing same-named package for commands: ${missingpkgs[*]}" install-pkg "${missingpkgs[@]}" fi } autopkg git curl wget rsync python3 pkg-not-found pip3 python3-pip if [ -z ${S_CORE_VER+x} ]; then echo "Checking if Privex ShellCore is installed / Downloading it..." _sc_fail() { >&2 echo "Failed to load or install Privex ShellCore..." && exit 1; } # Error handling function for Privex ShellCore [[ -f "${HOME}/.pv-shcore/load.sh" ]] || [[ -f "/usr/local/share/pv-shcore/load.sh" ]] || \ { curl -fsS https://cdn.privex.io/github/shell-core/install.sh | bash >/dev/null; } || _sc_fail echo "Loading Privex ShellCore..." [[ -d "${HOME}/.pv-shcore" ]] && . "${HOME}/.pv-shcore/load.sh" || . "/usr/local/share/pv-shcore/load.sh" || _sc_fail fi sg-has-binary() { sg_has_binary "$@"; } has_binary() { sg_has_binary "$@"; } has-binary() { sg_has_binary "$@"; } export -f has_binary sg_has_binary has-binary sg-has-binary if ! sg-has-binary sudo && [ "$EUID" -eq 0 ]; then has_sudo() { return 0; } else has_sudo() { sudo -n ls > /dev/null; } fi sg_copyright() { msg "${_LN}" msg bold green " ############################################################" msg bold green " ### ###" msg bold green " ### Someguy Scripts - (C) 2019 github.com/Someguy123 ###" msg bold green " ### Released as open source under the GNU AGPL v3 ###" msg bold green " ### ###" msg bold green " ############################################################" msg "${_LN}" sleep 2 } sgs_clone() { if [[ "$SKIP_CLONE" != "y" ]]; then msg cyan " >>> Cloning 'github.com/Someguy123/someguy-scripts.git' into temp folder: $LIB_DIR" git clone --recurse-submodules -q https://github.com/Someguy123/someguy-scripts.git "$LIB_DIR" msg green " [+] Done.\n" else if [[ ! -d "${LIB_DIR}" ]]; then msg bold red " [!!!] Critical Error. SKIP_CLONE is 'y' but the LIB_DIR folder doesn't exist: $LIB_DIR " msg bold red " [!!!] Cannot continue without LIB_DIR pointing to a valid someguy-scripts installation\n" return 1 elif [[ ! -f "${LIB_DIR}/lib.sh" ]]; then msg bold red " [!!!] Critical Error. SKIP_CLONE is 'y' but the file '${LIB_DIR}/lib.sh' does not exist." msg bold red " [!!!] Cannot continue without LIB_DIR pointing to a valid someguy-scripts installation\n" return 1 fi msg yellow " [-] Skipping clone as SKIP_CLONE is 'y'. Using someguy-scripts in folder: $LIB_DIR" fi return 0 } [ -z ${ZSH_USERS+x} ] && ZSH_USERS=(root ubuntu debian centos oracle redhat admin linux fedora user chris privex kale someguy someguy123) sgs_provision() { local u uh sgs_var_defaults msg msg cyan " >>> Checking both 'git' and 'curl' are available, otherwise installing them..." autopkg git curl msg green " [+] Done.\n" if [ -z ${SGLIB_LOADED+x} ]; then sgs_clone msg "${_LN}" msg cyan " >>> Importing library file: ${LIB_DIR}/lib.sh" cd "$LIB_DIR" . "lib.sh" || { >&2 echo "!!! ERROR !!! Could not load lib.sh. Cannot continue."; exit 1; } msg green " [+] Done.\n" fi msg "${_LN}" [[ "$SKIP_LOCALE" == "y" ]] || { msg cyan " >>> Preventing locale issues..."; fix_locale; msg green " [+] Done.\n"; } msg "${_LN}" [[ "$SKIP_INSTALL" == "y" ]] || { install_essential; msg green " [+] Done.\n"; } msg "${_LN}" [[ "$SKIP_GLOBAL" == "y" ]] || { msg cyan " >>> Installing global configs and zsh files..."; install_global; msg green " [+] Done.\n"; } msg "${_LN}" [[ "$SKIP_HARDEN" == "y" ]] || { harden; msg green " [+] Done.\n"; } msg "${_LN}" msg cyan " >>> Setting zsh as the default shell for ZSH_USERS: ${ZSH_USERS[*]}" for u in "${ZSH_USERS[@]}"; do if ! getent passwd "$u" > /dev/null; then msg yellow " [!] User '$u' doesn't exist. Skipping.\n" continue fi msg green " [+] Setting ZSH as the default shell for user '$u'" change_shell "$u" > /dev/null msg green " [+] Checking if user '$u' has a .zshrc file" local uh=$(get_home "$u") if (($(len "$uh")<3)); then msg yellow " [!] User home folder too short (< 3 chars)... Skipping for safety. Folder was: ${BOLD}$uh" continue fi _copy_zshrc "$uh" > /dev/null && msg green " [+] User '$u' has .zshrc file, or one was installed successfully.\n" && \ OMZSH_INSTALLED='y' || msg red " [!] Error while attempting to install .zshrc file into '$uh'...\n" done msg green " [+] Done.\n"; msg bold green " [+++] Finished running Someguy-Scripts lite auto-provisioner.\n" sg_copyright } ### -------------------------------------- ### Someguy123/someguy-scripts/scripts/full.sh ### -------------------------------------- _LN="\n==========================================================================\n" echo -e "\n${_LN}" echo " ############################################################" echo " ### ###" echo " ### Someguy Scripts - (C) 2019 github.com/Someguy123 ###" echo " ### Released as open source under the GNU AGPL v3 ###" echo " ### ###" echo " ############################################################" echo -e "${_LN}" sleep 1 SGLITE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" : ${SKIP_HARDEN='y'} # Do not run server hardening sg_copyright IS_FRESH='y' # We set IS_FRESH to true to skip any prompts requiring user input. sgs_provision