v2.2.0 - added dry-run option

This commit is contained in:
pyr0ball 2023-04-12 13:37:20 -07:00
parent 6f3f7b90df
commit e413bee104

View file

@ -4,7 +4,7 @@
################################################################### ###################################################################
# initial vars # initial vars
VERSION=2.1.0 VERSION=2.2.0
scripttitle="Pyr0ball's Reductive Bash Library Installer - v$VERSION" scripttitle="Pyr0ball's Reductive Bash Library Installer - v$VERSION"
scriptname="${BASH_SOURCE[0]##*/}" scriptname="${BASH_SOURCE[0]##*/}"
rundir="${BASH_SOURCE[0]%/*}" rundir="${BASH_SOURCE[0]%/*}"
@ -128,7 +128,11 @@ check-deps(){
install-deps(){ install-deps(){
boxborder "Installing packages $packages" boxborder "Installing packages $packages"
if [[ dry_run == true ]] ; then
boxline "DryRun: spin \"for $_package in $packages ; do sudo apt=get install -y $_package ; done\""
else
spin "for $_package in $packages ; do sudo apt=get install -y $_package ; done" spin "for $_package in $packages ; do sudo apt=get install -y $_package ; done"
fi
depsinstalled=true depsinstalled=true
} }
@ -147,6 +151,16 @@ export prbl_functions=\"${installdir}/functions\""
} }
take-backup(){ take-backup(){
if [[ dry_run == true ]] ; then
if [[ -e $name.bak || -L $name.bak ]] ; then
boxline "DryRun: $name.bak backup already exists"
else
boxline "DryRun: cp $1 \"$name\".bak"
backup_files+=($name)
boxline "DryRun: $name >> $rundir/backup_files.list"
fi
else
name="$1" name="$1"
if [[ -e $name.bak || -L $name.bak ]] ; then if [[ -e $name.bak || -L $name.bak ]] ; then
echo " $name.bak backup already exists" echo " $name.bak backup already exists"
@ -155,6 +169,7 @@ take-backup(){
backup_files+=($name) backup_files+=($name)
echo $name >> $rundir/backup_files.list echo $name >> $rundir/backup_files.list
fi fi
fi
} }
restore-backup(){ restore-backup(){
@ -174,7 +189,11 @@ install-file(){
local _source="$1" local _source="$1"
local _destination="$2" local _destination="$2"
installed_files+=("${_destination}/${_source##*/}") installed_files+=("${_destination}/${_source##*/}")
if [[ $dry_run == true ]] ; then
boxline "DryRun: cp -r $_source $_destination"
else
cp -r $_source $_destination && boxline "Installed ${_source##*/}" || warn "Unable to install ${_source##*/}" cp -r $_source $_destination && boxline "Installed ${_source##*/}" || warn "Unable to install ${_source##*/}"
fi
echo "${_destination}/${_source##*/}" >> $rundir/installed_files.list echo "${_destination}/${_source##*/}" >> $rundir/installed_files.list
} }
@ -359,6 +378,13 @@ update(){
install install
} }
dry-run-report(){
boxborder \
"bins_missing= ${bins_missing[@]}" \
"backup_files= ${backup_files[@]}" \
"installed_files= ${installed_files[@]}"
}
#------------------------------------------------------# #------------------------------------------------------#
# Options and Arguments Parser # Options and Arguments Parser
#------------------------------------------------------# #------------------------------------------------------#
@ -373,6 +399,12 @@ case $1 in
-d | --dependencies) -d | --dependencies)
install-deps && success "${red}P${lrd}R${ylw}b${ong}L${dfl} Dependencies installed!" install-deps && success "${red}P${lrd}R${ylw}b${ong}L${dfl} Dependencies installed!"
;; ;;
-D | --dry-run)
dry_run=true
install
dry-run-report
success "${red}P${lrd}R${ylw}b${ong}L${dfl} Dry-Run Complete!"
;;
-u | --update) -u | --update)
update && success " [${red}P${lrd}R${ylw}b${ong}L ${lyl}Updated${dfl}]" update && success " [${red}P${lrd}R${ylw}b${ong}L ${lyl}Updated${dfl}]"
;; ;;