#!/bin/bash ################################################################### # Pyr0ball's Reductive Bash Language Installer # ################################################################### # initial vars VERSION=1.1 scripttitle="Pyr0ball's Reductive Bash Language Installer - v$VERSION" rundir=${0%/*} source ${rundir}/pyr0-bash-functions/functions scriptname=${0##*/} runuser=$(whoami) userinstalldir="$HOME/.local/share/prbl" globalinstalldir="/usr/share/prbl" #-----------------------------------------------------------------# # Script-specific Parameters #-----------------------------------------------------------------# read -r -d bashrc_append << EOF # Pyr0ball's Reductive Bash Language (PRbL) Functions library v$VERSION and greeting page setup export prbl_functions="${installdir}/functions" "if [ -n \"\$BASH_VERSION\" ]; then # include .bashrc if it exists if [ -d \"\$HOME/.bashrc.d\" ]; then for file in \$HOME/.bashrc.d/*.bashrc ; do source \"\$file\" done fi fi" EOF # List of dependency packaged to be istalled via apt packages="git vim lm-sensors net-tools update-notifier-common " #-----------------------------------------------------------------# # Script-specific Funcitons #-----------------------------------------------------------------# usage(){ boxborder \ "${lyl}$scripttitle${dfl}" \ "${lbl}Usage:${dfl}" \ "${lyl}./$scriptname ${bld}[args]${dfl}" \ "$(boxseparator)" \ "[args:]" \ " -i [--install]" \ " -r [--remove]" \ " -u [--update]" \ " -h [--help]" \ "" \ "Running this installer as 'root' will install globally to $globalinstalldir" \ "You must run as 'root' for this script to automatically resolve dependencies" } detectvim(){ if [ -d /usr/share/vim ] ; then viminstall=$(ls -lah /usr/share/vim/ | grep vim | grep -v rc | awk '{print $NF}') else viminstall=null boxborder "vim is not currently installed, unable to set up colorscheme and formatting" fi } check-deps(){ for bin in $packages ; do local _bin=$(which $bin | grep -c "/") if [[ $_bin == 0 ]] ; then 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 } install-deps(){ sudo /bin/bash -c "apt install -y $packages" depsinstalled=true } userinstall(){ mkdir -p ${userinstalldir} cp ${rundir}/pyr0-bash-functions/functions ${userinstalldir}/functions cp -r ${rundir}/lib/skel/* $HOME cp -r ${rundir}/lib/skel/.* $HOME 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" echo -e "After this installer completes, run:" boxseparator echo -en "\n${lbl}sudo apt install -y $bins_missing\n${dfl}" boxborder "Press 'Enter' key when ready to proceed" read proceed fi 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 prbl) = 0 ]] ; then echo -e $bashrc_append >> $HOME/.bashrc && boxborder "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 - && boxborder "QuickInfo cron task created." || warn "QuickInfo cron task creation failed. Check ${lbl}crontab -e${dfl} for errors" mkdir -p $HOME/.quickinfo if [[ "$bins_missing" == "false" ]] ; then bash $HOME/.bashrc.d/11-quickinfo.bashrc -c fi clear boxborder "${grn}Please be sure to run ${lyl}sensors-detect --auto${grn} after installation completes${dfl}" success "${red}P${lrd}R${ylw}b${ong}L ${lyl}Installed${dfl}" } globalinstall(){ mkdir -p ${globalinstalldir} cp ${rundir}/pyr0-bash-functions/functions ${globalinstalldir}/functions cp -r ${rundir}/lib/skel/* /etc/skel/ cp -r ${rundir}/lib/skel/.* /etc/skel/ 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" echo -e "Would you like to install? (this will require root password)" utilsmissing_menu=( "$(boxline "${green_check} Yes")" "$(boxline "${red_x} No")" ) case `select_opt "${utilsmissing_menu[@]}"` in 0) until [[ $depsinstalled == true ]] ; do center "${grn}Installing dependencies...${dfl}" spin install-deps done endspin ;; 1) warn "Dependent Utilities missing: $bins_missing" ;; esac fi detectvim if [[ $viminstall != null ]] ; then cp $rundir/lib/vimfiles/crystallite.vim /usr/share/vim/${viminstall}/colors/crystallite.vim cp $rundir/lib/vimfiles/vimrc.local /etc/vim/vimrc.local fi if [[ $(cat /etc/skel/.bashrc | grep -c prbl) = 0 ]] ; then echo -e $bashrc_append >> /etc/skel/.bashrc && center "bashc.d installed..." || fail "Unable to append .bashrc" fi crontab -l -u $runuser | cat - ${rundir}/lib/quickinfo.cron | crontab -u $runuser - sensors-detect --auto mkdir -p $HOME/.quickinfo bash $HOME/.bashrc.d/11-quickinfo.bashrc -c clear success " [${red}P${lrd}R${ylw}b${ong}L ${lyl}Installed${dfl}]" } remove(){ sudo rm -rf ${globalinstalldir} for file in $(pushd lib/skel/ ; find ; popd) ; do rm $HOME/$file 2>&1 >dev/null rmdir $HOME/$file 2>&1 >dev/null done } update(){ pushd $rundir remove git stash -m "$pretty_date stashing changes before update to latest" git fetch && git pull install popd } #------------------------------------------------------# # Options and Arguments Parser #------------------------------------------------------# case $1 in -i | --install) install ;; -r | --remove) remove ;; -d | --dependencies) install-deps ;; -u | --update) update #sleep $ratelimit exit 0 ;; -h | --help) usage ;; *) warn "Invalid argument $@" usage #exit 2 ;; esac #------------------------------------------------------# # Script begins here #------------------------------------------------------#