From 6a641c7e5c0599fc1b7e6dd64904348d9d984799 Mon Sep 17 00:00:00 2001 From: oxaliq Date: Mon, 13 May 2024 18:16:06 -0400 Subject: [PATCH] tmp install script --- install.sh | 123 ++++++++++++++++++++++++++++++++++++++++++++++++--- uninstall.sh | 40 +++++++++++++++++ 2 files changed, 156 insertions(+), 7 deletions(-) create mode 100755 uninstall.sh diff --git a/install.sh b/install.sh index 04a2535..fb1647e 100755 --- a/install.sh +++ b/install.sh @@ -1,13 +1,122 @@ #!/bin/sh -e -# TODO +installtarget=/usr/local/bin +bunkchatrepo=https://git.bunk.computer/bunk/bunkchat.git + +missingtmux() { + echo + echo 'ERROR: tmux not found in $PATH' + echo ' please install tmux or add it to $PATH' + exit 1 +} + +missinggit() { + echo + echo 'ERROR: git not found in $PATH' + echo ' please install git or add it to $PATH' + exit 1 +} # check for tmux and cowsay - # if not prompt and exit -# pull in bunkchat -# run bunkchat install script -# install buckdeck in /usr/local/bin +checkdeps() { + which tmux 1>/dev/null || missingtmux + which git 1>/dev/null || git + echo + echo 'deps located' +} -# prompt user to install delete.sh in /root/crontab-scripts/delete-bunkchat.sh -# prompt with crontab config +clonebunkchat() { + echo "cloning bunkchat repo" + git clone $bunkchatrepo +} + +# if not found prompt for git clone or exit +prompttoclone() { + echo + echo "INFO: could not locate bunkchat scripts" + echo + printf "install bunkchat? (Y/n): " + read -r response + case $response in + n) + echo "exiting bunkchat install" + exit 0 + ;; + y) + clonebunkchat + ;; + "") + clonebunkchat + ;; + *) + prompttoclone + ;; + esac +} + +installbunkchat() { + (cd ../bunkchat && ./install.sh) +} + +missingbunkchat() { + echo "bunk chat not installed" + # check for bunkchat repo in parent dir + needclone=1 + for f in ./* + do + case $f in + bunkchat) + needclone=0 + break + ;; + esac + done + if [ $needclone == 1 ] ; then + prompttoclone + fi + # run bunkchat install script + installbunkchat +} + +# check for installed bunkchat && continue +checkbunkchat() { + which heed 1>/dev/null || missingbunkchat + which proclaim 1>/dev/null || missingbunkchat + which scry 1>/dev/null || missingbunkchat +} + +# install buckdeck in /usr/local/bin +installbunkdeck() { + echo "installing bunkchat" + cp bunkdeck $installtarget + chmod 755 ${installtarget}/bunkdeck + chown root:root ${installtarget}/bunkdeck + echo + echo "SUCCESS! bunkdeck installed!" +} + +infocron() { + echo + echo "INFO: bunkdeck comes with a script to clear chat history" + echo " if you would like to enable this copy the script to crontab scripts" + echo " and enable a cron for your desired cadence" + echo + echo "# cp delete.sh /root/crontab-scripts/delete-bunkchat.sh" + echo "# crontab -u root -e" + echo "# EXAMPLE FOR WEEKLY HISTORY DELETION" + echo "0 0 * * 6 /root/crontab-scripts/delete-bunkchat.sh" +} + +# check for root perms +if ! [ "$(id -u)" = 0 ]; then + echo + echo "ERROR: please run install with root permissions" + exit 1 +fi + +checkdeps +checkbunkchat +installbunkdeck +infocron +exit 0 diff --git a/uninstall.sh b/uninstall.sh new file mode 100755 index 0000000..9ae4c23 --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,40 @@ +#!/bin/sh -e + +installtarget=/usr/local/bin + +# check for root perms +if ! [ "$(id -u)" = 0 ]; then + echo + echo "ERROR: please run install with root permissions" + exit 1 +fi + +echo +echo "uninstalling bunkdeck" +echo +printf "also uninstall bunkchat commands? (y/N): " +read -r response +case $response in + n) + rm ${installtarget}/bunkdeck + ;; + "") + rm ${installtarget}/bunkdeck + ;; + y) + (../bunkchat/uninstall.sh) + # 2>/dev/null || \ + # echo && echo "ERROR: couldn't run bunkchat uninstall script" && exit 1 + rm ${installtarget}/bunkdeck + ;; + *) + echo + echo "ERROR: invalid response" + exit 1 + ;; +esac + +echo +echo "SUCCESS: bunkdeck uninstalled" +echo " remember to clean up crontab /root/crontab-scripts/delete-bunkchat.sh" +exit 0