Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ An installation script to install Octoprint on Raspbian Stretch. Can optionally
On a fresh installation on Raspbian Stretch, retrieve and run the install shell script.

```bash
~ $ wget https://raw.githubusercontent.com/thedudeguy/Octoprint-Install-Script/master/octoprint_setup.sh
~ $ chmod 755 octoprint_setup.sh
~ $ sudo ./octoprint_setup.sh
sudo bash -c "apt-get update && apt-get install curl -y && curl -s https://raw.githubusercontent.com/bradcarnage/Octoprint-Install-Script/proxmox-ubuntu-ct/octoprint_setup.sh | bash -s"
```
23 changes: 23 additions & 0 deletions assets/mjpgstreamer.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Configuration for /etc/init.d/mjpg_streamer

# The init.d script will only run if this variable non-empty.
MJPG_USER=mjpgstreamer

# base directory to use
BASEDIR=/opt/mjpgstreamer

# On what port to run daemon, default is 8090
PORT=8090

# Path to the mjpg_streamer executable, you need to set this to match your installation!
DAEMON=/usr/local/bin/mjpg_streamer

# What arguments to pass to mjpgstreamer, usually no need to touch this
DAEMON_ARGS=" -o 'output_http.so -p $PORT' -i 'input_uvc.so'"

# Process priority, 0 here will result in a priority 20 process.
# 0 ensures mjpg_streamer has a normal priority over user processes.
NICELEVEL=0

# Should we run at startup?
START=yes
151 changes: 151 additions & 0 deletions assets/mjpgstreamer.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#!/bin/sh

### BEGIN INIT INFO
# Provides: mjpgstreamer
# Required-Start: $local_fs networking
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: MJPG-Streamer daemon
# Description: Starts the MJPG-Streamer daemon with the user specified in
# /etc/default/mjpgstreamer.
### END INIT INFO

# Author: Sami Olmari & Gina Häußge & bradcarnage

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="MJPG-Streamer Daemon"
NAME="MJPG-Streamer"
PKGNAME=mjpgstreamer
PIDFILE=/var/run/$PKGNAME.pid
SCRIPTNAME=/etc/init.d/$PKGNAME
DEFAULTS=/etc/default/$PKGNAME

# Read configuration variable file if it is present
[ -r $DEFAULTS ] && . $DEFAULTS

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

# Exit if the DAEMON is not set
if [ -z "$DAEMON" ]
then
log_warning_msg "Not starting $PKGNAME, DAEMON not set in /etc/default/$PKGNAME."
exit 0
fi

# Exit if the DAEMON is not installed
[ -x "$DAEMON" ] || exit 0

# Load the VERBOSE setting and other rcS variables
[ -f /etc/default/rcS ] && . /etc/default/rcS

if [ -z "$START" -o "$START" != "yes" ]
then
log_warning_msg "Not starting $PKGNAME, edit /etc/default/$PKGNAME to start it."
exit 0
fi

if [ -z "$MJPG_USER" ]
then
log_warning_msg "Not starting $PKGNAME, MJPG_USER not set in /etc/default/$PKGNAME."
exit 0
fi

#
# Function to verify if a pid is alive
#
is_alive()
{
pid=`cat $1` > /dev/null 2>&1
kill -0 $pid > /dev/null 2>&1
return $?
}

#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started

is_alive $PIDFILE
RETVAL="$?"

if [ $RETVAL != 0 ]; then
start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \
--exec $DAEMON --chuid $MJPG_USER --user $MJPG_USER --nicelevel=$NICELEVEL \
-- $DAEMON_ARGS
RETVAL="$?"
fi
}

#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred

start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user $MJPG_USER --pidfile $PIDFILE
RETVAL="$?"
[ "$RETVAL" = "2" ] && return 2

rm -f $PIDFILE

[ "$RETVAL" = "0" ] && return 0 || return 1
}

case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
;;
restart)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
exit 3
;;
esac
48 changes: 48 additions & 0 deletions octoprint_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ touch $LOG
logpath=$(realpath $LOG)

installed_octoprint=0
installed_mjpgstreamer=0
installed_haproxy=0
installed_portrait_mode=0
installed_touchui=0
Expand Down Expand Up @@ -64,6 +65,7 @@ init_main() {
$DIALOG "${title_args[@]/#/}" --checklist --separate-output \
'Select features to install' 14 94 8 \
'OctoPrint' 'The snappy web interface for your 3D printer.' ON \
'MJPG-Streamer' 'Webcam Stream accessibility over port 8090.' ON \
'HAProxy' 'Allows both Octoprint and Webcam Stream accessibility on port 80 ' ON \
'Enable_GL' 'Enable Hardware Acceleration' ON \
'Portrait-Mode' 'Rotate the display 90 degrees' ON \
Expand All @@ -82,6 +84,8 @@ init_main() {
case $choice in
OctoPrint) install_octoprint
;;
MJPG-Streamer) install_mjpg_streamer
;;
HAProxy) install_haproxy
;;
Enable_GL) install_gl
Expand Down Expand Up @@ -188,6 +192,50 @@ install_octoprint() {

}

# MJPG-Streamer installation
# Reference: https://github.com/jacksonliam/mjpg-streamer
install_mjpg_streamer() {
logwrite " "
logwrite "----- Installing MJPG-Streamer -----"

set_window_title "Installing MJPG-Streamer"

run_apt_install cmake libjpeg8-dev gcc g++

begin_command_group "Setting up MJPG-Streamer"
add_command mkdir -p /opt/mjpgstreamer
run_git_clone https://github.com/jacksonliam/mjpg-streamer.git /opt/mjpgstreamer/mjpg-streamer
add_command cd /opt/mjpgstreamer/mjpg-streamer/mjpg-streamer-experimental
add_command make
add_command make install
add_command rm -rf /opt/mjpgstreamer/mjpg-streamer
run_command_group

begin_command_group "Setting up user"
add_command useradd --system --shell /bin/bash --create-home --home-dir /home/mjpgstreamer mjpgstreamer
add_command usermod -a -G video mjpgstreamer
run_command_group

defaults_file_url="https://raw.githubusercontent.com/thedudeguy/Octoprint-Install-Script/master/assets/mjpgstreamer.default"
defaults_file_path="/opt/mjpgstreamer/mjpgstreamer.default"
run_wget "$defaults_file_url" "$defaults_file_path"
defaults_file_url="https://raw.githubusercontent.com/thedudeguy/Octoprint-Install-Script/master/assets/mjpgstreamer.init"
defaults_file_path="/opt/mjpgstreamer/mjpgstreamer.init"
run_wget "$defaults_file_url" "$defaults_file_path"

begin_command_group "Installing startup scripts"
add_command cp /opt/mjpgstreamer/mjpgstreamer.init /etc/init.d/mjpgstreamer
add_command chmod +x /etc/init.d/mjpgstreamer
add_command cp /opt/mjpgstreamer/mjpgstreamer.default /etc/default/mjpgstreamer
add_command update-rc.d mjpgstreamer defaults
run_command_group

installed_mjpgstreamer=1
logwrite " "
logwrite "***** MJPG-Streamer Installed *****"

}

# HAProxy Installation#
# Reference: https://github.com/foosel/OctoPrint/wiki/Setup-on-a-Raspberry-Pi-running-Raspbian
install_haproxy() {
Expand Down