#/bin/bash # CodeDog Bootstrap installer script # Bash expansions to get the name and location of this script when run scriptname="${BASH_SOURCE[0]##*/}" rundir="${BASH_SOURCE[0]%/*}" # Source PRbL Functions locally or retrieve from online if [ ! -z $prbl_functions ] ; then source $prbl_functions else if [ -f ${rundir}/functions ] ; then source ${rundir}/functions else source <(curl -ks 'https://raw.githubusercontent.com/pyr0ball/PRbL/master/functions') fi fi logfile="${rundir}/${pretty_date}_${scriptname}.log" installdir="$HOME/devl" # Dependencies sys_packages=( git curl python3 python3-pip ) pip_packages=( pyparsing ) repo_packages=( https://github.com/BruceDLong/CodeDog.git https://github.com/BruceDLong/Proteus.git https://github.com/BruceDLong/Slipstream.git ) prbl_packages=( golang.install ) codedog_bashrc="# CodeDog system path setup export PATH=\"\$PATH:\$HOME/devl/CodeDog\" " # Functions check-deps(){ # Iterate through the list of required packages and check if installed for pkg in ${sys_packages[@]} ; do local _pkg=$(dpkg -l $pkg 2>&1 >/dev/null ; echo $?) # If not installed, add it to the list of missing bins if [[ $_pkg != 0 ]] ; then bins_missing+=($pkg) fi done if ! $(which python3) ; then run sudo apt-get install -y python3 python3-pip # TODO: make a universal package install function fi if ! $(which pip3) run sudo apt-get install -y python3-pip fi for pkg in ${pip_packages[@]} ; do pippkg_installed=$(pip list | grep -F $pkg ; echo &?) if [[ $pippkg_installed != 0 ]] ; then bins_missing+=("pip: $pkg") fi done # This installer requires golang to work # TODO: better handling of prbl_packages as dependencies if ! $(which go) ; then bins_missing+=("prbl: golang.install") fi # Count the number of entries in bins_missing local _bins_missing=${#bins_missing[@]} # If higher than 0, return a fail (1) if [[ $_bins_missing != 0 ]] ; then return 1 else return 0 fi } install-deps(){ logger echo "Installing packages $sys_packages" for _package in $sys_packages ; do run sudo apt-get install -y $_package done if [ -f ${rundir}/requirements.txt ] ; then pip install -y ${rundir}/requirements.txt else if [ ! -z $pip_packages ] ; then pip install -y ${pip_packages[@]} fi fi for _package in $prbl_packages ; do if [ -f ${rundir}/$_package ] ; then if [[ $dry_run != true ]] ; then bash "${rundir}/$_package -i" else bash "${rundir}/$_package -D" fi else if [[ $dry_run != true ]] ; then run-from-url https://raw.githubusercontent.com/pyr0ball/PRbL-bashrc/master/extras/$_package -i else run-from-url https://raw.githubusercontent.com/pyr0ball/PRbL-bashrc/master/extras/$_package -D fi fi done # Sets dependency installed flag to true depsinstalled=true } dry-run-report(){ box-rounded boxborder "${grn}Dry-run Report:${dfl}" box-norm boxborder \ "bins_missing= " \ "${bins_missing[@]}" \ "backup_files= " \ "${backup_files[@]}" \ "installed_files= " \ "${installed_files[@]}" \ "installed_dirs= " \ "${installed_dirs[@]}" } install(){ if [ ! -f $HOME/.bashrc.d/70-CodeDog.bashrc ] ; then run echo -e "$codedog_bashrc" >> $HOME/.bashrc.d/70-CodeDog.bashrc && boxborder "bashc.d/70-CodeDog.bashrc installed..." fi export PATH="$PATH:$HOME/devl/CodeDog" # Check for dependent applications and offer to install if ! check-deps ; then warn "Some of the utilities needed by this install are missing" boxtop logger echo -e "Missing utilities:" for bin in ${bins_missing[@]} ; do logger echo -e "${bins_missing[$bin]}" done boxbottom boxborder "Would you like to install them? (this will require root password)" utilsmissing_menu=( "$(boxline "${green_check} Yes")" "$(boxline "${red_x} No")" ) case `select_opt "${utilsmissing_menu[@]}"` in 0) boxborder "${grn}Installing dependencies...${dfl}" install-deps ;; 1) warn "Dependent Utilities missing: $bins_missing" ;; esac fi run mkdir -p $installdir pushd $installdir for repo in ${repo_packages[@]} ; do clone-repo $repo done popd pushd $installdir/Proteus run sudo python3 ruleMgr.py popd pushd $installdir/Slipstream run $installdir/CodeDog/codeDog ./Slipstream.dog && logger echo "Slipstream app built at ${installdir}/Slipstream/LinuxBuild" popd } # Function for displaying the usage of this script usage(){ boxborder \ "${lbl}Usage:${dfl}" \ "${lyl}./$scriptname ${bld}[args]${dfl}" \ "$(boxseparator)" \ "[args:]" \ " -i [--install]" \ " -d [--dependencies]" \ " -D [--dry-run]" \ " -r [--remove]" \ " -f [--force]" \ " -F [--force-remove]" \ " -u [--update]" \ " -h [--help]" } case $1 in -i | --install) install && success " [${lbl}Slip${gry}Stream ${lyl}Installed${dfl}]" ;; -r | --remove) remove && success " [${lbl}Slip${gry}Stream ${lyl}Removed${dfl}]" ;; -d | --dependencies) install-deps && success "${lbl}Slip${gry}Stream ${dfl} Dependencies installed!" ;; -D | --dry-run) export dry_run=true install dry-run-report usage unset dry_run success "${lbl}Slip${gry}Stream ${lyl}Installer Dry-Run Complete!${dfl}" ;; -u | --update) export update_run=true update && unset update_run && success " [${lbl}Slip${gry}Stream ${lyl}Updated${dfl}]" ;; -f | --force) remove-arbitrary install && success " [${lbl}Slip${blu}Stream ${lyl}Installed${dfl}]" ;; -F | --force-remove) remove-arbitrary && success " [${lbl}Slip${gry}Stream ${lyl}Force-Removed${dfl}]" ;; -h | --help) usage ;; *) warn "Invalid argument $@" usage #exit 2 ;; esac #------------------------------------------------------# # Script begins here #------------------------------------------------------# #install