From 003e8159d515db5168636159ca3e83bb560ce25a Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Sun, 7 May 2023 22:04:08 -0700 Subject: [PATCH 01/14] added Slipstream installation to extras and added menu stub --- extras/Slipstream.install | 57 ++++++++++++++++++++++----------------- install.sh | 42 +++++++++++++++++++++++------ 2 files changed, 66 insertions(+), 33 deletions(-) diff --git a/extras/Slipstream.install b/extras/Slipstream.install index 2ddd996..266e271 100755 --- a/extras/Slipstream.install +++ b/extras/Slipstream.install @@ -4,7 +4,7 @@ # Bash expansions to get the name and location of this script when run scriptname="${BASH_SOURCE[0]##*/}" rundir="${BASH_SOURCE[0]%/*}" -logfile +logfile="$rundir/$scriptname.log" # Source PRbL Functions locally or retrieve from online if [ ! -z $prbl_functions ] ; then @@ -37,16 +37,6 @@ codedog_bashrc="# CodeDog system path setup export PATH=\"\$PATH:\$HOME/devl/CodeDog\" " -run(){ - _cmd=$@ - if [[ dry_run == true ]] ; then - boxline "DryRun: $_cmd" - else - boxline "not a dry run" - $_cmd - fi -} - check-deps(){ # Iterate through the list of required packages and check if installed for pkg in ${packages[@]} ; do @@ -67,7 +57,7 @@ check-deps(){ } install-deps(){ - boxborder "Installing packages $packages" + logger "Installing packages $packages" run "for $_package in $packages ; do sudo apt-get install -y $_package ; done" # Sets dependency installed flag to true depsinstalled=true @@ -187,9 +177,9 @@ clone-repo(){ local _url=$1 local _destination=$2 if [ ! -z $_destination ] ; then - mkdir -p $_destination + run mkdir -p $_destination fi - git clone --recurse-submodules $_url $_destination + run git clone --recurse-submodules $_url $_destination } dry-run-report(){ @@ -213,11 +203,11 @@ install(){ export PATH="$PATH:$HOME/devl/CodeDog" # Check for dependent applications and offer to install if ! check-deps ; then - run warn "Some of the utilities needed by this script are missing" + warn "Some of the utilities needed by this install are missing" boxtop - run boxline "Missing utilities:" + logger echo -e "Missing utilities:" for bin in ${bins_missing[@]} ; do - run boxline "${bins_missing[$bin]}" + logger echo -e "${bins_missing[$bin]}" done boxbottom boxborder "Would you like to install them? (this will require root password)" @@ -227,7 +217,7 @@ install(){ ) case `select_opt "${utilsmissing_menu[@]}"` in 0) boxborder "${grn}Installing dependencies...${dfl}" - run sudo install-deps + install-deps ;; 1) run warn "Dependent Utilities missing: $bins_missing" ;; esac @@ -246,15 +236,32 @@ install(){ popd } +# 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 " [${red}P${lrd}R${ylw}b${ong}L ${lyl}Installed${dfl}]" + install && success " [${lbl}Slip${blu}Stream ${lyl}Installed${dfl}]" ;; -r | --remove) - remove && success " [${red}P${lrd}R${ylw}b${ong}L ${lyl}Removed${dfl}]" + remove && success " [${lbl}Slip${blu}Stream ${lyl}Removed${dfl}]" ;; -d | --dependencies) - install-deps && success "${red}P${lrd}R${ylw}b${ong}L${dfl} Dependencies installed!" + install-deps && success "${lbl}Slip${blu}Stream ${dfl} Dependencies installed!" ;; -D | --dry-run) export dry_run=true @@ -263,18 +270,18 @@ case $1 in dry-run-report usage unset dry_run - success "${red}P${lrd}R${ylw}b${ong}L${dfl} Dry-Run Complete!" + success "${lbl}Slip${blu}Stream Installer Dry-Run Complete!" ;; -u | --update) export update_run=true - update && unset update_run && success " [${red}P${lrd}R${ylw}b${ong}L ${lyl}Updated${dfl}]" + update && unset update_run && success " [${lbl}Slip${blu}Stream ${lyl}Updated${dfl}]" ;; -f | --force) remove-arbitrary - install && success " [${red}P${lrd}R${ylw}b${ong}L ${lyl}Installed${dfl}]" + install && success " [${lbl}Slip${blu}Stream ${lyl}Installed${dfl}]" ;; -F | --force-remove) - remove-arbitrary && success " [${red}P${lrd}R${ylw}b${ong}L ${lyl}Force-Removed${dfl}]" + remove-arbitrary && success " [${lbl}Slip${blu}Stream ${lyl}Force-Removed${dfl}]" ;; -h | --help) usage diff --git a/install.sh b/install.sh index 9761db0..d5fad20 100755 --- a/install.sh +++ b/install.sh @@ -4,7 +4,7 @@ ################################################################### # initial vars -VERSION=2.2.0 +VERSION=2.2.1 scripttitle="Pyr0ball's Reductive Bash Library Installer - v$VERSION" # Bash expansions to get the name and location of this script when run @@ -317,6 +317,25 @@ install-dir() { done < <(find "$_source" -type f -print0) } +install-extras(){ + _extras=() + for file in ${rundir_absolute}/extras/*.install ; do + _extras+=("${rundir_absolute}/extras/$file.install") + done + + boxborder "Which extras should be installed?" + multiselect result _extras "false" + + # For each extra, compare input choice and apply installs + idx=0 + for extra in "${_extras[@]}"; do + # If the selected user is set to true + if [[ "${result[idx]}" == "true" ]] ; then + run /bin/bash "$extra" + fi + done +} + # install-dir(){ # local _source="$1" # local _destination="$2" @@ -399,10 +418,17 @@ userinstall(){ #clear # Download and install any other extras - if [ -f "${rundir_absolute}/extras/*.install" ] ; then - for file in ${rundir_absolute}/extras/*.install ; do - run /bin/bash "${rundir_absolute}/extras/$file" - done + if [ -d "${rundir_absolute}/extras/" ] ; then + extras_menu=( + "$(boxline "${green_check} Yes")" + "$(boxline "${red_x} No")" + ) + case `select_opt "${extras_menu[@]}"` in + 0) boxborder "${grn}Installing extras...${dfl}" + install-extras + ;; + 1) logger "Skipping extras installs" ;; + esac fi if [[ $dry_run != true ]] ; then boxborder "${grn}Please be sure to run ${lyl}sensors-detect --auto${grn} after installation completes${dfl}" @@ -420,9 +446,9 @@ globalinstall(){ # Check for dependent applications and offer to install if ! check-deps ; then warn "Some of the utilities needed by this script are missing" - echo -e "Missing utilities:" - echo -e "${bins_missing[@]}" - echo -e "Would you like to install them? (this will require root password)" + logger "Missing utilities:" + logger "${bins_missing[@]}" + logger "Would you like to install them? (this will require root password)" utilsmissing_menu=( "$(boxline "${green_check} Yes")" "$(boxline "${red_x} No")" From 3342b42de73934607720d836282dbb1d8c5423ea Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Sun, 7 May 2023 22:13:24 -0700 Subject: [PATCH 02/14] fixed dependency install function --- extras/Slipstream.install | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/extras/Slipstream.install b/extras/Slipstream.install index 266e271..1b9042f 100755 --- a/extras/Slipstream.install +++ b/extras/Slipstream.install @@ -57,8 +57,15 @@ check-deps(){ } install-deps(){ - logger "Installing packages $packages" - run "for $_package in $packages ; do sudo apt-get install -y $_package ; done" + logger "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 } @@ -219,7 +226,7 @@ install(){ 0) boxborder "${grn}Installing dependencies...${dfl}" install-deps ;; - 1) run warn "Dependent Utilities missing: $bins_missing" ;; + 1) warn "Dependent Utilities missing: $bins_missing" ;; esac fi run mkdir -p $installdir From 796bf57aecf57c92d9302ca5e2d8c3f891095d4d Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Sun, 7 May 2023 22:21:59 -0700 Subject: [PATCH 03/14] fixed repo clone function array access --- extras/Slipstream.install | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extras/Slipstream.install b/extras/Slipstream.install index 1b9042f..ac5eee7 100755 --- a/extras/Slipstream.install +++ b/extras/Slipstream.install @@ -148,7 +148,7 @@ install-file(){ fi } -install-dir() { +install-dir(){ local _source="$1" local _destination="$2" installed_dirs+=("$_source -> $_destination") @@ -231,8 +231,8 @@ install(){ fi run mkdir -p $installdir pushd $installdir - for repo in $repo_packages ; do - run clone-repo $repo + for repo in ${repo_packages[@]} ; do + clone-repo $repo done popd pushd $installdir/Proteus From dd6e58a43e61616f9e52dd598eb988c12ba97e3e Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Sun, 7 May 2023 23:54:56 -0700 Subject: [PATCH 04/14] install vim install edits --- PRbL | 2 +- extras/Slipstream.install | 17 ++++++++--------- install.sh | 4 +++- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/PRbL b/PRbL index a2aabfb..adf0fec 160000 --- a/PRbL +++ b/PRbL @@ -1 +1 @@ -Subproject commit a2aabfb78f068db4ee2f26208394632fc41b2aa7 +Subproject commit adf0fecbdbed55a6956c5a6f7a0f2909eb304055 diff --git a/extras/Slipstream.install b/extras/Slipstream.install index ac5eee7..54669b4 100755 --- a/extras/Slipstream.install +++ b/extras/Slipstream.install @@ -132,7 +132,7 @@ restore-backup(){ install-file(){ local _source="$1" local _destination="$2" - local _source_root="$3" + local _source_root="$3" # Optional 3rd argument if root dir is different than rundir local _filename=${_source##*/} local _destination_file=${_destination}/${_filename#${_source_root}} installed_files+=("${_destination_file}") @@ -239,7 +239,7 @@ install(){ run sudo python3 ruleMgr.py popd pushd $installdir/Slipstream - run codeDog ./Slipstream.dog && success "Slipstream app built at ${installdir}/Slipstream/LinuxBuild" + run $installdir/CodeDog/codeDog ./Slipstream.dog && logger "Slipstream app built at ${installdir}/Slipstream/LinuxBuild" popd } @@ -262,33 +262,32 @@ usage(){ case $1 in -i | --install) - install && success " [${lbl}Slip${blu}Stream ${lyl}Installed${dfl}]" + install && success " [${lbl}Slip${gry}Stream ${lyl}Installed${dfl}]" ;; -r | --remove) - remove && success " [${lbl}Slip${blu}Stream ${lyl}Removed${dfl}]" + remove && success " [${lbl}Slip${gry}Stream ${lyl}Removed${dfl}]" ;; -d | --dependencies) - install-deps && success "${lbl}Slip${blu}Stream ${dfl} Dependencies installed!" + install-deps && success "${lbl}Slip${gry}Stream ${dfl} Dependencies installed!" ;; -D | --dry-run) export dry_run=true - echo dry_run=$dry_run install dry-run-report usage unset dry_run - success "${lbl}Slip${blu}Stream Installer Dry-Run Complete!" + success "${lbl}Slip${gry}Stream ${lyl}Installer Dry-Run Complete!${dfl}" ;; -u | --update) export update_run=true - update && unset update_run && success " [${lbl}Slip${blu}Stream ${lyl}Updated${dfl}]" + 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${blu}Stream ${lyl}Force-Removed${dfl}]" + remove-arbitrary && success " [${lbl}Slip${gry}Stream ${lyl}Force-Removed${dfl}]" ;; -h | --help) usage diff --git a/install.sh b/install.sh index d5fad20..42159f9 100755 --- a/install.sh +++ b/install.sh @@ -396,7 +396,9 @@ userinstall(){ mkdir -p ${HOME}/.vim/colors install-file $rundir/lib/vimfiles/crystallite.vim ${HOME}/.vim/colors take-backup $HOME/.vimrc - install-file $rundir/lib/vimfiles/vimrc.local $HOME/.vimrc + cp $rundir/lib/vimfiles/vimrc.local $rundir/lib/vimfiles/.vimrc + install-file $rundir/lib/vimfiles/.vimrc $HOME + rm $rundir/lib/vimfiles/.vimrc fi # Check for existing bashrc config, append if missing From cf2af69032eda245a0426635892383dd3c997bbb Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Mon, 8 May 2023 15:11:35 -0700 Subject: [PATCH 05/14] commented out tab enforcement --- lib/vimfiles/vimrc.local | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/vimfiles/vimrc.local b/lib/vimfiles/vimrc.local index 0af757c..fb2d1ef 100644 --- a/lib/vimfiles/vimrc.local +++ b/lib/vimfiles/vimrc.local @@ -12,8 +12,8 @@ set mouse-=a filetype plugin indent on " show existing tab with 2 spaces width -set tabstop=2 -" " when indenting with '>', use 2 spaces width -set shiftwidth=2 -" " On pressing tab, insert 2 spaces -set expandtab +" set tabstop=2 +" " " when indenting with '>', use 2 spaces width +" set shiftwidth=2 +" " " On pressing tab, insert 2 spaces +" set expandtab From 3a2b38d154ebdbb69b7153d47a5d1a5bd5561481 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Mon, 8 May 2023 15:12:09 -0700 Subject: [PATCH 06/14] switched around run function logic --- install.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index 42159f9..941963d 100755 --- a/install.sh +++ b/install.sh @@ -135,19 +135,19 @@ usage(){ run(){ _cmd=$@ - if [[ dry_run == true ]] ; then - boxline "DryRun: $_cmd" - else + if [[ $dry_run != true ]] ; then $_cmd + else + boxline "DryRun: $_cmd" fi } run-and-log(){ _cmd=$@ - if [[ dry_run == true ]] ; then - logger "DryRun: $_cmd" - else + if [[ $dry_run != true ]] ; then logger $_cmd + else + logger "DryRun: $_cmd" fi } From 8c2ceb1b1f4419d2c056be9190d00f5138cc1836 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Mon, 8 May 2023 15:12:33 -0700 Subject: [PATCH 07/14] changed detectvim to look for latest version --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 941963d..d278892 100755 --- a/install.sh +++ b/install.sh @@ -154,7 +154,7 @@ run-and-log(){ detectvim(){ # If the vim install directory exists, check for and store the highest numerical value version installed if [[ -d /usr/share/vim ]] ; then - viminstall=$(ls -lah /usr/share/vim/ | grep vim | grep -v rc | awk '{print $NF}') + viminstall=$(ls -lah /usr/share/vim/ | grep vim | grep -v rc | awk '{print $NF}' | tail -n 1) else viminstall=null warn "vim is not currently installed, unable to set up colorscheme and formatting" From 426caaade7cc7887e8cf9b0571c4d12ca7ba6f8a Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Mon, 8 May 2023 15:14:52 -0700 Subject: [PATCH 08/14] switched over dry-run logic to run function --- install.sh | 116 ++++++++++++++++++----------------------------------- 1 file changed, 40 insertions(+), 76 deletions(-) diff --git a/install.sh b/install.sh index d278892..380d1cc 100755 --- a/install.sh +++ b/install.sh @@ -211,59 +211,37 @@ export prbl_functions=\"${installdir}/functions\"" take-backup(){ name="$1" if [[ $update_run != true ]] ; then - if [[ $dry_run == true ]] ; then - # Check if a backup file or symbolic link already exists - if [[ -e "$name.bak" || -L "$name.bak" ]]; then - boxline "DryRun: $name.bak backup already exists" - else - # Check if the file is a hidden file (starts with a dot) - if [[ "$name" == .* ]]; then - # Add a dot to the beginning of the backup file name - backup_name=".${name}.bak" - else - # Create the backup file name by appending ".bak" to the original file name - backup_name="${name}.bak" - fi - # Copy the file to the backup file with preservation of file attributes - boxline "DryRun: cp -p $name $backup_name" - # Add the original file to the list of backup files - backup_files+=("$name") - # Log the original file name to the backup file list file - boxline "DryRun: echo $name >> $rundir/backup_files.list" - fi + # Check if a backup file or symbolic link already exists + if [[ -e "$name.bak" || -L "$name.bak" ]]; then + run boxline " $name.bak backup already exists" else - # Check if a backup file or symbolic link already exists - if [[ -e "$name.bak" || -L "$name.bak" ]]; then - boxline " $name.bak backup already exists" + # Check if the file is a hidden file (starts with a dot) + if [[ "$name" == .* ]]; then + # Add a dot to the beginning of the backup file name + backup_name=".${name}.bak" else - # Check if the file is a hidden file (starts with a dot) - if [[ "$name" == .* ]]; then - # Add a dot to the beginning of the backup file name - backup_name=".${name}.bak" - else - # Create the backup file name by appending ".bak" to the original file name - backup_name="${name}.bak" - fi - # Copy the file to the backup file with preservation of file attributes - cp -p "$name" "$backup_name" - # Add the original file to the list of backup files - backup_files+=("$name") - # Log the original file name to the backup file list file - boxline "$name" >> "$rundir/backup_files.list" + # Create the backup file name by appending ".bak" to the original file name + backup_name="${name}.bak" fi + # Copy the file to the backup file with preservation of file attributes + run cp -p "$name" "$backup_name" + # Add the original file to the list of backup files + backup_files+=("$name") + # Log the original file name to the backup file list file + run echo "$name" >> "$rundir/backup_files.list" fi fi } restore-backup(){ - echo "${#backup_files[@]}" + run echo "${#backup_files[@]}" for file in "${backup_files[@]}" ; do - cp "$file".bak $file - echo "$file is restored" + run cp "$file".bak $file + run echo "$file is restored" done backup_files=() if [ -f $rundir/backup_files.list ] ; then - rm $rundir/backup_files.list + run rm $rundir/backup_files.list fi } @@ -275,14 +253,10 @@ install-file(){ local _destination_file=${_destination}/${_filename#${_source_root}} installed_files+=("${_destination_file}") if [[ $update_run == true ]] ; then - boxline "$scriptname: added file ${_destination_file} to list" + run boxline "$scriptname: added file ${_destination_file} to list" else - if [[ $dry_run == true ]] ; then - boxline "DryRun: cp -p $_source $_destination_file" - else - cp -p $_source $_destination_file && boxline "Installed ${_filename}" || warn "Unable to install ${_filename}" - fi - echo "${_destination_file}" >> $rundir/installed_files.list + run cp -p $_source $_destination_file && boxline "Installed ${_filename}" || warn "Unable to install ${_filename}" + run echo "${_destination_file}" >> $rundir/installed_files.list fi } @@ -301,18 +275,11 @@ install-dir() { #echo "$destination_file" >> "$logfile" installed_files+=($destination_file) if [[ $update_run == true ]] ; then - boxline "$scriptname: added file ${destination_file} to list" + run boxline "$scriptname: added file ${destination_file} to list" else - if [[ $dry_run == true ]] ; then - # Create the destination directory if it doesn't exist - boxline "DryRun: mkdir -p $(dirname $destination_file)" - boxline "DryRun: cp -p ${_source}${_filename} $destination_file" - else - # Create the destination directory if it doesn't exist - mkdir -p "$(dirname "$destination_file")" - cp -p ${_source}${_filename} $destination_file && boxline "Installed ${_filename}" || warn "Unable to install ${_filename}" - fi - echo "${destination_file}" >> $rundir/installed_files.list + run mkdir -p "$(dirname "$destination_file")" + run cp -p ${_source}${_filename} $destination_file && boxline "Installed ${_filename}" || warn "Unable to install ${_filename}" + run echo "${destination_file}" >> $rundir/installed_files.list fi done < <(find "$_source" -type f -print0) } @@ -331,7 +298,7 @@ install-extras(){ for extra in "${_extras[@]}"; do # If the selected user is set to true if [[ "${result[idx]}" == "true" ]] ; then - run /bin/bash "$extra" + run exec "$extra" fi done } @@ -355,14 +322,14 @@ install-extras(){ userinstall(){ # Create install directory under user's home directory - mkdir -p ${installdir} + run mkdir -p ${installdir} # Check if functions already exist, and check if functions are out of date if [ -f ${installdir}/functions ] ; then # if functions are out of date, remove before installing new version local installerfrev=$(cat ${rundir}/functions | grep functionsrev ) if [[ $(vercomp ${installerfrev##*=} $installer_functionsrev ) == 2 ]] ; then - rm ${installdir}/functions + run rm ${installdir}/functions fi fi @@ -370,11 +337,7 @@ userinstall(){ install-file ${rundir}/PRbL/functions ${installdir} # Copy bashrc scripts to home folder - #cp -r ${rundir}/lib/skel/* $HOME/ install-dir ${rundir}/lib/skel/ $HOME - # for file in $(ls -a -I . -I .. ${rundir}/lib/skel/) ; do - # install-dir ${rundir}/lib/skel/$file $HOME - # done # Check for dependent applications and warn user if any are missing if ! check-deps ; then @@ -404,8 +367,8 @@ userinstall(){ # Check for existing bashrc config, append if missing if [[ $(cat ${HOME}/.bashrc | grep -c 'bashrc.d') == 0 ]] ; then take-backup $HOME/.bashrc - echo -e "$bashrc_append" >> $HOME/.bashrc && boxborder "bashc.d installed..." || warn "Malformed append on ${lbl}${HOME}/.bashrc${dfl}. Check this file for errors" - echo -e "$prbl_bashrc" >> $HOME/.bashrc.d/00-prbl.bashrc && boxborder "bashc.d/00-prbl installed..." || warn "Malformed append on ${lbl}${HOME}/.bashrc.d/00-prbl.bashrc${dfl}. Check this file for errors" + run echo -e "$bashrc_append" >> $HOME/.bashrc && boxborder "bashc.d installed..." || warn "Malformed append on ${lbl}${HOME}/.bashrc${dfl}. Check this file for errors" + run echo -e "$prbl_bashrc" >> $HOME/.bashrc.d/00-prbl.bashrc && boxborder "bashc.d/00-prbl installed..." || warn "Malformed append on ${lbl}${HOME}/.bashrc.d/00-prbl.bashrc${dfl}. Check this file for errors" fi @@ -439,7 +402,7 @@ userinstall(){ globalinstall(){ # Create global install directory - mkdir -p ${globalinstalldir} + run mkdir -p ${globalinstalldir} # Copy functions install-file ${rundir}/PRbL/functions ${globalinstalldir}/functions @@ -479,12 +442,12 @@ globalinstall(){ # done if [[ $(cat /home/${selecteduser}/.bashrc | grep -c prbl) == 0 ]] ; then take-backup /home/${selecteduser}/.bashrc - echo -e "$bashrc_append" >> /home/${selecteduser}/.bashrc && boxborder "bashc.d installed..." || warn "Malformed append on ${lbl}/home/${selecteduser}/.bashrc${dfl}. Check this file for errors" + run echo -e "$bashrc_append" >> /home/${selecteduser}/.bashrc && boxborder "bashc.d installed..." || warn "Malformed append on ${lbl}/home/${selecteduser}/.bashrc${dfl}. Check this file for errors" fi - chown -R ${selecteduser}:${selecteduser} /home/${selecteduser} + run sudo chown -R ${selecteduser}:${selecteduser} ${installdir} if [[ "$bins_missing" == "false" ]] ; then boxborder "Checking ${selecteduser}'s bashrc..." - su ${selecteduser} -c /home/${selecteduser}.bashrc.d/11-quickinfo.bashrc + run su ${selecteduser} -c /home/${selecteduser}.bashrc.d/11-quickinfo.bashrc fi fi done @@ -496,7 +459,7 @@ globalinstall(){ install-file $rundir/lib/vimfiles/vimrc.local /etc/vim/vimrc.local fi if [ ! -z $(which sensors-detect) ] ; then - sensors-detect --auto + run sensors-detect --auto fi # Download and install any other extras @@ -548,10 +511,11 @@ remove-arbitrary(){ update(){ remove-arbitrary - git stash -m "$pretty_date stashing changes before update to latest" - git fetch && git pull --recurse-submodules + run git stash -m "$pretty_date stashing changes before update to latest" + run git fetch && run git pull --recurse-submodules pushd PRbL - git pull + run git checkout master + run git pull popd install } From 4b3da346bcf7d155840bbb0af3fe116ab0a1e7d9 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Mon, 8 May 2023 15:15:10 -0700 Subject: [PATCH 09/14] added extras menu functions into install --- install.sh | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/install.sh b/install.sh index 380d1cc..e90e00d 100755 --- a/install.sh +++ b/install.sh @@ -11,8 +11,10 @@ scripttitle="Pyr0ball's Reductive Bash Library Installer - v$VERSION" scriptname="${BASH_SOURCE[0]##*/}" rundir="${BASH_SOURCE[0]%/*}" + # Source PRbL functions from installer directory source ${rundir}/functions +rundir_absolute=$(pushd $rundir ; pwd ; popd) #-----------------------------------------------------------------# # Script-specific Parameters @@ -286,8 +288,8 @@ install-dir() { install-extras(){ _extras=() - for file in ${rundir_absolute}/extras/*.install ; do - _extras+=("${rundir_absolute}/extras/$file.install") + for file in $(ls ${rundir}/extras/*.install) ; do + _extras+=("$file") done boxborder "Which extras should be installed?" @@ -303,6 +305,23 @@ install-extras(){ done } +extras-menu(){ + # Download and install any other extras + #if [ -d "${rundir_absolute}/extras/" ] ; then + boxborder "Extra installs available. Select and install?" + extras_menu=( + "$(boxline "${green_check} Yes")" + "$(boxline "${red_x} No")" + ) + case `select_opt "${extras_menu[@]}"` in + 0) boxborder "${grn}Installing extras...${dfl}" + install-extras + ;; + 1) logger "Skipping extras installs" ;; + esac + #fi +} + # install-dir(){ # local _source="$1" # local _destination="$2" @@ -382,19 +401,7 @@ userinstall(){ #fi #clear - # Download and install any other extras - if [ -d "${rundir_absolute}/extras/" ] ; then - extras_menu=( - "$(boxline "${green_check} Yes")" - "$(boxline "${red_x} No")" - ) - case `select_opt "${extras_menu[@]}"` in - 0) boxborder "${grn}Installing extras...${dfl}" - install-extras - ;; - 1) logger "Skipping extras installs" ;; - esac - fi + extras-menu if [[ $dry_run != true ]] ; then boxborder "${grn}Please be sure to run ${lyl}sensors-detect --auto${grn} after installation completes${dfl}" fi @@ -463,11 +470,7 @@ globalinstall(){ fi # Download and install any other extras - if [ -f "${rundir_absolute}/extras/*.install" ] ; then - for file in ${rundir_absolute}/extras/*.install ; do - run /bin/bash "${rundir_absolute}/extras/$file" - done - fi + extras-menu #clear } @@ -551,12 +554,12 @@ case $1 in ;; -D | --dry-run) export dry_run=true - box-light + box-double boxtop install boxbottom dry-run-report - usage + usage unset dry_run success "${red}P${lrd}R${ylw}b${ong}L${dfl} Dry-Run Complete!" ;; From b64f4b128683cbe6dfe8ecea711c8e6da880cac4 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Mon, 8 May 2023 17:33:56 -0700 Subject: [PATCH 10/14] added functions fallbacks and removed commented code --- install.sh | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/install.sh b/install.sh index e90e00d..c671648 100755 --- a/install.sh +++ b/install.sh @@ -4,7 +4,7 @@ ################################################################### # initial vars -VERSION=2.2.1 +VERSION=2.2.2 scripttitle="Pyr0ball's Reductive Bash Library Installer - v$VERSION" # Bash expansions to get the name and location of this script when run @@ -13,9 +13,19 @@ rundir="${BASH_SOURCE[0]%/*}" # Source PRbL functions from installer directory -source ${rundir}/functions +# Source PRbL Functions locally or retrieve from online +# TODO: Add version check to this +if [ ! -z $prbl_functions ] ; then + source $prbl_functions +else + if [ -f ${rundir}/functions ] ; then + source ${rundir}/functions + else + source <(curl -ks 'https://raw.githubusercontent.com/pyr0ball/PRbL/master/functions') + fi +fi rundir_absolute=$(pushd $rundir ; pwd ; popd) - +logfile="${rundir}/${pretty_date}_${scriptname}.log" #-----------------------------------------------------------------# # Script-specific Parameters #-----------------------------------------------------------------# @@ -288,7 +298,7 @@ install-dir() { install-extras(){ _extras=() - for file in $(ls ${rundir}/extras/*.install) ; do + for file in $(ls ${rundir_absolute}/extras/*.install) ; do _extras+=("$file") done @@ -300,7 +310,11 @@ install-extras(){ for extra in "${_extras[@]}"; do # If the selected user is set to true if [[ "${result[idx]}" == "true" ]] ; then - run exec "$extra" + if [[ $dry_run != true ]] ; then + bash "$extra -i" + else + bash "$extra -D" + fi fi done } @@ -322,22 +336,6 @@ extras-menu(){ #fi } -# install-dir(){ -# local _source="$1" -# local _destination="$2" -# installed_dirs+=("${_destination}/${_source##*/}") -# if [[ $update_run == true ]] ; then -# boxline "PRbL updater: added directory ${_destination}/${_source##*/} to list" -# else -# if [[ $dry_run == true ]] ; then -# boxline "DryRun: cp -r $_source $_destination" -# else -# cp -r $_source $_destination && boxline "Installed ${_source##*/}" || warn "Unable to install ${_source##*/}" -# fi -# echo "${_destination}/${_source}" >> $rundir/installed_dirs.list -# fi -# } - userinstall(){ # Create install directory under user's home directory @@ -474,7 +472,6 @@ globalinstall(){ #clear } - remove(){ if [ -f $rundir/installed_files.list ] ; then _installed_list=($(cat $rundir/installed_files.list)) From 6f93b407264740765e8f16083de3098994b3ba8e Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Mon, 8 May 2023 17:35:04 -0700 Subject: [PATCH 11/14] fixed logging output --- extras/Slipstream.install | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/extras/Slipstream.install b/extras/Slipstream.install index 54669b4..ddfd029 100755 --- a/extras/Slipstream.install +++ b/extras/Slipstream.install @@ -4,18 +4,18 @@ # Bash expansions to get the name and location of this script when run scriptname="${BASH_SOURCE[0]##*/}" rundir="${BASH_SOURCE[0]%/*}" -logfile="$rundir/$scriptname.log" # Source PRbL Functions locally or retrieve from online if [ ! -z $prbl_functions ] ; then source $prbl_functions else - curl -k 'https://raw.githubusercontent.com/pyr0ball/PRbL/master/functions' > $rundir/functions - source $rundir/functions + source <(curl -ks 'https://raw.githubusercontent.com/pyr0ball/PRbL/master/functions') fi +logfile="${rundir}/${pretty_date}_${scriptname}.log" installdir="$HOME/devl" +# Dependencies sys_packages=( git curl @@ -57,7 +57,7 @@ check-deps(){ } install-deps(){ - logger "Installing packages $sys_packages" + 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 @@ -239,7 +239,7 @@ install(){ run sudo python3 ruleMgr.py popd pushd $installdir/Slipstream - run $installdir/CodeDog/codeDog ./Slipstream.dog && logger "Slipstream app built at ${installdir}/Slipstream/LinuxBuild" + run $installdir/CodeDog/codeDog ./Slipstream.dog && logger echo "Slipstream app built at ${installdir}/Slipstream/LinuxBuild" popd } From 371037c316b7a3a15e8d896134310dfc81156b80 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Mon, 8 May 2023 17:35:22 -0700 Subject: [PATCH 12/14] updated to latest functions --- PRbL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PRbL b/PRbL index adf0fec..868ff88 160000 --- a/PRbL +++ b/PRbL @@ -1 +1 @@ -Subproject commit adf0fecbdbed55a6956c5a6f7a0f2909eb304055 +Subproject commit 868ff8831fd5b4bf0f7e75673178fbf51da98a91 From dcf0d517f3b6a8c8186734e0ec9f9bcee9b34e2b Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Mon, 8 May 2023 22:19:39 -0700 Subject: [PATCH 13/14] migrated file handling to PRbL functions --- PRbL | 2 +- extras/Slipstream.install | 121 +------------------------------------- 2 files changed, 2 insertions(+), 121 deletions(-) diff --git a/PRbL b/PRbL index 868ff88..87d3e36 160000 --- a/PRbL +++ b/PRbL @@ -1 +1 @@ -Subproject commit 868ff8831fd5b4bf0f7e75673178fbf51da98a91 +Subproject commit 87d3e369cd55f6e04765e64791e4c5a8e636823a diff --git a/extras/Slipstream.install b/extras/Slipstream.install index ddfd029..30b6689 100755 --- a/extras/Slipstream.install +++ b/extras/Slipstream.install @@ -36,7 +36,7 @@ repo_packages=( codedog_bashrc="# CodeDog system path setup export PATH=\"\$PATH:\$HOME/devl/CodeDog\" " - +# Functions check-deps(){ # Iterate through the list of required packages and check if installed for pkg in ${packages[@]} ; do @@ -70,125 +70,6 @@ install-deps(){ depsinstalled=true } -take-backup(){ - name="$1" - if [[ $update_run != true ]] ; then - if [[ $dry_run == true ]] ; then - # Check if a backup file or symbolic link already exists - if [[ -e "$name.bak" || -L "$name.bak" ]]; then - boxline "DryRun: $name.bak backup already exists" - else - # Check if the file is a hidden file (starts with a dot) - if [[ "$name" == .* ]]; then - # Add a dot to the beginning of the backup file name - backup_name=".${name}.bak" - else - # Create the backup file name by appending ".bak" to the original file name - backup_name="${name}.bak" - fi - # Copy the file to the backup file with preservation of file attributes - boxline "DryRun: cp -p $name $backup_name" - # Add the original file to the list of backup files - backup_files+=("$name") - # Log the original file name to the backup file list file - boxline "DryRun: echo $name >> $rundir/backup_files.list" - fi - else - # Check if a backup file or symbolic link already exists - if [[ -e "$name.bak" || -L "$name.bak" ]]; then - boxline " $name.bak backup already exists" - else - # Check if the file is a hidden file (starts with a dot) - if [[ "$name" == .* ]]; then - # Add a dot to the beginning of the backup file name - backup_name=".${name}.bak" - else - # Create the backup file name by appending ".bak" to the original file name - backup_name="${name}.bak" - fi - # Copy the file to the backup file with preservation of file attributes - cp -p "$name" "$backup_name" - # Add the original file to the list of backup files - backup_files+=("$name") - # Log the original file name to the backup file list file - boxline "$name" >> "$rundir/backup_files.list" - fi - fi - fi -} - -restore-backup(){ - echo "${#backup_files[@]}" - for file in "${backup_files[@]}" ; do - cp "$file".bak $file - echo "$file is restored" - done - backup_files=() - if [ -f $rundir/backup_files.list ] ; then - rm $rundir/backup_files.list - fi -} - -install-file(){ - local _source="$1" - local _destination="$2" - local _source_root="$3" # Optional 3rd argument if root dir is different than rundir - local _filename=${_source##*/} - local _destination_file=${_destination}/${_filename#${_source_root}} - installed_files+=("${_destination_file}") - if [[ $update_run == true ]] ; then - boxline "$scriptname: added file ${_destination_file} to list" - else - if [[ $dry_run == true ]] ; then - boxline "DryRun: cp -p $_source $_destination_file" - else - cp -p $_source $_destination_file && boxline "Installed ${_filename}" || warn "Unable to install ${_filename}" - fi - echo "${_destination_file}" >> $rundir/installed_files.list - fi -} - -install-dir(){ - local _source="$1" - local _destination="$2" - installed_dirs+=("$_source -> $_destination") - # Iterate through all files in the source directory recursively - while IFS= read -r -d '' source_file; do - # Construct the destination file path by removing the source directory path - # and appending it to the destination directory path - local _filename="${source_file#${_source}}" - local destination_file="${_destination}/${source_file#${_source}}" - # Create the parent directory of the destination file if it doesn't exist - # Log the destination file path to the logfile - #echo "$destination_file" >> "$logfile" - installed_files+=($destination_file) - if [[ $update_run == true ]] ; then - boxline "$scriptname: added file ${destination_file} to list" - else - if [[ $dry_run == true ]] ; then - # Create the destination directory if it doesn't exist - boxline "DryRun: mkdir -p $(dirname $destination_file)" - boxline "DryRun: cp -p ${_source}${_filename} $destination_file" - else - # Create the destination directory if it doesn't exist - mkdir -p "$(dirname "$destination_file")" - cp -p ${_source}${_filename} $destination_file && boxline "Installed ${_filename}" || warn "Unable to install ${_filename}" - fi - echo "${destination_file}" >> $rundir/installed_files.list - fi - done < <(find "$_source" -type f -print0) -} - -clone-repo(){ - # git clone - local _url=$1 - local _destination=$2 - if [ ! -z $_destination ] ; then - run mkdir -p $_destination - fi - run git clone --recurse-submodules $_url $_destination -} - dry-run-report(){ box-rounded boxborder "${grn}Dry-run Report:${dfl}" From e7dc5fe06a8b710e1bacc67115c26e1ab194d713 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Mon, 8 May 2023 22:21:06 -0700 Subject: [PATCH 14/14] fixed apt-get syntax --- install.sh | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/install.sh b/install.sh index c671648..2eb830a 100755 --- a/install.sh +++ b/install.sh @@ -145,24 +145,6 @@ usage(){ "You must run as 'root' for this script to automatically resolve dependencies" } -run(){ - _cmd=$@ - if [[ $dry_run != true ]] ; then - $_cmd - else - boxline "DryRun: $_cmd" - fi -} - -run-and-log(){ - _cmd=$@ - if [[ $dry_run != true ]] ; then - logger $_cmd - else - logger "DryRun: $_cmd" - fi -} - detectvim(){ # If the vim install directory exists, check for and store the highest numerical value version installed if [[ -d /usr/share/vim ]] ; then @@ -195,7 +177,7 @@ check-deps(){ install-deps(){ boxborder "Installing packages $packages" if [[ dry_run == true ]] ; then - boxline "DryRun: spin \"for $_package in $packages ; do sudo apt=get install -y $_package ; done\"" + boxline "DryRun: spin \"for $_package in $packages ; do sudo apt-get install -y $_package ; done\"" else # using a spinner function block to track installation progress spin "for $_package in $packages ; do sudo apt-get install -y $_package ; done"