From 426caaade7cc7887e8cf9b0571c4d12ca7ba6f8a Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Mon, 8 May 2023 15:14:52 -0700 Subject: [PATCH] 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 }