From cf1e37fb2add0ead6db6c292f498a65842922170 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 20 Jan 2021 20:23:55 +0100 Subject: [PATCH] fix: rework octoprint remove function for removing multi instances --- kiauh.sh | 3 -- scripts/remove.sh | 79 +++++++++++++++++++++++------------------------ 2 files changed, 39 insertions(+), 43 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index efa91d3..9b08080 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -35,9 +35,6 @@ DWC_ENV_DIR=${HOME}/dwc-env DWC2_DIR=${HOME}/sdcard/web #octoprint OCTOPRINT_DIR=${HOME}/OctoPrint -OCTOPRINT_CFG_DIR=${HOME}/.octoprint -OCTOPRINT_SERVICE1=/etc/init.d/octoprint -OCTOPRINT_SERVICE2=/etc/default/octoprint #KlipperScreen KLIPPERSCREEN_DIR=${HOME}/KlipperScreen KLIPPERSCREEN_ENV_DIR=${HOME}/.KlipperScreen-env diff --git a/scripts/remove.sh b/scripts/remove.sh index bb2dfb6..8988302 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -40,6 +40,7 @@ remove_klipper(){ ok_msg "Done!" done fi + ###remove multi instance logfiles if [ "$(find /tmp -maxdepth 1 -name "klippy-*.log")" ]; then for logfile in $(find /tmp -maxdepth 1 -name "klippy-*.log") @@ -47,6 +48,7 @@ remove_klipper(){ status_msg "Removing $logfile ..." && rm -f $logfile && ok_msg "Done!" done fi + ###remove multi instance UDS if [ "$(find /tmp -maxdepth 1 -name "klippy_uds-*")" ]; then for uds in $(find /tmp -maxdepth 1 -name "klippy_uds-*") @@ -54,6 +56,7 @@ remove_klipper(){ status_msg "Removing $uds ..." && rm -f $uds && ok_msg "Done!" done fi + ###remove multi instance tmp-printer if [ "$(find /tmp -maxdepth 1 -name "printer-*")" ]; then for tmp_printer in $(find /tmp -maxdepth 1 -name "printer-*") @@ -271,47 +274,43 @@ remove_fluidd(){ ############################################################# remove_octoprint(){ - data_arr=( - $OCTOPRINT_SERVICE1 - $OCTOPRINT_SERVICE2 - $OCTOPRINT_DIR - $OCTOPRINT_CFG_DIR - ${HOME}/octoprint.log - /etc/sudoers.d/octoprint-shutdown - /etc/nginx/sites-available/octoprint - /etc/nginx/sites-enabled/octoprint - ) - print_error "OctoPrint" && data_count=() - if [ "$ERROR_MSG" = "" ]; then - stop_octoprint - if [[ -e $OCTOPRINT_SERVICE1 || -e $OCTOPRINT_SERVICE2 ]]; then - status_msg "Removing OctoPrint Service ..." - sudo update-rc.d -f octoprint remove - sudo rm -rf $OCTOPRINT_SERVICE1 $OCTOPRINT_SERVICE2 && ok_msg "OctoPrint Service removed!" - fi - if [[ -d $OCTOPRINT_DIR || -d $OCTOPRINT_CFG_DIR ]]; then - status_msg "Removing OctoPrint and .octoprint directory ..." - rm -rf $OCTOPRINT_DIR $OCTOPRINT_CFG_DIR && ok_msg "Directories removed!" - fi - if [ -f /etc/sudoers.d/octoprint-shutdown ]; then - sudo rm -rf /etc/sudoers.d/octoprint-shutdown - fi - if [ -L ${HOME}/octoprint.log ]; then - status_msg "Removing octoprint.log Symlink ..." - rm -rf ${HOME}/octoprint.log && ok_msg "Symlink removed!" - fi - #remove octoprint config for nginx - if [ -e /etc/nginx/sites-available/octoprint ]; then - status_msg "Removing OctoPrint configuration for Nginx ..." - sudo rm /etc/nginx/sites-available/octoprint && ok_msg "File removed!" - fi - #remove octoprint symlink for nginx - if [ -L /etc/nginx/sites-enabled/octoprint ]; then - status_msg "Removing OctoPrint Symlink for Nginx ..." - sudo rm /etc/nginx/sites-enabled/octoprint && ok_msg "File removed!" - fi - CONFIRM_MSG=" OctoPrint successfully removed!" + ###remove single instance + if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "octoprint.service")" ]; then + status_msg "Removing OctoPrint Service ..." + sudo systemctl stop octoprint + sudo systemctl disable octoprint + sudo rm -f $SYSTEMDDIR/octoprint.service + ok_msg "OctoPrint Service removed!" fi + + ###remove multi instance services + if [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "octoprint-[[:digit:]].service")" ]; then + status_msg "Removing OctoPrint Services ..." + for service in $(find $SYSTEMDDIR -maxdepth 1 -name "octoprint-*.service" | cut -d"/" -f5) + do + status_msg "Removing $service ..." + sudo systemctl stop $service + sudo systemctl disable $service + sudo rm -f $SYSTEMDDIR/$service + ok_msg "OctoPrint Service removed!" + done + fi + + ###reloading units + sudo systemctl daemon-reload + + ### remove .octoprint directories + if [ -d ${HOME}/OctoPrint ] || [ -d ${HOME}/.octoprint* ]; then + status_msg "Removing OctoPrint and .octoprint directory ..." + rm -rf ${HOME}/OctoPrint ${HOME}/.octoprint* && ok_msg "Directories removed!" + fi + + ### remove sudoers file + if [ -f /etc/sudoers.d/octoprint-shutdown ]; then + sudo rm -rf /etc/sudoers.d/octoprint-shutdown + fi + + CONFIRM_MSG=" OctoPrint successfully removed!" } #############################################################