initial code changes

This commit is contained in:
2024-07-27 16:47:44 -05:00
parent 26b0a5fa19
commit d83353e61f
12 changed files with 196 additions and 194 deletions

View File

@@ -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! # 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 * 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. * 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 # How to use
* OctoPi * 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. * 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!). * 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 `git clone https://github.com/paukstelis/octodocker_deploy`.
* run the command `sudo octoprint_deploy/octoprint_deploy.sh`. * run the command `sudo octodocker_deploy/octodocker_deploy.sh`.
* Choose `Prepare System` from the menu. * 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 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. * 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. * 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! * To add more printers at a later date, just run the script again!
* General Linux (Ubuntu/Mint/RPiOS/Debian/Fedora/Arch/etc.) * 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.__ * __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. * 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 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`. * 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 `git clone https://github.com/paukstelis/octodocker_deploy`.
* run the command `sudo octoprint_deploy/octoprint_deploy.sh`. * 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. * 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 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 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 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 setup the admin user and do the first run wizard via the commandline.
* You will be prompted if you want to install recommended plugins. * 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. * 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. * 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. * 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. * 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: * Utility menu - use the utility menu in the script to:
* Add or remove instances or cameras * Add or remove instances or cameras
* Check the status of all instances * 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 which camera streaming software is used (WIP)
* Modify a setting for all instances using the OctoPrint CLI interface (WIP) * Modify a setting for all instances using the OctoPrint CLI interface (WIP)
* Add/Remove udev rules for printers and cameras * 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 * Other features from commandline arguments
* Want to get rid of everything? `sudo octoprint_deploy/octoprint_deploy.sh remove` * 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 octoprint_deploy/octoprint_deploy backup` * 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 octoprint_deploy/octoprint_deploy.sh restart_all` * 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. * 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 # Recent Changes
* Include additional libcamera packages and libcamerify when ustreamer is used with PiCam * 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 an issue with Fedora python versioning.
* Fix change for ustreamer executable being renamed ustreamer.bin * Fix change for ustreamer executable being renamed ustreamer.bin
* Improve Instance Status function. * 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`. * Camera settings written to separate env file. This can be found and edited at `/etc/cam_instancename.env`.
# TODO # TODO
* Integration with OctoPi new camera stack. This may or may not happen. * Integration with OctoPi new camera stack. This may or may not happen.

2
README.old Normal file
View File

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

View File

@@ -58,7 +58,6 @@ write_camera() {
#mjpg-streamer #mjpg-streamer
if [ "$STREAMER" == mjpg-streamer ]; then if [ "$STREAMER" == mjpg-streamer ]; then
cat $SCRIPTDIR/octocam_mjpg.service | \ cat $SCRIPTDIR/octocam_mjpg.service | \
sed -e "s/OCTOUSER/$OCTOUSER/" \
-e "s/OCTOCAM/$CAMDEVICE/" \ -e "s/OCTOCAM/$CAMDEVICE/" \
-e "s/RESOLUTION/$RESOLUTION/" \ -e "s/RESOLUTION/$RESOLUTION/" \
-e "s/FRAMERATE/$FRAMERATE/" \ -e "s/FRAMERATE/$FRAMERATE/" \
@@ -69,12 +68,10 @@ write_camera() {
if [ "$STREAMER" == ustreamer ]; then if [ "$STREAMER" == ustreamer ]; then
if [ "$PI" == true ]; then if [ "$PI" == true ]; then
cat $SCRIPTDIR/octocam_ustream.service | \ cat $SCRIPTDIR/octocam_ustream.service | \
sed -e "s/OCTOUSER/$OCTOUSER/" \
-e "s/OCTOCAM/cam${INUM}_$INSTANCE/" \ -e "s/OCTOCAM/cam${INUM}_$INSTANCE/" \
-e "s|ExecStart=|ExecStart=/usr/bin/libcamerify |" > $SCRIPTDIR/$OUTFILE.service -e "s|ExecStart=|ExecStart=/usr/bin/libcamerify |" > $SCRIPTDIR/$OUTFILE.service
else else
cat $SCRIPTDIR/octocam_ustream.service | \ cat $SCRIPTDIR/octocam_ustream.service | \
sed -e "s/OCTOUSER/$OCTOUSER/" \
-e "s/OCTOCAM/cam${INUM}_$INSTANCE/" > $SCRIPTDIR/$OUTFILE.service -e "s/OCTOCAM/cam${INUM}_$INSTANCE/" > $SCRIPTDIR/$OUTFILE.service
fi fi
fi fi
@@ -83,11 +80,9 @@ write_camera() {
if [ "$STREAMER" == camera-streamer ]; then if [ "$STREAMER" == camera-streamer ]; then
if [ "$PI" == true ]; then if [ "$PI" == true ]; then
cat $SCRIPTDIR/picam_camstream.service | \ cat $SCRIPTDIR/picam_camstream.service | \
sed -e "s/OCTOUSER/$OCTOUSER/" \
-e "s/OCTOCAM/cam${INUM}_$INSTANCE/" > $SCRIPTDIR/$OUTFILE.service -e "s/OCTOCAM/cam${INUM}_$INSTANCE/" > $SCRIPTDIR/$OUTFILE.service
else else
cat $SCRIPTDIR/octocam_camstream.service | \ cat $SCRIPTDIR/octocam_camstream.service | \
sed -e "s/OCTOUSER/$OCTOUSER/" \
-e "s/OCTOCAM/cam${INUM}_$INSTANCE/" > $SCRIPTDIR/$OUTFILE.service -e "s/OCTOCAM/cam${INUM}_$INSTANCE/" > $SCRIPTDIR/$OUTFILE.service
fi fi
fi fi
@@ -96,27 +91,27 @@ write_camera() {
CAMWIDTH=$(sed -r 's/^([0-9]+)x[0-9]+/\1/' <<<"$RESOLUTION") CAMWIDTH=$(sed -r 's/^([0-9]+)x[0-9]+/\1/' <<<"$RESOLUTION")
CAMHEIGHT=$(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 echo "DEVICE=$CAMDEVICE" >> /etc/$OUTFILE.env
sudo -u $user echo "RES=$RESOLUTION" >> /etc/$OUTFILE.env echo "RES=$RESOLUTION" >> /etc/$OUTFILE.env
sudo -u $user echo "FRAMERATE=$FRAMERATE" >> /etc/$OUTFILE.env echo "FRAMERATE=$FRAMERATE" >> /etc/$OUTFILE.env
sudo -u $user echo "PORT=$CAMPORT" >> /etc/$OUTFILE.env echo "PORT=$CAMPORT" >> /etc/$OUTFILE.env
sudo -u $user echo "WIDTH=$CAMWIDTH" >> /etc/$OUTFILE.env echo "WIDTH=$CAMWIDTH" >> /etc/$OUTFILE.env
sudo -u $user echo "HEIGHT=$CAMHEIGHT" >> /etc/$OUTFILE.env echo "HEIGHT=$CAMHEIGHT" >> /etc/$OUTFILE.env
cp $SCRIPTDIR/$OUTFILE.service /etc/systemd/system/ cp $SCRIPTDIR/$OUTFILE.service /etc/systemd/system/
echo "camera:cam${INUM}_$INSTANCE port:$CAMPORT udev:true" >> /etc/octoprint_cameras echo "camera:cam${INUM}_$INSTANCE port:$CAMPORT udev:true" >> /etc/octoprint_cameras
#config.yaml modifications - only if INUM not set #config.yaml modifications - only if INUM not set
if [ -z "$INUM" ]; then 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 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 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 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 if prompt_confirm "Instance must be restarted for settings to take effect. Restart now?"; then
systemctl restart $INSTANCE systemctl restart $INSTANCE
@@ -189,9 +184,8 @@ add_camera() {
fi fi
echo "Selected instance for camera: ${cyan}$camopt${white}" echo "Selected instance for camera: ${cyan}$camopt${white}"
INSTANCE=$camopt INSTANCE=$camopt
OCTOCONFIG="/home/$user/" OCTOCONFIG="/opt/octoprint/"
BASE="/home/$user/.$INSTANCE" BASE="/opt/octoprint/$INSTANCE"
OCTOUSER=$user
if grep -q "cam_$INSTANCE" /etc/udev/rules.d/99-octoprint.rules; then if grep -q "cam_$INSTANCE" /etc/udev/rules.d/99-octoprint.rules; then
echo "It appears this instance already has at least one camera." 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 if prompt_confirm "Do you want to add an additional camera for this instance?"; then

21
docker-compose.yml Normal file
View File

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

81
instance.sh Normal file → Executable file
View File

@@ -84,29 +84,20 @@ new_instance() {
fi fi
if prompt_confirm "Ready to begin instance creation?"; then if prompt_confirm "Ready to begin instance creation?"; then
#CHANGE PORT=5000
if [ -f /etc/octoprint_instances ]; then PORTS_INUSE=$(join_by , $(cat /etc/octoprint_instances 2>/dev/null | sed -n -e 's/^.*\(port:\)\(.*\) udev:.*/\2/p'))
PORT=$(tail -1 /etc/octoprint_instances 2>/dev/null | sed -n -e 's/^.*\(port:\)\(.*\) udev:.*/\2/p') until [[ "${PORTS_INUSE}" != *"${PORT}"* ]]; do ((PORT++)); done
fi
if [ -z "$PORT" ]; then
PORT=4999
fi
PORT=$((PORT+1))
echo Selected port is: $PORT echo Selected port is: $PORT
#CHANGE OCTOCONFIG="/opt/octoprint"
OCTOUSER=$user
OCTOPATH=$OCTOEXEC
OCTOCONFIG="/home/$user"
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
echo echo
else else
if [ "$firstrun" == "true" ]; then if [ "$firstrun" == "true" ]; then
echo "${red}You will need to restart your installation.${white}" 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 remove_everything
exit exit
else else
@@ -115,7 +106,7 @@ new_instance() {
fi fi
if [ -n "$TEMPLATE" ]; then if [ -n "$TEMPLATE" ]; then
BFOLD="/home/$user/.$TEMPLATE" BFOLD="/opt/octoprint/$INSTANCE$TEMPLATE"
#check to make sure first run is complete #check to make sure first run is complete
if grep -q 'firstRun: true' $BFOLD/config.yaml; then if grep -q 'firstRun: true' $BFOLD/config.yaml; then
echo "Template profile and admin user will have to be setup." 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 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 | \ cat $SCRIPTDIR/docker-compose.yml | \
sed -e "s/OCTOUSER/$OCTOUSER/" \ sed -e "s/NEWINSTANCE/$INSTANCE/" \
-e "s#OCTOPATH#$OCTOPATH#" \ -e "s/NEWPORT/$PORT/" > /opt/octoprint/docker-compose.yml
-e "s#OCTOCONFIG#$OCTOCONFIG#" \
-e "s/NEWINSTANCE/$INSTANCE/" \
-e "s/NEWPORT/$PORT/" > /etc/systemd/system/$INSTANCE.service
#write phase #write phase
if [ -n "$UDEV" ] || [ -n "$USB" ]; then if [ -n "$UDEV" ] || [ -n "$USB" ]; then
@@ -170,39 +158,37 @@ new_instance() {
fi fi
if [ -n "$TEMPLATE" ]; then 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 if [ $COPY -eq 1 ]; then
sudo -u $user rsync -r \ rsync -r \
--exclude 'timelapse' \ --exclude 'timelapse' \
--exclude 'uploads' \ --exclude 'uploads' \
--exclude 'logs' \ --exclude 'logs' \
$BFOLD/* $OCTOCONFIG/.$INSTANCE/ $BFOLD/* $OCTOCONFIG/$INSTANCE/octoprint/
fi fi
if [ $COPY -eq 2 ]; then if [ $COPY -eq 2 ]; then
sudo -u $user rsync -r \ rsync -r \
--exclude 'timelapse' \ --exclude 'timelapse' \
--exclude 'logs' \ --exclude 'logs' \
$BFOLD/* $OCTOCONFIG/.$INSTANCE/ $BFOLD/* $OCTOCONFIG/$INSTANCE/octoprint/
fi fi
echo "${magenta}Copying template files....${white}"
#cp -rp $BFOLD/* $OCTOCONFIG/.$INSTANCE
fi fi
#uniquify instances #uniquify instances
echo 'Uniquifying instance...' echo 'Uniquifying instance...'
BASE=$OCTOCONFIG/.$INSTANCE BASE=$OCTOCONFIG/$INSTANCE
sudo -u $user $OCTOEXEC --basedir $BASE config set appearance.name $INSTANCE docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set appearance.name $INSTANCE
sudo -u $user $OCTOEXEC --basedir $BASE config set server.commands.serverRestartCommand "sudo systemctl restart $INSTANCE" docker exec -it $INSTANCE $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" docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.commands.systemRestartCommand "sudo reboot"
sudo -u $user $OCTOEXEC --basedir $BASE config set plugins.discovery.upnpUuid $(uuidgen) docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set plugins.discovery.upnpUuid $(uuidgen)
sudo -u $user $OCTOEXEC --basedir $BASE config set plugins.errortracking.unique_id $(uuidgen) docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set plugins.errortracking.unique_id $(uuidgen)
sudo -u $user $OCTOEXEC --basedir $BASE config set plugins.tracking.unique_id $(uuidgen) docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set plugins.tracking.unique_id $(uuidgen)
sudo -u $user $OCTOEXEC --basedir $BASE config set serial.port /dev/octo_$INSTANCE docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set serial.port /dev/octo_$INSTANCE
#clear additional ports #clear additional ports
sudo -u $user $OCTOEXEC --basedir $BASE config remove serial.additionalPorts docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config remove serial.additionalPorts
sudo -u $user $OCTOEXEC --basedir $BASE config append_value serial.additionalPorts "/dev/octo_$INSTANCE" docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config append_value serial.additionalPorts "/dev/octo_$INSTANCE"
sudo -u $user $OCTOEXEC --basedir $BASE config set feature.modelSizeDetection false --bool docker exec -it $INSTANCE $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 set webcam.ffmpeg /usr/bin/ffmpeg
if [ "$HAPROXY" == true ]; then if [ "$HAPROXY" == true ]; then
HAversion=$(haproxy -v | sed -n 's/^.*version \([0-9]\).*/\1/p') HAversion=$(haproxy -v | sed -n 's/^.*version \([0-9]\).*/\1/p')
@@ -333,11 +319,10 @@ printer_udev() {
remove_instance() { remove_instance() {
opt=$1 opt=$1
#disable and remove service file #stop and remove docker
if [ -f /etc/systemd/system/$opt.service ]; then if [ "$(docker ps -a | grep $opt)" ]; then
systemctl stop $opt.service docker stop $opt
systemctl disable $opt.service docker rm $opt
rm /etc/systemd/system/$opt.service 2>/dev/null
fi fi
#Get all cameras associated with this instance. #Get all cameras associated with this instance.
@@ -350,7 +335,7 @@ remove_instance() {
#remove udev entry #remove udev entry
sed -i "/$opt/d" /etc/udev/rules.d/99-octoprint.rules sed -i "/$opt/d" /etc/udev/rules.d/99-octoprint.rules
#remove files #remove files
rm -rf /home/$user/.$opt rm -rf /opt/octoprint/s$opt
#remove from octoprint_instances #remove from octoprint_instances
sed -i "/$opt/d" /etc/octoprint_instances sed -i "/$opt/d" /etc/octoprint_instances
#remove haproxy entry #remove haproxy entry

8
menu.sh Normal file → Executable file
View File

@@ -9,7 +9,7 @@ yellow=$(echo -en "\e[93m")
main_menu() { main_menu() {
VERSION=1.0.11 VERSION=0.1
#reset #reset
UDEV='' UDEV=''
TEMPUSB='' TEMPUSB=''
@@ -21,11 +21,11 @@ main_menu() {
echo echo
echo echo
echo "${cyan}*************************${white}" echo "${cyan}*************************${white}"
echo "${green}octoprint_deploy${white} $VERSION" echo "${green}octodocker_deploy${white} $VERSION"
echo "${cyan}*************************${white}" echo "${cyan}*************************${white}"
echo echo
PS3="${green}Select operation: ${white}" 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") options=("Add instance" "Delete instance" "Add USB Camera" "Add PiCam" "Delete Camera" "Utilities" "Backup Menu" "Update" "Quit")
else else
options=("Prepare system" "Update" "Quit") options=("Prepare system" "Update" "Quit")
@@ -258,7 +258,7 @@ restore_menu() {
clear clear
PS3="${green}Select backup to restore: ${white}" 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") options+=("Quit")
select zipfile in "${options[@]}" select zipfile in "${options[@]}"
do do

View File

@@ -3,9 +3,9 @@ Description=camera-streamer web camera for USB camera on Generic platform
After=network.target After=network.target
[Service] [Service]
User=OCTOUSER User=root
EnvironmentFile=/etc/OCTOCAM.env EnvironmentFile=/etc/OCTOCAM.env
ExecStart=/home/OCTOUSER/camera-streamer/camera-streamer \ ExecStart=/opt/octoprint/camera-streamer/camera-streamer \
--camera-path=${DEVICE} \ --camera-path=${DEVICE} \
--camera-format=JPEG \ --camera-format=JPEG \
--camera-width=${WIDTH} -camera-height=${HEIGHT} \ --camera-width=${WIDTH} -camera-height=${HEIGHT} \

View File

@@ -6,21 +6,21 @@ if (( $EUID != 0 )); then
exit exit
fi fi
#this is a weak check, but will catch most cases # #this is a weak check, but will catch most cases
if [ $SUDO_USER ]; then # if [ $SUDO_USER ]; then
user=$SUDO_USER # user=$SUDO_USER
else # else
echo "You should not run this script as root. Use sudo as a normal user" # echo "You should not run this script as root. Use sudo as a normal user"
exit # exit
fi # fi
#
if [ "$user" == root ]; then # if [ "$user" == root ]; then
echo "You should not run this script as root. Use sudo as a normal user" # echo "You should not run this script as root. Use sudo as a normal user"
exit # exit
fi # fi
# initiate logging # initiate logging
logfile='octoprint_deploy.log' logfile='octodocker_deploy.log'
SCRIPTDIR=$(dirname $(readlink -f $0)) SCRIPTDIR=$(dirname $(readlink -f $0))
source $SCRIPTDIR/plugins.sh source $SCRIPTDIR/plugins.sh
source $SCRIPTDIR/prepare.sh source $SCRIPTDIR/prepare.sh

View File

@@ -5,8 +5,8 @@ Wants=network.online.target
[Service] [Service]
Environment="PORT=NEWPORT" Environment="PORT=NEWPORT"
Environment="BASEDIR=OCTOCONFIG/.NEWINSTANCE" Environment="BASEDIR=OCTOCONFIG/NEWINSTANCE"
Environment="CONFIGFILE=OCTOCONFIG/.NEWINSTANCE/config.yaml" Environment="CONFIGFILE=OCTOCONFIG/NEWINSTANCE/config.yaml"
User=OCTOUSER User=OCTOUSER
ExecStart=OCTOPATH serve --config=${CONFIGFILE} --basedir=${BASEDIR} --port=${PORT} ExecStart=OCTOPATH serve --config=${CONFIGFILE} --basedir=${BASEDIR} --port=${PORT}

View File

@@ -2,7 +2,7 @@
install_plugin() { install_plugin() {
echo "Installing $plugin...." echo "Installing $plugin...."
sudo -u $user $OCTOPIP install "$plugin_path" $OCTOPIP install "$plugin_path"
} }
plugin_menu() { plugin_menu() {

View File

@@ -6,10 +6,10 @@ detect_installs() {
echo "OctoPi installation detected." echo "OctoPi installation detected."
echo "Adding standard OctoPi instance to instance list." echo "Adding standard OctoPi instance to instance list."
echo "instance:octoprint port:5000 udev:false" >> /etc/octoprint_instances echo "instance:octoprint port:5000 udev:false" >> /etc/octoprint_instances
echo "octoexec: /home/$user/oprint/bin/octoprint" >> /etc/octoprint_deploy echo "octoexec: /opt/octoprint/oprint/bin/octoprint" >> /etc/octodocker_deploy
echo "octopip: /home/$user/oprint/bin/pip" >> /etc/octoprint_deploy echo "octopip: /opt/octoprint/oprint/bin/pip" >> /etc/octodocker_deploy
echo "haproxy: true" >> /etc/octoprint_deploy echo "haproxy: true" >> /etc/octodocker_deploy
echo "octopi: true" >> /etc/octoprint_deploy echo "octopi: true" >> /etc/octodocker_deploy
echo "Adding systemctl and reboot to sudo" echo "Adding systemctl and reboot to sudo"
echo "$user ALL=NOPASSWD: /usr/bin/systemctl" > /etc/sudoers.d/octoprint_systemctl echo "$user ALL=NOPASSWD: /usr/bin/systemctl" > /etc/sudoers.d/octoprint_systemctl
echo "$user ALL=NOPASSWD: /usr/sbin/reboot" > /etc/sudoers.d/octoprint_reboot echo "$user ALL=NOPASSWD: /usr/sbin/reboot" > /etc/sudoers.d/octoprint_reboot
@@ -31,8 +31,8 @@ detect_installs() {
printer_udev true printer_udev true
udevadm control --reload-rules udevadm control --reload-rules
udevadm trigger udevadm trigger
sudo -u $user $OCTOEXEC config set serial.port /dev/octo_$INSTANCE docker exec -it $INSTANCE $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 append_value serial.additionalPorts "/dev/octo_$INSTANCE"
#convert UDEV to true #convert UDEV to true
sed -i "s/udev:false/udev:true/" /etc/octoprint_instances sed -i "s/udev:false/udev:true/" /etc/octoprint_instances
systemctl restart $INSTANCE systemctl restart $INSTANCE
@@ -40,12 +40,12 @@ detect_installs() {
fi fi
#streamer_install #streamer_install
echo "streamer: camera-streamer" >> /etc/octoprint_deploy echo "streamer: camera-streamer" >> /etc/octodocker_deploy
main_menu main_menu
fi fi
echo "Searching home directory for existing OctoPrint venv/binary....." 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 if [ -n "$octopresent" ]; then
echo "OctoPrint binary found at $octopresent" echo "OctoPrint binary found at $octopresent"
echo "Did you try and setup OctoPrint in another way?" echo "Did you try and setup OctoPrint in another way?"
@@ -255,7 +255,7 @@ prepare () {
} }
old_install() { old_install() {
echo "octoexec:$octopresent" >> /etc/octoprint_deploy echo "octoexec:$octopresent" >> /etc/octodocker_deploy
user_groups user_groups
haproxy_install haproxy_install
streamer_install streamer_install
@@ -264,7 +264,7 @@ old_install() {
new_install() { new_install() {
user_groups user_groups
OCTOEXEC=/home/$user/OctoPrint/bin/octoprint OCTOEXEC=/usr/local/bin/octoprint
echo "Adding systemctl and reboot to sudo" echo "Adding systemctl and reboot to sudo"
echo "$user ALL=NOPASSWD: /usr/bin/systemctl" > /etc/sudoers.d/octoprint_systemctl echo "$user ALL=NOPASSWD: /usr/bin/systemctl" > /etc/sudoers.d/octoprint_systemctl
echo "$user ALL=NOPASSWD: /usr/sbin/reboot" > /etc/sudoers.d/octoprint_reboot echo "$user ALL=NOPASSWD: /usr/sbin/reboot" > /etc/sudoers.d/octoprint_reboot
@@ -311,18 +311,18 @@ new_install() {
echo "Enabling ssh server..." echo "Enabling ssh server..."
systemctl enable ssh.service systemctl enable ssh.service
echo "Installing OctoPrint virtual environment in /home/$user/OctoPrint" echo "Installing OctoPrint virtual environment in /opt/octoprint/OctoPrint"
#make venv #make venv
sudo -u $user $PYVERSION -m venv /home/$user/OctoPrint $PYVERSION -m venv /opt/octoprint/OctoPrint
#update pip #update pip
sudo -u $user /home/$user/OctoPrint/bin/pip install --upgrade pip /opt/octoprint/OctoPrint/bin/pip install --upgrade pip
#pre-install wheel #pre-install wheel
sudo -u $user /home/$user/OctoPrint/bin/pip install wheel /opt/octoprint/OctoPrint/bin/pip install wheel
#install oprint #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 #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}" echo "${cyan}OctoPrint apppears to have been installed successfully${white}"
else else
echo "${red}WARNING! WARNING! WARNING!${white}" echo "${red}WARNING! WARNING! WARNING!${white}"
@@ -336,8 +336,8 @@ new_install() {
streamer_install streamer_install
#These will retreived as settings #These will retreived as settings
echo "octoexec: /home/$user/OctoPrint/bin/octoprint" >> /etc/octoprint_deploy echo "octoexec: /opt/octoprint/OctoPrint/bin/octoprint" >> /etc/octodocker_deploy
echo "octopip: /home/$user/OctoPrint/bin/pip" >> /etc/octoprint_deploy echo "octopip: /opt/octoprint/OctoPrint/bin/pip" >> /etc/octodocker_deploy
#Create first instance #Create first instance
echo echo
@@ -363,9 +363,9 @@ haproxy_install() {
echo echo
echo echo
if prompt_confirm "Use haproxy?"; then if prompt_confirm "Use haproxy?"; then
echo 'haproxy: true' >> /etc/octoprint_deploy echo 'haproxy: true' >> /etc/octodocker_deploy
#Check if using improved haproxy rules #Check if using improved haproxy rules
#echo 'haproxynew: true' >> /etc/octoprint_deploy #echo 'haproxynew: true' >> /etc/octodocker_deploy
systemctl stop haproxy systemctl stop haproxy
#get haproxy version #get haproxy version
HAversion=$(haproxy -v | sed -n 's/^.*version \([0-9]\).*/\1/p') 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 #If we run this function directly, clean up streamer setting before installing
get_settings get_settings
sed -i "/streamer/d" /etc/octoprint_deploy sed -i "/streamer/d" /etc/octodocker_deploy
if [ $VID -eq 1 ]; then 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 #install mjpg-streamer, not doing any error checking or anything
echo 'Installing mjpeg-streamer' 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 #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 mv /opt/octoprint/mjpeg/mjpg-streamer-experimental /opt/octoprint/mjpg-streamer
sudo -u $user rm -rf /home/$user/mjpeg rm -rf /opt/octoprint/mjpeg
if [ -f "/home/$user/mjpg-streamer/mjpg_streamer" ]; then if [ -f "/opt/octoprint/mjpg-streamer/mjpg_streamer" ]; then
echo "Streamer installed successfully" echo "Streamer installed successfully"
else else
echo "${red}WARNING! WARNING! WARNING!${white}" echo "${red}WARNING! WARNING! WARNING!${white}"
@@ -436,15 +436,15 @@ streamer_install() {
streamer_install streamer_install
fi fi
fi fi
echo 'streamer: mjpg-streamer' >> /etc/octoprint_deploy echo 'streamer: mjpg-streamer' >> /etc/octodocker_deploy
fi fi
if [ $VID -eq 2 ]; then if [ $VID -eq 2 ]; then
rm -rf /home/$user/ustreamer 2>/dev/null rm -rf /opt/octoprint/ustreamer 2>/dev/null
#install ustreamer #install ustreamer
sudo -u $user git -C /home/$user clone --depth=1 https://github.com/pikvm/ustreamer git -C /opt/octoprint clone --depth=1 https://github.com/pikvm/ustreamer
sudo -u $user make -C /home/$user/ustreamer > /dev/null make -C /opt/octoprint/ustreamer > /dev/null
if [ -f "/home/$user/ustreamer/ustreamer" ] || [ -f "/home/$user/ustreamer/ustreamer.bin" ]; then if [ -f "/opt/octoprint/ustreamer/ustreamer" ] || [ -f "/opt/octoprint/ustreamer/ustreamer.bin" ]; then
echo "Streamer installed successfully" echo "Streamer installed successfully"
else else
echo "${red}WARNING! WARNING! WARNING!${white}" echo "${red}WARNING! WARNING! WARNING!${white}"
@@ -453,18 +453,18 @@ streamer_install() {
streamer_install streamer_install
fi fi
fi fi
if [ -f "/home/$user/ustreamer/ustreamer.bin" ]; then if [ -f "/opt/octoprint/ustreamer/ustreamer.bin" ]; then
sudo -u $user ln -s /home/$user/ustreamer/ustreamer.bin /home/$user/ustreamer/ustreamer ln -s /opt/octoprint/ustreamer/ustreamer.bin /opt/octoprint/ustreamer/ustreamer
fi fi
echo 'streamer: ustreamer' >> /etc/octoprint_deploy echo 'streamer: ustreamer' >> /etc/octodocker_deploy
fi fi
if [ $VID -eq 4 ]; then 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 #install camera-streamer
sudo -u $user git -C /home/$user clone https://github.com/ayufan-research/camera-streamer.git --recursive git -C /opt/octoprint clone https://github.com/ayufan-research/camera-streamer.git --recursive
sudo -u $user make -C /home/$user/camera-streamer > /dev/null make -C /opt/octoprint/camera-streamer > /dev/null
if [ -f "/home/$user/camera-streamer/camera-streamer" ]; then if [ -f "/opt/octoprint/camera-streamer/camera-streamer" ]; then
echo "Streamer installed successfully" echo "Streamer installed successfully"
else else
echo "${red}WARNING! WARNING! WARNING!${white}" echo "${red}WARNING! WARNING! WARNING!${white}"
@@ -473,11 +473,11 @@ streamer_install() {
streamer_install streamer_install
fi fi
fi fi
echo 'streamer: camera-streamer' >> /etc/octoprint_deploy echo 'streamer: camera-streamer' >> /etc/octodocker_deploy
fi fi
if [ $VID -eq 3 ]; then 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." echo "Good for you! Cameras are just annoying anyway."
fi fi
@@ -522,7 +522,7 @@ firstrun_install() {
done done
echo "Admin password: ${cyan}$OCTOPASS${white}" 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 fi
if [ -n "$OCTOADMIN" ]; then if [ -n "$OCTOADMIN" ]; then
@@ -534,13 +534,13 @@ firstrun_install() {
echo echo
echo echo
if prompt_confirm "Complete first run wizards now?"; then if prompt_confirm "Complete first run wizards now?"; then
sudo -u $user $OCTOEXEC --basedir $BASE config set server.firstRun false --bool docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.firstRun false --bool
sudo -u $user $OCTOEXEC --basedir $BASE config set server.seenWizards.backup null docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.seenWizards.backup null
sudo -u $user $OCTOEXEC --basedir $BASE config set server.seenWizards.corewizard 4 --int docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.seenWizards.corewizard 4 --int
sudo -u $user $OCTOEXEC --basedir $BASE config set server.onlineCheck.enabled true --bool docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.onlineCheck.enabled true --bool
sudo -u $user $OCTOEXEC --basedir $BASE config set server.pluginBlacklist.enabled true --bool docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.pluginBlacklist.enabled true --bool
sudo -u $user $OCTOEXEC --basedir $BASE config set plugins.tracking.enabled true --bool docker exec -it $INSTANCE $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 printerProfiles.default _default
fi fi
fi fi

73
util.sh Normal file → Executable file
View File

@@ -26,12 +26,12 @@ has-space () {
} }
get_settings() { get_settings() {
#Get octoprint_deploy settings, all of which are written on system prepare #Get octodocker_deploy settings, all of which are written on system prepare
if [ -f /etc/octoprint_deploy ]; then if [ -f /etc/octodocker_deploy ]; then
OCTOEXEC=$(cat /etc/octoprint_deploy | sed -n -e 's/^octoexec: \(\.*\)/\1/p') OCTOEXEC=/usr/local/bin/octoprint
OCTOPIP=$(cat /etc/octoprint_deploy | sed -n -e 's/^octopip: \(\.*\)/\1/p') OCTOPIP=/usr/local/bin/pip
STREAMER=$(cat /etc/octoprint_deploy | sed -n -e 's/^streamer: \(\.*\)/\1/p') STREAMER=$(cat /etc/octodocker_deploy | sed -n -e 's/^streamer: \(\.*\)/\1/p')
HAPROXY=$(cat /etc/octoprint_deploy | sed -n -e 's/^haproxy: \(\.*\)/\1/p') HAPROXY=$(cat /etc/octodocker_deploy | sed -n -e 's/^haproxy: \(\.*\)/\1/p')
fi fi
} }
@@ -53,26 +53,26 @@ global_config() {
} }
octo_deploy_update() { octo_deploy_update() {
sudo -u $user git -C $SCRIPTDIR pull git -C $SCRIPTDIR pull
exit exit
} }
back_up() { back_up() {
INSTANCE=$1 INSTANCE=$1
echo "Creating backup of $INSTANCE...." echo "Creating backup of $INSTANCE...."
sudo -u $user $OCTOEXEC --basedir /home/$user/.$INSTANCE plugins backup:backup --exclude timelapse docker exec -it $INSTANCE $OCTOEXEC --basedir /opt/octoprint/$INSTANCE plugins backup:backup --exclude timelapse
sudo -u $user mkdir /home/$user/instance_backup 2>/dev/null mkdir /opt/octoprint/instance_backup 2>/dev/null
sudo -u $user mv /home/$user/.$INSTANCE/data/backup/*.zip /home/$user/instance_backup/ mv /opt/octoprint/$INSTANCE/data/backup/*.zip /opt/octoprint/instance_backup/
echo "Zipped instance backup created in /home/$user/instance_backup" echo "Zipped instance backup created in /opt/octoprint/instance_backup"
} }
restore() { restore() {
INSTANCE=$1 INSTANCE=$1
TAR=$2 TAR=$2
echo "Restoring backup of $INSTANCE...." echo "Restoring backup of $INSTANCE...."
systemctl stop $INSTANCE docker stop $INSTANCE
sudo -u $user $OCTOEXEC --basedir /home/$user/.$INSTANCE plugins backup:restore $TAR docker exec -it $INSTANCE $OCTOEXEC --basedir /opt/octoprint/$INSTANCE plugins backup:restore $TAR
systemctl start $INSTANCE docker start $INSTANCE
} }
@@ -119,14 +119,14 @@ sync_users() {
fi fi
if prompt_confirm "Copy users from instance $opt to all other instances?"; then 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 #re-read to avoid the Quit
get_instances false get_instances false
for instance in "${INSTANCE_ARR[@]}"; do for instance in "${INSTANCE_ARR[@]}"; do
if [ "$instance" == "$opt" ]; then if [ "$instance" == "$opt" ]; then
continue continue
fi fi
sudo -u $user cp $userfile /home/$user/.$instance/ cp $userfile /opt/octoprint/$instance/
done done
if prompt_confirm "Restart all instances now for changes to take effect?"; then if prompt_confirm "Restart all instances now for changes to take effect?"; then
@@ -157,7 +157,7 @@ share_uploads() {
fi fi
if [ "$opt" == "Custom" ]; then if [ "$opt" == "Custom" ]; then
echo "Enter full path (should start /home/$user/):" echo "Enter full path (should start /opt/octoprint/):"
read ULPATH read ULPATH
if [ -d "$ULPATH" ]; then if [ -d "$ULPATH" ]; then
if prompt_confirm "This folder already exists. Are you sure you want to use it?"; then if prompt_confirm "This folder already exists. Are you sure you want to use it?"; then
@@ -168,19 +168,19 @@ share_uploads() {
break break
fi fi
else else
sudo -u $user mkdir $ULPATH mkdir $ULPATH
opt=$ULPATH opt=$ULPATH
fi fi
else else
opt=/home/$user/.$opt/uploads opt=/opt/octoprint/$opt/uploads
fi fi
echo echo
#Remove Quit and Custom from array, is there a cleaner way? #Remove Quit and Custom from array, is there a cleaner way?
unset 'INSTANCE_ARR[-1]' unset 'INSTANCE_ARR[-1]'
unset 'INSTANCE_ARR[-1]' unset 'INSTANCE_ARR[-1]'
for instance in "${INSTANCE_ARR[@]}"; do 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 done
break break
done done
@@ -293,7 +293,7 @@ instance_status() {
echo "$instance - $status" echo "$instance - $status"
done done
echo "${cyan}*******************************************${white}" 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 echo
main_menu main_menu
} }
@@ -322,21 +322,14 @@ remove_everything() {
done done
echo "Removing system stuff" echo "Removing system stuff"
rm /etc/systemd/system/octoprint.service 2>/dev/null
rm /etc/octoprint_streamer 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_instances 2>/dev/null
rm /etc/octoprint_cameras 2>/dev/null rm /etc/octoprint_cameras 2>/dev/null
rm /etc/udev/rules.d/99-octoprint.rules 2>/dev/null rm /etc/udev/rules.d/99-octoprint.rules 2>/dev/null
rm /etc/sudoers.d/octoprint_reboot 2>/dev/null rm -rf /opt/octoprint/ustreamer 2>/dev/null
rm /etc/sudoers.d/octoprint_systemctl 2>/dev/null rm -rf /opt/octoprint/mjpg-streamer 2>/dev/null
rm -rf /home/$user/.octoprint 2>/dev/null rm -rf /opt/octoprint/camera-streamer 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
fi fi
} }
@@ -346,7 +339,7 @@ restart_all() {
get_instances false get_instances false
for instance in "${INSTANCE_ARR[@]}"; do for instance in "${INSTANCE_ARR[@]}"; do
echo "Trying to restart instance $instance" echo "Trying to restart instance $instance"
systemctl restart $instance docker restart $instance
done done
main_menu main_menu
} }
@@ -381,9 +374,9 @@ diagnostic_output() {
diagnostics() { diagnostics() {
get_settings get_settings
logfile='octoprint_deploy_diagnostic.log' logfile='octodocker_deploy_diagnostic.log'
echo "octoprint_deploy diagnostic information. Please provide ALL output for support help" echo "octodocker_deploy diagnostic information. Please provide ALL output for support help"
diagnostic_output /etc/octoprint_deploy | log diagnostic_output /etc/octodocker_deploy | log
diagnostic_output /etc/octoprint_instances | log diagnostic_output /etc/octoprint_instances | log
diagnostic_output /etc/octoprint_cameras | log diagnostic_output /etc/octoprint_cameras | log
diagnostic_output /etc/udev/rules.d/99-octoprint.rules | log diagnostic_output /etc/udev/rules.d/99-octoprint.rules | log
@@ -395,9 +388,9 @@ diagnostics() {
echo "**************************************" | log echo "**************************************" | log
systemctl status $instance -l --no-pager | log systemctl status $instance -l --no-pager | log
#get needed config info #get needed config info
sudo -u $user $OCTOEXEC --basedir=/home/$user/.$INSTANCE config get plugins.classicwebcam | log docker exec -it $INSTANCE $OCTOEXEC --basedir=/opt/octoprint/$INSTANCE config get plugins.classicwebcam | log
#sudo -u $user $OCTOEXEC --basedir=/home/$user/.$INSTANCE config get plugins.classicwebcam.snapshot | log #docker exec -it $INSTANCE $OCTOEXEC --basedir=/opt/octoprint/$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 webcam | log
done done
#get all cam status #get all cam status
get_cameras false get_cameras false
@@ -408,6 +401,6 @@ diagnostics() {
#get haproxy status #get haproxy status
echo "**************************************" | log echo "**************************************" | log
systemctl status haproxy -l --no-pager | log systemctl status haproxy -l --no-pager | log
logfile='octoprint_deploy.log' logfile='octodocker_deploy.log'
main_menu main_menu
} }