Compare commits
2 commits
b94fcfc1c9
...
1f9e8d5269
Author | SHA1 | Date | |
---|---|---|---|
1f9e8d5269 | |||
bd1dd3554f |
16 changed files with 154 additions and 48 deletions
5
TODO.md
5
TODO.md
|
@ -1,18 +1,13 @@
|
|||
# TODO:
|
||||
|
||||
## First time/Octo-Config
|
||||
- Change OctoPrint listening address and port
|
||||
- Change frontend listening address and port
|
||||
- Add network configuration (replace nmtui)
|
||||
- Add hostname configuration (replace nmtui)
|
||||
- Consolidate shared functions into a single file
|
||||
|
||||
## Frontend
|
||||
- Autodetect OctoPrint port if hosted locally
|
||||
- Add on screen keyboard to Openbox autostart
|
||||
|
||||
## Misc
|
||||
- Add MJPEG streamer
|
||||
- 64 bit builds
|
||||
- More security
|
||||
- e
|
||||
|
|
|
@ -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/.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}/root/.dialogrc"
|
||||
mkdir -p "${ROOTFS_DIR}/etc/skel/.config/openbox"
|
||||
install -m 644 files/autostart "${ROOTFS_DIR}/etc/skel/.config/openbox/autostart"
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#!/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
|
||||
|
||||
# Wait until OctoPrint comes up
|
||||
while ! curl "$HOST:$PORT" 2>&1 >/dev/null; do
|
||||
while ! curl "$LISTEN" 2>&1 >/dev/null; do
|
||||
sleep 1
|
||||
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
|
||||
git
|
||||
libyaml-dev
|
||||
nginx
|
||||
|
|
|
@ -2,7 +2,11 @@
|
|||
|
||||
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
|
||||
systemctl enable nginx
|
||||
if ! pip list | grep -F octoprint; then
|
||||
if [[ ! -d /srv/octoprint ]]; then mkdir -p /srv/octoprint; fi
|
||||
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
|
||||
User=octoprint
|
||||
Group=octoprint
|
||||
ExecStart=/usr/local/bin/start-octoprint
|
||||
ExecStart=/srv/octoprint/venv/bin/octoprint --host localhost --port 5000
|
||||
|
||||
[Install]
|
||||
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/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/start-octoprint "${ROOTFS_DIR}/usr/local/bin/start-octoprint"
|
||||
|
||||
mkdir -p ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/
|
||||
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
|
||||
|
||||
if dialog --title "OctoPrint Config" --yesno "Do you wish to change the default OctoPrint listening address and/or port?" 10 60; then
|
||||
octo_config
|
||||
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
|
||||
nginx_config
|
||||
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
|
||||
suggested_menu || return 1
|
||||
chown -R octoprint:octoprint /srv/octoprint
|
|
@ -9,20 +9,22 @@ source /usr/local/lib/octo-lib.sh
|
|||
|
||||
main_menu () {
|
||||
local MAINMENU=$(dialog --nocancel --title "Pi Setup" --menu "" 10 50 0 \
|
||||
"1" "Configure Networking" \
|
||||
"1" "Configure networking" \
|
||||
"2" "Change password for pi" \
|
||||
"3" "Configure services" \
|
||||
"4" "Configure screen timeout" \
|
||||
"5" "Configure OctoPrint" \
|
||||
"6" "Exit" 3>&1 1>&2 2>&3)
|
||||
"5" "Configure Nginx" \
|
||||
"6" "Configure MJPG" \
|
||||
"7" "Exit" 3>&1 1>&2 2>&3)
|
||||
|
||||
case $MAINMENU in
|
||||
"1") nmtui; main_menu; return 0;;
|
||||
"2") change_password; main_menu; return 0;;
|
||||
"3") service_select; main_menu; return 0;;
|
||||
"4") screen_timeout; main_menu; return 0;;
|
||||
"5") octo_config; main_menu; return 0;;
|
||||
"6") return 0;;
|
||||
"5") nginx_config; main_menu; return 0;;
|
||||
"6") video_config; main_menu; return 0;;
|
||||
"7") return 0;;
|
||||
esac
|
||||
}
|
||||
|
|
@ -20,20 +20,23 @@ change_password () {
|
|||
service_select () {
|
||||
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) \
|
||||
"2" "GUI" $(if [[ $(systemctl get-default) == "graphical.target" ]]; 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)
|
||||
"2" "MJPG-Streamer" $(if [[ -f /etc/systemd/system/multi-user.target.wants/mjpg-streamer.service ]]; then echo "ON"; else echo "OFF"; fi) \
|
||||
"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)
|
||||
|
||||
local ENABLE_OCTO=false
|
||||
local ENABLE_MJPG=false
|
||||
local ENABLE_GUI=false
|
||||
local ENABLE_SSH=false
|
||||
|
||||
for i in "${SERVICE_MENU[@]}"; do
|
||||
case $i in
|
||||
"1") ENABLE_OCTO=true ;;
|
||||
"2") ENABLE_GUI=true ;;
|
||||
"3") ENABLE_SSH=true ;;
|
||||
"2") ENABLE_MJPG=true ;;
|
||||
"3") ENABLE_GUI=true ;;
|
||||
"4") ENABLE_SSH=true ;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
@ -43,6 +46,12 @@ service_select () {
|
|||
systemctl disable octoprint
|
||||
fi
|
||||
|
||||
if [[ $ENABLE_MJPG == true ]]; then
|
||||
systemctl enable mjpg-streamer
|
||||
else
|
||||
systemctl disable mjpg-streamer
|
||||
fi
|
||||
|
||||
if [[ $ENABLE_GUI == true ]]; then
|
||||
systemctl set-default graphical.target
|
||||
else
|
||||
|
@ -78,30 +87,39 @@ EOF
|
|||
}
|
||||
|
||||
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
|
||||
xset s ${TIMEOUT}
|
||||
xset -dpms
|
||||
EOF
|
||||
}
|
||||
|
||||
octo_config () {
|
||||
if [[ -f /srv/octoprint/host ]]; then
|
||||
source /srv/octoprint/host
|
||||
nginx_config () {
|
||||
local LISTEN=""
|
||||
|
||||
if [[ -f /etc/nginx/listen.conf ]]; then
|
||||
LISTEN=$(grep -i listen /etc/nginx/listen.conf | awk '{gsub(";",""); print $2}')
|
||||
else
|
||||
HOST="0.0.0.0"
|
||||
PORT="5000"
|
||||
LISTEN="80"
|
||||
fi
|
||||
|
||||
local OCTOFORM=$(dialog --title "OctoPrint Config" --nocancel --form "Configure what port and IP OctoPrint listen on." 10 50 0 \
|
||||
"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)
|
||||
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)
|
||||
|
||||
HOST=${OCTOFORM[0]}
|
||||
PORT=${OCTOFORM[1]}
|
||||
|
||||
echo -e "HOST=$HOST\nPORT=$PORT" > /srv/octoprint/host
|
||||
echo "listen $LISTEN;" > /etc/nginx/listen.conf
|
||||
}
|
||||
|
||||
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