switched over dry-run logic to run function
This commit is contained in:
parent
8c2ceb1b1f
commit
426caaade7
1 changed files with 40 additions and 76 deletions
116
install.sh
116
install.sh
|
|
@ -211,59 +211,37 @@ export prbl_functions=\"${installdir}/functions\""
|
||||||
take-backup(){
|
take-backup(){
|
||||||
name="$1"
|
name="$1"
|
||||||
if [[ $update_run != true ]] ; then
|
if [[ $update_run != true ]] ; then
|
||||||
if [[ $dry_run == true ]] ; then
|
# Check if a backup file or symbolic link already exists
|
||||||
# Check if a backup file or symbolic link already exists
|
if [[ -e "$name.bak" || -L "$name.bak" ]]; then
|
||||||
if [[ -e "$name.bak" || -L "$name.bak" ]]; then
|
run boxline " $name.bak backup already exists"
|
||||||
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
|
else
|
||||||
# Check if a backup file or symbolic link already exists
|
# Check if the file is a hidden file (starts with a dot)
|
||||||
if [[ -e "$name.bak" || -L "$name.bak" ]]; then
|
if [[ "$name" == .* ]]; then
|
||||||
boxline " $name.bak backup already exists"
|
# Add a dot to the beginning of the backup file name
|
||||||
|
backup_name=".${name}.bak"
|
||||||
else
|
else
|
||||||
# Check if the file is a hidden file (starts with a dot)
|
# Create the backup file name by appending ".bak" to the original file name
|
||||||
if [[ "$name" == .* ]]; then
|
backup_name="${name}.bak"
|
||||||
# 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
|
||||||
|
# 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
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
restore-backup(){
|
restore-backup(){
|
||||||
echo "${#backup_files[@]}"
|
run echo "${#backup_files[@]}"
|
||||||
for file in "${backup_files[@]}" ; do
|
for file in "${backup_files[@]}" ; do
|
||||||
cp "$file".bak $file
|
run cp "$file".bak $file
|
||||||
echo "$file is restored"
|
run echo "$file is restored"
|
||||||
done
|
done
|
||||||
backup_files=()
|
backup_files=()
|
||||||
if [ -f $rundir/backup_files.list ] ; then
|
if [ -f $rundir/backup_files.list ] ; then
|
||||||
rm $rundir/backup_files.list
|
run rm $rundir/backup_files.list
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -275,14 +253,10 @@ install-file(){
|
||||||
local _destination_file=${_destination}/${_filename#${_source_root}}
|
local _destination_file=${_destination}/${_filename#${_source_root}}
|
||||||
installed_files+=("${_destination_file}")
|
installed_files+=("${_destination_file}")
|
||||||
if [[ $update_run == true ]] ; then
|
if [[ $update_run == true ]] ; then
|
||||||
boxline "$scriptname: added file ${_destination_file} to list"
|
run boxline "$scriptname: added file ${_destination_file} to list"
|
||||||
else
|
else
|
||||||
if [[ $dry_run == true ]] ; then
|
run cp -p $_source $_destination_file && boxline "Installed ${_filename}" || warn "Unable to install ${_filename}"
|
||||||
boxline "DryRun: cp -p $_source $_destination_file"
|
run echo "${_destination_file}" >> $rundir/installed_files.list
|
||||||
else
|
|
||||||
cp -p $_source $_destination_file && boxline "Installed ${_filename}" || warn "Unable to install ${_filename}"
|
|
||||||
fi
|
|
||||||
echo "${_destination_file}" >> $rundir/installed_files.list
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -301,18 +275,11 @@ install-dir() {
|
||||||
#echo "$destination_file" >> "$logfile"
|
#echo "$destination_file" >> "$logfile"
|
||||||
installed_files+=($destination_file)
|
installed_files+=($destination_file)
|
||||||
if [[ $update_run == true ]] ; then
|
if [[ $update_run == true ]] ; then
|
||||||
boxline "$scriptname: added file ${destination_file} to list"
|
run boxline "$scriptname: added file ${destination_file} to list"
|
||||||
else
|
else
|
||||||
if [[ $dry_run == true ]] ; then
|
run mkdir -p "$(dirname "$destination_file")"
|
||||||
# Create the destination directory if it doesn't exist
|
run cp -p ${_source}${_filename} $destination_file && boxline "Installed ${_filename}" || warn "Unable to install ${_filename}"
|
||||||
boxline "DryRun: mkdir -p $(dirname $destination_file)"
|
run echo "${destination_file}" >> $rundir/installed_files.list
|
||||||
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
|
fi
|
||||||
done < <(find "$_source" -type f -print0)
|
done < <(find "$_source" -type f -print0)
|
||||||
}
|
}
|
||||||
|
|
@ -331,7 +298,7 @@ install-extras(){
|
||||||
for extra in "${_extras[@]}"; do
|
for extra in "${_extras[@]}"; do
|
||||||
# If the selected user is set to true
|
# If the selected user is set to true
|
||||||
if [[ "${result[idx]}" == "true" ]] ; then
|
if [[ "${result[idx]}" == "true" ]] ; then
|
||||||
run /bin/bash "$extra"
|
run exec "$extra"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
@ -355,14 +322,14 @@ install-extras(){
|
||||||
userinstall(){
|
userinstall(){
|
||||||
|
|
||||||
# Create install directory under user's home directory
|
# 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
|
# Check if functions already exist, and check if functions are out of date
|
||||||
if [ -f ${installdir}/functions ] ; then
|
if [ -f ${installdir}/functions ] ; then
|
||||||
# if functions are out of date, remove before installing new version
|
# if functions are out of date, remove before installing new version
|
||||||
local installerfrev=$(cat ${rundir}/functions | grep functionsrev )
|
local installerfrev=$(cat ${rundir}/functions | grep functionsrev )
|
||||||
if [[ $(vercomp ${installerfrev##*=} $installer_functionsrev ) == 2 ]] ; then
|
if [[ $(vercomp ${installerfrev##*=} $installer_functionsrev ) == 2 ]] ; then
|
||||||
rm ${installdir}/functions
|
run rm ${installdir}/functions
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -370,11 +337,7 @@ userinstall(){
|
||||||
install-file ${rundir}/PRbL/functions ${installdir}
|
install-file ${rundir}/PRbL/functions ${installdir}
|
||||||
|
|
||||||
# Copy bashrc scripts to home folder
|
# Copy bashrc scripts to home folder
|
||||||
#cp -r ${rundir}/lib/skel/* $HOME/
|
|
||||||
install-dir ${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
|
# Check for dependent applications and warn user if any are missing
|
||||||
if ! check-deps ; then
|
if ! check-deps ; then
|
||||||
|
|
@ -404,8 +367,8 @@ userinstall(){
|
||||||
# Check for existing bashrc config, append if missing
|
# Check for existing bashrc config, append if missing
|
||||||
if [[ $(cat ${HOME}/.bashrc | grep -c 'bashrc.d') == 0 ]] ; then
|
if [[ $(cat ${HOME}/.bashrc | grep -c 'bashrc.d') == 0 ]] ; then
|
||||||
take-backup $HOME/.bashrc
|
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"
|
run 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 "$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
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -439,7 +402,7 @@ userinstall(){
|
||||||
|
|
||||||
globalinstall(){
|
globalinstall(){
|
||||||
# Create global install directory
|
# Create global install directory
|
||||||
mkdir -p ${globalinstalldir}
|
run mkdir -p ${globalinstalldir}
|
||||||
|
|
||||||
# Copy functions
|
# Copy functions
|
||||||
install-file ${rundir}/PRbL/functions ${globalinstalldir}/functions
|
install-file ${rundir}/PRbL/functions ${globalinstalldir}/functions
|
||||||
|
|
@ -479,12 +442,12 @@ globalinstall(){
|
||||||
# done
|
# done
|
||||||
if [[ $(cat /home/${selecteduser}/.bashrc | grep -c prbl) == 0 ]] ; then
|
if [[ $(cat /home/${selecteduser}/.bashrc | grep -c prbl) == 0 ]] ; then
|
||||||
take-backup /home/${selecteduser}/.bashrc
|
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
|
fi
|
||||||
chown -R ${selecteduser}:${selecteduser} /home/${selecteduser}
|
run sudo chown -R ${selecteduser}:${selecteduser} ${installdir}
|
||||||
if [[ "$bins_missing" == "false" ]] ; then
|
if [[ "$bins_missing" == "false" ]] ; then
|
||||||
boxborder "Checking ${selecteduser}'s bashrc..."
|
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
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
@ -496,7 +459,7 @@ globalinstall(){
|
||||||
install-file $rundir/lib/vimfiles/vimrc.local /etc/vim/vimrc.local
|
install-file $rundir/lib/vimfiles/vimrc.local /etc/vim/vimrc.local
|
||||||
fi
|
fi
|
||||||
if [ ! -z $(which sensors-detect) ] ; then
|
if [ ! -z $(which sensors-detect) ] ; then
|
||||||
sensors-detect --auto
|
run sensors-detect --auto
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Download and install any other extras
|
# Download and install any other extras
|
||||||
|
|
@ -548,10 +511,11 @@ remove-arbitrary(){
|
||||||
|
|
||||||
update(){
|
update(){
|
||||||
remove-arbitrary
|
remove-arbitrary
|
||||||
git stash -m "$pretty_date stashing changes before update to latest"
|
run git stash -m "$pretty_date stashing changes before update to latest"
|
||||||
git fetch && git pull --recurse-submodules
|
run git fetch && run git pull --recurse-submodules
|
||||||
pushd PRbL
|
pushd PRbL
|
||||||
git pull
|
run git checkout master
|
||||||
|
run git pull
|
||||||
popd
|
popd
|
||||||
install
|
install
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue