Added MJPG Streamer. OctoPrint now uses Nginx reverse proxy
MJPG streamer has been added to allow for video to work inside of OctoPrint (url is http://rpi-ip/webcam/) OctoPrint + MJPG now uses Nginx as a reverse proxy. This is to simpify the frontend and eventually this will allow me to add HTTPS support Changed dialogrc background color to black to save eyeballs
This commit is contained in:
parent
b94fcfc1c9
commit
bd1dd3554f
15 changed files with 154 additions and 43 deletions
|
@ -6,6 +6,7 @@ install -v -m 644 files/fstab "${ROOTFS_DIR}/etc/fstab"
|
||||||
install -m 755 files/.xprofile "${ROOTFS_DIR}/etc/skel/.xprofile"
|
install -m 755 files/.xprofile "${ROOTFS_DIR}/etc/skel/.xprofile"
|
||||||
install -m 755 files/.browser.sh "${ROOTFS_DIR}/etc/skel/.browser.sh"
|
install -m 755 files/.browser.sh "${ROOTFS_DIR}/etc/skel/.browser.sh"
|
||||||
install -m 644 files/.dialogrc "${ROOTFS_DIR}/etc/skel/.dialogrc"
|
install -m 644 files/.dialogrc "${ROOTFS_DIR}/etc/skel/.dialogrc"
|
||||||
|
install -m 644 files/.dialogrc "${ROOTFS_DIR}/root/.dialogrc"
|
||||||
mkdir -p "${ROOTFS_DIR}/etc/skel/.config/openbox"
|
mkdir -p "${ROOTFS_DIR}/etc/skel/.config/openbox"
|
||||||
install -m 644 files/autostart "${ROOTFS_DIR}/etc/skel/.config/openbox/autostart"
|
install -m 644 files/autostart "${ROOTFS_DIR}/etc/skel/.config/openbox/autostart"
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
source /srv/octoprint/host
|
LISTEN=$(grep -i listen /etc/nginx/port.conf | awk '{gsub(";",""); print $2}')
|
||||||
|
|
||||||
if [[ -f ~/.overrideurl.sh ]]; then source ./.overrideurl.sh; fi
|
if [[ -f ~/.overrideurl.sh ]]; then source ./.overrideurl.sh; fi
|
||||||
|
|
||||||
# Wait until OctoPrint comes up
|
# Wait until OctoPrint comes up
|
||||||
while ! curl "$HOST:$PORT" 2>&1 >/dev/null; do
|
while ! curl "$LISTEN" 2>&1 >/dev/null; do
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
surf -d -F -g -K -n -p "$HOST:$PORT"
|
surf -d -F -g -K -n -p "$LISTEN"
|
||||||
|
|
|
@ -4,3 +4,4 @@ python-setuptools
|
||||||
python-virtualenv
|
python-virtualenv
|
||||||
git
|
git
|
||||||
libyaml-dev
|
libyaml-dev
|
||||||
|
nginx
|
||||||
|
|
|
@ -2,7 +2,11 @@
|
||||||
|
|
||||||
install -m 644 files/octoprint.service ${ROOTFS_DIR}/etc/systemd/system/octoprint.service
|
install -m 644 files/octoprint.service ${ROOTFS_DIR}/etc/systemd/system/octoprint.service
|
||||||
|
|
||||||
|
install -m 644 files/nginx.conf ${ROOTFS_DIR}/etc/nginx/nginx.conf
|
||||||
|
echo -e "listen 80;" > ${ROOTFS_DIR}/etc/nginx/listen.conf
|
||||||
|
|
||||||
on_chroot << EOF
|
on_chroot << EOF
|
||||||
|
systemctl enable nginx
|
||||||
if ! pip list | grep -F octoprint; then
|
if ! pip list | grep -F octoprint; then
|
||||||
if [[ ! -d /srv/octoprint ]]; then mkdir -p /srv/octoprint; fi
|
if [[ ! -d /srv/octoprint ]]; then mkdir -p /srv/octoprint; fi
|
||||||
cd /srv/octoprint || exit 1
|
cd /srv/octoprint || exit 1
|
||||||
|
|
53
stage2/04-octoprint/files/nginx.conf
Normal file
53
stage2/04-octoprint/files/nginx.conf
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
worker_processes auto;
|
||||||
|
|
||||||
|
events {
|
||||||
|
worker_connections 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
http {
|
||||||
|
include mime.types;
|
||||||
|
default_type application/octet-stream;
|
||||||
|
sendfile on;
|
||||||
|
keepalive_timeout 65;
|
||||||
|
|
||||||
|
map $http_upgrade $connection_upgrade {
|
||||||
|
default upgrade;
|
||||||
|
'' close;
|
||||||
|
}
|
||||||
|
|
||||||
|
upstream "octoprint" {
|
||||||
|
server 127.0.0.1:5000;
|
||||||
|
}
|
||||||
|
|
||||||
|
upstream "mjpg-streamer" {
|
||||||
|
server 127.0.0.1:8080;
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
include /etc/nginx/listen.conf;
|
||||||
|
server_name localhost;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://octoprint/;
|
||||||
|
proxy_set_header Host $http_host;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Scheme $scheme;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
|
||||||
|
client_max_body_size 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /webcam/ {
|
||||||
|
proxy_pass http://mjpg-streamer/;
|
||||||
|
}
|
||||||
|
|
||||||
|
# redirect server error pages to the static page /50x.html
|
||||||
|
error_page 500 502 503 504 /50x.html;
|
||||||
|
location = /50x.html {
|
||||||
|
root html;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,7 @@ Description=OctoPrint Daemon
|
||||||
Type=simple
|
Type=simple
|
||||||
User=octoprint
|
User=octoprint
|
||||||
Group=octoprint
|
Group=octoprint
|
||||||
ExecStart=/usr/local/bin/start-octoprint
|
ExecStart=/srv/octoprint/venv/bin/octoprint --host localhost --port 5000
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
6
stage2/05-mjpgstreamer/00-packages
Normal file
6
stage2/05-mjpgstreamer/00-packages
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
cmake
|
||||||
|
libjpeg8-dev
|
||||||
|
v4l-utils
|
||||||
|
libv4l-dev
|
||||||
|
gcc
|
||||||
|
g++
|
18
stage2/05-mjpgstreamer/01-run.sh
Executable file
18
stage2/05-mjpgstreamer/01-run.sh
Executable file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
install -m 644 files/mjpg-streamer.service ${ROOTFS_DIR}/etc/systemd/system/mjpg-streamer.service
|
||||||
|
install -m 755 files/start-mjpg ${ROOTFS_DIR}/usr/local/bin/start-mjpg
|
||||||
|
|
||||||
|
on_chroot << EOF
|
||||||
|
if ! which mjpg_streamer; then
|
||||||
|
cd /tmp
|
||||||
|
rm -rf /tmp/mjpg-streamer
|
||||||
|
git clone https://github.com/jacksonliam/mjpg-streamer/
|
||||||
|
cd mjpg-streamer/mjpg-streamer-experimental/
|
||||||
|
make
|
||||||
|
make install
|
||||||
|
cd /
|
||||||
|
rm -rf /tmp/mjpg-streamer
|
||||||
|
fi
|
||||||
|
EOF
|
||||||
|
|
12
stage2/05-mjpgstreamer/files/mjpg-streamer.service
Normal file
12
stage2/05-mjpgstreamer/files/mjpg-streamer.service
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
[Unit]
|
||||||
|
Description=MJPG-Streamer Daemon
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=octoprint
|
||||||
|
Group=octoprint
|
||||||
|
ExecStart=/usr/local/bin/start-mjpg
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
2
stage2/05-mjpgstreamer/files/start-mjpg
Normal file
2
stage2/05-mjpgstreamer/files/start-mjpg
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/bash
|
||||||
|
/usr/local/bin/mjpg_streamer -i input_uvc.so -o "output_http.so --port 8080"
|
|
@ -1,10 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
source /srv/octoprint/venv/bin/activate
|
|
||||||
|
|
||||||
source /srv/octoprint/host
|
|
||||||
|
|
||||||
[[ "$HOST" == "" ]] && HOST="0.0.0.0"
|
|
||||||
[[ "$PORT" == "" ]] && PORT="5000"
|
|
||||||
|
|
||||||
/srv/octoprint/venv/bin/octoprint serve --host $HOST --port $PORT
|
|
|
@ -4,7 +4,6 @@ mkdir -p "${ROOTFS_DIR}/usr/local/bin/"
|
||||||
install -m 755 files/octo-config "${ROOTFS_DIR}/usr/local/bin/octo-config"
|
install -m 755 files/octo-config "${ROOTFS_DIR}/usr/local/bin/octo-config"
|
||||||
install -m 755 files/first-time.sh "${ROOTFS_DIR}/etc/profile.d/first-time.sh"
|
install -m 755 files/first-time.sh "${ROOTFS_DIR}/etc/profile.d/first-time.sh"
|
||||||
install -m 755 files/octo-lib.sh "${ROOTFS_DIR}/usr/local/lib/octo-lib.sh"
|
install -m 755 files/octo-lib.sh "${ROOTFS_DIR}/usr/local/lib/octo-lib.sh"
|
||||||
install -m 755 files/start-octoprint "${ROOTFS_DIR}/usr/local/bin/start-octoprint"
|
|
||||||
|
|
||||||
mkdir -p ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/
|
mkdir -p ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/
|
||||||
cat > ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/override.conf << 'EOF'
|
cat > ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/override.conf << 'EOF'
|
|
@ -73,11 +73,15 @@ service_select || return 1
|
||||||
|
|
||||||
screen_timeout || return 1
|
screen_timeout || return 1
|
||||||
|
|
||||||
if dialog --title "OctoPrint Config" --yesno "Do you wish to change the default OctoPrint listening address and/or port?" 10 60; then
|
if [[ -f /etc/systemd/system/multi-user.target.wants/octoprint.service ]] && dialog --title "OctoPrint Config" --yesno "Do you wish to change the default OctoPrint listening address and/or port?" 10 60; then
|
||||||
octo_config
|
nginx_config
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if dialog --title "Plugin Manager" --yesno "Do you wish to preinstall some suggested plugins?" 10 60; then
|
if [[ -f /etc/systemd/system/multi-user.target.wants/mjpg-streamer.service ]]; then
|
||||||
|
video_config
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -f /etc/systemd/system/multi-user.target.wants/octoprint.service ]] && dialog --title "Plugin Manager" --yesno "Do you wish to preinstall some suggested plugins?" 10 60; then
|
||||||
recommended_menu || return 1
|
recommended_menu || return 1
|
||||||
suggested_menu || return 1
|
suggested_menu || return 1
|
||||||
chown -R octoprint:octoprint /srv/octoprint
|
chown -R octoprint:octoprint /srv/octoprint
|
|
@ -9,20 +9,22 @@ source /usr/local/lib/octo-lib.sh
|
||||||
|
|
||||||
main_menu () {
|
main_menu () {
|
||||||
local MAINMENU=$(dialog --nocancel --title "Pi Setup" --menu "" 10 50 0 \
|
local MAINMENU=$(dialog --nocancel --title "Pi Setup" --menu "" 10 50 0 \
|
||||||
"1" "Configure Networking" \
|
"1" "Configure networking" \
|
||||||
"2" "Change password for pi" \
|
"2" "Change password for pi" \
|
||||||
"3" "Configure services" \
|
"3" "Configure services" \
|
||||||
"4" "Configure screen timeout" \
|
"4" "Configure screen timeout" \
|
||||||
"5" "Configure OctoPrint" \
|
"5" "Configure Nginx" \
|
||||||
"6" "Exit" 3>&1 1>&2 2>&3)
|
"6" "Configure MJPG" \
|
||||||
|
"7" "Exit" 3>&1 1>&2 2>&3)
|
||||||
|
|
||||||
case $MAINMENU in
|
case $MAINMENU in
|
||||||
"1") nmtui; main_menu; return 0;;
|
"1") nmtui; main_menu; return 0;;
|
||||||
"2") change_password; main_menu; return 0;;
|
"2") change_password; main_menu; return 0;;
|
||||||
"3") service_select; main_menu; return 0;;
|
"3") service_select; main_menu; return 0;;
|
||||||
"4") screen_timeout; main_menu; return 0;;
|
"4") screen_timeout; main_menu; return 0;;
|
||||||
"5") octo_config; main_menu; return 0;;
|
"5") nginx_config; main_menu; return 0;;
|
||||||
"6") return 0;;
|
"6") video_config; main_menu; return 0;;
|
||||||
|
"7") return 0;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,20 +20,23 @@ change_password () {
|
||||||
service_select () {
|
service_select () {
|
||||||
local SERVICE_MENU=$(dialog --separate-output --nocancel --title "Select services" --checklist "Enable/disable services" 0 0 0 \
|
local SERVICE_MENU=$(dialog --separate-output --nocancel --title "Select services" --checklist "Enable/disable services" 0 0 0 \
|
||||||
"1" "OctoPrint" $(if [[ -f /etc/systemd/system/multi-user.target.wants/octoprint.service ]]; then echo "ON"; else echo "OFF"; fi) \
|
"1" "OctoPrint" $(if [[ -f /etc/systemd/system/multi-user.target.wants/octoprint.service ]]; then echo "ON"; else echo "OFF"; fi) \
|
||||||
"2" "GUI" $(if [[ $(systemctl get-default) == "graphical.target" ]]; then echo "ON"; else echo "OFF"; fi) \
|
"2" "MJPG-Streamer" $(if [[ -f /etc/systemd/system/multi-user.target.wants/mjpg-streamer.service ]]; then echo "ON"; else echo "OFF"; fi) \
|
||||||
"3" "SSH" $(if [[ -f /etc/systemd/system/multi-user.target.wants/ssh.service ]]; then echo "ON"; else echo "OFF"; fi) 3>&1 1>&2 2>&3)
|
"3" "GUI" $(if [[ $(systemctl get-default) == "graphical.target" ]]; then echo "ON"; else echo "OFF"; fi) \
|
||||||
|
"4" "SSH" $(if [[ -f /etc/systemd/system/multi-user.target.wants/ssh.service ]]; then echo "ON"; else echo "OFF"; fi) 3>&1 1>&2 2>&3)
|
||||||
|
|
||||||
SERVICE_MENU=($SERVICE_MENU)
|
SERVICE_MENU=($SERVICE_MENU)
|
||||||
|
|
||||||
local ENABLE_OCTO=false
|
local ENABLE_OCTO=false
|
||||||
|
local ENABLE_MJPG=false
|
||||||
local ENABLE_GUI=false
|
local ENABLE_GUI=false
|
||||||
local ENABLE_SSH=false
|
local ENABLE_SSH=false
|
||||||
|
|
||||||
for i in "${SERVICE_MENU[@]}"; do
|
for i in "${SERVICE_MENU[@]}"; do
|
||||||
case $i in
|
case $i in
|
||||||
"1") ENABLE_OCTO=true ;;
|
"1") ENABLE_OCTO=true ;;
|
||||||
"2") ENABLE_GUI=true ;;
|
"2") ENABLE_MJPG=true ;;
|
||||||
"3") ENABLE_SSH=true ;;
|
"3") ENABLE_GUI=true ;;
|
||||||
|
"4") ENABLE_SSH=true ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -43,6 +46,12 @@ service_select () {
|
||||||
systemctl disable octoprint
|
systemctl disable octoprint
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ $ENABLE_MJPG == true ]]; then
|
||||||
|
systemctl enable mjpg-streamer
|
||||||
|
else
|
||||||
|
systemctl disable mjpg-streamer
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $ENABLE_GUI == true ]]; then
|
if [[ $ENABLE_GUI == true ]]; then
|
||||||
systemctl set-default graphical.target
|
systemctl set-default graphical.target
|
||||||
else
|
else
|
||||||
|
@ -78,30 +87,39 @@ EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
screen_timeout() {
|
screen_timeout() {
|
||||||
local TIMEOUT=$(dialog --nocancel --title "Screen Timeout" --inputbox "Input your desired screen timeout in seconds.\nEnter \"off\" to disable the screen timeout.\n\nAdding a screen timeout can reduce screen burn in." 11 60 "0" 3>&1 1>&2 2>&3)
|
local TIMEOUT=$(dialog --nocancel --title "Screen Timeout" --inputbox "Input your desired screen timeout in seconds.\nEnter \"off\" to disable the screen timeout.\n\nAdding a screen timeout can reduce screen burn in.\n\nDefault: off" 12 60 "off" 3>&1 1>&2 2>&3)
|
||||||
cat > /home/pi/.xtimeout << EOF
|
cat > /home/pi/.xtimeout << EOF
|
||||||
xset s ${TIMEOUT}
|
xset s ${TIMEOUT}
|
||||||
xset -dpms
|
xset -dpms
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
octo_config () {
|
nginx_config () {
|
||||||
if [[ -f /srv/octoprint/host ]]; then
|
local LISTEN=""
|
||||||
source /srv/octoprint/host
|
|
||||||
|
if [[ -f /etc/nginx/listen.conf ]]; then
|
||||||
|
LISTEN=$(grep -i listen /etc/nginx/listen.conf | awk '{gsub(";",""); print $2}')
|
||||||
else
|
else
|
||||||
HOST="0.0.0.0"
|
LISTEN="80"
|
||||||
PORT="5000"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local OCTOFORM=$(dialog --title "OctoPrint Config" --nocancel --form "Configure what port and IP OctoPrint listen on." 10 50 0 \
|
LISTEN=$(dialog --title "Nginx Config" --nocancel --inputbox "Configure what port and IP Nginx should listen on.\nTo listen on all IPs, just enter the port.\nDefault: 80" 11 50 "$LISTEN" 3>&1 1>&2 2>&3)
|
||||||
"Listening IP:" 1 1 "$HOST" 1 17 20 0 \
|
|
||||||
"Listening Port:" 2 1 "$PORT" 2 17 6 0 3>&1 1>&2 2>&3)
|
|
||||||
OCTOFORM=($OCTOFORM)
|
|
||||||
|
|
||||||
HOST=${OCTOFORM[0]}
|
echo "listen $LISTEN;" > /etc/nginx/listen.conf
|
||||||
PORT=${OCTOFORM[1]}
|
|
||||||
|
|
||||||
echo -e "HOST=$HOST\nPORT=$PORT" > /srv/octoprint/host
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
video_config () {
|
||||||
|
local DEVICES=($(ls /dev/video*))
|
||||||
|
|
||||||
|
local DEVICELIST=""
|
||||||
|
|
||||||
|
for ((i = 0; i < ${#DEVICES[@]}; i++)); do
|
||||||
|
DEVICELIST+="${DEVICES[$i]} $i OFF "
|
||||||
|
done
|
||||||
|
|
||||||
|
local DEVICE_MENU=$(dialog --title "Video Config" --nocancel --radiolist "Choose which video device you wish to use for MJPG-Streamer" 10 50 0 $DEVICELIST 3>&1 1>&2 2>&3)
|
||||||
|
|
||||||
|
[[ "$DEVICE_MENU" == "" ]] && return 0
|
||||||
|
|
||||||
|
echo -e '#!/bin/bash'"\n/usr/local/bin/mjpg_streamer -i \"input_uvc.so -d $DEVICE_MENU\" -o \"output_http.so --port 8080\"" > /usr/local/bin/start-mjpg
|
||||||
|
}
|
Loading…
Reference in a new issue