refactor(installl): refactor install chain

This commit should cover the following:

Missing insatllation candidate of libjpeg8-dev in bullseye images,
fixes #16 and #15

Refactores installation of ustreamer.
This should cover #12

Dropped ustreamer as submodule and clone it via install script.
For buster based images it reset the repo to last commit of v4.13 (omx support)
All other will get master branch (latest commit at insatllation)

This enables posibility to write an app updater.

Fixes custompios module according to changes.
This commit is contained in:
Stephan Wendel 2022-06-11 18:48:44 +02:00
parent dc710d0abe
commit 6071c6fc76
No known key found for this signature in database
GPG Key ID: F465B83ACBA45639
14 changed files with 180 additions and 423 deletions

3
.gitignore vendored
View File

@ -22,3 +22,6 @@ lost*
# Ignore rtsp-simple-server binary
bin/rtsp-simple-server/rtsp*
bin/rtsp-simple-server/*.yml
# Ignore Custom Config for Intsaller
tools/config.local

6
.gitmodules vendored
View File

@ -1,6 +0,0 @@
[submodule "bin/ustreamer"]
path = bin/ustreamer
url = https://github.com/pikvm/ustreamer
branch = master
ignore = untracked

View File

@ -7,7 +7,7 @@
#### This File is distributed under GPLv3
####
.PHONY: help install unsinstall build buildclean uninstallgo update
.PHONY: help install unsinstall build buildclean
# Setup
USER = $(shell whoami)
@ -27,7 +27,6 @@ help:
@echo ""
@echo " install Installs crowsnest"
@echo " uninstall Uninstalls crowsnest"
@echo " update Updates crowsnest (if needed)"
@echo " build builds binaries"
@echo " buildclean cleans binaries (for recompile)"
@echo ""
@ -41,11 +40,7 @@ unattended:
uninstall:
@bash -c 'tools/uninstall.sh'
update:
@bash -c 'tools/update.sh'
build:
@git submodule update
$(MAKE) -C $(BIN_FOLDER)
buildclean:

View File

@ -37,14 +37,6 @@ to your moonraker.conf, to get latest and possibly greatest Features.
cd ~/crowsnest
make uninstall
### To manually update 'crowsnest'
Normally, you can update via moonraker's Update Manager.
Sometimes manual intervention is needed! See commit messages.
cd ~/crowsnest
make update
### Are there more options?
Yes.

@ -1 +0,0 @@
Subproject commit 61ab2a81a50c2347685b9993ddf84d0833ca7cfa

View File

@ -22,7 +22,7 @@
# ustreamer
[ -n "$CROWSNEST_USTREAMER_DEPS" ] || CROWSNEST_USTREAMER_DEPS="git build-essential libevent-dev libjpeg8-dev \
[ -n "$CROWSNEST_USTREAMER_DEPS" ] || CROWSNEST_USTREAMER_DEPS="git build-essential libevent-dev libjpeg-dev \
libbsd-dev libraspberrypi-dev libgpiod-dev"
[ -n "$CROWSNEST_USTREAMER_WITH_OMX" ] || CROWSNEST_USTREAMER_WITH_OMX="y"
[ -n "$CROWSNEST_USTREAMER_WITH_GPIO" ] || CROWSNEST_USTREAMER_WITH_GPIO="n"

View File

@ -22,7 +22,8 @@ echo_green "Installing crowsnest and enable webcam Service ..."
# force apt update
apt update
# It could use inbuilt dependencie check, but should speed up if preinstalled.
check_install_pkgs "${CROWSNEST_CROWSNEST_DEPS}"
# shellcheck disable=SC2086
check_install_pkgs ${CROWSNEST_CROWSNEST_DEPS} ${CROWSNEST_USTREAMER_DEPS}
# Move to $HOME dir
pushd "/home/${BASE_USER}" &> /dev/null || exit 1
# make sure config folder exist

28
tools/config.bullseye Normal file
View File

@ -0,0 +1,28 @@
#!/bin/bash
#### webcamd - A webcam Service for multiple Cams and Stream Services.
####
#### Written by Stephan Wendel aka KwadFan <me@stephanwe.de>
#### Copyright 2021
#### https://github.com/mainsail-crew/crowsnest
####
#### This File is distributed under GPLv3
####
# shellcheck disable=all
[ -n "$CROWSNEST_CROWSNEST_DEPS" ] || CROWSNEST_CROWSNEST_DEPS="git crudini bsdutils findutils v4l-utils ffmpeg"
[ -n "$CROWSNEST_DEFAULT_CONF" ] || CROWSNEST_DEFAULT_CONF="mainsail_default.conf"
[ -n "$CROWSNEST_DEFAULT_CONF_DIR" ] || CROWSNEST_DEFAULT_CONF_DIR="/home/${BASE_USER}/klipper_config"
# Force Raspicam fix bool (1:yes / 0:no)
[ -n "$CROWSNEST_FORCE_RASPICAMFIX" ] || CROWSNEST_FORCE_RASPICAMFIX=1
# Add Crowsnest to moonraker.conf (update manager) bool (1:yes / 0:no)
[ -n "$CROWSNEST_ADD_CROWSNEST_MOONRAKER" ] || CROWSNEST_ADD_CROWSNEST_MOONRAKER=1
# ustreamer
[ -n "$CROWSNEST_USTREAMER_REPO_SHIP" ] || CROWSNEST_USTREAMER_REPO_SHIP=https://github.com/pikvm/ustreamer.git
[ -n "$CROWSNEST_USTREAMER_REPO_BRANCH" ] || CROWSNEST_USTREAMER_REPO_BRANCH=master
[ -n "$CROWSNEST_USTREAMER_DEPS" ] || CROWSNEST_USTREAMER_DEPS="git build-essential libevent-dev libjpeg62-turbo-dev \
libbsd-dev libgpiod-dev"
[ -n "$CROWSNEST_USTREAMER_WITH_OMX" ] || CROWSNEST_USTREAMER_WITH_OMX="n"
[ -n "$CROWSNEST_USTREAMER_WITH_GPIO" ] || CROWSNEST_USTREAMER_WITH_GPIO="n"

28
tools/config.buster Normal file
View File

@ -0,0 +1,28 @@
#!/bin/bash
#### webcamd - A webcam Service for multiple Cams and Stream Services.
####
#### Written by Stephan Wendel aka KwadFan <me@stephanwe.de>
#### Copyright 2021
#### https://github.com/mainsail-crew/crowsnest
####
#### This File is distributed under GPLv3
####
# shellcheck disable=all
[ -n "$CROWSNEST_CROWSNEST_DEPS" ] || CROWSNEST_CROWSNEST_DEPS="git crudini bsdutils findutils v4l-utils ffmpeg"
[ -n "$CROWSNEST_DEFAULT_CONF" ] || CROWSNEST_DEFAULT_CONF="mainsail_default.conf"
[ -n "$CROWSNEST_DEFAULT_CONF_DIR" ] || CROWSNEST_DEFAULT_CONF_DIR="/home/${BASE_USER}/klipper_config"
# Force Raspicam fix bool (1:yes / 0:no)
[ -n "$CROWSNEST_FORCE_RASPICAMFIX" ] || CROWSNEST_FORCE_RASPICAMFIX=1
# Add Crowsnest to moonraker.conf (update manager) bool (1:yes / 0:no)
[ -n "$CROWSNEST_ADD_CROWSNEST_MOONRAKER" ] || CROWSNEST_ADD_CROWSNEST_MOONRAKER=1
# ustreamer
[ -n "$CROWSNEST_USTREAMER_REPO_SHIP" ] || CROWSNEST_USTREAMER_REPO_SHIP=https://github.com/pikvm/ustreamer
[ -n "$CROWSNEST_USTREAMER_REPO_BRANCH" ] || CROWSNEST_USTREAMER_REPO_BRANCH=master
[ -n "$CROWSNEST_USTREAMER_DEPS" ] || CROWSNEST_USTREAMER_DEPS="git build-essential libevent-dev libjpeg8-dev \
libbsd-dev libraspberrypi-dev libgpiod-dev"
[ -n "$CROWSNEST_USTREAMER_WITH_OMX" ] || CROWSNEST_USTREAMER_WITH_OMX="y"
[ -n "$CROWSNEST_USTREAMER_WITH_GPIO" ] || CROWSNEST_USTREAMER_WITH_GPIO="n"

View File

@ -0,0 +1,28 @@
#!/bin/bash
#### webcamd - A webcam Service for multiple Cams and Stream Services.
####
#### Written by Stephan Wendel aka KwadFan <me@stephanwe.de>
#### Copyright 2021
#### https://github.com/mainsail-crew/crowsnest
####
#### This File is distributed under GPLv3
####
# shellcheck disable=all
[ -n "$CROWSNEST_CROWSNEST_DEPS" ] || CROWSNEST_CROWSNEST_DEPS="git crudini bsdutils findutils v4l-utils ffmpeg"
[ -n "$CROWSNEST_DEFAULT_CONF" ] || CROWSNEST_DEFAULT_CONF="mainsail_default.conf"
[ -n "$CROWSNEST_DEFAULT_CONF_DIR" ] || CROWSNEST_DEFAULT_CONF_DIR="/home/${BASE_USER}/klipper_config"
# Force Raspicam fix bool (1:yes / 0:no)
[ -n "$CROWSNEST_FORCE_RASPICAMFIX" ] || CROWSNEST_FORCE_RASPICAMFIX=0
# Add Crowsnest to moonraker.conf (update manager) bool (1:yes / 0:no)
[ -n "$CROWSNEST_ADD_CROWSNEST_MOONRAKER" ] || CROWSNEST_ADD_CROWSNEST_MOONRAKER=0
# ustreamer
[ -n "$CROWSNEST_USTREAMER_REPO_SHIP" ] || CROWSNEST_USTREAMER_REPO_SHIP=https://github.com/pikvm/ustreamer.git
[ -n "$CROWSNEST_USTREAMER_REPO_BRANCH" ] || CROWSNEST_USTREAMER_REPO_BRANCH=master
[ -n "$CROWSNEST_USTREAMER_DEPS" ] || CROWSNEST_USTREAMER_DEPS="git build-essential libevent-dev libjpeg62-turbo-dev \
libbsd-dev libgpiod-dev"
[ -n "$CROWSNEST_USTREAMER_WITH_OMX" ] || CROWSNEST_USTREAMER_WITH_OMX="n"
[ -n "$CROWSNEST_USTREAMER_WITH_GPIO" ] || CROWSNEST_USTREAMER_WITH_GPIO="n"

View File

@ -17,6 +17,8 @@ libxcomposite1 libxtst6"
[ -n "$CROWSNEST_MOONRAKER_SUPPORT" ] || CROWSNEST_MOONRAKER_SUPPORT="y"
# ustreamer
[ -n "$CROWSNEST_USTREAMER_REPO_SHIP" ] || CROWSNEST_USTREAMER_REPO_SHIP=https://github.com/pikvm/ustreamer.git
[ -n "$CROWSNEST_USTREAMER_REPO_BRANCH" ] || CROWSNEST_USTREAMER_REPO_BRANCH=master
[ -n "$CROWSNEST_USTREAMER_DEPS" ] || CROWSNEST_USTREAMER_DEPS="git build-essential libevent-dev libjpeg-dev \
libbsd-dev"
[ -n "$CROWSNEST_USTREAMER_WITH_OMX" ] || CROWSNEST_USTREAMER_WITH_OMX="n"

View File

@ -84,22 +84,47 @@ function err_exit {
### Init ERR Trap
trap 'err_exit $? $LINENO' ERR
## helper func
## call get_os_version <keyword>
function get_os_version {
if [ -n "${1}" ]; then
grep -c "${1}" /etc/os-release
fi
}
### Import config from custompios.
function import_config {
if [ "$(uname -m)" == "x86_64" ] &&
[ -f tools/x86_config ]; then
## Source Custom config if present
if [ -s tools/config.local ]; then
# shellcheck disable=SC1091
source tools/x86_config
else
if [ -f "${HOME}/crowsnest/custompios/crowsnest/config" ]; then
# shellcheck disable=SC1091
source custompios/crowsnest/config
else
echo -e "${TITLE}\n"
echo -e "OOPS!\nConfiguration File missing! Exiting..."
echo -e "Try to git clone a second time please ...\n"
exit 1
fi
source tools/config.local
return 0
fi
## X86 machines
if [ "$(uname -m)" == "x86_64" ] &&
[ -f tools/config.x86 ]; then
# shellcheck disable=SC1091
source tools/config.x86
return 0
fi
## rpi os buster
if [ "$(uname -m)" != "x86_64" ] &&
[ "$(get_os_version buster)" != "0" ] &&
[ -f "tools/config.buster" ]; then
# shellcheck disable=SC1091
source tools/config.buster
return 0
fi
## rpi os bullseye
if [ "$(uname -m)" != "x86_64" ] &&
[ "$(get_os_version bullseye)" != "0" ] &&
[ -f "tools/config.bullseye" ]; then
# shellcheck disable=SC1091
source tools/config.bullseye
return 0
fi
}
@ -167,12 +192,17 @@ function install_crowsnest {
moonraker_update="${PWD}/file_templates/moonraker_update.txt"
## helper func moonraker update_manager
function add_update_entry {
sudo -u "${BASE_USER}" \
cp "${moonraker_conf}" "${moonraker_conf}.backup" &&
cat "${moonraker_conf}" "${moonraker_update}" > /tmp/moonraker.conf &&
cp -rf /tmp/moonraker.conf "${moonraker_conf}"
if [ "${UNATTENDED}" == "true" ]; then
sudo rm -f "${moonraker_conf}.backup"
if [ -f "${moonraker_conf}" ]; then
echo -e "Adding [update_manager] entry ..."
sudo -u "${BASE_USER}" \
cp "${moonraker_conf}" "${moonraker_conf}.backup" &&
cat "${moonraker_conf}" "${moonraker_update}" > /tmp/moonraker.conf &&
cp -rf /tmp/moonraker.conf "${moonraker_conf}"
if [ "${UNATTENDED}" == "true" ]; then
sudo rm -f "${moonraker_conf}.backup"
fi
else
echo -e "moonraker.conf is missing ... [SKIPPED]"
fi
}
echo -e "\nInstall webcamd Service ..."
@ -230,7 +260,8 @@ function install_crowsnest {
echo -e "Adding Crowsnest Update Manager entry to moonraker.conf ... [OK]"
fi
## Manual install
if [ "${UNATTENDED}" != "true" ]; then
if [ "${UNATTENDED}" != "true" ] &&
[ "${CROWSNEST_ADD_CROWSNEST_MOONRAKER}" != "0" ]; then
read -rp "Do you want to add [update_manager] entry?(y/n) " addconf
case "${addconf}" in
y*|Y*)
@ -254,17 +285,27 @@ function install_crowsnest {
fi
}
# Make sure submodules are initialized
function sub_init {
if [ ! -f "${HOME}/crowsnest/bin/ustreamer/Makefile" ]; then
echo -e "Submodule is not initialized ..."
git submodule update --init > /dev/null
echo -e "Submodule is not initialized ... [OK]"
function clone_ustreamer {
## remove bin/ustreamer if exist
if [ -d bin/ustreamer ]; then
rm -rf bin/ustreamer
fi
git clone "${CROWSNEST_USTREAMER_REPO_SHIP}" \
-b "${CROWSNEST_USTREAMER_REPO_BRANCH}" bin/ustreamer
## Buster workaround
## ustreamer support omx only till version 4.13
## so stick to that version
if [ "$(get_os_version buster)" != "0" ]; then
pushd bin/ustreamer &> /dev/null || exit 1
git reset --hard 61ab2a8
popd &> /dev/null || exit 1
fi
}
function build_apps {
echo -e "Build dependend Stream Apps ..."
echo -e "Cloning ustreamer repository ..."
clone_ustreamer
echo -e "Installing 'ustreamer' Dependencies ..."
# shellcheck disable=2086
sudo apt install --yes --no-install-recommends ${CROWSNEST_USTREAMER_DEPS} > /dev/null
@ -287,6 +328,21 @@ function install_raspicam_fix {
fi
}
function enable_legacy_cam {
local cfg
cfg="/boot/config.txt"
echo -en "Enable legacy camera stack ... \r"
sudo sed -i "s/camera_auto_detect=1/#camera_auto_detect=1/" "${cfg}"
if [ "$(grep -c "start_x" "${cfg}")" == "0" ]; then
sudo crudini --set --inplace "${cfg}" all start_x 1 &> /dev/null
fi
if [ "$(grep -c "gpu_mem" "${cfg}")" == "0" ]; then
sudo crudini --set --inplace "${cfg}" pi4 gpu_mem 256 &> /dev/null
sudo crudini --set --inplace "${cfg}" all gpu_mem 128 &> /dev/null
fi
echo -e "Enable legacy camera stack ... [OK]"
}
#### MAIN
while getopts "z" arg; do
case ${arg} in
@ -309,11 +365,14 @@ fi
echo -e "Running apt update first ..."
sudo apt update
install_crowsnest
sub_init
build_apps
if [ "${UNATTENDED}" != "true" ]; then
if [ "${UNATTENDED}" != "true" ] &&
[ "${CROWSNEST_FORCE_RASPICAMFIX}" != "0" ]; then
install_raspicam_fix
fi
if [ "$(get_os_version bullseye)" != "0" ]; then
enable_legacy_cam
fi
goodbye_msg
exit 0

View File

@ -75,9 +75,6 @@ function ask_uninstall {
read -rp "Do you REALLY want to remove existing 'crowsnest'? (YES/NO) " remove
if [ "${remove}" = "YES" ]; then
uninstall_crowsnest
uninstall_v4l2rtsp
# go unsinstaller is deprecated will be removed in future
uninstall_go
remove_raspicam_fix
remove_logrotate
goodbye_msg
@ -109,37 +106,6 @@ function uninstall_crowsnest {
echo -e "Uninstalling webcamd.service...[OK]\r"
}
#obsolete will be removed in future
function uninstall_v4l2rtsp {
local bin_path v4l2rtsp_dir
bin_path="/usr/local/bin/v4l2rtspserver"
v4l2rtsp_dir="${HOME}/v4l2rtspserver"
if [ -d "${v4l2rtsp_dir}" ]; then
echo -en "Uninstalling 'v4l2rtspserver' ...\r"
if [ -x "${bin_path}" ]; then
sudo rm -f "${bin_path}"
fi
sudo rm -rf "${v4l2rtsp_dir}"
echo -e "Uninstalling 'v4l2rtspserver' ... [OK]\r"
fi
}
#obsolete will be removed in future
function uninstall_go {
if [ -n "$(whereis -b go | awk '{print $2}')" ]; then
echo -e "\nFound $(go version)\n"
else
echo -e "No Version of Go Lang found ... [SKIPPED]"
fi
if [ -d "/usr/local/go" ] && [ -f "${HOME}/.gorc" ]; then
sudo rm -rf "$(whereis -b go | awk '{print $2}')"
rm -f "${HOME}/.gorc"
sudo rm -rf "${HOME}/golang"
sed -i '/# Add Go/d;/.gorc/d' "${HOME}/.profile"
echo -e "\nUninstall complete!"
fi
}
function remove_raspicam_fix {
if [ -f /etc/modprobe.d/bcm2835-v4l2.conf ] &&
[ -f /proc/device-tree/model ] &&

View File

@ -1,338 +0,0 @@
#!/usr/bin/env bash
#### webcamd - A webcam Service for multiple Cams and Stream Services.
####
#### Written by Stephan Wendel aka KwadFan <me@stephanwe.de>
#### Copyright 2021
#### https://github.com/mainsail-crew/crowsnest
####
#### This File is distributed under GPLv3
####
# shellcheck enable=requires-variable-braces
# Global Vars
BASE_USER=$(whoami)
TITLE="crowsnest - A Webcam Daemon for Raspberry Pi OS"
### Non root
if [ ${UID} == '0' ]; then
echo -e "DO NOT RUN THIS SCRIPT AS ROOT!\nExiting..."
exit 1
fi
### noninteractive Check
if [ -z "${DEBIAN_FRONTEND}" ]; then
export DEBIAN_FRONTEND=noninteractive
fi
### Functions
### Messages
# Welcome Message
function welcome_msg {
echo -e "${TITLE}\n"
echo -e "\tYou will be prompted for your 'sudo' password, if needed."
echo -e "\tSome Parts of the Updater requires 'root' privileges."
# Dirty hack to gain root permissions
sudo echo -e "\n"
}
# Goodbye Message
function goodbye_msg {
echo -e "\nInstallation complete.\n"
echo -e "\tIn case something was updated:\n\tPlease reboot your machine!"
echo -e "I hope you enjoy crowsnest, GoodBye ..."
}
# No longer needed Message
function remove_message {
echo -e "Found ${1}, remove because it is not longer needed."
}
### General
## These two functions are reused from custompios common.sh
## Credits to guysoft!
## https://github.com/guysoft/CustomPiOS
function install_cleanup_trap() {
# kills all child processes of the current process on SIGINT or SIGTERM
trap 'cleanup' SIGINT SIGTERM
}
function cleanup() {
# make sure that all child processed die when we die
echo -e "Killed by user ...\r\nGoodBye ...\r"
# shellcheck disable=2046
[ -n "$(jobs -pr)" ] && kill $(jobs -pr) && sleep 5 && kill -9 $(jobs -pr)
}
function err_exit {
if [ "${1}" != "0" ]; then
echo -e "ERROR: Error ${1} occured on line ${2}"
echo -e "ERROR: Stopping $(basename "$0")."
echo -e "Goodbye..."
fi
# shellcheck disable=2046
[ -n "$(jobs -pr)" ] && kill $(jobs -pr) && sleep 5 && kill -9 $(jobs -pr)
exit 1
}
### Init ERR Trap
trap 'err_exit $? $LINENO' ERR
# Helper funcs
function stop_webcamd {
if [ "$(sudo systemctl is-active webcamd.service)" = "active" ]; then
sudo systemctl stop webcamd &> /dev/null
fi
}
function start_webcamd {
if [ "$(sudo systemctl is-active webcamd.service)" = "active" ]; then
sudo systemctl start webcamd &> /dev/null
fi
}
function daemon_reload {
echo -en "Reload systemd to enable new deamon ...\r"
sudo systemctl daemon-reload &> /dev/null
echo -e "Reload systemd to enable new daemon ... [OK]"
}
function compare_files {
local installed template
installed="$(sha256sum "${1}" | awk '{print $1}')"
template="$(sha256sum "${2}" | awk '{print $1}')"
if [ -f "${1}" ] && [ "${installed}" != "${template}" ]; then
echo "1"
else
echo "0"
fi
}
### Import config from custompios.
function import_config {
if [ -f "${HOME}/crowsnest/custompios/crowsnest/config" ]; then
# shellcheck disable=SC1091
source custompios/crowsnest/config
else
echo -e "${TITLE}\n"
echo -e "OOPS!\nConfiguration File missing! Exiting..."
echo -e "Try to git clone a second time please ...\n"
exit 1
fi
}
# Copy Files funcs
function copy_service {
local servicefile template origin
origin="/etc/systemd/system/webcamd.service"
if [ ! "${BASE_USER}" == "pi" ]; then
template="${HOME}/crowsnest/file_templates/webcamd.service"
cp -rf "${template}" /tmp/webcamd.service
sudo sed -i 's|pi|'"${BASE_USER}"'|g' /tmp/webcamd.service
servicefile="/tmp/webcamd.service"
else
servicefile="${HOME}/crowsnest/file_templates/webcamd.service"
fi
if [ "$(compare_files "${origin}" "${servicefile}")" -eq 1 ]; then
echo -en "Copying webcamd.service file ...\r"
sudo cp -rf "${servicefile}" "${origin}" > /dev/null
echo -e "Copying webcamd.service file ... [OK]\r"
daemon_reload
else
echo -e "No update of '${origin}' required."
fi
# Clean Temp File
if [ -f /tmp/webcamd.service ]; then
sudo rm -f /tmp/webcamd.service
fi
}
function copy_logrotate {
local logrotatefile template origin
origin="/etc/logrotate.d/webcamd"
if [ ! "${BASE_USER}" == "pi" ]; then
template="${HOME}/crowsnest/file_templates/logrotate_webcamd"
cp -rf "${template}" /tmp/webcamd
sudo sed -i 's|pi|'"${BASE_USER}"'|g' /tmp/webcamd
logrotatefile="/tmp/webcamd"
else
logrotatefile="${HOME}/crowsnest/file_templates/logrotate_webcamd"
fi
if [ "$(compare_files "${origin}" "${logrotatefile}")" -eq 1 ]; then
echo -en "Copying logrotate file ...\r"
sudo cp -rf "${logrotatefile}" "${origin}" > /dev/null
echo -e "Copying logrotate file ... [OK]\r"
else
echo -e "No update of '${origin}' required."
fi
# Clean Temp File
if [ -f /tmp/webcamd ]; then
sudo rm -f /tmp/webcamd
fi
}
function copy_raspicam_fix {
local moduleconf origin
origin="/etc/modprobe.d/bcm2835-v4l2.conf"
moduleconf="${HOME}/crowsnest/file_templates/bcm2835-v4l2.conf"
if [ ! -f "${origin}" ]; then
echo -en "Copying bcm2835-v4l2.conf file ...\r"
sudo cp -rf "${moduleconf}" "${origin}" > /dev/null
echo -e "Copying bcm2835-v4l2.conf file ... [OK]\r"
else
if [ "$(compare_files "${origin}" "${moduleconf}")" -eq 1 ]; then
echo -en "Copying bcm2835-v4l2.conf file ...\r"
sudo cp -rf "${moduleconf}" "${origin}" > /dev/null
echo -e "Copying bcm2835-v4l2.conf file ... [OK]\r"
else
echo -e "No update of '${origin}' required."
fi
fi
}
# Uninstall funcs
function uninstall_v4l2rtsp {
local bin_path v4l2rtsp_dir
bin_path="/usr/local/bin/v4l2rtspserver"
v4l2rtsp_dir="${HOME}/v4l2rtspserver"
if [ -d "${v4l2rtsp_dir}" ]; then
remove_message "v4l2rtspserver"
echo -en "Uninstalling 'v4l2rtspserver' ...\r"
if [ -x "${bin_path}" ]; then
sudo rm -f "${bin_path}"
fi
sudo rm -rf "${v4l2rtsp_dir}"
echo -e "Uninstalling 'v4l2rtspserver' ... [OK]\r"
fi
}
# This removes ustreamer if not inside of crowsnest! ( $HOME/ustreamer )
function uninstall_ustreamer {
local bin_path ustreamer_dir
bin_path="/usr/local/bin/ustreamer"
ustreamer_dir="${HOME}/ustreamer"
if [ -d "${ustreamer_dir}" ]; then
remove_message "ustreamer"
echo -en "Uninstalling '${HOME}/ustreamer' ...\r"
if [ -x "${bin_path}" ]; then
sudo rm -f "${bin_path}"
fi
sudo rm -rf "${ustreamer_dir}"
echo -e "Uninstalling '${HOME}/ustreamer' ... [OK]\r"
fi
}
# Remove no longer needed Go installation
function uninstall_go {
if [ -n "$(whereis -b go | awk '{print $2}')" ]; then
echo -e "\nFound $(go version)\n"
else
echo -e "No Version of Go Lang found ... [SKIPPED]"
fi
if [ -d "/usr/local/go" ] && [ -f "${HOME}/.gorc" ]; then
sudo rm -rf "$(whereis -b go | awk '{print $2}')"
rm -f "${HOME}/.gorc"
sudo rm -rf "${HOME}/golang"
sed -i '/# Add Go/d;/.gorc/d' "${HOME}/.profile"
echo -e "\nUninstall complete!"
fi
}
# remove obsolete RTSPtoWebRTC
function uninstall_rtsp2webrtc {
if [ -d "${HOME}/crowsnest/bin/RTSPtoWebRTC" ];then
echo -e "Removing RTSPtoWebRTC ..."
sudo rm -rf "${HOME}/crowsnest/bin/RTSPtoWebRTC"
echo -e "Removing RTSPtoWebRTC ... [OK]"
fi
}
# Install funcs
# Make sure ustreamer submodule is initialized
function sub_init {
if [ ! -f "${HOME}/crowsnest/bin/ustreamer/Makefile" ]; then
echo -e "Submodules are not initialized ..."
git submodule update --init > /dev/null
echo -e "Submodules are not initialized ... [OK]"
fi
}
# Build Apps
function build_apps {
echo -e "\nDependency Check: Check for compiled Apps ..."
if [ ! -x "bin/ustreamer/src/ustreamer.bin" ] \
|| [ ! -x "bin/rtsp-simple-server/rtsp-simple-server" ]; then
echo -e "Build dependend Stream Apps ..."
echo -e "Installing 'ustreamer' Dependencies ..."
# shellcheck disable=2086
sudo apt install --yes --no-install-recommends ${CROWSNEST_USTREAMER_DEPS} > /dev/null
echo -e "Installing 'ustreamer' Dependencies ... [OK]"
pushd bin > /dev/null || exit 1
make all
popd > /dev/null || exit 1
else
echo -e "All Apps are present ... [OK]"
update_ustreamer
update_rtsp
fi
}
function update_ustreamer {
local sm_version us_version
sm_version="$(cd bin/ustreamer && git describe --always --tags | sed 's/^v//')"
us_version="$(bin/ustreamer/ustreamer -v)"
echo -en "Checking ustreamer Version ${sm_version} ... \r"
if [ "${sm_version}" == "${us_version}" ]; then
echo -e "Checking ustreamer Version ${us_version} ... [SKIPPED]"
echo -e "\t==> Version match, no update needed."
else
echo -e "Checking ustreamer Version ${sm_version} ... [UPDATE]"
echo -e "\t==> Version (${us_version}) mismatch, update needed."
pushd bin/ &> /dev/null || exit 1
make ustreamer
popd &> /dev/null || exit 1
echo -e "Ustreamer Update ... [OK]"
fi
}
function update_rtsp {
local dl_version rtsp_version
dl_version="$(cat bin/rtsp-simple-server/version)"
rtsp_version="$(bin/rtsp-simple-server/rtsp-simple-server --version)"
echo -en "Checking rtsp-simple-server Version ... \r"
if [ "${dl_version}" == "${rtsp_version}" ]; then
echo -e "Checking rtsp-simple-server Version ${dl_version} ... [SKIPPED]"
echo -e "\t==> Version match, no update needed."
else
echo -e "Checking rtsp-simple-server Version ... [UPDATE]"
echo -e "\t==> Version (${rtsp_version}) mismatch, update needed."
pushd bin/ &> /dev/null || exit 1
make rtsp
popd &> /dev/null || exit 1
echo -e "rtsp-simple-server Update ... [OK]"
fi
}
#### MAIN
install_cleanup_trap
import_config
welcome_msg
stop_webcamd
uninstall_ustreamer
uninstall_v4l2rtsp
uninstall_rtsp2webrtc
uninstall_go
copy_service
copy_logrotate
copy_raspicam_fix
sub_init
build_apps
start_webcamd
goodbye_msg
exit 0