refactored to accomodate for user/root installer

This commit is contained in:
Alan Weinstock 2022-09-01 13:17:18 -07:00
parent 53b474dbbb
commit 42a495e6b6
2 changed files with 77 additions and 25 deletions

View file

@ -1,20 +1,24 @@
#!/bin/bash #!/bin/bash
###################################################################
# Pyr0ball's Reductive Bash Language Installer #
###################################################################
# initial vars # initial vars
VERSION=0.3 VERSION=1.1
rundir=${0%/*} rundir=${0%/*}
source ${rundir}/pyr0-bash-functions/functions source ${rundir}/pyr0-bash-functions/functions
scriptname=${0##*/} scriptname=${0##*/}
runuser=$(whoami) runuser=$(whoami)
globalinstalldir="$HOME/.local/share/pyr0-bash" userinstalldir="$HOME/.local/share/prbl"
globalinstalldir="/usr/share/prbl"
#-----------------------------------------------------------------# #-----------------------------------------------------------------#
# Script-specific Parameters # Script-specific Parameters
#-----------------------------------------------------------------# #-----------------------------------------------------------------#
VERSION=1.0
read -r -d bashrc_append << EOF read -r -d bashrc_append << EOF
# Pyr0ball's Bash Functions library v$VERSION and greeting page setup # Pyr0ball's Reductive Bash Language (PRbL) Functions library v$VERSION and greeting page setup
export pyr0-bash-functions="\$HOME/.local/share/pyr0-bash/functions" export prbl-functions="${installdir}/functions"
"if [ -n \"\$BASH_VERSION\" ]; then "if [ -n \"\$BASH_VERSION\" ]; then
# include .bashrc if it exists # include .bashrc if it exists
if [ -d \"\$HOME/.bashrc.d\" ]; then if [ -d \"\$HOME/.bashrc.d\" ]; then
@ -53,6 +57,11 @@ usage(){
boxline " -r [--remove]" boxline " -r [--remove]"
boxline " -u [--update]" boxline " -u [--update]"
boxline " -h [--help]" boxline " -h [--help]"
boxline ""
boxline "Running this installer as 'root' will install"
boxline "globally to $globalinstalldir"
boxline "You must run as 'root' for this script to"
boxline "automatically resolve dependencies"
boxbottom boxbottom
} }
@ -66,23 +75,66 @@ detectvim(){
} }
check-deps(){ check-deps(){
for bin in $packages ; do for bin in $packages ; do
local _bin=$(which $bin | grep -c "/") local _bin=$(which $bin | grep -c "/")
if [[ $_bin == 0 ]] ; then if [[ $_bin == 0 ]] ; then
bins_missing="${bins_missing} $bin" bins_missing="${bins_missing} $bin"
fi
done
local _bins_missing=$(echo -e \"${bins_missing}\" | grep -c \"*\")
if [[ $_bins_missing == 0 ]] ; then
bins_missing="false"
fi
}
install(){
if [[ $runuser == root ]] ; then
installdir="${globalinstalldir}"
globalinstall
else
installdir="${userinstalldir}"
userinstall
fi fi
done
local _bins_missing=$(echo -e \"${bins_missing}\" | grep -c \"*\")
if [[ $_bins_missing == 0 ]] ; then
bins_missing="false"
fi
} }
install-deps(){ install-deps(){
sudo /bin/bash -c "apt install -y $packages" sudo /bin/bash -c "apt install -y $packages"
depsinstalled=true
} }
install(){ userinstall(){
mkdir -p ${userinstalldir}
cp ${rundir}/pyr0-bash-functions/functions ${userinstalldir}/functions
cp -r ${rundir}/lib/skel/* $HOME
cp -r ${rundir}/lib/skel/.* $HOME
detectvim
if [[ $viminstall != null ]] ; then
mkdir -p ${HOME}/.vim/colors
cp $rundir/lib/vimfiles/crystallite.vim ${HOME}/.vim/colors/crystallite.vim
cp $rundir/lib/vimfiles/vimrc.local $HOME/.vimrc
fi
if [[ $(cat ${HOME}/.bashrc | grep -c pyr0) = 0 ]] ; then
echo -e $bashrc_append >> $HOME/.bashrc && center "bashc.d installed..." || warn "Malformed append on ${lbl}${HOME}/.bashrc${dfl}. Check this file for errors"
fi
crontab -l -u $runuser | cat - ${rundir}/lib/quickinfo.cron | crontab -u $runuser - && center "QuickInfo cron task created." || warn "QuickInfo cron task creation failed. Check ${lbl}crontab -e${dfl} for errors"
mkdir -p $HOME/.quickinfo
bash $HOME/.bashrc.d/11-quickinfo.bashrc -c
clear
check-deps
if [[ "$bins_missing" != "false" ]] ; then
warn "Some of the utilities needed by this script are missing"
echo -e "Missing utilities:"
echo -e "$bins_missing"
center "After this installer completes, run:"
echo -en "\n${lbl}sudo apt install -y $binsmissing\n"
center "Press 'Enter' key when ready to proceed"
read proceed
fi
boxborder "${grn}Please be sure to run ${lyl}sensors-detect --auto${grn} after installation completes"
success "${red}P${lrd}R${ylw}b${ong}L ${lyl}Installed${dfl}"
}
globalinstall(){
mkdir -p ${globalinstalldir} mkdir -p ${globalinstalldir}
cp ${rundir}/pyr0-bash-functions/functions ${globalinstalldir}/functions cp ${rundir}/pyr0-bash-functions/functions ${globalinstalldir}/functions
cp -r ${rundir}/lib/skel/* $HOME cp -r ${rundir}/lib/skel/* $HOME
@ -90,7 +142,7 @@ install(){
detectvim detectvim
if [[ $viminstall != null ]] ; then if [[ $viminstall != null ]] ; then
cp $rundir/lib/vimfiles/crystallite.vim /usr/share/vim/${viminstall}/colors/crystallite.vim cp $rundir/lib/vimfiles/crystallite.vim /usr/share/vim/${viminstall}/colors/crystallite.vim
cp $rundir/lib/vimfiles/vimrc.local $HOME/.vimrc cp $rundir/lib/vimfiles/vimrc.local /etc/vim/vimrc.local
fi fi
if [[ $(cat ${HOME}/.bashrc | grep -c pyr0) = 0 ]] ; then if [[ $(cat ${HOME}/.bashrc | grep -c pyr0) = 0 ]] ; then
echo -e $bashrc_append >> $HOME/.bashrc && center "bashc.d installed..." || fail "Unable to append .bashrc" echo -e $bashrc_append >> $HOME/.bashrc && center "bashc.d installed..." || fail "Unable to append .bashrc"
@ -110,7 +162,13 @@ install(){
"$(boxline "${red_x} No")" "$(boxline "${red_x} No")"
) )
case `select_opt "${utilsmissing_menu[@]}"` in case `select_opt "${utilsmissing_menu[@]}"` in
0) install-deps ;; 0) until [[ $depsinstalled == true ]] ; do
center "${grn}Installing dependencies...${dfl}"
spin
install-deps
done
endspin
;;
1) warn "Dependent Utilities missing: $bins_missing" ;; 1) warn "Dependent Utilities missing: $bins_missing" ;;
esac esac
fi fi
@ -118,6 +176,7 @@ install(){
success "${red}P${lrd}R${ylw}b${ong}L ${lyl}Installed${dfl}" success "${red}P${lrd}R${ylw}b${ong}L ${lyl}Installed${dfl}"
} }
remove(){ remove(){
sudo rm -rf ${globalinstalldir} sudo rm -rf ${globalinstalldir}
for file in $(pushd lib/skel/ ; find ; popd) ; do for file in $(pushd lib/skel/ ; find ; popd) ; do
@ -126,13 +185,6 @@ remove(){
done done
} }
install-deps(){
if [[ $runuser == root ]] ; then
apt install -y $packages && success "Dependencies installed successfully!" || fail "Dependency install failed"
else
fail "Dependency install must be run as user 'root'"
fi
}
update(){ update(){
pushd $rundir pushd $rundir

View file

@ -11,7 +11,7 @@
scriptname=${0##*/} scriptname=${0##*/}
rundir=$(cd `dirname $0` && pwd) rundir=$(cd `dirname $0` && pwd)
source $pyr0-bash-functions source $prbl-functions
# Set to only run on interactive sessions (Disabled as cache # Set to only run on interactive sessions (Disabled as cache
# generation is non-interactive, so this would cause outdated # generation is non-interactive, so this would cause outdated