diff --git a/README.md b/README.md index d78e2cf..39a2a95 100644 --- a/README.md +++ b/README.md @@ -2,21 +2,28 @@ This is direct fork from https://github.com/paukstelis/octoprint_deploy at v1.0. # THIS PRJECT IS VERY MUCH IN THE EARLY STAGES YET! +<<<<<<< Updated upstream +======= +Updated April 1, 2024. -# octoprint_deploy 1.0.11 +Want to support this work? Buy Me a Coffee. https://www.buymeacoffee.com/ppaukstelis. +Need help with octodocker_deploy? Visit support-octoprint-deploy on the OctoPrint Discord: https://discord.com/invite/yA7stPp +>>>>>>> Stashed changes + +# octodocker_deploy 1.0.11 * These files provide a bash script for quickly deploying multiple octoprint instances on a single computer. For Linux systems (Ubuntu, Fedora, etc.) it will also install OctoPrint and a video streamer (ustreamer). No need for lots of file editing or complicated Docker compose scripts! A background video on how it generally works from my ERRF2022 talk can be found here: https://www.youtube.com/watch?v=q0iCNl8-kJI&t=15378s -* octoprint_deploy and octoprint_install are being merged! Maintaining two separate scripts was close to twice the amount of work. By merging the scripts many new features have been included, while also providing greater simplicity in setup. +* octodocker_deploy and octoprint_install are being merged! Maintaining two separate scripts was close to twice the amount of work. By merging the scripts many new features have been included, while also providing greater simplicity in setup. * The biggest change is that there is no longer the notion of a single 'template' OctoPrint instance. Now, _any_ previously configured instance can be used as a template when a new instance is created. The choice is up to the user. -* Unfortunately, octoprint_deploy > 1.0.0 is not directly compatible with older versions, as so much has changed. If you want to use the new version of octoprint_deploy with an older setup, create backups (either with OctoPrint UI or with octoprint_deploy), then use the `remove` commandline argument before updating octoprint_deploy. Re-make your instances using the same instance names, then recover your backups. +* Unfortunately, octodocker_deploy > 1.0.0 is not directly compatible with older versions, as so much has changed. If you want to use the new version of octodocker_deploy with an older setup, create backups (either with OctoPrint UI or with octodocker_deploy), then use the `remove` commandline argument before updating octodocker_deploy. Re-make your instances using the same instance names, then recover your backups. # How to use * OctoPi * OctoPi is intended as a single printer environment. This script makes adding multiple instances easy, but it cannot take into account everything OctoPi does (mostly surrounding cameras). You have been warned. * ssh into your Pi (pi@octopi.local; good idea to change your password now!). - * run the command `git clone https://github.com/paukstelis/octoprint_deploy`. - * run the command `sudo octoprint_deploy/octoprint_deploy.sh`. + * run the command `git clone https://github.com/paukstelis/octodocker_deploy`. + * run the command `sudo octodocker_deploy/octodocker_deploy.sh`. * Choose `Prepare System` from the menu. - * This will register the OctoPi-created instance in octoprint_deploy. + * This will register the OctoPi-created instance in octodocker_deploy. * You will be prompted for udev detection (only needed if you are adding multiple printers). * You will be prompted for installing a new streamer. This will be the default streamer for any _additional_ cameras that are installed. Users of the new OctoPi camera stack can just choose `Skip/None` and setup all cameras manually. * To add more printers choose `Add Instance` and follow the instructions. @@ -27,24 +34,24 @@ This is direct fork from https://github.com/paukstelis/octoprint_deploy at v1.0. * To add more printers at a later date, just run the script again! * 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 all 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). Similarly, LXC containers do not work well with udev rules and USB peripherals, so those should be avoided. + * octodocker_deploy uses systemd services, so avoid distros that do not use systemd by default (MX Linux or chroot based systems like Chrome+crouton). Similarly, LXC containers do not work well with udev rules and USB peripherals, so those should be avoided. * All commands assume you are operating out of your home directory. * Install Ubuntu 20+, Mint 20.3+, Debian, DietPi, RPiOS, Armbian, Fedora35+, ArchLinux, or openSUSE on your system (make sure your user is admin for sudo). * Install git if it isn't already: `sudo apt install git` or `sudo dnf install git` or `sudo pacman -S git` or `sudo zypper in git`. - * run the command `git clone https://github.com/paukstelis/octoprint_deploy`. - * run the command `sudo octoprint_deploy/octoprint_deploy.sh`. + * run the command `git clone https://github.com/paukstelis/octodocker_deploy`. + * run the command `sudo octodocker_deploy/octodocker_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 prompt you to create the first instance. * You will be asked if you want to use haproxy. This will make your instances available on port 80 e.g. http://hostname.local/instancename/ * You will be asked which streamer you would like to install (ustreamer, mjpg-streamer or camera-streamer). Please note, not all distributions will be compatible with camera-streamer. __camera-streamer support will be added at a later date__ * You will be asked to plug in a printer via USB for udev rule creation. __If you cannot plug in the printer and are only creating a single instance you can simply allow the detection to time-out__. The first instance will still be created. You can generate a udev rule later through the utility menu. Additional instances will require the printers to be plugged in (as will USB cameras). * You will be prompted if you want to setup the admin user and do the first run wizard via the commandline. * You will be prompted if you want to install recommended plugins. - * Continue with octoprint_deploy script, choose `Add Instance` and follow the instructions. + * Continue with octodocker_deploy script, choose `Add Instance` and follow the instructions. * You will be prompted if you want to use a previously created instance as a template for your new instance. * If your printer does not have a serial number (all Creality printers) it will be detected by the USB port you plugged it in to. * You can also setup a camera for the instance at this time. Follow the instructions. * Add as many instances as you have printers, following the instructions. - * To add more printers at a later date, or to add cameras to an instance later, simply run the script again (`sudo octoprint_deploy/octoprint_deploy.sh`) and choose the appropriate option. + * To add more printers at a later date, or to add cameras to an instance later, simply run the script again (`sudo octodocker_deploy/octodocker_deploy.sh`) and choose the appropriate option. * Utility menu - use the utility menu in the script to: * Add or remove instances or cameras * Check the status of all instances @@ -54,11 +61,11 @@ This is direct fork from https://github.com/paukstelis/octoprint_deploy at v1.0. * Modify which camera streaming software is used (WIP) * Modify a setting for all instances using the OctoPrint CLI interface (WIP) * Add/Remove udev rules for printers and cameras - * Generate diagnostic output about octoprint_deploy. __Use this and provide output when you are looking for support__ + * Generate diagnostic output about octodocker_deploy. __Use this and provide output when you are looking for support__ * Other features from commandline arguments - * Want to get rid of everything? `sudo octoprint_deploy/octoprint_deploy.sh remove` - * Backup and restore files for an instance from the menu, or backup all instances with `sudo octoprint_deploy/octoprint_deploy backup` - * Restart all instances from the command line: `sudo octoprint_deploy/octoprint_deploy.sh restart_all` + * Want to get rid of everything? `sudo octodocker_deploy/octodocker_deploy.sh remove` + * Backup and restore files for an instance from the menu, or backup all instances with `sudo octodocker_deploy/octodocker_deploy backup` + * Restart all instances from the command line: `sudo octodocker_deploy/octodocker_deploy.sh restart_all` * You can inject any function at start using the command line with the first argument `f` and the second argument the function name. # Recent Changes * Include additional libcamera packages and libcamerify when ustreamer is used with PiCam @@ -67,7 +74,7 @@ This is direct fork from https://github.com/paukstelis/octoprint_deploy at v1.0. * Fix an issue with Fedora python versioning. * Fix change for ustreamer executable being renamed ustreamer.bin * Improve Instance Status function. - * Remove octoprint_deploy backup technique and move entirely to native OctoPrint backups. Backups made in this way are moved to /home/$USER/instance_backup to make them easier to sort. + * Remove octodocker_deploy backup technique and move entirely to native OctoPrint backups. Backups made in this way are moved to /home/$USER/instance_backup to make them easier to sort. * Camera settings written to separate env file. This can be found and edited at `/etc/cam_instancename.env`. # TODO * Integration with OctoPi new camera stack. This may or may not happen. diff --git a/README.old b/README.old new file mode 100644 index 0000000..0209c40 --- /dev/null +++ b/README.old @@ -0,0 +1,2 @@ +This is direct fork from https://github.com/paukstelis/octoprint_deploy at v1.0.11, but meant to utilize docker containers instead for each Printer. +# THIS PRJECT IS VERY MUCH IN THE EARLY STAGES YET! diff --git a/cameras.sh b/cameras.sh index 78e3257..a897a46 100755 --- a/cameras.sh +++ b/cameras.sh @@ -58,7 +58,6 @@ write_camera() { #mjpg-streamer if [ "$STREAMER" == mjpg-streamer ]; then cat $SCRIPTDIR/octocam_mjpg.service | \ - sed -e "s/OCTOUSER/$OCTOUSER/" \ -e "s/OCTOCAM/$CAMDEVICE/" \ -e "s/RESOLUTION/$RESOLUTION/" \ -e "s/FRAMERATE/$FRAMERATE/" \ @@ -69,12 +68,10 @@ write_camera() { if [ "$STREAMER" == ustreamer ]; then if [ "$PI" == true ]; then cat $SCRIPTDIR/octocam_ustream.service | \ - sed -e "s/OCTOUSER/$OCTOUSER/" \ -e "s/OCTOCAM/cam${INUM}_$INSTANCE/" \ -e "s|ExecStart=|ExecStart=/usr/bin/libcamerify |" > $SCRIPTDIR/$OUTFILE.service else cat $SCRIPTDIR/octocam_ustream.service | \ - sed -e "s/OCTOUSER/$OCTOUSER/" \ -e "s/OCTOCAM/cam${INUM}_$INSTANCE/" > $SCRIPTDIR/$OUTFILE.service fi fi @@ -83,11 +80,9 @@ write_camera() { if [ "$STREAMER" == camera-streamer ]; then if [ "$PI" == true ]; then cat $SCRIPTDIR/picam_camstream.service | \ - sed -e "s/OCTOUSER/$OCTOUSER/" \ -e "s/OCTOCAM/cam${INUM}_$INSTANCE/" > $SCRIPTDIR/$OUTFILE.service else cat $SCRIPTDIR/octocam_camstream.service | \ - sed -e "s/OCTOUSER/$OCTOUSER/" \ -e "s/OCTOCAM/cam${INUM}_$INSTANCE/" > $SCRIPTDIR/$OUTFILE.service fi fi @@ -96,27 +91,27 @@ write_camera() { CAMWIDTH=$(sed -r 's/^([0-9]+)x[0-9]+/\1/' <<<"$RESOLUTION") CAMHEIGHT=$(sed -r 's/^[0-9]+x([0-9]+)/\1/' <<<"$RESOLUTION") - sudo -u $user echo "DEVICE=$CAMDEVICE" >> /etc/$OUTFILE.env - sudo -u $user echo "RES=$RESOLUTION" >> /etc/$OUTFILE.env - sudo -u $user echo "FRAMERATE=$FRAMERATE" >> /etc/$OUTFILE.env - sudo -u $user echo "PORT=$CAMPORT" >> /etc/$OUTFILE.env - sudo -u $user echo "WIDTH=$CAMWIDTH" >> /etc/$OUTFILE.env - sudo -u $user echo "HEIGHT=$CAMHEIGHT" >> /etc/$OUTFILE.env + echo "DEVICE=$CAMDEVICE" >> /etc/$OUTFILE.env + echo "RES=$RESOLUTION" >> /etc/$OUTFILE.env + echo "FRAMERATE=$FRAMERATE" >> /etc/$OUTFILE.env + echo "PORT=$CAMPORT" >> /etc/$OUTFILE.env + echo "WIDTH=$CAMWIDTH" >> /etc/$OUTFILE.env + echo "HEIGHT=$CAMHEIGHT" >> /etc/$OUTFILE.env cp $SCRIPTDIR/$OUTFILE.service /etc/systemd/system/ echo "camera:cam${INUM}_$INSTANCE port:$CAMPORT udev:true" >> /etc/octoprint_cameras #config.yaml modifications - only if INUM not set if [ -z "$INUM" ]; then - sudo -u $user $OCTOEXEC --basedir $BASE config set plugins.classicwebcam.snapshot "http://localhost:$CAMPORT?action=snapshot" + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set plugins.classicwebcam.snapshot "http://localhost:$CAMPORT?action=snapshot" if [ -z "$CAMHAPROXY" ]; then - sudo -u $user $OCTOEXEC --basedir $BASE config set plugins.classicwebcam.stream "http://$(hostname).local:$CAMPORT?action=stream" + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set plugins.classicwebcam.stream "http://$(hostname).local:$CAMPORT?action=stream" else - sudo -u $user $OCTOEXEC --basedir $BASE config set plugins.classicwebcam.stream "/cam_$INSTANCE/?action=stream" + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set plugins.classicwebcam.stream "/cam_$INSTANCE/?action=stream" fi - sudo -u $user $OCTOEXEC --basedir $BASE config append_value --json system.actions "{\"action\": \"Reset video streamer\", \"command\": \"sudo systemctl restart cam_$INSTANCE\", \"name\": \"Restart webcam\"}" + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config append_value --json system.actions "{\"action\": \"Reset video streamer\", \"command\": \"sudo systemctl restart cam_$INSTANCE\", \"name\": \"Restart webcam\"}" if prompt_confirm "Instance must be restarted for settings to take effect. Restart now?"; then systemctl restart $INSTANCE @@ -189,9 +184,8 @@ add_camera() { fi echo "Selected instance for camera: ${cyan}$camopt${white}" INSTANCE=$camopt - OCTOCONFIG="/home/$user/" - BASE="/home/$user/.$INSTANCE" - OCTOUSER=$user + OCTOCONFIG="/opt/octoprint/" + BASE="/opt/octoprint/$INSTANCE" 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 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7aba75d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +version: '2.4' + +services: + NEWINSTANCE: + image: octoprint/octoprint + container_name: octopi_NEWINSTANCE + restart: unless-stopped + ports: + - NEWPORT:5000 + - CAMPORT:8080 + #devices: + # - /dev/ttyACM0:/dev/ttyACM0 + # - /dev/video0:/dev/video0 + volumes: + - /opt/octoprint/NEWINSTANCE:/octoprint + # uncomment the lines below to ensure camera streaming is enabled when + # you add a video device + #environment: + # - ENABLE_MJPG_STREAMER=true + # - CAMERA_DEV=/dev/video0 + # - MJPG_STREAMER_INPUT="-y -n -r 1280x960 -f 30 \ No newline at end of file diff --git a/instance.sh b/instance.sh old mode 100644 new mode 100755 index 8c743a1..be174c6 --- a/instance.sh +++ b/instance.sh @@ -84,29 +84,20 @@ new_instance() { fi if prompt_confirm "Ready to begin instance creation?"; then - #CHANGE - if [ -f /etc/octoprint_instances ]; then - PORT=$(tail -1 /etc/octoprint_instances 2>/dev/null | sed -n -e 's/^.*\(port:\)\(.*\) udev:.*/\2/p') - fi - - if [ -z "$PORT" ]; then - PORT=4999 - fi - - PORT=$((PORT+1)) + PORT=5000 + PORTS_INUSE=$(join_by , $(cat /etc/octoprint_instances 2>/dev/null | sed -n -e 's/^.*\(port:\)\(.*\) udev:.*/\2/p')) + until [[ "${PORTS_INUSE}" != *"${PORT}"* ]]; do ((PORT++)); done + echo Selected port is: $PORT - #CHANGE - OCTOUSER=$user - OCTOPATH=$OCTOEXEC - OCTOCONFIG="/home/$user" + OCTOCONFIG="/opt/octoprint" - echo "Your new OctoPrint instance will be installed at ${cyan}/home/$user/.$INSTANCE${white}" + echo "Your new OctoPrint instance will be installed at ${cyan}/opt/octoprint/$INSTANCE${white}" echo echo else if [ "$firstrun" == "true" ]; then echo "${red}You will need to restart your installation.${white}" - echo "${red}Answer Y and re-run octoprint_deploy${white}" + echo "${red}Answer Y and re-run octodocker_deploy${white}" remove_everything exit else @@ -115,7 +106,7 @@ new_instance() { fi if [ -n "$TEMPLATE" ]; then - BFOLD="/home/$user/.$TEMPLATE" + BFOLD="/opt/octoprint/$INSTANCE$TEMPLATE" #check to make sure first run is complete if grep -q 'firstRun: true' $BFOLD/config.yaml; then echo "Template profile and admin user will have to be setup." @@ -148,14 +139,11 @@ new_instance() { if prompt_confirm "Ready to write all changes. Do you want to proceed?"; then - sudo -u $user mkdir $OCTOCONFIG/.$INSTANCE + mkdir $OCTOCONFIG/$INSTANCE - cat $SCRIPTDIR/octoprint_generic.service | \ - sed -e "s/OCTOUSER/$OCTOUSER/" \ - -e "s#OCTOPATH#$OCTOPATH#" \ - -e "s#OCTOCONFIG#$OCTOCONFIG#" \ - -e "s/NEWINSTANCE/$INSTANCE/" \ - -e "s/NEWPORT/$PORT/" > /etc/systemd/system/$INSTANCE.service + cat $SCRIPTDIR/docker-compose.yml | \ + sed -e "s/NEWINSTANCE/$INSTANCE/" \ + -e "s/NEWPORT/$PORT/" > /opt/octoprint/docker-compose.yml #write phase if [ -n "$UDEV" ] || [ -n "$USB" ]; then @@ -170,39 +158,37 @@ new_instance() { fi if [ -n "$TEMPLATE" ]; then - #There may be other combinations of things to include/exclude + echo "${magenta}Copying template files....${white}" if [ $COPY -eq 1 ]; then - sudo -u $user rsync -r \ + rsync -r \ --exclude 'timelapse' \ --exclude 'uploads' \ --exclude 'logs' \ - $BFOLD/* $OCTOCONFIG/.$INSTANCE/ + $BFOLD/* $OCTOCONFIG/$INSTANCE/octoprint/ fi if [ $COPY -eq 2 ]; then - sudo -u $user rsync -r \ + rsync -r \ --exclude 'timelapse' \ --exclude 'logs' \ - $BFOLD/* $OCTOCONFIG/.$INSTANCE/ + $BFOLD/* $OCTOCONFIG/$INSTANCE/octoprint/ fi - echo "${magenta}Copying template files....${white}" - #cp -rp $BFOLD/* $OCTOCONFIG/.$INSTANCE fi #uniquify instances echo 'Uniquifying instance...' - BASE=$OCTOCONFIG/.$INSTANCE - sudo -u $user $OCTOEXEC --basedir $BASE config set appearance.name $INSTANCE - sudo -u $user $OCTOEXEC --basedir $BASE config set server.commands.serverRestartCommand "sudo systemctl restart $INSTANCE" - sudo -u $user $OCTOEXEC --basedir $BASE config set server.commands.systemRestartCommand "sudo reboot" - sudo -u $user $OCTOEXEC --basedir $BASE config set plugins.discovery.upnpUuid $(uuidgen) - sudo -u $user $OCTOEXEC --basedir $BASE config set plugins.errortracking.unique_id $(uuidgen) - sudo -u $user $OCTOEXEC --basedir $BASE config set plugins.tracking.unique_id $(uuidgen) - sudo -u $user $OCTOEXEC --basedir $BASE config set serial.port /dev/octo_$INSTANCE + BASE=$OCTOCONFIG/$INSTANCE + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set appearance.name $INSTANCE + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.commands.serverRestartCommand "sudo systemctl restart $INSTANCE" + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.commands.systemRestartCommand "sudo reboot" + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set plugins.discovery.upnpUuid $(uuidgen) + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set plugins.errortracking.unique_id $(uuidgen) + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set plugins.tracking.unique_id $(uuidgen) + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set serial.port /dev/octo_$INSTANCE #clear additional ports - sudo -u $user $OCTOEXEC --basedir $BASE config remove serial.additionalPorts - sudo -u $user $OCTOEXEC --basedir $BASE config append_value serial.additionalPorts "/dev/octo_$INSTANCE" - sudo -u $user $OCTOEXEC --basedir $BASE config set feature.modelSizeDetection false --bool - sudo -u $user $OCTOEXEC --basedir $BASE config set webcam.ffmpeg /usr/bin/ffmpeg + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config remove serial.additionalPorts + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config append_value serial.additionalPorts "/dev/octo_$INSTANCE" + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set feature.modelSizeDetection false --bool + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set webcam.ffmpeg /usr/bin/ffmpeg if [ "$HAPROXY" == true ]; then HAversion=$(haproxy -v | sed -n 's/^.*version \([0-9]\).*/\1/p') @@ -333,11 +319,10 @@ printer_udev() { 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 2>/dev/null + #stop and remove docker + if [ "$(docker ps -a | grep $opt)" ]; then + docker stop $opt + docker rm $opt fi #Get all cameras associated with this instance. @@ -350,7 +335,7 @@ remove_instance() { #remove udev entry sed -i "/$opt/d" /etc/udev/rules.d/99-octoprint.rules #remove files - rm -rf /home/$user/.$opt + rm -rf /opt/octoprint/s$opt #remove from octoprint_instances sed -i "/$opt/d" /etc/octoprint_instances #remove haproxy entry diff --git a/menu.sh b/menu.sh old mode 100644 new mode 100755 index e4c722e..c8ec345 --- a/menu.sh +++ b/menu.sh @@ -9,7 +9,7 @@ yellow=$(echo -en "\e[93m") main_menu() { - VERSION=1.0.11 + VERSION=0.1 #reset UDEV='' TEMPUSB='' @@ -21,11 +21,11 @@ main_menu() { echo echo echo "${cyan}*************************${white}" - echo "${green}octoprint_deploy${white} $VERSION" + echo "${green}octodocker_deploy${white} $VERSION" echo "${cyan}*************************${white}" echo PS3="${green}Select operation: ${white}" - if [ -f "/etc/octoprint_deploy" ]; then + if [ -f "/etc/octodocker_deploy" ]; then options=("Add instance" "Delete instance" "Add USB Camera" "Add PiCam" "Delete Camera" "Utilities" "Backup Menu" "Update" "Quit") else options=("Prepare system" "Update" "Quit") @@ -258,7 +258,7 @@ restore_menu() { clear PS3="${green}Select backup to restore: ${white}" - readarray -t options < <(ls /home/$user/instance_backup/$opt-backup-*.zip) + readarray -t options < <(ls /opt/octoprint/instance_backup/$opt-backup-*.zip) options+=("Quit") select zipfile in "${options[@]}" do diff --git a/octocam_camstream.service b/octocam_camstream.service index 5ea34d6..bc8d207 100644 --- a/octocam_camstream.service +++ b/octocam_camstream.service @@ -3,9 +3,9 @@ Description=camera-streamer web camera for USB camera on Generic platform After=network.target [Service] -User=OCTOUSER +User=root EnvironmentFile=/etc/OCTOCAM.env -ExecStart=/home/OCTOUSER/camera-streamer/camera-streamer \ +ExecStart=/opt/octoprint/camera-streamer/camera-streamer \ --camera-path=${DEVICE} \ --camera-format=JPEG \ --camera-width=${WIDTH} -camera-height=${HEIGHT} \ diff --git a/octoprint_deploy.sh b/octoprint_deploy.sh index 78bdf9e..726c79f 100755 --- a/octoprint_deploy.sh +++ b/octoprint_deploy.sh @@ -6,21 +6,21 @@ if (( $EUID != 0 )); then exit fi -#this is a weak check, but will catch most cases -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 -fi +# #this is a weak check, but will catch most cases +# 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 +# fi # initiate logging -logfile='octoprint_deploy.log' +logfile='octodocker_deploy.log' SCRIPTDIR=$(dirname $(readlink -f $0)) source $SCRIPTDIR/plugins.sh source $SCRIPTDIR/prepare.sh diff --git a/octoprint_generic.service b/octoprint_generic.service index 638d9f5..099bf25 100644 --- a/octoprint_generic.service +++ b/octoprint_generic.service @@ -5,8 +5,8 @@ Wants=network.online.target [Service] Environment="PORT=NEWPORT" -Environment="BASEDIR=OCTOCONFIG/.NEWINSTANCE" -Environment="CONFIGFILE=OCTOCONFIG/.NEWINSTANCE/config.yaml" +Environment="BASEDIR=OCTOCONFIG/NEWINSTANCE" +Environment="CONFIGFILE=OCTOCONFIG/NEWINSTANCE/config.yaml" User=OCTOUSER ExecStart=OCTOPATH serve --config=${CONFIGFILE} --basedir=${BASEDIR} --port=${PORT} diff --git a/plugins.sh b/plugins.sh index d66c5d7..3cdab74 100755 --- a/plugins.sh +++ b/plugins.sh @@ -2,7 +2,7 @@ install_plugin() { echo "Installing $plugin...." - sudo -u $user $OCTOPIP install "$plugin_path" + $OCTOPIP install "$plugin_path" } plugin_menu() { diff --git a/prepare.sh b/prepare.sh index 049c052..8e86929 100644 --- a/prepare.sh +++ b/prepare.sh @@ -6,10 +6,10 @@ detect_installs() { echo "OctoPi installation detected." echo "Adding standard OctoPi instance to instance list." echo "instance:octoprint port:5000 udev:false" >> /etc/octoprint_instances - echo "octoexec: /home/$user/oprint/bin/octoprint" >> /etc/octoprint_deploy - echo "octopip: /home/$user/oprint/bin/pip" >> /etc/octoprint_deploy - echo "haproxy: true" >> /etc/octoprint_deploy - echo "octopi: true" >> /etc/octoprint_deploy + echo "octoexec: /opt/octoprint/oprint/bin/octoprint" >> /etc/octodocker_deploy + echo "octopip: /opt/octoprint/oprint/bin/pip" >> /etc/octodocker_deploy + echo "haproxy: true" >> /etc/octodocker_deploy + echo "octopi: true" >> /etc/octodocker_deploy echo "Adding systemctl and reboot to sudo" echo "$user ALL=NOPASSWD: /usr/bin/systemctl" > /etc/sudoers.d/octoprint_systemctl echo "$user ALL=NOPASSWD: /usr/sbin/reboot" > /etc/sudoers.d/octoprint_reboot @@ -31,8 +31,8 @@ detect_installs() { printer_udev true udevadm control --reload-rules udevadm trigger - sudo -u $user $OCTOEXEC config set serial.port /dev/octo_$INSTANCE - sudo -u $user $OCTOEXEC config append_value serial.additionalPorts "/dev/octo_$INSTANCE" + docker exec -it $INSTANCE $OCTOEXEC config set serial.port /dev/octo_$INSTANCE + docker exec -it $INSTANCE $OCTOEXEC config append_value serial.additionalPorts "/dev/octo_$INSTANCE" #convert UDEV to true sed -i "s/udev:false/udev:true/" /etc/octoprint_instances systemctl restart $INSTANCE @@ -40,12 +40,12 @@ detect_installs() { fi #streamer_install - echo "streamer: camera-streamer" >> /etc/octoprint_deploy + echo "streamer: camera-streamer" >> /etc/octodocker_deploy main_menu fi echo "Searching home directory for existing OctoPrint venv/binary....." - octopresent=$(find /home/$user/ -type f -executable -print | grep "bin/octoprint") + octopresent=$(find /opt/octoprint/ -type f -executable -print | grep "bin/octoprint") if [ -n "$octopresent" ]; then echo "OctoPrint binary found at $octopresent" echo "Did you try and setup OctoPrint in another way?" @@ -255,7 +255,7 @@ prepare () { } old_install() { - echo "octoexec:$octopresent" >> /etc/octoprint_deploy + echo "octoexec:$octopresent" >> /etc/octodocker_deploy user_groups haproxy_install streamer_install @@ -264,7 +264,7 @@ old_install() { new_install() { user_groups - OCTOEXEC=/home/$user/OctoPrint/bin/octoprint + OCTOEXEC=/usr/local/bin/octoprint echo "Adding systemctl and reboot to sudo" echo "$user ALL=NOPASSWD: /usr/bin/systemctl" > /etc/sudoers.d/octoprint_systemctl echo "$user ALL=NOPASSWD: /usr/sbin/reboot" > /etc/sudoers.d/octoprint_reboot @@ -311,18 +311,18 @@ new_install() { echo "Enabling ssh server..." systemctl enable ssh.service - echo "Installing OctoPrint virtual environment in /home/$user/OctoPrint" + echo "Installing OctoPrint virtual environment in /opt/octoprint/OctoPrint" #make venv - sudo -u $user $PYVERSION -m venv /home/$user/OctoPrint + $PYVERSION -m venv /opt/octoprint/OctoPrint #update pip - sudo -u $user /home/$user/OctoPrint/bin/pip install --upgrade pip + /opt/octoprint/OctoPrint/bin/pip install --upgrade pip #pre-install wheel - sudo -u $user /home/$user/OctoPrint/bin/pip install wheel + /opt/octoprint/OctoPrint/bin/pip install wheel #install oprint - sudo -u $user /home/$user/OctoPrint/bin/pip install OctoPrint + /opt/octoprint/OctoPrint/bin/pip install OctoPrint #Check to verify that OctoPrint binary is installed - if [ -f "/home/$user/OctoPrint/bin/octoprint" ]; then + if [ -f "/opt/octoprint/OctoPrint/bin/octoprint" ]; then echo "${cyan}OctoPrint apppears to have been installed successfully${white}" else echo "${red}WARNING! WARNING! WARNING!${white}" @@ -336,8 +336,8 @@ new_install() { streamer_install #These will retreived as settings - echo "octoexec: /home/$user/OctoPrint/bin/octoprint" >> /etc/octoprint_deploy - echo "octopip: /home/$user/OctoPrint/bin/pip" >> /etc/octoprint_deploy + echo "octoexec: /opt/octoprint/OctoPrint/bin/octoprint" >> /etc/octodocker_deploy + echo "octopip: /opt/octoprint/OctoPrint/bin/pip" >> /etc/octodocker_deploy #Create first instance echo @@ -363,9 +363,9 @@ haproxy_install() { echo echo if prompt_confirm "Use haproxy?"; then - echo 'haproxy: true' >> /etc/octoprint_deploy + echo 'haproxy: true' >> /etc/octodocker_deploy #Check if using improved haproxy rules - #echo 'haproxynew: true' >> /etc/octoprint_deploy + #echo 'haproxynew: true' >> /etc/octodocker_deploy systemctl stop haproxy #get haproxy version HAversion=$(haproxy -v | sed -n 's/^.*version \([0-9]\).*/\1/p') @@ -415,19 +415,19 @@ streamer_install() { #If we run this function directly, clean up streamer setting before installing get_settings - sed -i "/streamer/d" /etc/octoprint_deploy + sed -i "/streamer/d" /etc/octodocker_deploy if [ $VID -eq 1 ]; then - rm -rf /home/$user/mjpg_streamer 2>/dev/null + rm -rf /opt/octoprint/mjpg_streamer 2>/dev/null #install mjpg-streamer, not doing any error checking or anything echo 'Installing mjpeg-streamer' - sudo -u $user git -C /home/$user/ clone https://github.com/jacksonliam/mjpg-streamer.git mjpeg + git -C /opt/octoprint/ clone https://github.com/jacksonliam/mjpg-streamer.git mjpeg #apt -y install - sudo -u $user make -C /home/$user/mjpeg/mjpg-streamer-experimental > /dev/null + make -C /opt/octoprint/mjpeg/mjpg-streamer-experimental > /dev/null - sudo -u $user mv /home/$user/mjpeg/mjpg-streamer-experimental /home/$user/mjpg-streamer - sudo -u $user rm -rf /home/$user/mjpeg - if [ -f "/home/$user/mjpg-streamer/mjpg_streamer" ]; then + mv /opt/octoprint/mjpeg/mjpg-streamer-experimental /opt/octoprint/mjpg-streamer + rm -rf /opt/octoprint/mjpeg + if [ -f "/opt/octoprint/mjpg-streamer/mjpg_streamer" ]; then echo "Streamer installed successfully" else echo "${red}WARNING! WARNING! WARNING!${white}" @@ -436,15 +436,15 @@ streamer_install() { streamer_install fi fi - echo 'streamer: mjpg-streamer' >> /etc/octoprint_deploy + echo 'streamer: mjpg-streamer' >> /etc/octodocker_deploy fi if [ $VID -eq 2 ]; then - rm -rf /home/$user/ustreamer 2>/dev/null + rm -rf /opt/octoprint/ustreamer 2>/dev/null #install ustreamer - sudo -u $user git -C /home/$user clone --depth=1 https://github.com/pikvm/ustreamer - sudo -u $user make -C /home/$user/ustreamer > /dev/null - if [ -f "/home/$user/ustreamer/ustreamer" ] || [ -f "/home/$user/ustreamer/ustreamer.bin" ]; then + git -C /opt/octoprint clone --depth=1 https://github.com/pikvm/ustreamer + make -C /opt/octoprint/ustreamer > /dev/null + if [ -f "/opt/octoprint/ustreamer/ustreamer" ] || [ -f "/opt/octoprint/ustreamer/ustreamer.bin" ]; then echo "Streamer installed successfully" else echo "${red}WARNING! WARNING! WARNING!${white}" @@ -453,18 +453,18 @@ streamer_install() { streamer_install fi fi - if [ -f "/home/$user/ustreamer/ustreamer.bin" ]; then - sudo -u $user ln -s /home/$user/ustreamer/ustreamer.bin /home/$user/ustreamer/ustreamer + if [ -f "/opt/octoprint/ustreamer/ustreamer.bin" ]; then + ln -s /opt/octoprint/ustreamer/ustreamer.bin /opt/octoprint/ustreamer/ustreamer fi - echo 'streamer: ustreamer' >> /etc/octoprint_deploy + echo 'streamer: ustreamer' >> /etc/octodocker_deploy fi if [ $VID -eq 4 ]; then - rm -rf /home/$user/camera-streamer 2>/dev/null + rm -rf /opt/octoprint/camera-streamer 2>/dev/null #install camera-streamer - sudo -u $user git -C /home/$user clone https://github.com/ayufan-research/camera-streamer.git --recursive - sudo -u $user make -C /home/$user/camera-streamer > /dev/null - if [ -f "/home/$user/camera-streamer/camera-streamer" ]; then + git -C /opt/octoprint clone https://github.com/ayufan-research/camera-streamer.git --recursive + make -C /opt/octoprint/camera-streamer > /dev/null + if [ -f "/opt/octoprint/camera-streamer/camera-streamer" ]; then echo "Streamer installed successfully" else echo "${red}WARNING! WARNING! WARNING!${white}" @@ -473,11 +473,11 @@ streamer_install() { streamer_install fi fi - echo 'streamer: camera-streamer' >> /etc/octoprint_deploy + echo 'streamer: camera-streamer' >> /etc/octodocker_deploy fi if [ $VID -eq 3 ]; then - echo 'streamer: none' >> /etc/octoprint_deploy + echo 'streamer: none' >> /etc/octodocker_deploy echo "Good for you! Cameras are just annoying anyway." fi @@ -522,7 +522,7 @@ firstrun_install() { done echo "Admin password: ${cyan}$OCTOPASS${white}" - sudo -u $user $OCTOEXEC --basedir $BASE user add $OCTOADMIN --password $OCTOPASS --admin + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE user add $OCTOADMIN --password $OCTOPASS --admin fi if [ -n "$OCTOADMIN" ]; then @@ -534,13 +534,13 @@ firstrun_install() { echo echo if prompt_confirm "Complete first run wizards now?"; then - sudo -u $user $OCTOEXEC --basedir $BASE config set server.firstRun false --bool - sudo -u $user $OCTOEXEC --basedir $BASE config set server.seenWizards.backup null - sudo -u $user $OCTOEXEC --basedir $BASE config set server.seenWizards.corewizard 4 --int - sudo -u $user $OCTOEXEC --basedir $BASE config set server.onlineCheck.enabled true --bool - sudo -u $user $OCTOEXEC --basedir $BASE config set server.pluginBlacklist.enabled true --bool - sudo -u $user $OCTOEXEC --basedir $BASE config set plugins.tracking.enabled true --bool - sudo -u $user $OCTOEXEC --basedir $BASE config set printerProfiles.default _default + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.firstRun false --bool + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.seenWizards.backup null + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.seenWizards.corewizard 4 --int + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.onlineCheck.enabled true --bool + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.pluginBlacklist.enabled true --bool + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set plugins.tracking.enabled true --bool + docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set printerProfiles.default _default fi fi diff --git a/util.sh b/util.sh old mode 100644 new mode 100755 index fab8a25..357fc1d --- a/util.sh +++ b/util.sh @@ -26,12 +26,12 @@ has-space () { } get_settings() { - #Get octoprint_deploy settings, all of which are written on system prepare - if [ -f /etc/octoprint_deploy ]; then - OCTOEXEC=$(cat /etc/octoprint_deploy | sed -n -e 's/^octoexec: \(\.*\)/\1/p') - OCTOPIP=$(cat /etc/octoprint_deploy | sed -n -e 's/^octopip: \(\.*\)/\1/p') - STREAMER=$(cat /etc/octoprint_deploy | sed -n -e 's/^streamer: \(\.*\)/\1/p') - HAPROXY=$(cat /etc/octoprint_deploy | sed -n -e 's/^haproxy: \(\.*\)/\1/p') + #Get octodocker_deploy settings, all of which are written on system prepare + if [ -f /etc/octodocker_deploy ]; then + OCTOEXEC=/usr/local/bin/octoprint + OCTOPIP=/usr/local/bin/pip + STREAMER=$(cat /etc/octodocker_deploy | sed -n -e 's/^streamer: \(\.*\)/\1/p') + HAPROXY=$(cat /etc/octodocker_deploy | sed -n -e 's/^haproxy: \(\.*\)/\1/p') fi } @@ -53,26 +53,26 @@ global_config() { } octo_deploy_update() { - sudo -u $user git -C $SCRIPTDIR pull + git -C $SCRIPTDIR pull exit } back_up() { INSTANCE=$1 echo "Creating backup of $INSTANCE...." - sudo -u $user $OCTOEXEC --basedir /home/$user/.$INSTANCE plugins backup:backup --exclude timelapse - sudo -u $user mkdir /home/$user/instance_backup 2>/dev/null - sudo -u $user mv /home/$user/.$INSTANCE/data/backup/*.zip /home/$user/instance_backup/ - echo "Zipped instance backup created in /home/$user/instance_backup" + docker exec -it $INSTANCE $OCTOEXEC --basedir /opt/octoprint/$INSTANCE plugins backup:backup --exclude timelapse + mkdir /opt/octoprint/instance_backup 2>/dev/null + mv /opt/octoprint/$INSTANCE/data/backup/*.zip /opt/octoprint/instance_backup/ + echo "Zipped instance backup created in /opt/octoprint/instance_backup" } restore() { INSTANCE=$1 TAR=$2 echo "Restoring backup of $INSTANCE...." - systemctl stop $INSTANCE - sudo -u $user $OCTOEXEC --basedir /home/$user/.$INSTANCE plugins backup:restore $TAR - systemctl start $INSTANCE + docker stop $INSTANCE + docker exec -it $INSTANCE $OCTOEXEC --basedir /opt/octoprint/$INSTANCE plugins backup:restore $TAR + docker start $INSTANCE } @@ -119,14 +119,14 @@ sync_users() { fi if prompt_confirm "Copy users from instance $opt to all other instances?"; then - userfile=/home/$user/.$opt/users.yaml + userfile=/opt/octoprint/$opt/users.yaml #re-read to avoid the Quit get_instances false for instance in "${INSTANCE_ARR[@]}"; do if [ "$instance" == "$opt" ]; then continue fi - sudo -u $user cp $userfile /home/$user/.$instance/ + cp $userfile /opt/octoprint/$instance/ done if prompt_confirm "Restart all instances now for changes to take effect?"; then @@ -157,7 +157,7 @@ share_uploads() { fi if [ "$opt" == "Custom" ]; then - echo "Enter full path (should start /home/$user/):" + echo "Enter full path (should start /opt/octoprint/):" read ULPATH if [ -d "$ULPATH" ]; then if prompt_confirm "This folder already exists. Are you sure you want to use it?"; then @@ -168,19 +168,19 @@ share_uploads() { break fi else - sudo -u $user mkdir $ULPATH + mkdir $ULPATH opt=$ULPATH fi else - opt=/home/$user/.$opt/uploads + opt=/opt/octoprint/$opt/uploads fi echo #Remove Quit and Custom from array, is there a cleaner way? unset 'INSTANCE_ARR[-1]' unset 'INSTANCE_ARR[-1]' for instance in "${INSTANCE_ARR[@]}"; do - sudo -u $user $OCTOEXEC --basedir /home/$user/.$instance config set folder.uploads "$opt" + docker exec -it $INSTANCE $OCTOEXEC --basedir /opt/octoprint/$INSTANCEinstance config set folder.uploads "$opt" done break done @@ -293,7 +293,7 @@ instance_status() { echo "$instance - $status" done echo "${cyan}*******************************************${white}" - echo "Only instances and cameras made with octoprint_deploy are shown" + echo "Only instances and cameras made with octodocker_deploy are shown" echo main_menu } @@ -322,21 +322,14 @@ remove_everything() { done echo "Removing system stuff" - rm /etc/systemd/system/octoprint.service 2>/dev/null rm /etc/octoprint_streamer 2>/dev/null - rm /etc/octoprint_deploy 2>/dev/null + rm /etc/octodocker_deploy 2>/dev/null rm /etc/octoprint_instances 2>/dev/null rm /etc/octoprint_cameras 2>/dev/null rm /etc/udev/rules.d/99-octoprint.rules 2>/dev/null - rm /etc/sudoers.d/octoprint_reboot 2>/dev/null - rm /etc/sudoers.d/octoprint_systemctl 2>/dev/null - rm -rf /home/$user/.octoprint 2>/dev/null - rm -rf /home/$user/OctoPrint 2>/dev/null - rm -rf /home/$user/ustreamer 2>/dev/null - rm -rf /home/$user/mjpg-streamer 2>/dev/null - rm -rf /home/$user/camera-streamer 2>/dev/null - systemctl restart haproxy.service - systemctl daemon-reload + rm -rf /opt/octoprint/ustreamer 2>/dev/null + rm -rf /opt/octoprint/mjpg-streamer 2>/dev/null + rm -rf /opt/octoprint/camera-streamer 2>/dev/null fi } @@ -346,7 +339,7 @@ restart_all() { get_instances false for instance in "${INSTANCE_ARR[@]}"; do echo "Trying to restart instance $instance" - systemctl restart $instance + docker restart $instance done main_menu } @@ -381,9 +374,9 @@ diagnostic_output() { diagnostics() { get_settings - logfile='octoprint_deploy_diagnostic.log' - echo "octoprint_deploy diagnostic information. Please provide ALL output for support help" - diagnostic_output /etc/octoprint_deploy | log + logfile='octodocker_deploy_diagnostic.log' + echo "octodocker_deploy diagnostic information. Please provide ALL output for support help" + diagnostic_output /etc/octodocker_deploy | log diagnostic_output /etc/octoprint_instances | log diagnostic_output /etc/octoprint_cameras | log diagnostic_output /etc/udev/rules.d/99-octoprint.rules | log @@ -395,9 +388,9 @@ diagnostics() { echo "**************************************" | log systemctl status $instance -l --no-pager | log #get needed config info - sudo -u $user $OCTOEXEC --basedir=/home/$user/.$INSTANCE config get plugins.classicwebcam | log - #sudo -u $user $OCTOEXEC --basedir=/home/$user/.$INSTANCE config get plugins.classicwebcam.snapshot | log - sudo -u $user $OCTOEXEC --basedir=/home/$user/.$INSTANCE config get webcam | log + docker exec -it $INSTANCE $OCTOEXEC --basedir=/opt/octoprint/$INSTANCE config get plugins.classicwebcam | log + #docker exec -it $INSTANCE $OCTOEXEC --basedir=/opt/octoprint/$INSTANCE config get plugins.classicwebcam.snapshot | log + docker exec -it $INSTANCE $OCTOEXEC --basedir=/opt/octoprint/$INSTANCE config get webcam | log done #get all cam status get_cameras false @@ -408,6 +401,6 @@ diagnostics() { #get haproxy status echo "**************************************" | log systemctl status haproxy -l --no-pager | log - logfile='octoprint_deploy.log' + logfile='octodocker_deploy.log' main_menu } \ No newline at end of file