feat: add mjpg-streamer installer

This commit is contained in:
th33xitus
2021-03-22 19:09:56 +01:00
parent 48d97dab01
commit 104089ea3d
5 changed files with 185 additions and 25 deletions

View File

@@ -7,6 +7,30 @@ check_moonraker(){
fi
}
get_user_selection_mjpg-streamer(){
while true; do
unset INSTALL_MJPG
echo
top_border
echo -e "| Install MJGP-Streamer for webcam support? |"
bottom_border
read -p "${cyan}###### Install MJPG-Streamer? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
INSTALL_MJPG="true"
break;;
N|n|No|no)
echo -e "###### > No"
INSTALL_MJPG="false"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
}
get_user_selection_kiauh_macros(){
#ask user for webui default macros
while true; do
@@ -67,6 +91,9 @@ install_webui(){
### check if another site already listens to port 80
$1_port_check
### ask user to install mjpg-streamer
get_user_selection_mjpg-streamer
### ask user to install the recommended webinterface macros
get_user_selection_kiauh_macros "$IF_NAME2"
@@ -78,6 +105,13 @@ install_webui(){
### install mainsail/fluidd
$1_setup
### install mjpg-streamer
[ "$INSTALL_MJPG" = "true" ] && install_mjpg-streamer
### confirm message
CONFIRM_MSG="$IF_NAME1 has been set up!"
print_msg && clear_msg
}
install_kiauh_macros(){
@@ -247,8 +281,6 @@ mainsail_setup(){
if [ $(ls /etc/systemd/system/moonraker* | wc -l) -gt 1 ]; then
enable_mainsail_remotemode
fi
ok_msg "Mainsail installation complete!\n"
}
enable_mainsail_remotemode(){
@@ -272,6 +304,5 @@ fluidd_setup(){
### delete downloaded zip
status_msg "Remove downloaded archive ..."
rm -rf *.zip && ok_msg "Done!" && ok_msg "Fluidd installation complete!"
echo
rm -rf *.zip && ok_msg "Done!"
}

104
scripts/install_mjpg-streamer.sh Executable file
View File

@@ -0,0 +1,104 @@
### base variables
SYSTEMDDIR="/etc/systemd/system"
WEBCAMD_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/home/root/bin/webcamd"
WEBCAM_TXT_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/boot/mainsail.txt"
install_mjpg-streamer(){
### if there is a webcamd.service -> exit
if [ -e $SYSTEMDDIR/webcamd.service ]; then
ERROR_MSG="Looks like MJPG-streamer is already installed!\n Please remove it first before you try to re-install it!"
print_msg && clear_msg && return 0
fi
### checking dependencies
check_klipper_cfg_path
### set path for the webcam config textfile
WEBCAM_TXT="$klipper_cfg_loc/webcam.txt"
### check and install dependencies if missing
dep=(build-essential git imagemagick libv4l-dev libjpeg-dev libjpeg62-turbo-dev cmake)
dependency_check
### step 1: clone moonraker
status_msg "Downloading MJPG-Streamer ..."
cd ${HOME} && git clone https://github.com/jacksonliam/mjpg-streamer.git
ok_msg "Download complete!"
### step 2: compiling mjpg-streamer
status_msg "Compiling MJPG-Streamer ..."
cd ${HOME}/mjpg-streamer/mjpg-streamer-experimental && make
ok_msg "Compiling complete!"
#step 3: install mjpg-streamer
status_msg "Installing MJPG-Streamer ..."
cd ${HOME}/mjpg-streamer && mv mjpg-streamer-experimental/* .
mkdir www-mjpgstreamer
cat <<EOT >> ./www-mjpgstreamer/index.html
<html>
<head><title>mjpg_streamer test page</title></head>
<body>
<h1>Snapshot</h1>
<p>Refresh the page to refresh the snapshot</p>
<img src="./?action=snapshot" alt="Snapshot">
<h1>Stream</h1>
<img src="./?action=stream" alt="Stream">
</body>
</html>
EOT
sudo wget $WEBCAMD_SRC -O "/usr/local/bin/webcamd"
sudo sed -i "/MJPGSTREAMER_HOME/ s/pi/${USER}/" /usr/local/bin/webcamd
sudo sed -i "/^cfg_files+=/ s|=.*|=$WEBCAM_TXT|" /usr/local/bin/webcamd
sudo chmod +x /usr/local/bin/webcamd
### step 4: create webcam.txt config file
if [ ! -f $WEBCAM_TXT ]; then
### create the config dir if it doesn't exist
if [ ! -d $klipper_cfg_loc ]; then
status_msg "Creating $klipper_cfg_loc ..."
mkdir -p $klipper_cfg_loc
fi
status_msg "Creating webcam.txt config file ..."
wget $WEBCAM_TXT_SRC -O $WEBCAM_TXT
ok_msg "Done!"
fi
### step 5: create systemd service
status_msg "Creating MJPG-Streamer service ..."
sudo /bin/sh -c "cat > ${SYSTEMDDIR}/webcamd.service" << EOF
[Unit]
Description=Starts mjpg-streamer on startup
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=forking
User=${USER}
WorkingDirectory=/usr/local/bin
StandardOutput=append:/var/log/webcamd.log
StandardError=append:/var/log/webcamd.log
ExecStart=/usr/local/bin/webcamd
Restart=always
RestartSec=10
EOF
### step 6: enabling and starting mjpg-streamer service
status_msg "Starting MJPG-Streamer service ..."
sudo systemctl enable webcamd.service
sudo systemctl start webcamd.service
ok_msg "MJPG-Streamer service started!"
### confirm message
CONFIRM_MSG="MJPG-Streamer has been set up!"
print_msg && clear_msg
### print webcam ip adress/url
IP=$(hostname -I | cut -d" " -f1)
WEBCAM_IP="http://$IP:8080/?action=stream"
WEBCAM_URL="http://$IP/webcam/?action=stream"
echo -e " ${cyan}● Webcam URL:${default} $WEBCAM_IP"
echo -e " ${cyan}● Webcam URL:${default} $WEBCAM_URL"
echo
}

View File

@@ -386,3 +386,25 @@ remove_klipperscreen(){
CONFIRM_MSG="KlipperScreen successfully removed!"
}
remove_mjpg-streamer(){
### remove MJPG-Streamer service
if [ -e $SYSTEMDDIR/webcamd.service ]; then
status_msg "Removing MJPG-Streamer service ..."
sudo systemctl stop webcamd && sudo systemctl disable webcamd
sudo rm -f $SYSTEMDDIR/webcamd.service
###reloading units
sudo systemctl daemon-reload
sudo systemctl reset-failed
ok_msg "MJPG-Streamer Service removed!"
fi
### remove MJPG-Streamer directory
if [ -d ${HOME}/mjpg-streamer ]; then
status_msg "Removing MJPG-Streamer directory ..."
rm -rf ${HOME}/mjpg-streamer
ok_msg "MJPG-Streamer directory removed!"
fi
CONFIRM_MSG="MJPG-Streamer successfully removed!"
}

View File

@@ -6,16 +6,16 @@ install_ui(){
echo -e "| all necessary dependencies for the various | "
echo -e "| functions on a completely fresh system. | "
hr
echo -e "| Firmware: | Klipper Webinterface: | "
echo -e "| 1) [Klipper] | 3) [Mainsail] | "
echo -e "| | 4) [Fluidd] | "
echo -e "| Klipper API: | | "
echo -e "| 2) [Moonraker] | HDMI Screen: | "
echo -e "| | 5) [KlipperScreen] | "
echo -e "| | | "
echo -e "| | Other: | "
echo -e "| | 6) [Duet Web Control] | "
echo -e "| | 7) [OctoPrint] | "
echo -e "| Firmware: | Touchscreen GUI: | "
echo -e "| 1) [Klipper] | 5) [KlipperScreen] | "
echo -e "| | | "
echo -e "| Klipper API: | Other: | "
echo -e "| 2) [Moonraker] | 6) [Duet Web Control] | "
echo -e "| | 7) [OctoPrint] | "
echo -e "| Klipper Webinterface: | | "
echo -e "| 3) [Mainsail] | Webcam: | "
echo -e "| 4) [Fluidd] | 8) [MJPG-Streamer] | "
echo -e "| | | "
quit_footer
}
@@ -38,6 +38,8 @@ install_menu(){
do_action "dwc_setup_dialog" "install_ui";;
7)
do_action "octoprint_setup_dialog" "install_ui";;
8)
do_action "install_mjpg-streamer" "install_ui";;
Q|q)
clear; main_menu; break;;
*)

View File

@@ -7,17 +7,16 @@ remove_ui(){
echo -e "| --> ~/kiauh-backups | "
echo -e "| You need remove them manually if you wish so. | "
hr
echo -e "| Firmware: | Klipper Webinterface: | "
echo -e "| 1) [Klipper] | 3) [Mainsail] | "
echo -e "| | 4) [Fluidd] | "
echo -e "| Klipper API: | | "
echo -e "| 2) [Moonraker] | HDMI Screen: | "
echo -e "| | 5) [KlipperScreen] | "
echo -e "| | | "
echo -e "| | Other: | "
echo -e "| | 6) [Duet Web Control] | "
echo -e "| | 7) [OctoPrint] | "
echo -e "| | 8) [NGINX] | "
echo -e "| Firmware: | Touchscreen GUI: | "
echo -e "| 1) [Klipper] | 5) [KlipperScreen] | "
echo -e "| | | "
echo -e "| Klipper API: | Other: | "
echo -e "| 2) [Moonraker] | 6) [Duet Web Control] | "
echo -e "| | 7) [OctoPrint] | "
echo -e "| Klipper Webinterface: | 8) [NGINX] | "
echo -e "| 3) [Mainsail] | 9) [MJPG-Streamer] | "
echo -e "| 4) [Fluidd] | | "
echo -e "| | | "
quit_footer
}
@@ -42,6 +41,8 @@ remove_menu(){
do_action "remove_octoprint" "remove_ui";;
8)
do_action "remove_nginx" "remove_ui";;
9)
do_action "remove_mjpg-streamer" "remove_ui";;
Q|q)
clear; main_menu; break;;
*)