first uninstall script

This commit is contained in:
paukstelis
2021-03-06 19:50:13 -05:00
parent 4475aa5204
commit a33efb3548
2 changed files with 48 additions and 11 deletions

View File

@@ -36,7 +36,7 @@ do
esac esac
done 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):" echo "Enter the name for new printer/instance (no spaces):"
read INSTANCE read INSTANCE
if [ -z "$INSTANCE" ]; then if [ -z "$INSTANCE" ]; then
@@ -49,7 +49,7 @@ if test -f "/etc/systemd/system/$INSTANCE.service"; then
exit 1 exit 1
fi 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 read PORT
if [ -z "$PORT" ]; then if [ -z "$PORT" ]; then
PORT=$(tail -1 /etc/octoprint_instances | sed -n -e 's/^.*\(port:\)\(.*\)/\2/p') 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 [ -f /etc/octoprint_instances ]; then
if grep -q $PORT /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 exit 1
fi fi
fi fi
@@ -115,7 +115,7 @@ if grep -q 'firstRun: true' $BFOLD/config.yaml; then
exit 1 exit 1
fi 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 echo #new line
if [[ $REPLY =~ ^[Yy]$ ]] if [[ $REPLY =~ ^[Yy]$ ]]
then then
@@ -128,15 +128,13 @@ then
while [[ -z "$UDEV" ]] && [[ $counter -lt 30 ]]; do while [[ -z "$UDEV" ]] && [[ $counter -lt 30 ]]; do
UDEV=$(timeout 1s journalctl -kf | sed -n -e 's/^.*SerialNumber: //p') 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 )) counter=$(( $counter + 1 ))
done done
fi fi
if [ -z "$UDEV" ]; then if [ -z "$UDEV" ]; then
echo "Printer Serial Number not detected" 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 if [[ $REPLY =~ ^[Yy]$ ]]; then
echo echo
USB=$TEMPUSB USB=$TEMPUSB
@@ -144,16 +142,16 @@ if [ -z "$UDEV" ]; then
echo $USB echo $USB
echo echo
else else
echo "You are welcome to try again"
exit 1 exit 1
fi fi
else else
echo "Serial number detected as: $UDEV" echo "Serial number detected as: $UDEV"
fi fi
echo echo
#Octobuntu cameras #Octobuntu cameras
if [[ -n $INSTALL ]]; then 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]$ ]] if [[ $REPLY =~ ^[Yy]$ ]]
then then
echo echo

39
uninstall_instance.sh Executable file
View File

@@ -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