+
The OctoPrint server is currently not running
+
+
+ If you just started up your Raspberry Pi, please wait a couple of seconds, then
+ try to refresh this page.
+
+
+
+ If the issue persists, please log into your Raspberry Pi via SSH and check the following:
+
+
+
+
+
+ If all that doesn't help to trouble shoot the issue, you can seek
+ support on the OctoPrint Community Forum.
+ Please provide your OctoPi and OctoPrint versions as well as your octoprint.log
+ and explain what you already tried and observed as detailed as possible.
+
+
+
+
+
diff --git a/src/modules/octopi/filesystem/root/etc/haproxy/errors/503-no-webcam-hls.http b/src/modules/octopi/filesystem/root/etc/haproxy/errors/503-no-webcam-hls.http
new file mode 100644
index 00000000..e94373b1
--- /dev/null
+++ b/src/modules/octopi/filesystem/root/etc/haproxy/errors/503-no-webcam-hls.http
@@ -0,0 +1,68 @@
+HTTP/1.0 503 Service Unavailable
+Cache-Control: no-cache
+Connection: close
+Content-Type: text/html
+
+
+
+
+
The webcam server is currently not running
+
+
+ If you do not have a camera attached, this is normal and can be safely ignored.
+
+
+
+ Otherwise, if you just started up your Raspberry Pi or just plugged in your camera,
+ please wait a couple of seconds.
+
+
+
+ If the issue persists, please check the following:
+
+
+
+
+
+ If all that doesn't help to trouble shoot the issue, you can seek
+ support on the OctoPrint Community Forum.
+ Please provide your camera model, lsusb
output and /var/log/webcamd.log
and explain what you
+ already tried and observed as detailed as possible.
+
+
+
+
+
diff --git a/src/filesystem/root/etc/haproxy/haproxy.cfg b/src/modules/octopi/filesystem/root/etc/haproxy/haproxy.1.x.cfg
similarity index 51%
rename from src/filesystem/root/etc/haproxy/haproxy.cfg
rename to src/modules/octopi/filesystem/root/etc/haproxy/haproxy.1.x.cfg
index c12058d0..443dd002 100644
--- a/src/filesystem/root/etc/haproxy/haproxy.cfg
+++ b/src/modules/octopi/filesystem/root/etc/haproxy/haproxy.1.x.cfg
@@ -2,12 +2,13 @@ global
maxconn 4096
user haproxy
group haproxy
- daemon
- log 127.0.0.1 local0 debug
+ log /dev/log local1 debug
+ tune.ssl.default-dh-param 2048
defaults
log global
mode http
+ compression algo gzip
option httplog
option dontlognull
retries 3
@@ -20,18 +21,29 @@ defaults
timeout server 15min
frontend public
- bind *:80
- bind 0.0.0.0:443 ssl crt /etc/ssl/snakeoil.pem
+ bind :::80 v4v6
+ bind :::443 v4v6 ssl crt /etc/ssl/snakeoil.pem
option forwardfor except 127.0.0.1
use_backend webcam if { path_beg /webcam/ }
+ use_backend webcam_hls if { path_beg /hls/ }
+ use_backend webcam_hls if { path_beg /jpeg/ }
default_backend octoprint
backend octoprint
+ acl needs_scheme req.hdr_cnt(X-Scheme) eq 0
+
reqrep ^([^\ :]*)\ /(.*) \1\ /\2
- reqadd X-Scheme:\ https if { ssl_fc }
+ reqadd X-Scheme:\ https if needs_scheme { ssl_fc }
+ reqadd X-Scheme:\ http if needs_scheme !{ ssl_fc }
option forwardfor
server octoprint1 127.0.0.1:5000
+ errorfile 503 /etc/haproxy/errors/503-no-octoprint.http
backend webcam
reqrep ^([^\ :]*)\ /webcam/(.*) \1\ /\2
server webcam1 127.0.0.1:8080
+ errorfile 503 /etc/haproxy/errors/503-no-webcam.http
+
+backend webcam_hls
+ server webcam_hls_1 127.0.0.1:28126
+ errorfile 503 /etc/haproxy/errors/503-no-webcam-hls.http
diff --git a/src/modules/octopi/filesystem/root/etc/haproxy/haproxy.2.x.cfg b/src/modules/octopi/filesystem/root/etc/haproxy/haproxy.2.x.cfg
new file mode 100644
index 00000000..b9c30185
--- /dev/null
+++ b/src/modules/octopi/filesystem/root/etc/haproxy/haproxy.2.x.cfg
@@ -0,0 +1,49 @@
+global
+ maxconn 4096
+ user haproxy
+ group haproxy
+ log /dev/log local1 debug
+ tune.ssl.default-dh-param 2048
+
+defaults
+ log global
+ mode http
+ compression algo gzip
+ option httplog
+ option dontlognull
+ retries 3
+ option redispatch
+ option http-server-close
+ option forwardfor
+ maxconn 2000
+ timeout connect 5s
+ timeout client 15m
+ timeout server 15m
+
+frontend public
+ bind :::80 v4v6
+ bind :::443 v4v6 ssl crt /etc/ssl/snakeoil.pem
+ option forwardfor except 127.0.0.1
+ use_backend webcam if { path_beg /webcam/ }
+ use_backend webcam_hls if { path_beg /hls/ }
+ use_backend webcam_hls if { path_beg /jpeg/ }
+ default_backend octoprint
+
+backend octoprint
+ acl needs_scheme req.hdr_cnt(X-Scheme) eq 0
+
+ http-request replace-path ^([^\ :]*)\ /(.*) \1\ /\2
+ http-request add-header X-Scheme https if needs_scheme { ssl_fc }
+ http-request add-header X-Scheme http if needs_scheme !{ ssl_fc }
+ option forwardfor
+ server octoprint1 127.0.0.1:5000
+ errorfile 503 /etc/haproxy/errors/503-no-octoprint.http
+
+backend webcam
+ http-request replace-path /webcam/(.*) /\1
+ server webcam1 127.0.0.1:8080
+ errorfile 503 /etc/haproxy/errors/503-no-webcam.http
+
+backend webcam_hls
+ server webcam_hls_1 127.0.0.1:28126
+ errorfile 503 /etc/haproxy/errors/503-no-webcam-hls.http
diff --git a/src/modules/octopi/filesystem/root/etc/init.d/change_hostname b/src/modules/octopi/filesystem/root/etc/init.d/change_hostname
new file mode 100755
index 00000000..7c5ef568
--- /dev/null
+++ b/src/modules/octopi/filesystem/root/etc/init.d/change_hostname
@@ -0,0 +1,60 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides: change_hostname
+# Required-Start: $local_fs
+# Required-Stop:
+# Default-Start: 3
+# Default-Stop:
+# Short-Description: Change pi's hostname via /boot/octopi-hostname.txt
+# Description:
+### END INIT INFO
+
+. /lib/lsb/init-functions
+
+do_start () {
+ text_file="/boot/octopi-hostname.txt"
+ if [ ! -f "$text_file" ]
+ then
+ exit 0
+ fi
+
+ old_hostname=`hostname`
+ new_hostname=`head -n1 "$text_file" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | tr -d '\n'`
+
+ if [ ! -n "$new_hostname" ]
+ then
+ log_failure_msg "No new host name provided, refusing to change to empty host name"
+ exit 1
+ fi
+
+ # make sure we do have a valid hostname here (see RFC 952 and 1123, a-zA-Z0-9 only)
+ sanitized_hostname=`echo "$new_hostname" | tr -cd '[[:alnum:]]-'`
+ if [ "$new_hostname" = "$sanitized_hostname" ]
+ then
+ rm "$text_file"
+ echo "$new_hostname" > /etc/hostname
+ sed -i -e "s@$old_hostname@$new_hostname@g" /etc/hosts
+
+ log_success_msg "Change of host name prepared, rebooting to apply..."
+ /sbin/reboot
+ else
+ log_failure_msg "Hostname $new_hostname contains invalid characters (only a-zA-Z0-9 are allowed), refusing to change"
+ fi
+}
+
+case "$1" in
+ start|"")
+ do_start
+ ;;
+ restart|reload|force-reload)
+ echo "Error: argument '$1' not supported" >&2
+ exit 3
+ ;;
+ stop)
+ # No-op
+ ;;
+ *)
+ echo "Usage: change_hostname [start|stop]" >&2
+ exit 3
+ ;;
+esac
diff --git a/src/modules/octopi/filesystem/root/etc/init.d/change_password b/src/modules/octopi/filesystem/root/etc/init.d/change_password
new file mode 100755
index 00000000..851d3e2b
--- /dev/null
+++ b/src/modules/octopi/filesystem/root/etc/init.d/change_password
@@ -0,0 +1,46 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides: change_password
+# Required-Start: $local_fs
+# Required-Stop:
+# Default-Start: 3
+# Default-Stop:
+# Short-Description: Change pi's password via /boot/octopi-password.txt
+# Description:
+### END INIT INFO
+
+. /lib/lsb/init-functions
+
+do_start () {
+ text_file="/boot/octopi-password.txt"
+ if [ ! -f "$text_file" ]
+ then
+ exit 0
+ fi
+
+ new_password=`head -n1 "$text_file" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | tr -d '\n'`
+ if [ ! -n "$new_password" ]
+ then
+ log_failure_msg "No new password provided, refusing to change to empty password"
+ exit 1
+ fi
+
+ (echo "pi:$new_password" | chpasswd && rm "$text_file" && log_success_msg "Password for user pi changed and change file deleted") || log_failure_msg "Could not change password"
+}
+
+case "$1" in
+ start|"")
+ do_start
+ ;;
+ restart|reload|force-reload)
+ echo "Error: argument '$1' not supported" >&2
+ exit 3
+ ;;
+ stop)
+ # No-op
+ ;;
+ *)
+ echo "Usage: change_password [start|stop]" >&2
+ exit 3
+ ;;
+esac
diff --git a/src/modules/octopi/filesystem/root/etc/logrotate.d/webcamd b/src/modules/octopi/filesystem/root/etc/logrotate.d/webcamd
new file mode 100644
index 00000000..2c5b5c68
--- /dev/null
+++ b/src/modules/octopi/filesystem/root/etc/logrotate.d/webcamd
@@ -0,0 +1,10 @@
+/var/log/webcamd.log
+{
+ rotate 4
+ weekly
+ missingok
+ notifempty
+ compress
+ delaycompress
+ sharedscripts
+}
diff --git a/src/modules/octopi/filesystem/root/etc/network/if-up.d/powersave_off b/src/modules/octopi/filesystem/root/etc/network/if-up.d/powersave_off
new file mode 100755
index 00000000..9801cf33
--- /dev/null
+++ b/src/modules/octopi/filesystem/root/etc/network/if-up.d/powersave_off
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+set -e
+
+# Don't bother for loopback
+if [ "$IFACE" = lo ]; then
+ exit 0
+fi
+
+# Only run from ifup.
+if [ "$MODE" != start ]; then
+ exit 0
+fi
+
+# Only run once
+if [ "$ADDRFAM" != meta ]; then
+ exit 0
+fi
+
+/usr/sbin/iw dev wlan0 set power_save off
+
+exit 0
+
diff --git a/src/modules/octopi/filesystem/root/etc/nginx/sites-available/default b/src/modules/octopi/filesystem/root/etc/nginx/sites-available/default
new file mode 100644
index 00000000..a4183d87
--- /dev/null
+++ b/src/modules/octopi/filesystem/root/etc/nginx/sites-available/default
@@ -0,0 +1,11 @@
+server {
+ listen 127.0.0.1:28126;
+
+ root /run/webcam;
+
+ location / {
+ # First attempt to serve request as file, then
+ # as directory, then fall back to displaying a 404.
+ try_files $uri $uri/ =404;
+ }
+}
\ No newline at end of file
diff --git a/src/modules/octopi/filesystem/root/etc/systemd/system/ffmpeg_hls.service b/src/modules/octopi/filesystem/root/etc/systemd/system/ffmpeg_hls.service
new file mode 100644
index 00000000..3a1f463b
--- /dev/null
+++ b/src/modules/octopi/filesystem/root/etc/systemd/system/ffmpeg_hls.service
@@ -0,0 +1,54 @@
+[Unit]
+Description=FFMPEG HLS webcam streaming service
+ConditionPathExists=/etc/octopi_streamer/hls
+
+[Service]
+User=root
+Restart=always
+RestartSec=5
+WatchdogSec=21600
+Nice=10
+ExecStartPre=/bin/rm -rf /run/webcam
+ExecStartPre=/bin/mkdir -p /run/webcam/hls
+ExecStartPre=/bin/mkdir -p /run/webcam/hls/240p
+ExecStartPre=/bin/mkdir -p /run/webcam/hls/480p
+ExecStartPre=/bin/mkdir -p /run/webcam/jpeg
+ExecStartPre=/bin/cp /var/lib/ffmpeg_hls/stream.m3u8 /run/webcam/hls/stream.m3u8
+ExecStartPre=/bin/chown -R webcam:webcam /run/webcam
+ExecStartPre=/bin/chmod -R 0755 /run/webcam
+
+ExecStart=/usr/bin/sudo -u webcam \
+ /opt/ffmpeg-hls/ffmpeg \
+ \
+ -framerate 30 -video_size 640x480 \
+ -i /dev/video0 \
+ -pix_fmt yuv420p \
+ \
+ -c:v mjpeg -q:v 0 \
+ -f image2 -r 1 -update 1 -atomic_writing 1 \
+ /run/webcam/jpeg/frame.jpg \
+ \
+ -c:v h264_v4l2m2m -level:v 4.0 \
+ -b:v 1264k -flags +cgop \
+ -g 30 -keyint_min 30 \
+ \
+ -f hls -hls_time 1 \
+ -hls_flags delete_segments+program_date_time+temp_file+independent_segments \
+ -hls_allow_cache 0 -hls_segment_type fmp4 \
+ -hls_list_size 32 -hls_delete_threshold 64 \
+ /run/webcam/hls/480p/stream.m3u8 \
+ \
+ -vf scale=-1:240 \
+ \
+ -c:v h264_v4l2m2m -level:v 4.0 \
+ -b:v 240k -flags +cgop \
+ -g 30 -keyint_min 30 \
+ \
+ -f hls -hls_time 1 \
+ -hls_flags delete_segments+program_date_time+temp_file+independent_segments \
+ -hls_allow_cache 0 -hls_segment_type fmp4 \
+ -hls_list_size 32 -hls_delete_threshold 64 \
+ /run/webcam/hls/240p/stream.m3u8
+
+[Install]
+WantedBy=multi-user.target
\ No newline at end of file
diff --git a/src/modules/octopi/filesystem/root/etc/systemd/system/gencert.service b/src/modules/octopi/filesystem/root/etc/systemd/system/gencert.service
new file mode 100644
index 00000000..c22b6ffa
--- /dev/null
+++ b/src/modules/octopi/filesystem/root/etc/systemd/system/gencert.service
@@ -0,0 +1,17 @@
+[Unit]
+Description=Ensure that haproxy certs are generated
+
+DefaultDependencies=no
+
+Before=network-pre.target
+Wants=network-pre.target
+
+After=local-fs.target
+Wants=local-fs.target
+
+[Service]
+Type=oneshot
+ExecStart=/root/bin/gencert
+
+[Install]
+WantedBy=multi-user.target
diff --git a/src/modules/octopi/filesystem/root/etc/systemd/system/networkcheck.service b/src/modules/octopi/filesystem/root/etc/systemd/system/networkcheck.service
new file mode 100644
index 00000000..ec4a008e
--- /dev/null
+++ b/src/modules/octopi/filesystem/root/etc/systemd/system/networkcheck.service
@@ -0,0 +1,8 @@
+[Unit]
+ Description=Network Monitor
+ ConditionPathExists=/usr/local/bin/networkcheck
+
+[Service]
+ User=root
+ Type=simple
+ ExecStart=/usr/local/bin/networkcheck &
diff --git a/src/modules/octopi/filesystem/root/etc/systemd/system/networkcheck.timer b/src/modules/octopi/filesystem/root/etc/systemd/system/networkcheck.timer
new file mode 100644
index 00000000..940694fe
--- /dev/null
+++ b/src/modules/octopi/filesystem/root/etc/systemd/system/networkcheck.timer
@@ -0,0 +1,10 @@
+[Unit]
+ Description=Network Monitor Trigger (every 1 minutes)
+ After=network.target
+
+[Timer]
+ OnCalendar=*-*-* *:*:00
+ AccuracySec=1s
+
+[Install]
+ WantedBy=timers.target
diff --git a/src/modules/octopi/filesystem/root/etc/systemd/system/octoprint.service b/src/modules/octopi/filesystem/root/etc/systemd/system/octoprint.service
new file mode 100644
index 00000000..191f4e05
--- /dev/null
+++ b/src/modules/octopi/filesystem/root/etc/systemd/system/octoprint.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=The snappy web interface for your 3D printer
+After=network.online.target
+Wants=network.online.target
+
+[Service]
+Environment="HOST=127.0.0.1"
+Environment="PORT=5000"
+Type=simple
+User=pi
+ExecStart=/home/pi/oprint/bin/octoprint serve --host=${HOST} --port=${PORT}
+
+[Install]
+WantedBy=multi-user.target
diff --git a/src/modules/octopi/filesystem/root/etc/systemd/system/streamer_select.service b/src/modules/octopi/filesystem/root/etc/systemd/system/streamer_select.service
new file mode 100644
index 00000000..402fd512
--- /dev/null
+++ b/src/modules/octopi/filesystem/root/etc/systemd/system/streamer_select.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=OctoPi streamer selector
+Before=webcamd.service ffmpeg_hls.service nginx.service
+
+[Service]
+Type=oneshot
+ExecStart=/root/bin/streamer_select
+
+[Install]
+WantedBy=multi-user.target
diff --git a/src/modules/octopi/filesystem/root/etc/systemd/system/user-fix.service b/src/modules/octopi/filesystem/root/etc/systemd/system/user-fix.service
new file mode 100644
index 00000000..b95981ca
--- /dev/null
+++ b/src/modules/octopi/filesystem/root/etc/systemd/system/user-fix.service
@@ -0,0 +1,18 @@
+# Written by Gina Häußge originally at https://github.com/OctoPrint/OctoPi-UpToDate/blob/e70ccdaf0cd4ef4adfaa3f9b6b288fb6bfda116a/scripts/files/user-fix.service
+[Unit]
+Description=Ensure that user name changes are applied as needed
+
+DefaultDependencies=no
+
+Before=network-pre.target
+Wants=network-pre.target
+
+After=local-fs.target
+Wants=local-fs.target
+
+[Service]
+Type=oneshot
+ExecStart=/root/bin/user-fix
+
+[Install]
+WantedBy=multi-user.target
diff --git a/src/modules/octopi/filesystem/root/etc/systemd/system/webcamd.service b/src/modules/octopi/filesystem/root/etc/systemd/system/webcamd.service
new file mode 100644
index 00000000..451d2377
--- /dev/null
+++ b/src/modules/octopi/filesystem/root/etc/systemd/system/webcamd.service
@@ -0,0 +1,15 @@
+[Unit]
+Description=the OctoPi webcam daemon with the user specified config
+ConditionPathExists=/etc/octopi_streamer/mjpeg
+
+[Service]
+WorkingDirectory=/root/bin
+StandardOutput=append:/var/log/webcamd.log
+StandardError=append:/var/log/webcamd.log
+ExecStart=/root/bin/webcamd
+Restart=always
+Type=simple
+RestartSec=1
+
+[Install]
+WantedBy=multi-user.target
diff --git a/src/filesystem/root/etc/udev/rules.d/95-ads7846.rules b/src/modules/octopi/filesystem/root/etc/udev/rules.d/95-ads7846.rules
similarity index 100%
rename from src/filesystem/root/etc/udev/rules.d/95-ads7846.rules
rename to src/modules/octopi/filesystem/root/etc/udev/rules.d/95-ads7846.rules
diff --git a/src/modules/octopi/filesystem/root/usr/lib/systemd/system/nginx.service b/src/modules/octopi/filesystem/root/usr/lib/systemd/system/nginx.service
new file mode 100644
index 00000000..8ef64228
--- /dev/null
+++ b/src/modules/octopi/filesystem/root/usr/lib/systemd/system/nginx.service
@@ -0,0 +1,20 @@
+# NGINX service definition based on Debian buster version.
+[Unit]
+Description=NGINX server for serving HLS and JPEG frames
+Documentation=man:nginx(8)
+After=network.target nss-lookup.target
+ConditionPathExists=/etc/octopi_streamer/hls
+
+[Service]
+Type=forking
+PIDFile=/run/nginx.pid
+ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
+ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
+ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
+ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid
+TimeoutStopSec=5
+KillMode=mixed
+Nice=10
+
+[Install]
+WantedBy=multi-user.target
\ No newline at end of file
diff --git a/src/modules/octopi/filesystem/root/usr/local/bin/networkcheck b/src/modules/octopi/filesystem/root/usr/local/bin/networkcheck
new file mode 100755
index 00000000..0ab1f406
--- /dev/null
+++ b/src/modules/octopi/filesystem/root/usr/local/bin/networkcheck
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+source /boot/octopi.txt
+
+if [ $enable_network_monitor == 1 ] && [ "$destination_host" != "" ]; then
+
+ if [ -f /boot/octopi-wpa-supplicant.txt ]; then # check if config file exists
+ input="/boot/octopi-wpa-supplicant.txt"
+ while IFS= read -r line; do # read config file line by line
+ if [[ $line =~ ^network=.* ]]; then # check if we have a network config if a line starts with "network="
+ echo "network config found..."
+ ping -c4 $destination_host > /dev/null # check if destination is reachable - possible by default the router
+ if [ $? != 0 ]; then
+ echo "Destination not reachable - reconfigure interface..."
+ sudo wpa_cli -i wlan0 reconfigure # reconfigure network to trigger reconnect
+ sudo dhclient -v # ensure connection will be established by refresh dhcp lease
+ echo "Reconnect done."
+ exit 0 # if we detect multiple network configs exit after 1st one - one reconnect is enough :-)
+ else
+ echo "Destination reachable - no action needed."
+ exit 0 # destination reached - exit loop
+ fi
+ fi
+ done < "$input"
+ fi
+else
+ echo "Network monitoring not enabled."
+fi
diff --git a/src/modules/octopi/filesystem/root/var/lib/ffmpeg_hls/stream.m3u8 b/src/modules/octopi/filesystem/root/var/lib/ffmpeg_hls/stream.m3u8
new file mode 100644
index 00000000..a28b385e
--- /dev/null
+++ b/src/modules/octopi/filesystem/root/var/lib/ffmpeg_hls/stream.m3u8
@@ -0,0 +1,6 @@
+#EXTM3U
+#EXT-X-VERSION:3
+#EXT-X-STREAM-INF:BANDWIDTH=245760,RESOLUTION=320x240
+240p/stream.m3u8
+#EXT-X-STREAM-INF:BANDWIDTH=1294336,RESOLUTION=640x480
+480p/stream.m3u8
\ No newline at end of file
diff --git a/src/modules/octopi/start_chroot_script b/src/modules/octopi/start_chroot_script
new file mode 100755
index 00000000..d78f49e6
--- /dev/null
+++ b/src/modules/octopi/start_chroot_script
@@ -0,0 +1,349 @@
+#!/usr/bin/env bash
+# OctoPI generation script
+# Helper script that runs in a Raspbian chroot to create the OctoPI distro
+# Written by Guy Sheffer