From 2644613cb0a9d31183abbf6dc0bcab57f8af00a0 Mon Sep 17 00:00:00 2001 From: paukstelis Date: Tue, 13 Dec 2022 19:45:08 -0500 Subject: [PATCH 01/13] tar restore flags --- octoprint_deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octoprint_deploy.sh b/octoprint_deploy.sh index 6fff684..358b18a 100755 --- a/octoprint_deploy.sh +++ b/octoprint_deploy.sh @@ -1217,7 +1217,7 @@ restore_menu() { fi echo "Selected $opt to restore" | log - tar -xvf $opt + tar --same-owner -xvfp $opt main_menu done } From 84a82ebafd643b55269969566208be9cbe307de2 Mon Sep 17 00:00:00 2001 From: paukstelis Date: Thu, 15 Dec 2022 17:16:56 -0500 Subject: [PATCH 02/13] haproxy work --- octoprint_deploy.sh | 98 +++++++++++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 31 deletions(-) diff --git a/octoprint_deploy.sh b/octoprint_deploy.sh index 358b18a..504e4e9 100755 --- a/octoprint_deploy.sh +++ b/octoprint_deploy.sh @@ -263,6 +263,39 @@ new_instance () { $DAEMONPATH --basedir $OCTOCONFIG/.$INSTANCE config set plugins.tracking.unique_id $(uuidgen) $DAEMONPATH --basedir $OCTOCONFIG/.$INSTANCE config set serial.port /dev/octo_$INSTANCE + if [ "$HAPROXY" == true ]; then + HAversion=$(haproxy -v | sed -n 's/^.*version \([0-9]\).*/\1/p') + #find frontend line, do insert + sed -i "/option forwardfor except 127.0.0.1/a\ use_backend $INSTANCE if { path_beg /$INSTANCE/ }" /etc/haproxy/haproxy.cfg + echo "#$INSTANCE start" >> /etc/haproxy/haproxy.cfg + echo "backend $INSTANCE" >> /etc/haproxy/haproxy.cfg + if [ $HAversion -gt 1 ]; then + /bin/sh "cat >> /etc/haproxy/haproxy.cfg" << PROX + http-request replace-path /$INSTANCE/(.*) /\1 + acl needs_scheme req.hdr_cnt(X-Scheme) eq 0 + http-request add-header X-Scheme https if needs_scheme { ssl_fc } + http-request add-header X-Scheme http if needs_scheme !{ ssl_fc } + http-request add-header X-Script-Name /$INSTANCE + server octoprint1 127.0.0.1:$PORT + option forwardfor + PROX + else + echo " reqrep ^([^\ :]*)\ /$INSTANCE/(.*) \1\ /\2" >> /etc/haproxy/haproxy.cfg + echo " server octoprint1 127.0.0.1:$PORT" >> /etc/haproxy/haproxy.cfg + echo " option forwardfor" >> /etc/haproxy/haproxy.cfg + echo " acl needs_scheme req.hdr_cnt(X-Scheme) eq 0" >> /etc/haproxy/haproxy.cfg + echo " reqadd X-Scheme:\ https if needs_scheme { ssl_fc }" >> /etc/haproxy/haproxy.cfg + echo " reqadd X-Scheme:\ http if needs_scheme !{ ssl_fc }" >> /etc/haproxy/haproxy.cfg + echo " reqadd X-Script-Name:\ /$INSTANCE" >> /etc/haproxy/haproxy.cfg + fi + + echo "#$INSTANCE stop" >> /etc/haproxy/haproxy.cfg + + #restart haproxy + sudo systemctl restart haproxy.service + + fi + if [[ -n $CAM || -n $USBCAM ]]; then write_camera fi @@ -281,36 +314,6 @@ new_instance () { systemctl enable cam_$INSTANCE.service fi - if [ "$HAPROXY" == true ]; then - HAversion=$(haproxy -v | sed -n 's/^.*version \([0-9]\).*/\1/p') - #find frontend line, do insert - sed -i "/option forwardfor except 127.0.0.1/a\ use_backend $INSTANCE if { path_beg /$INSTANCE/ }" /etc/haproxy/haproxy.cfg - echo "#$INSTANCE start" >> /etc/haproxy/haproxy.cfg - echo "backend $INSTANCE" >> /etc/haproxy/haproxy.cfg - if [ $HAversion -gt 1 ]; then - echo " http-request replace-path /$INSTANCE/(.*) /\1" >> /etc/haproxy/haproxy.cfg - echo " acl needs_scheme req.hdr_cnt(X-Scheme) eq 0" >> /etc/haproxy/haproxy.cfg - echo " http-request add-header X-Scheme https if needs_scheme { ssl_fc }" >> /etc/haproxy/haproxy.cfg - echo " http-request add-header X-Scheme http if needs_scheme !{ ssl_fc }" >> /etc/haproxy/haproxy.cfg - echo " http-request add-header X-Script-Name /$INSTANCE" >> /etc/haproxy/haproxy.cfg - echo " server octoprint1 127.0.0.1:$PORT" >> /etc/haproxy/haproxy.cfg - echo " option forwardfor" >> /etc/haproxy/haproxy.cfg - else - echo " reqrep ^([^\ :]*)\ /$INSTANCE/(.*) \1\ /\2" >> /etc/haproxy/haproxy.cfg - echo " server octoprint1 127.0.0.1:$PORT" >> /etc/haproxy/haproxy.cfg - echo " option forwardfor" >> /etc/haproxy/haproxy.cfg - echo " acl needs_scheme req.hdr_cnt(X-Scheme) eq 0" >> /etc/haproxy/haproxy.cfg - echo " reqadd X-Scheme:\ https if needs_scheme { ssl_fc }" >> /etc/haproxy/haproxy.cfg - echo " reqadd X-Scheme:\ http if needs_scheme !{ ssl_fc }" >> /etc/haproxy/haproxy.cfg - echo " reqadd X-Script-Name:\ /$INSTANCE" >> /etc/haproxy/haproxy.cfg - fi - - echo "#$INSTANCE stop" >> /etc/haproxy/haproxy.cfg - - #restart haproxy - sudo systemctl restart haproxy.service - - fi fi main_menu @@ -348,7 +351,12 @@ write_camera() { #config.yaml modifications echo "webcam:" >> $OCTOCONFIG/.$INSTANCE/config.yaml echo " snapshot: http://$(hostname).local:$CAMPORT?action=snapshot" >> $OCTOCONFIG/.$INSTANCE/config.yaml - echo " stream: http://$(hostname).local:$CAMPORT?action=stream" >> $OCTOCONFIG/.$INSTANCE/config.yaml + if [ -z "$CAMHAPROXY" ]; then + echo " stream: http://$(hostname).local:$CAMPORT?action=stream" >> $OCTOCONFIG/.$INSTANCE/config.yaml + else + echo " stream: /cam_$INSTANCE/?action=stream" >> $OCTOCONFIG/.$INSTANCE/config.yaml + fi + $OCTOEXEC --basedir $OCTOCONFIG/.$INSTANCE config append_value --json system.actions "{\"action\": \"Reset video streamer\", \"command\": \"sudo systemctl restart cam_$INSTANCE\", \"name\": \"Restart webcam\"}" #Either Serial number or USB port @@ -362,6 +370,21 @@ write_camera() { echo SUBSYSTEM==\"video4linux\",KERNELS==\"$USBCAM\", SUBSYSTEMS==\"usb\", ATTR{index}==\"0\", DRIVERS==\"uvcvideo\", SYMLINK+=\"cam_$INSTANCE\" >> /etc/udev/rules.d/99-octoprint.rules fi + if [ -n $CAMHAPROXY ]; then + HAversion=$(haproxy -v | sed -n 's/^.*version \([0-9]\).*/\1/p') + #find frontend line, do insert + sed -i "/option forwardfor except 127.0.0.1/a\ use_backend cam_$INSTANCE if { path_beg /cam_$INSTANCE/ }" /etc/haproxy/haproxy.cfg + echo "#cam_$INSTANCE start" >> /etc/haproxy/haproxy.cfg + echo "backend cam_$INSTANCE" >> /etc/haproxy/haproxy.cfg + if [ $HAversion -gt 1 ]; then + echo " reqrep ^([^\ :]*)\ /cam_$INSTANCE/(.*) \1\ /\2" >> /etc/haproxy/haproxy.cfg + echo " server webcam1 127.0.0.1:$CAMPORT" + else + echo " reqrep ^([^\ :]*)\ /cam_$INSTANCE/(.*) \1\ /\2" >> /etc/haproxy/haproxy.cfg + echo " server webcam1 127.0.0.1:$CAMPORT" >> /etc/haproxy/haproxy.cfg + fi + echo "#cam_$INSTANCE stop" >> /etc/haproxy/haproxy.cfg + fi } add_camera() { @@ -386,6 +409,12 @@ add_camera() { break done fi + #for now just set a flag that we are going to write cameras behind haproxy + if [ "$HAPROXY" == true ]; then + if prompt_confirm "Add cameras behind haproxy?"; then + CAMHAPROXY=1 + fi + fi if [ -z "$PI" ]; then detect_camera @@ -549,6 +578,8 @@ remove_instance() { 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 @@ -986,6 +1017,8 @@ remove_everything() { 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 done echo "Removing system stuff" @@ -1000,6 +1033,8 @@ remove_everything() { echo "Removing template" rm -rf /home/$user/.octoprint rm -rf /home/$user/OctoPrint + rm -rf /home/$user/ustreamer + rm -rf /home/$user/mjpg-streamer systemctl restart haproxy.service systemctl daemon-reload @@ -1303,6 +1338,7 @@ main_menu() { TEMPUSBCAM='' INSTANCE='' INSTALL='' + CAMHAPROXY='' echo echo echo "*************************" From 278877c2c4c95abbf03af55985f7e19787cbd31f Mon Sep 17 00:00:00 2001 From: paukstelis Date: Fri, 23 Dec 2022 15:48:11 -0500 Subject: [PATCH 03/13] cam haproxy work --- octoprint_deploy.sh | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/octoprint_deploy.sh b/octoprint_deploy.sh index 504e4e9..08312fa 100755 --- a/octoprint_deploy.sh +++ b/octoprint_deploy.sh @@ -270,15 +270,13 @@ new_instance () { echo "#$INSTANCE start" >> /etc/haproxy/haproxy.cfg echo "backend $INSTANCE" >> /etc/haproxy/haproxy.cfg if [ $HAversion -gt 1 ]; then - /bin/sh "cat >> /etc/haproxy/haproxy.cfg" << PROX - http-request replace-path /$INSTANCE/(.*) /\1 - acl needs_scheme req.hdr_cnt(X-Scheme) eq 0 - http-request add-header X-Scheme https if needs_scheme { ssl_fc } - http-request add-header X-Scheme http if needs_scheme !{ ssl_fc } - http-request add-header X-Script-Name /$INSTANCE - server octoprint1 127.0.0.1:$PORT - option forwardfor - PROX + echo " http-request replace-path /$INSTANCE/(.*) /\1" >> /etc/haproxy/haproxy.cfg + echo " acl needs_scheme req.hdr_cnt(X-Scheme) eq 0" >> /etc/haproxy/haproxy.cfg + echo " http-request add-header X-Scheme https if needs_scheme { ssl_fc }" >> /etc/haproxy/haproxy.cfg + echo " http-request add-header X-Scheme http if needs_scheme !{ ssl_fc }" >> /etc/haproxy/haproxy.cfg + echo " http-request add-header X-Script-Name /$INSTANCE" >> /etc/haproxy/haproxy.cfg + echo " server octoprint1 127.0.0.1:$PORT" >> /etc/haproxy/haproxy.cfg + echo " option forwardfor" >> /etc/haproxy/haproxy.cfg else echo " reqrep ^([^\ :]*)\ /$INSTANCE/(.*) \1\ /\2" >> /etc/haproxy/haproxy.cfg echo " server octoprint1 127.0.0.1:$PORT" >> /etc/haproxy/haproxy.cfg @@ -411,7 +409,7 @@ add_camera() { fi #for now just set a flag that we are going to write cameras behind haproxy if [ "$HAPROXY" == true ]; then - if prompt_confirm "Add cameras behind haproxy?"; then + if prompt_confirm "Add cameras to haproxy?"; then CAMHAPROXY=1 fi fi From 986740cda9c1520abd9061d4304d50ad44d34223 Mon Sep 17 00:00:00 2001 From: paukstelis Date: Fri, 23 Dec 2022 16:14:48 -0500 Subject: [PATCH 04/13] settings update --- octoprint_deploy.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/octoprint_deploy.sh b/octoprint_deploy.sh index 08312fa..15f9640 100755 --- a/octoprint_deploy.sh +++ b/octoprint_deploy.sh @@ -387,6 +387,7 @@ write_camera() { add_camera() { PI=$1 + get_settings if [ $SUDO_USER ]; then user=$SUDO_USER; fi echo 'Adding camera' | log if [ -z "$INSTANCE" ]; then From d06e0310661f969837a27b827e4fe502e47c6628 Mon Sep 17 00:00:00 2001 From: paukstelis Date: Fri, 23 Dec 2022 16:25:51 -0500 Subject: [PATCH 05/13] fix echo --- octoprint_deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octoprint_deploy.sh b/octoprint_deploy.sh index 15f9640..deac1f8 100755 --- a/octoprint_deploy.sh +++ b/octoprint_deploy.sh @@ -376,7 +376,7 @@ write_camera() { echo "backend cam_$INSTANCE" >> /etc/haproxy/haproxy.cfg if [ $HAversion -gt 1 ]; then echo " reqrep ^([^\ :]*)\ /cam_$INSTANCE/(.*) \1\ /\2" >> /etc/haproxy/haproxy.cfg - echo " server webcam1 127.0.0.1:$CAMPORT" + echo " server webcam1 127.0.0.1:$CAMPORT" >> /etc/haproxy/haproxy.cfg else echo " reqrep ^([^\ :]*)\ /cam_$INSTANCE/(.*) \1\ /\2" >> /etc/haproxy/haproxy.cfg echo " server webcam1 127.0.0.1:$CAMPORT" >> /etc/haproxy/haproxy.cfg From 526b0bee982e9361d90434bd75ab2aeaeec8ea45 Mon Sep 17 00:00:00 2001 From: paukstelis Date: Fri, 23 Dec 2022 16:41:53 -0500 Subject: [PATCH 06/13] fix haproxy2 --- octoprint_deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octoprint_deploy.sh b/octoprint_deploy.sh index deac1f8..81d343e 100755 --- a/octoprint_deploy.sh +++ b/octoprint_deploy.sh @@ -375,7 +375,7 @@ write_camera() { echo "#cam_$INSTANCE start" >> /etc/haproxy/haproxy.cfg echo "backend cam_$INSTANCE" >> /etc/haproxy/haproxy.cfg if [ $HAversion -gt 1 ]; then - echo " reqrep ^([^\ :]*)\ /cam_$INSTANCE/(.*) \1\ /\2" >> /etc/haproxy/haproxy.cfg + echo " http-request replace-path /cam_$INSTANCE/(.*) /\1" >> /etc/haproxy/haproxy.cfg echo " server webcam1 127.0.0.1:$CAMPORT" >> /etc/haproxy/haproxy.cfg else echo " reqrep ^([^\ :]*)\ /cam_$INSTANCE/(.*) \1\ /\2" >> /etc/haproxy/haproxy.cfg From b2f1ce88ba814ad1de8254e37d677dbe1347dc05 Mon Sep 17 00:00:00 2001 From: paukstelis Date: Sat, 24 Dec 2022 16:16:33 -0500 Subject: [PATCH 07/13] fix sudo/root stuff --- octoprint_deploy.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/octoprint_deploy.sh b/octoprint_deploy.sh index 81d343e..15c2ba8 100755 --- a/octoprint_deploy.sh +++ b/octoprint_deploy.sh @@ -7,7 +7,13 @@ if (( $EUID != 0 )); then fi #this is a weak check, but will catch most cases -if [ $SUDO_USER ]; then user=$SUDO_USER; fi +if [ $SUDO_USER ]; then + user=$SUDO_USER +else + echo "You should not run this script as root. Use sudo as a normal user" + exit +fi + if [ "$user" == root ]; then echo "You should not run this script as root. Use sudo as a normal user" exit From 6ea17794351fac6e6e4b81e60a6bc3450c995c32 Mon Sep 17 00:00:00 2001 From: paukstelis Date: Thu, 29 Dec 2022 22:45:02 -0500 Subject: [PATCH 08/13] restart haproxy --- octoprint_deploy.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/octoprint_deploy.sh b/octoprint_deploy.sh index 15c2ba8..15c0966 100755 --- a/octoprint_deploy.sh +++ b/octoprint_deploy.sh @@ -388,6 +388,7 @@ write_camera() { echo " server webcam1 127.0.0.1:$CAMPORT" >> /etc/haproxy/haproxy.cfg fi echo "#cam_$INSTANCE stop" >> /etc/haproxy/haproxy.cfg + systemctl restart haproxy fi } From 38ea6f65a3276cfae98702c2ce8623a5e05fa994 Mon Sep 17 00:00:00 2001 From: paukstelis Date: Fri, 30 Dec 2022 08:04:07 -0500 Subject: [PATCH 09/13] version, readme --- README.md | 13 +++---------- octoprint_deploy.sh | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 12332a3..c8da558 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ These files provide a bash script for quickly deploying multiple octoprint insta * General Linux (Ubuntu/Mint/RPiOS/Debian/Fedora/Arch/etc.) * __You do not need to install OctoPrint using any Wiki instructions, snap, etc. The script will do it for you.__ * octoprint_deploy uses systemd services, so avoid distros that do not use systemd by default (MX Linux or chroot based systems like Chrome+crouton) + * SELinux (Fedora) casues issues, particularly with camera services. Use at your own risk (or desiable SELinux). * Basic guide video here: https://youtu.be/1YINWQ5fNn0 * All commands assume you are operating out of your home directory. * Install Ubuntu 20+, Mint 20.3+, Debian, DietPi, RPiOS, Armbian, Fedora35+, or ArchLinux on your system (make sure your user is admin for sudo). @@ -59,20 +60,12 @@ 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 +* If haproxy is used, cameras stream can be placed behind it. * 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. -* Filter out `generic` instance from lists where it does not need to be. -* Added `Instance Status` option which will report the status of each instance (as seen been systemctl status). -* Added `Sync Users` option. It will copy users.yaml file from selected instances to all other instances (including template) -* Starting with 0.1.4, added `Update` in the menu which will update octoprint_deploy via git (then exit) -* Rename printers_udev.sh to udev_rules.sh. Allows writing udev rules for both printers and cameras without full deployment. -* 0.1.3, printer and camera detection now done with dmesg instead of journalctl. This allows faster timeouts when a device is detected by the USB port but it does not have a serial number. -* Fail if sudouser is root. -* Add MIT license -# TODO -* Multiple cameras for an instance (see multi-camera branch) + diff --git a/octoprint_deploy.sh b/octoprint_deploy.sh index 15c0966..a3bd8b7 100755 --- a/octoprint_deploy.sh +++ b/octoprint_deploy.sh @@ -1336,7 +1336,7 @@ instance_status() { } main_menu() { - VERSION=0.1.9 + VERSION=0.2.0 #reset UDEV='' TEMPUSB='' From c08cef0a3c625214f11b42fe1ef76155d783eab5 Mon Sep 17 00:00:00 2001 From: paukstelis Date: Fri, 30 Dec 2022 08:41:49 -0500 Subject: [PATCH 10/13] multi-camera integration --- README.md | 1 + octoprint_deploy.sh | 80 +++++++++++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index c8da558..dda8518 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ 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 +* Multi-camera support (experimental). * If haproxy is used, cameras stream can be placed behind it. * 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. diff --git a/octoprint_deploy.sh b/octoprint_deploy.sh index a3bd8b7..d2cc4bf 100755 --- a/octoprint_deploy.sh +++ b/octoprint_deploy.sh @@ -11,7 +11,7 @@ if [ $SUDO_USER ]; then user=$SUDO_USER else echo "You should not run this script as root. Use sudo as a normal user" - exit + exit fi if [ "$user" == root ]; then @@ -334,66 +334,68 @@ write_camera() { if [ "$STREAMER" == mjpg-streamer ]; then cat $SCRIPTDIR/octocam_mjpg.service | \ sed -e "s/OCTOUSER/$OCTOUSER/" \ - -e "s/OCTOCAM/cam_$INSTANCE/" \ + -e "s/OCTOCAM/cam${INUM}_$INSTANCE/" \ -e "s/RESOLUTION/$RESOLUTION/" \ -e "s/FRAMERATE/$FRAMERATE/" \ - -e "s/CAMPORT/$CAMPORT/" > $SCRIPTDIR/cam_$INSTANCE.service + -e "s/CAMPORT/$CAMPORT/" > $SCRIPTDIR/cam${INUM}_$INSTANCE.service fi #ustreamer if [ "$STREAMER" == ustreamer ]; then cat $SCRIPTDIR/octocam_ustream.service | \ sed -e "s/OCTOUSER/$OCTOUSER/" \ - -e "s/OCTOCAM/cam_$INSTANCE/" \ + -e "s/OCTOCAM/cam${INUM}_$INSTANCE/" \ -e "s/RESOLUTION/$RESOLUTION/" \ -e "s/FRAMERATE/$FRAMERATE/" \ - -e "s/CAMPORT/$CAMPORT/" > $SCRIPTDIR/cam_$INSTANCE.service + -e "s/CAMPORT/$CAMPORT/" > $SCRIPTDIR/cam${INUM}_$INSTANCE.service fi - mv $SCRIPTDIR/cam_$INSTANCE.service /etc/systemd/system/ + mv $SCRIPTDIR/cam${INUM}_$INSTANCE.service /etc/systemd/system/ echo $CAMPORT >> /etc/camera_ports - #config.yaml modifications - echo "webcam:" >> $OCTOCONFIG/.$INSTANCE/config.yaml - echo " snapshot: http://$(hostname).local:$CAMPORT?action=snapshot" >> $OCTOCONFIG/.$INSTANCE/config.yaml - if [ -z "$CAMHAPROXY" ]; then - echo " stream: http://$(hostname).local:$CAMPORT?action=stream" >> $OCTOCONFIG/.$INSTANCE/config.yaml - else - echo " stream: /cam_$INSTANCE/?action=stream" >> $OCTOCONFIG/.$INSTANCE/config.yaml + #config.yaml modifications - only if INUM not set + if [ -z "$INUM" ]; then + echo "webcam:" >> $OCTOCONFIG/.$INSTANCE/config.yaml + echo " snapshot: http://$(hostname).local:$CAMPORT?action=snapshot" >> $OCTOCONFIG/.$INSTANCE/config.yaml + if [ -z "$CAMHAPROXY" ]; then + echo " stream: http://$(hostname).local:$CAMPORT?action=stream" >> $OCTOCONFIG/.$INSTANCE/config.yaml + else + echo " stream: /cam_$INSTANCE/?action=stream" >> $OCTOCONFIG/.$INSTANCE/config.yaml + fi + $OCTOEXEC --basedir $OCTOCONFIG/.$INSTANCE config append_value --json system.actions "{\"action\": \"Reset video streamer\", \"command\": \"sudo systemctl restart cam_$INSTANCE\", \"name\": \"Restart webcam\"}" fi - $OCTOEXEC --basedir $OCTOCONFIG/.$INSTANCE config append_value --json system.actions "{\"action\": \"Reset video streamer\", \"command\": \"sudo systemctl restart cam_$INSTANCE\", \"name\": \"Restart webcam\"}" #Either Serial number or USB port - #Serial Number if [ -n "$CAM" ]; then - echo SUBSYSTEM==\"video4linux\", ATTRS{serial}==\"$CAM\", ATTR{index}==\"0\", SYMLINK+=\"cam_$INSTANCE\" >> /etc/udev/rules.d/99-octoprint.rules + echo SUBSYSTEM==\"video4linux\", ATTRS{serial}==\"$CAM\", ATTR{index}==\"0\", SYMLINK+=\"cam${INUM}_$INSTANCE\" >> /etc/udev/rules.d/99-octoprint.rules fi #USB port camera if [ -n "$USBCAM" ]; then - echo SUBSYSTEM==\"video4linux\",KERNELS==\"$USBCAM\", SUBSYSTEMS==\"usb\", ATTR{index}==\"0\", DRIVERS==\"uvcvideo\", SYMLINK+=\"cam_$INSTANCE\" >> /etc/udev/rules.d/99-octoprint.rules + echo SUBSYSTEM==\"video4linux\",KERNELS==\"$USBCAM\", SUBSYSTEMS==\"usb\", ATTR{index}==\"0\", DRIVERS==\"uvcvideo\", SYMLINK+=\"cam${INUM}_$INSTANCE\" >> /etc/udev/rules.d/99-octoprint.rules fi if [ -n $CAMHAPROXY ]; then HAversion=$(haproxy -v | sed -n 's/^.*version \([0-9]\).*/\1/p') #find frontend line, do insert - sed -i "/option forwardfor except 127.0.0.1/a\ use_backend cam_$INSTANCE if { path_beg /cam_$INSTANCE/ }" /etc/haproxy/haproxy.cfg - echo "#cam_$INSTANCE start" >> /etc/haproxy/haproxy.cfg - echo "backend cam_$INSTANCE" >> /etc/haproxy/haproxy.cfg + sed -i "/option forwardfor except 127.0.0.1/a\ use_backend cam${INUM}_$INSTANCE if { path_beg /cam${INUM}_$INSTANCE/ }" /etc/haproxy/haproxy.cfg + echo "#cam${INUM}_$INSTANCE start" >> /etc/haproxy/haproxy.cfg + echo "backend cam${INUM}_$INSTANCE" >> /etc/haproxy/haproxy.cfg if [ $HAversion -gt 1 ]; then - echo " http-request replace-path /cam_$INSTANCE/(.*) /\1" >> /etc/haproxy/haproxy.cfg + echo " http-request replace-path /cam${INUM}_$INSTANCE/(.*) /\1" >> /etc/haproxy/haproxy.cfg echo " server webcam1 127.0.0.1:$CAMPORT" >> /etc/haproxy/haproxy.cfg else - echo " reqrep ^([^\ :]*)\ /cam_$INSTANCE/(.*) \1\ /\2" >> /etc/haproxy/haproxy.cfg + echo " reqrep ^([^\ :]*)\ /cam${INUM}_$INSTANCE/(.*) \1\ /\2" >> /etc/haproxy/haproxy.cfg echo " server webcam1 127.0.0.1:$CAMPORT" >> /etc/haproxy/haproxy.cfg fi - echo "#cam_$INSTANCE stop" >> /etc/haproxy/haproxy.cfg + echo "#cam${INUM}_$INSTANCE stop" >> /etc/haproxy/haproxy.cfg systemctl restart haproxy fi } add_camera() { PI=$1 + INUM='' get_settings if [ $SUDO_USER ]; then user=$SUDO_USER; fi echo 'Adding camera' | log @@ -402,7 +404,6 @@ add_camera() { readarray -t options < <(cat /etc/octoprint_instances | sed -n -e 's/^instance:\([[:graph:]]*\) .*/\1/p') options+=("Quit") unset 'options[0]' - #Not yet check to see if instance already has a camera select camopt in "${options[@]}" do if [ "$camopt" == Quit ]; then @@ -412,6 +413,21 @@ add_camera() { INSTANCE=$camopt OCTOCONFIG="/home/$user/" OCTOUSER=$user + if grep -q "cam_$INSTANCE" /etc/udev/rules.d/99-octoprint.rules; then + echo "It appears this instance already has at least one camera." + if prompt_confirm "Do you want to add an additional camera for this instance?"; then + echo "Enter a number for this camera." + echo "Ex. entering 2 will setup a service called cam2_$INSTANCE" + echo + read INUM + if [ -z "$INUM" ]; then + echo "No value given, setting as 2" + INUM='2' + fi + else + main_menu + fi + fi break done fi @@ -437,11 +453,11 @@ add_camera() { if [ -z "$CAM" ]; then echo "Camera Serial Number not detected" | log - echo -e "Camera will be setup with physical USB address of \033[0;34m $TEMPUSBCAM.\033[0m" | log + echo -e "Camera will be setup with physical USB address of \033[0;32m $TEMPUSBCAM.\033[0m" | log echo "The camera will have to stay plugged into this location." | log USBCAM=$TEMPUSBCAM else - echo -e "Camera detected with serial number: \033[0;34m $CAM \033[0m" | log + echo -e "Camera detected with serial number: \033[0;32m $CAM \033[0m" | log check_sn "$CAM" fi @@ -467,7 +483,7 @@ add_camera() { CAMPORT=$((CAMPORT+1)) echo Selected port is: $CAMPORT | log fi - echo "Settings can be modified after initial setup in /etc/systemd/system/cam_$INSTANCE.service" + echo "Settings can be modified after initial setup in /etc/systemd/system/cam${INUM}_$INSTANCE.service" echo while true; do echo "Camera Resolution [default: 640x480]:" @@ -495,10 +511,10 @@ add_camera() { write_camera #Pi Cam setup, replace cam_INSTANCE with /dev/video0 if [ -n "$PI" ]; then - echo SUBSYSTEM==\"video4linux\", ATTRS{name}==\"camera0\", SYMLINK+=\"cam_$INSTANCE\" >> /etc/udev/rules.d/99-octoprint.rules + echo SUBSYSTEM==\"video4linux\", ATTRS{name}==\"camera0\", SYMLINK+=\"cam${INUM}_$INSTANCE\" >> /etc/udev/rules.d/99-octoprint.rules fi - systemctl start cam_$INSTANCE.service - systemctl enable cam_$INSTANCE.service + systemctl start cam${INUM}_$INSTANCE.service + systemctl enable cam${INUM}_$INSTANCE.service systemctl daemon-reload udevadm control --reload-rules udevadm trigger @@ -571,8 +587,8 @@ remove_instance() { 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 + 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 From a9b8c6615c9a6834f769e6997db8a309f2b90f50 Mon Sep 17 00:00:00 2001 From: paukstelis Date: Fri, 30 Dec 2022 08:45:42 -0500 Subject: [PATCH 11/13] readme warning --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dda8518..e7d628d 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ 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 -* Multi-camera support (experimental). +* 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. * 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. From 161cd6b07fb4f2cda50108918109b1fbb1a352be Mon Sep 17 00:00:00 2001 From: paukstelis Date: Fri, 30 Dec 2022 09:01:56 -0500 Subject: [PATCH 12/13] readme updates --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e7d628d..f11640a 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ These files provide a bash script for quickly deploying multiple octoprint insta * Always a good idea to update octoprint_deploy from time-to-time with `git -C octoprint_deploy pull` # Recent Changes * 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. +* 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. From a613d0b63e16eb8c309b9cd2eec96c64043e8bf9 Mon Sep 17 00:00:00 2001 From: paukstelis Date: Fri, 30 Dec 2022 09:03:47 -0500 Subject: [PATCH 13/13] more trailing slash warnings --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f11640a..91fe56c 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ These files provide a bash script for quickly deploying multiple octoprint insta * run the command `git clone https://github.com/paukstelis/octoprint_deploy.git`. * run the command `sudo octoprint_deploy/octoprint_deploy.sh`. * Choose `Prepare System` from the menu. Select your distribution type. All deb-based system use the same selection. This will install necessary packages, install OctoPrint, and start a template instance. - * You will be asked if you want to use haproxy. This will make your instances available on port 80 (e.g. http://localhost/instancename/). + * You will be asked if you want to use haproxy. This will make your instances available on port 80 e.g. http://localhost/instancename/. PLEASE NOTE that the trailing slash is required! * You will be asked which streamer you would like to install (mjpg-streamer or ustreamer). * You will be prompted if you want to setup the admin user and do the first run wizard via the commandline. If you do this now you can start making new instances as soon as the system preparation is complete. * You will be prompted if you want to install recommended plugins and cloud plugins. This can be useful if you want to configure plugins in your template instance, before adding new instances.