From a33efb35488426bb9bff2fa2688c6152d0da4ab9 Mon Sep 17 00:00:00 2001 From: paukstelis Date: Sat, 6 Mar 2021 19:50:13 -0500 Subject: [PATCH] first uninstall script --- addnew_printer.sh | 20 +++++++++----------- uninstall_instance.sh | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 11 deletions(-) create mode 100755 uninstall_instance.sh diff --git a/addnew_printer.sh b/addnew_printer.sh index 360ce2b..60563e3 100755 --- a/addnew_printer.sh +++ b/addnew_printer.sh @@ -36,7 +36,7 @@ do esac done -echo "UNPLUG PRINTER FROM USB" +echo "UNPLUG PRINTER YOU ARE INSTALLING NOW (other printers can remain)" echo "Enter the name for new printer/instance (no spaces):" read INSTANCE if [ -z "$INSTANCE" ]; then @@ -49,7 +49,7 @@ if test -f "/etc/systemd/system/$INSTANCE.service"; then exit 1 fi -echo "Port on which this instance will run (ENTER will increment last value in /etc/octoprint_instances):" +echo "Port on which this instance will run (ENTER will increment from last value in /etc/octoprint_instances):" read PORT if [ -z "$PORT" ]; then PORT=$(tail -1 /etc/octoprint_instances | sed -n -e 's/^.*\(port:\)\(.*\)/\2/p') @@ -64,7 +64,7 @@ fi if [ -f /etc/octoprint_instances ]; then if grep -q $PORT /etc/octoprint_instances; then - echo "Port in use! Check /etc/octoprint_instances. Exiting." + echo "Port may be in use! Check /etc/octoprint_instances and select a different port. Exiting." exit 1 fi fi @@ -115,7 +115,7 @@ if grep -q 'firstRun: true' $BFOLD/config.yaml; then exit 1 fi -read -p "Begin auto-detect printer serial number for udev entry?" -n 1 -r +read -p "Begin auto-detect printer serial number for udev entry? (y/n)" -n 1 -r echo #new line if [[ $REPLY =~ ^[Yy]$ ]] then @@ -127,16 +127,14 @@ then counter=0 while [[ -z "$UDEV" ]] && [[ $counter -lt 30 ]]; do UDEV=$(timeout 1s journalctl -kf | sed -n -e 's/^.*SerialNumber: //p') - TEMPUSB=$(timeout 1s journalctl -kf | sed -n -e 's/^.*\(cdc_acm\|ftdi_sio\) \([0-9].*[0-9]\): \(tty.*\|FTD.*\).*/\2/p') - + TEMPUSB=$(timeout 1s journalctl -kf | sed -n -e 's/^.*\(cdc_acm\|ftdi_sio\) \([0-9].*[0-9]\): \(tty.*\|FTD.*\).*/\2/p') counter=$(( $counter + 1 )) done - fi if [ -z "$UDEV" ]; then echo "Printer Serial Number not detected" - read -p "Do you want to use the physical USB port to assign the udev entry? If you use this all USB hubs and printers must stay plugged into the same USB positions on your machine as they are right now (y/n)." -n 1 -r + read -p "Do you want to use the physical USB port to assign the udev entry? If you use this any USB hubs and printers detected this way must stay plugged into the same USB positions on your machine as they are right now (y/n)." -n 1 -r if [[ $REPLY =~ ^[Yy]$ ]]; then echo USB=$TEMPUSB @@ -144,16 +142,16 @@ if [ -z "$UDEV" ]; then echo $USB echo else + echo "You are welcome to try again" exit 1 - fi - + fi else echo "Serial number detected as: $UDEV" fi echo #Octobuntu cameras if [[ -n $INSTALL ]]; then - read -p "Would you like to auto detect an associated USB camera (experimental)?" -n 1 -r + read -p "Would you like to auto detect an associated USB camera (experimental; y/n)?" -n 1 -r if [[ $REPLY =~ ^[Yy]$ ]] then echo diff --git a/uninstall_instance.sh b/uninstall_instance.sh new file mode 100755 index 0000000..9a07d1a --- /dev/null +++ b/uninstall_instance.sh @@ -0,0 +1,39 @@ +#!/bin/bash +if (( $EUID != 0 )); then + echo "Please run as root (sudo)" + exit +fi + +if [ $SUDO_USER ]; then user=$SUDO_USER; fi +echo 'Do not remove the generic instance!' +PS3='Select instance to remove: ' +readarray -t options < <(cat /etc/octoprint_instances | sed -n -e 's/^instance:\([[:alnum:]]*\) .*/\1/p') +select opt in "${options[@]}" +do + echo "Selected instance: $opt" + break +done + +read -p "Do you want to remove everything associated with this instance?" -n 1 -r +echo #new line +if [[ $REPLY =~ ^[Yy]$ ]]; then + #disable and remove service file + if [ -f /etc/systemd/system/$opt.service ]; then + systemctl stop $opt.service + systemctl disable $opt.service + rm /etc/systemd/system/$opt.service + fi + + if [ -f /etc/systemd/system/cam_$opt.service ]; then + systemctl stop cam_$opt.service + systemctl disable cam_$opt.service + rm /etc/systemd/system/cam_$opt.service + sed -i "/cam_$opt/d" /etc/udev/rules.d/99-octoprint.rules + fi + #remove udev entry + sed -i "/$opt/d" /etc/udev/rules.d/99-octoprint.rules + #remove files + rm -rf /home/$user/.$opt + #remove from octoprint_instances + sed -i "/$opt/d" /etc/octoprint_instances +fi