From fbe1ea988672c7433ec32066e17506bc6d8df87b Mon Sep 17 00:00:00 2001 From: paukstelis Date: Sun, 17 Apr 2022 10:38:17 -0400 Subject: [PATCH 1/4] basic architecture detection --- README.md | 7 ++++-- octoprint_deploy.sh | 53 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 39855fb..2b56818 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Updated February 2022. +Updated April 2022. Want to support this work? Buy Me a Coffee. https://www.buymeacoffee.com/ppaukstelis # octoprint_deploy These files provide a simple bash script for quickly deploying multiple octoprint instances on a single computer. @@ -19,7 +19,7 @@ YouTube video for OctoPi setup here: https://www.youtube.com/watch?v=J5VzI4AFav4 * haproxy entries are updated so you can connect via http://octopi.local/instancename/ * Ubuntu/Mint/Fedora (Fedora not completely tested) * Install Ubuntu 20-21.X, Mint 20.3+, or Fedora35+ on your system (make sure your user is admin for sudo) - * Install git if it isn't already: `sudo apt install git` + * Install git if it isn't already: `sudo apt install git` or `sudo dnf install git` * 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. This will install necessary packages, install octoprint, and start an instance @@ -31,3 +31,6 @@ YouTube video for OctoPi setup here: https://www.youtube.com/watch?v=J5VzI4AFav4 * Remove instances * Add USB webcams AFTER you've created the instance * Test USB connections +# Recent Changes +* Add duplicate serial number detection. +* Add architecture check to minimize errors where a system gets prepared as OctoPi when someone is using Ubuntu/Fedora/etc. diff --git a/octoprint_deploy.sh b/octoprint_deploy.sh index bd72f51..0e73ad0 100755 --- a/octoprint_deploy.sh +++ b/octoprint_deploy.sh @@ -6,7 +6,10 @@ if (( $EUID != 0 )); then exit fi - +#Get abbreviated architecture +ARCH=$(arch) +ARCH=${ARCH:0:3} +echo $ARCH # from stackoverflow.com/questions/3231804 prompt_confirm() { while true; do @@ -37,7 +40,7 @@ new_instance () { BUDEFAULT="/home/$user/OctoPrint/bin/octoprint" OTHERDEFAULT="" PS3='Installation type: ' - options=("OctoPi" "OctoBuntu" "Other" "Quit") + options=("OctoPi" "Linux/OctoBuntu" "Other" "Quit") select opt in "${options[@]}" do case $opt in @@ -46,7 +49,7 @@ new_instance () { INSTALL=1 break ;; - "OctoBuntu") + "Linux/OctoBuntu") DAEMONPATH=$BUDEFAULT INSTALL=2 break @@ -349,6 +352,7 @@ add_camera() { USBCAM=$TEMPUSBCAM else echo -e "Camera detected with serial number: \033[0;34m $CAM \033[0m" | log + check_sn "$CAM" fi echo "Camera Port (ENTER will increment last value in /etc/camera_ports):" read CAMPORT @@ -446,6 +450,7 @@ usb_testing() { fi if [ -n "$UDEV" ]; then echo "Serial Number detected: $UDEV" | log + check_sn "$UDEV" fi done main_menu @@ -487,6 +492,18 @@ prepare () { *) echo "invalid option $REPLY";; esac done + + if [ $INSTALL -eq 1 ] && [[ "$ARCH" != arm ]]; then + echo "WARNING! You have selected OctoPi, but are not using an ARM processor." + echo "If you are using generic another linux distribution, select it from the list." + echo "Unless you really know what you are doing, select N." + if prompt_confirm "Continue with OctoPi? (Y/N)"; then + echo "OK!" + else + main_menu + fi + fi + if prompt_confirm "Ready to begin?" then echo 'instance:generic port:5000' > /etc/octoprint_instances @@ -496,7 +513,6 @@ prepare () { usermod -a -G dialout,video $user - if [ $INSTALL -eq 1 ]; then echo 'Disabling unneeded services....' systemctl disable octoprint.service @@ -512,7 +528,9 @@ prepare () { echo 'Modifying config.yaml' cp -p $SCRIPTDIR/config.basic /home/pi/.octoprint/config.yaml echo 'Connect to your octoprint instance and setup admin user' + fi + if [ $INSTALL -gt 1 ]; then echo "Creating OctoBuntu installation equivalent." echo "Adding systemctl and reboot to sudo" @@ -538,7 +556,7 @@ prepare () { if [ $INSTALL -eq 5 ]; then dnf -y install python3-devel cmake libjpeg-turbo-devel fi - + echo "Installing OctoPrint in /home/$user/OctoPrint" #make venv sudo -u $user python3 -m venv /home/$user/OctoPrint @@ -557,7 +575,7 @@ prepare () { echo 'Updating config.yaml' sudo -u $user mkdir /home/$user/.octoprint sudo -u $user cp -p $SCRIPTDIR/config.basic /home/$user/.octoprint/config.yaml - + #install mjpg-streamer, not doing any error checking or anything echo 'Installing mjpeg-streamer' sudo -u $user git clone https://github.com/jacksonliam/mjpg-streamer.git mjpeg @@ -567,12 +585,12 @@ prepare () { sudo -u $user rm -rf mjpeg #Fedora has SELinux on by default so must make adjustments? Don't really know what these do... if [ $INSTALL -eq 5 ]; then - semanage fcontext -a -t bin_t "/home/$user/OctoPrint/bin/.*" - chcon -Rv -u system_u -t bin_t "/home/$user/OctoPrint/bin/" - restorecon -R -v /home/$user/OctoPrint/bin - semanage fcontext -a -t bin_t "/home/$user/mjpg-streamer/.*" - chcon -Rv -u system_u -t bin_t "/home/$user/mjpg-streamer/" - restorecon -R -v /home/$user/mjpg-streamer + semanage fcontext -a -t bin_t "/home/$user/OctoPrint/bin/.*" + chcon -Rv -u system_u -t bin_t "/home/$user/OctoPrint/bin/" + restorecon -R -v /home/$user/OctoPrint/bin + semanage fcontext -a -t bin_t "/home/$user/mjpg-streamer/.*" + chcon -Rv -u system_u -t bin_t "/home/$user/mjpg-streamer/" + restorecon -R -v /home/$user/mjpg-streamer fi echo 'Starting generic service on port 5000' systemctl start octoprint_default.service @@ -582,6 +600,17 @@ prepare () { fi main_menu } + +check_sn() { + if [ -f "/etc/udev/rules.d/99-octoprint.rules" ]; then + if grep -q $1 /etc/udev/rules.d/99-octoprint.rules; then + echo "An identical serial number has been detected in the udev rules. Please be warned, this will likely cause instability!" | log + else + echo "No duplicate serial number detected" | log + fi + fi +} + main_menu() { #reset UDEV='' From e5baee5c475f665bfe2549133a204b18ec1f1b31 Mon Sep 17 00:00:00 2001 From: paukstelis Date: Sun, 17 Apr 2022 10:42:27 -0400 Subject: [PATCH 2/4] Update README --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2b56818..28ee239 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,10 @@ YouTube video for OctoPi setup here: https://www.youtube.com/watch?v=J5VzI4AFav4 * Install git if it isn't already: `sudo apt install git` or `sudo dnf install git` * 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. This will install necessary packages, install octoprint, and start an instance - * This converts your installation into an 'OctoBuntu'-style installation. + * Choose `Prepare System` from the menu. Select your distribution type. This will install necessary packages, install octoprint, and start a template instance + * This converts your installation into an 'OctoBuntu'-style installation. Use `OctoBuntu` for all identifiers after this point. * Setup admin user by connecting to your system (either http://localhost:5000 or http://[hostname]:5000 via browser * Continue with octoprint_deploy script and setup all your instances. - * You may have to logout/reboot before connecting to printers or cameras as dialout and video permissions are established during setup. * What else can you do? * Remove instances * Add USB webcams AFTER you've created the instance From b19acfa3b238376a9c5b385f698dd3743cb1ba1e Mon Sep 17 00:00:00 2001 From: paukstelis Date: Sun, 17 Apr 2022 10:50:17 -0400 Subject: [PATCH 3/4] Fix USB testing --- octoprint_deploy.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/octoprint_deploy.sh b/octoprint_deploy.sh index 0e73ad0..7b848b0 100755 --- a/octoprint_deploy.sh +++ b/octoprint_deploy.sh @@ -181,6 +181,8 @@ new_instance () { echo else echo -e "Serial number detected as: \033[0;34m $UDEV\033[0m" | log + check_sn "$UDEV" + echo fi echo @@ -446,7 +448,7 @@ usb_testing() { TEMPUSB=$(timeout 1s journalctl -kf | sed -n -e 's/^.*\(cdc_acm\|ftdi_sio\|ch341\) \([0-9].*[0-9]\): \(tty.*\|FTD.*\|ch341-uart.*\).*/\2/p') counter=$(( $counter + 1 )) if [ -n "$TEMPUSB" ]; then - echo 'Detected devince at $TEMPUSB' | log + echo "Detected device at $TEMPUSB" | log fi if [ -n "$UDEV" ]; then echo "Serial Number detected: $UDEV" | log From 610346eeef7518afb457f983c5cd9b353ad63a0e Mon Sep 17 00:00:00 2001 From: paukstelis Date: Tue, 19 Apr 2022 16:56:39 -0400 Subject: [PATCH 4/4] typo fix --- octoprint_deploy.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/octoprint_deploy.sh b/octoprint_deploy.sh index 7b848b0..496d902 100755 --- a/octoprint_deploy.sh +++ b/octoprint_deploy.sh @@ -368,7 +368,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/octocam_$INSTANCE" + echo "Settings can be modified after initial setup in /etc/systemd/system/cam_$INSTANCE" echo echo "Camera Resolution (no sanity check, so get it right) [default: 640x480]:" read RESOLUTION @@ -497,8 +497,8 @@ prepare () { if [ $INSTALL -eq 1 ] && [[ "$ARCH" != arm ]]; then echo "WARNING! You have selected OctoPi, but are not using an ARM processor." - echo "If you are using generic another linux distribution, select it from the list." - echo "Unless you really know what you are doing, select N." + echo "If you are using another linux distribution, select it from the list." + echo "Unless you really know what you are doing, select N now." if prompt_confirm "Continue with OctoPi? (Y/N)"; then echo "OK!" else