Remove cameras (#64)
* bits of removal * simply camera and instance removal * add PS3 * testing * haproxy fixes * sed haproxy fix * instance removal * more instance removal
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
Updated February 17, 2023.
|
||||
Updated February 21, 2023.
|
||||
Want to support this work? Buy Me a Coffee. https://www.buymeacoffee.com/ppaukstelis.
|
||||
Need help with octoprint_deploy? Ask on Discord: https://discord.gg/6vgSjgvR6u
|
||||
# octoprint_deploy
|
||||
@@ -60,14 +60,13 @@ These files provide a bash script for quickly deploying multiple octoprint insta
|
||||
* Change udev rules for an instance with `sudo octoprint_deploy/octoprint_deploy.sh replace`
|
||||
* Always a good idea to update octoprint_deploy from time-to-time with `git -C octoprint_deploy pull`
|
||||
# Recent Changes
|
||||
* Allow removal of individual camera services. Improvements to instance and camera removal.
|
||||
* Haproxy fixed! No more trailing slash required! Running new octoprint_deploy on an older installation automatically update these entries.
|
||||
* Multi-camera support (experimental). Clean-up of haproxy.cfg on instance removal still needs work.
|
||||
* If haproxy is used, cameras stream can be placed behind it. PLEASE NOTE: if cameras are used with haproxy a relative stream path is used. This means that your stream will not show up in the Control tab unless you access with the haproxy path (http://host/instancename/) (remember, trailing slash is required!)
|
||||
* Allow making backups of generic instance.
|
||||
* Add 'noserial' command line option. Currently for cameras only, this will unset the serial number in cases where cameras are known to share a serial number.
|
||||
* Add detection for ch34x driver. This is used by Weedo printers and must be compiled separately.
|
||||
* Utility sub-menu for less used options.
|
||||
* Share Uploads option which will set the same upload directory for all instances.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -277,12 +277,13 @@ new_instance () {
|
||||
HAversion=$(haproxy -v | sed -n 's/^.*version \([0-9]\).*/\1/p')
|
||||
#find frontend line, do insert
|
||||
#Don't know how to do the formatting correctly here. This works, however.
|
||||
|
||||
SEDREPLACE="#$INSTANCE start\n\
|
||||
acl is_$INSTANCE url_beg /$INSTANCE\n\
|
||||
http-request redirect scheme http drop-query append-slash if is_$INSTANCE ! { path_beg /$INSTANCE/ }\n\
|
||||
use_backend $INSTANCE if { path_beg /$INSTANCE/ }\n\
|
||||
#$INSTANCE stop"
|
||||
|
||||
|
||||
sed -i "/option forwardfor except 127.0.0.1/a $SEDREPLACE" /etc/haproxy/haproxy.cfg
|
||||
echo "#$INSTANCE start" >> /etc/haproxy/haproxy.cfg
|
||||
echo "backend $INSTANCE" >> /etc/haproxy/haproxy.cfg
|
||||
@@ -392,25 +393,21 @@ write_camera() {
|
||||
sed -i "/use_backend $INSTANCE if/a\ use_backend cam${INUM}_$INSTANCE if { path_beg /cam${INUM}_$INSTANCE/ }" /etc/haproxy/haproxy.cfg
|
||||
if [ $HAversion -gt 1 ]; then
|
||||
EXTRACAM="backend cam${INUM}_$INSTANCE\n\
|
||||
http-request replace-path /cam${INUM}_$INSTANCE/(.*) /|\1 \n\
|
||||
server webcam1 127.0.0.1:$CAMPORT"
|
||||
http-request replace-path /cam${INUM}_$INSTANCE/(.*) /|\1\n\
|
||||
server webcam1 127.0.0.1:$CAMPORT"
|
||||
else
|
||||
EXTRACAM="backend cam${INUM}_$INSTANCE\n\
|
||||
reqrep ^([^\ :]*)\ /cam${INUM}_$INSTANCE/(.*) \1\ /|\2 \n\
|
||||
server webcam1 127.0.0.1:$CAMPORT"
|
||||
fi
|
||||
reqrep ^([^\ :]*)\ /cam${INUM}_$INSTANCE/(.*) \1\ /|\2 \n\
|
||||
server webcam1 127.0.0.1:$CAMPORT"
|
||||
|
||||
#Need to set this up for first camera
|
||||
if [ -z "$INUM" ]; then
|
||||
echo "#cam_$INSTANCE start" >> /etc/haproxy/haproxy.cfg
|
||||
fi
|
||||
|
||||
echo "#cam${INUM}_$INSTANCE start" >> /etc/haproxy/haproxy.cfg
|
||||
sed -i "/#cam${INUM}_$INSTANCE start/a $EXTRACAM" /etc/haproxy/haproxy.cfg
|
||||
#these are necessary because sed append seems to have issues with escaping for the /\1
|
||||
sed -i 's/\/|1/\/\\1/' /etc/haproxy/haproxy.cfg
|
||||
sed -i 's/\/|2/\/\\2/' /etc/haproxy/haproxy.cfg
|
||||
if [ -z "$INUM" ]; then
|
||||
echo "#cam_$INSTANCE stop" >> /etc/haproxy/haproxy.cfg
|
||||
fi
|
||||
echo "#cam${INUM}_$INSTANCE stop" >> /etc/haproxy/haproxy.cfg
|
||||
|
||||
systemctl restart haproxy
|
||||
fi
|
||||
}
|
||||
@@ -578,58 +575,7 @@ detect_camera() {
|
||||
dmesg -C
|
||||
}
|
||||
|
||||
remove_instance() {
|
||||
echo
|
||||
echo
|
||||
if [ $SUDO_USER ]; then user=$SUDO_USER; fi
|
||||
if [ -f "/etc/octoprint_instances" ]; then
|
||||
|
||||
PS3='Select instance number to remove: '
|
||||
readarray -t options < <(cat /etc/octoprint_instances | sed -n -e 's/^instance:\([[:graph:]]*\) port:.*/\1/p')
|
||||
options+=("Quit")
|
||||
unset 'options[0]'
|
||||
select opt in "${options[@]}"
|
||||
do
|
||||
if [ "$opt" == Quit ]; then
|
||||
main_menu
|
||||
fi
|
||||
echo "Selected instance to remove: $opt" | log
|
||||
break
|
||||
done
|
||||
|
||||
if prompt_confirm "Do you want to remove everything associated with this instance?"
|
||||
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
|
||||
#remove haproxy entry
|
||||
if [ -f /etc/haproxy/haproxy.cfg ]; then
|
||||
sed -i "/use_backend $opt/d" /etc/haproxy/haproxy.cfg
|
||||
sed -i "/#$opt start/,/#$opt stop/d" /etc/haproxy/haproxy.cfg
|
||||
sed -i "/use_backend cam_$opt/d" /etc/haproxy/haproxy.cfg
|
||||
sed -i "/#cam_$opt start/,/#cam_$opt stop/d" /etc/haproxy/haproxy.cfg
|
||||
systemctl restart haproxy.service
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
main_menu
|
||||
}
|
||||
|
||||
|
||||
usb_testing() {
|
||||
echo
|
||||
@@ -1054,29 +1000,108 @@ check_sn() {
|
||||
fi
|
||||
fi
|
||||
}
|
||||
remove_instance() {
|
||||
opt=$1
|
||||
#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
|
||||
|
||||
#Get all cameras associated with this instance
|
||||
readarray -t cameras < <(ls -1 /etc/systemd/system/cam*.service | sed -n -e 's/^.*\/\(.*\).service/\1/p')
|
||||
for camera in "${cameras[@]}"; do
|
||||
remove_camera $camera
|
||||
done
|
||||
|
||||
#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
|
||||
#remove haproxy entry
|
||||
if [ "$HAPROXY" == true ]; then
|
||||
sed -i "/use_backend $opt/d" /etc/haproxy/haproxy.cfg
|
||||
sed -i "/#$opt start/,/#$opt stop/d" /etc/haproxy/haproxy.cfg
|
||||
systemctl restart haproxy.service
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
remove_instance_menu() {
|
||||
echo
|
||||
echo
|
||||
get_settings
|
||||
if [ $SUDO_USER ]; then user=$SUDO_USER; fi
|
||||
if [ -f "/etc/octoprint_instances" ]; then
|
||||
|
||||
PS3='Select instance number to remove: '
|
||||
readarray -t options < <(cat /etc/octoprint_instances | sed -n -e 's/^instance:\([[:graph:]]*\) port:.*/\1/p')
|
||||
options+=("Quit")
|
||||
unset 'options[0]'
|
||||
select opt in "${options[@]}"
|
||||
do
|
||||
if [ "$opt" == Quit ]; then
|
||||
main_menu
|
||||
fi
|
||||
echo "Selected instance to remove: $opt" | log
|
||||
break
|
||||
done
|
||||
|
||||
if prompt_confirm "Do you want to remove everything associated with this instance?"; then
|
||||
remove_instance $opt
|
||||
fi
|
||||
fi
|
||||
main_menu
|
||||
}
|
||||
remove_camera() {
|
||||
systemctl stop $1.service
|
||||
systemctl disable $1.service
|
||||
rm /etc/systemd/system/$1.service
|
||||
sed -i "/$1/d" /etc/udev/rules.d/99-octoprint.rules
|
||||
if [ "$HAPROXY" == true ]; then
|
||||
sed -i "/use_backend $1/d" /etc/haproxy/haproxy.cfg
|
||||
sed -i "/#$1 start/,/#$1 stop/d" /etc/haproxy/haproxy.cfg
|
||||
systemctl restart haproxy
|
||||
fi
|
||||
}
|
||||
|
||||
remove_camera_menu() {
|
||||
get_settings
|
||||
#must choose where to find which cameras have been installed
|
||||
#probably safest to go with service files
|
||||
PS3='Select camera number to remove: '
|
||||
readarray -t cameras < <(ls -1 /etc/systemd/system/cam*.service | sed -n -e 's/^.*\/\(.*\).service/\1/p')
|
||||
cameras+=("Quit")
|
||||
|
||||
select camera in "${cameras[@]}"
|
||||
do
|
||||
if [ "$camera" == Quit ]; then
|
||||
main_menu
|
||||
fi
|
||||
|
||||
echo "Removing udev, service files, and haproxy entry for $camera" | log
|
||||
remove_camera $camera
|
||||
main_menu
|
||||
done
|
||||
}
|
||||
|
||||
remove_everything() {
|
||||
get_settings
|
||||
if prompt_confirm "Remove everything?"; then
|
||||
readarray -t instances < <(cat /etc/octoprint_instances | sed -n -e 's/^instance:\([[:graph:]]*\) .*/\1/p')
|
||||
unset 'instances[0]'
|
||||
readarray -t cameras < <(ls -1 /etc/systemd/system/cam*.service | sed -n -e 's/^.*\/\(.*\).service/\1/p')
|
||||
for instance in "${instances[@]}"; do
|
||||
echo "Trying to remove instance $instance"
|
||||
systemctl stop $instance
|
||||
systemctl disable $instance
|
||||
rm /etc/systemd/system/$instance.service
|
||||
echo "Trying to remove camera for $instance"
|
||||
systemctl stop cam_$instance
|
||||
systemctl disable cam_$instance
|
||||
rm /etc/systemd/system/cam_$instance.service
|
||||
echo "Removing instance..."
|
||||
rm -rf /home/$user/.$instance
|
||||
if [ -f /etc/haproxy/haproxy.cfg ]; then
|
||||
sed -i "/use_backend $instance/d" /etc/haproxy/haproxy.cfg
|
||||
sed -i "/#$instance start/,/#$instance stop/d" /etc/haproxy/haproxy.cfg
|
||||
sed -i "/use_backend cam_$instance/d" /etc/haproxy/haproxy.cfg
|
||||
sed -i "/#cam_$instance start/,/#cam_$instance stop/d" /etc/haproxy/haproxy.cfg
|
||||
fi
|
||||
remove_instance $instance
|
||||
done
|
||||
|
||||
for camera in "${cameras[@]}"; do
|
||||
remove_camera $camera
|
||||
done
|
||||
|
||||
echo "Removing system stuff"
|
||||
rm /etc/systemd/system/octoprint_default.service
|
||||
rm /etc/octoprint_streamer
|
||||
@@ -1386,7 +1411,7 @@ instance_status() {
|
||||
}
|
||||
|
||||
main_menu() {
|
||||
VERSION=0.2.2
|
||||
VERSION=0.2.3
|
||||
#reset
|
||||
UDEV=''
|
||||
TEMPUSB=''
|
||||
@@ -1403,7 +1428,7 @@ main_menu() {
|
||||
echo
|
||||
PS3='Select operation: '
|
||||
if [ -f "/etc/octoprint_instances" ]; then
|
||||
options=("New instance" "Delete instance" "Add Camera" "Utilities" "Backup Menu" "Update" "Quit")
|
||||
options=("New instance" "Delete instance" "Add Camera" "Delete Camera" "Utilities" "Backup Menu" "Update" "Quit")
|
||||
else
|
||||
options=("Prepare system" "USB port testing" "Update" "Quit")
|
||||
fi
|
||||
@@ -1420,13 +1445,17 @@ main_menu() {
|
||||
break
|
||||
;;
|
||||
"Delete instance")
|
||||
remove_instance
|
||||
remove_instance_menu
|
||||
break
|
||||
;;
|
||||
"Add Camera")
|
||||
add_camera
|
||||
break
|
||||
;;
|
||||
"Delete Camera")
|
||||
remove_camera_menu
|
||||
break
|
||||
;;
|
||||
"Utilities")
|
||||
utility_menu
|
||||
break
|
||||
@@ -1485,11 +1514,11 @@ if [ "$HAPROXYNEW" == false ] && [ "$HAPROXY" == true ]; then
|
||||
unset 'instances[0]'
|
||||
for instance in "${instances[@]}"; do
|
||||
sed -i "/use_backend $instance/d" /etc/haproxy/haproxy.cfg
|
||||
SEDREPLACE="#$instance start\n\
|
||||
SEDREPLACE="#$instance start\n\
|
||||
acl is_$instance url_beg /$instance\n\
|
||||
http-request redirect scheme http drop-query append-slash if is_$instance ! { path_beg /$instance/ }\n\
|
||||
use_backend $instance if { path_beg /$instance/ }\n\
|
||||
#$instance stop"
|
||||
#$instance stop"
|
||||
sed -i "/option forwardfor except 127.0.0.1/a $SEDREPLACE" /etc/haproxy/haproxy.cfg
|
||||
done
|
||||
echo 'haproxynew: true' >> /etc/octoprint_deploy
|
||||
|
||||
Reference in New Issue
Block a user