Stephan Wendel b331de5bc2 Changed Paths according to new git repo
Signed-off-by: Stephan Wendel <me@stephanwe.de>
2021-10-27 18:52:49 +02:00

183 lines
6.2 KiB
Bash

#!/usr/bin/env bash
# Crow's Nest
# A multiple Cam and Stream Service for mainsailOS
# Written by Stephan Wendel aka KwadFan
# Copyright 2021
# https://github.com/KwadFan/webcamtest.git
# GPL V3
########
# Error handling, leave this in place
# set -x
set -e
source /common.sh
install_cleanup_trap
### Module Specific functions
function copy_config {
echo_green "Copying Default configuration File to ${CROWSNEST_DEFAULT_CONF_DIR}"
sudo -u "${BASE_USER}" cp sample_configs/${CROWSNEST_DEFAULT_CONF} "${CROWSNEST_DEFAULT_CONF_DIR}"/webcam.conf
}
## Check Dependencies, install if not installed
apt_update_skip
check_install_pkgs ${CROWSNEST_DEPS}
# Move to $HOME dir
cd /home/${BASE_USER}
### Install crowsnest
## Clone Repo
gitclone CROWSNEST_CROWSNEST_REPO crowsnest
# Check succsessfull clone.
if [ -d "/home/${BASE_USER}/webcamd" ]; then
pushd webcamd > /dev/null
if [ -d "$CROWSNEST_DEFAULT_CONF_DIR" ]; then
copy_config
else
echo_red "${CROWSNEST_DEFAULT_CONF_DIR} does not exist!"
echo_green "Creating ${CROWSNEST_DEFAULT_CONF_DIR}."
sudo -u ${BASE_USER} mkdir -p ${CROWSNEST_DEFAULT_CONF_DIR}
copy_config
fi
# Create symlink to webcamd script in /usr/local/bin
echo_green "Create Sym Link to ${PWD}/webcamd in /usr/local/bin ..."
sudo ln -sf $PWD/webcamd /usr/local/bin/
# Add webcamd to moonraker.conf
if [ "${CROWSNEST_MOONRAKER_SUPPORT}" = "y" ]; then
echo_green "Add webcamd (crowsnest) to Moonraker's Update Manager"
# Make sure moonraker.conf exists
if [ -f "${CROWSNEST_DEFAULT_CONF_DIR}/moonraker.conf" ]; then
echo -e "\n" >> ${CROWSNEST_DEFAULT_CONF_DIR}/moonraker.conf
while read -r line; do
echo -e "${line}" >> ${CROWSNEST_DEFAULT_CONF_DIR}/moonraker.conf
done < "$PWD/file_templates/moonraker_update.txt"
echo -e "\n" >> ${CROWSNEST_DEFAULT_CONF_DIR}/moonraker.conf
else
echo_red "File 'moonraker.conf' does not exist. [SKIPPING]"
fi
else
echo_red "Moonraker's Update Manager Support disabled [SKIPPING]"
fi
### Install Service
echo_green "Copying webcamd.service file \
to '/etc/systemd/system/webcamd.service'.. "
cp -p file_templates/webcamd.service /etc/systemd/system/
## Make sure raspicam become /dev/video0 Workaround
sudo sh -c "echo bcm2835-v4l2 >> /etc/modules"
## Enable systemd service
echo_green "Enable webcamd.service ..."
systemctl_if_exists enable webcamd.service
popd > /dev/null
fi
echo_green "Installing mjpeg-streamer ..."
### Clone and compile mjpg_streamer
## Due the fact that used mjpg_streamer has a weird folder structure
## We need some 'magic' to workaround that.
echo_green "Cloning mjpg-streamer Sources."
gitclone CROWSNEST_MJPG_REPO mjpg_tmp
sudo -u ${BASE_USER} mkdir -p mjpg-streamer
sudo -u ${BASE_USER} mv mjpg_tmp/mjpg-streamer-experimental/* mjpg-streamer/
## This Part is out of the original mjpg-streamer Module
## Credits to: Raymond Himle
## (Adapted from the OctoPi image creation scripts. Thanks Gina and Guysoft!)
echo_green "Installing mjpg-streamer Dependencies."
apt update
check_install_pkgs ${CROWSNEST_MJPG_DEPS}
apt install -y --allow-downgrades cmake=3.13.4-1 cmake-data=3.13.4-1
if [ $( is_in_apt libjpeg62-turbo-dev ) -eq 1 ]; then
apt-get -y --force-yes install libjpeg62-turbo-dev
elif [ $( is_in_apt libjpeg8-dev ) -eq 1 ]; then
apt-get -y --force-yes install libjpeg8-dev
fi
## Compile mjpg_streamer
echo_green "Compiling mjpg-streamer"
pushd mjpg-streamer > /dev/null
MJPG_STREAMER_BUILD_DIR=_build
[ -d ${MJPG_STREAMER_BUILD_DIR} ] || (mkdir ${MJPG_STREAMER_BUILD_DIR} && \
chown ${BASE_USER}:${BASE_USER} ${MJPG_STREAMER_BUILD_DIR})
[ -f ${MJPG_STREAMER_BUILD_DIR}/Makefile ] || (cd ${MJPG_STREAMER_BUILD_DIR} && \
sudo -u ${BASE_USER} cmake -DCMAKE${MJPG_STREAMER_BUILD_DIR}_TYPE=Release ..)
sudo -u ${BASE_USER} make -j $(nproc) -C ${MJPG_STREAMER_BUILD_DIR}
sudo -u ${BASE_USER} cp ${MJPG_STREAMER_BUILD_DIR}/mjpg_streamer .
sudo -u ${BASE_USER} find ${MJPG_STREAMER_BUILD_DIR} -name "*.so" -type f -exec cp {} . \;
popd > /dev/null
## Cleanup
echo_green "Removing temporary Repo Folder."
rm -rf mjpg_tmp
## Due the fact mjpg uses an older version of cmake we have to upgrade it.
apt install cmake cmake-data
## Create sym links
echo_green "Creating sym links..."
sudo ln -sf $PWD/mjpg-streamer/mjpg_streamer /usr/local/bin/
# Finished
echo_green "Successful installed mjpg-streamer."
### Install ustreamer
echo_green "Installing ustreamer ..."
### Clone and compile ustreamer
echo_green "Cloning ustreamer Sources."
gitclone CROWSNEST_USTREAMER_REPO ustreamer
echo_green "Installing ustreamer Dependencies."
apt update
apt --yes install ${CROWSNEST_USTREAMER_DEPS}
## Compile ustreamer
echo_green "Compiling ustreamer"
pushd ustreamer > /dev/null
if [ "${CROWSNEST_USTREAMER_WITH_OMX}" = "y" ] && \
[ "${CROWSNEST_USTREAMER_WITH_GPIO}" = "y" ]; then
echo_green "Compile ustreamer with OMX and GPIO Support..."
WITH_OMX=1 WITH_GPIO=1 make -j $(nproc)
elif [ "${CROWSNEST_USTREAMER_WITH_OMX}" = "y" ] && \
[ "${CROWSNEST_USTREAMER_WITH_GPIO}" = "n" ]; then
echo_green "Compile ustreamer with OMX Support..."
WITH_OMX=1 make -j $(nproc)
else
"Compile ustreamer without OMX and GPIO Support..."
make -j $(nproc)
fi
popd > /dev/null
## Create sym links
echo_green "Creating sym links..."
sudo ln -sf $PWD/ustreamer/ustreamer /usr/local/bin/
# Finished
echo_green "Successful installed ustreamer."
### Install v4l2rtspserver
echo_green "Installing v4l2rtspserver ..."
### Clone and compile ustreamer
echo_green "Cloning v4l2rtspserver Sources."
gitclone CROWSNEST_V4L2RTSP_REPO v4l2rtspserver
echo_green "Installing v4l2rtspserv Dependencies."
apt update
apt --yes install ${CROWSNEST_V4L2RTSP_DEPS}
# It seems v4l2rtspserver has trouble to compile with cmake 3.16
apt install -y --allow-downgrades cmake=3.13.4-1 cmake-data=3.13.4-1
## Compile ustreamer
echo_green "Compiling v4l2rtspserver"
pushd v4l2rtspserver > /dev/null
cmake -j $(nproc) . && make -j $(nproc)
popd > /dev/null
## Create sym links
echo_green "Creating sym links..."
sudo ln -sf $PWD/v4l2rtspserver/v4l2rtspserver /usr/local/bin/
# Finished
echo_green "Successful installed v4l2rtspserver."
### Final Cleanup
apt clean --yes
apt autoclean --yes
apt autoremove --purge --yes