#!/usr/bin/env bash readonly toolName=motioneye readonly sq_meUrl='https://github.com/motioneye-project/motioneye/archive/dev.tar.gz' # Already defined by sequencer.sh, but may be overwritten #readonly seq_configName="${sq_scriptName}.cfg" #readonly seq_configTemplate="${seq_origin}/${sq_configName}.example" sq_aptOpt= sq_config=0 seq_config() { ## Called once before executing steps. ## e.g. to source a config file manually: #. "${seq_origin}/${seq_configName}" ## or to use sequencer api with profile config file support: #if initSeqConfig -p "${seq_fileName}" "${seq_configTemplate}" ; then ## or to use sequencer api with global config file: #if initSeqConfig "${seq_configName}" "${seq_configTemplate}" ; then # sq_config=1 #else # # End if no configuration file exists # dry || return -1 #fi dry || root || fatal "Needs to be root" # Since RasperryPi OS bullseye motion is provided with expected version 4.3.2-1 lsb_release -c | grep bullseye >/dev/null 2>&1 || fatal "Only debian bullseye supported to install motion directly" ## Apt cmdline option to suppress user interaction interactive || sq_aptOpt="-y" ## Disable error checks if external scripts are used ## e.g. error on unbound variables #disableErrorCheck ## Return of non zero value will abort the sequence return 0 } step_1_info() { echo "Show status"; } step_1_alias() { echo "status"; } step_1() { info "Status of $toolName .." exe service motioneye status } step_20_info() { echo "Install motioneye dependencies"; } step_20_alias() { echo "install"; } step_20() { exe apt update exe apt --no-install-recommends install ca-certificates curl python3 python3-dev python3-pip python3-venv libcurl4-openssl-dev gcc libssl-dev ${sq_aptOpt} exep DEBIAN_FRONTEND="noninteractive" apt-get -y --no-install-recommends install motion v4l-utils ffmpeg curl info "Disable motion service" info -a "(Will be started by motioneye)" exe systemctl disable --now motion } step_21_info() { echo "Create virtual environment"; } step_21() { [[ -d "${sc_meVenvHome}" ]] && fatal "$tooName already installed" exe python3 -m venv "${sc_meVenvHome}" } sc_meVenvHome="/opt/motioneye" sc_mePip="${sc_meVenvHome}/bin/pip" step_22_info() { echo "Install $toolName in venv"; } step_22() { exe "${sc_mePip}" install "${sq_meUrl}" } step_23_info() { echo "Setup $toolName service and config"; } step_23() { local lMeConfDir="$(dirname -- "${sc_meConfigFile}")" if [[ ! -d "${lMeConfDir}" ]] ; then exe mkdir -p "${lMeConfDir}" addConf -s -f "${sc_meConfigExample}" "${sc_meConfigFile}" exe chown -R motion: "${lMeConfDir}" fi addConf -s "${sc_meSystemd}" "${sc_meServiceFile}" exe systemctl daemon-reload exe systemctl enable --now motioneye } sc_meConfigFile="/etc/motioneye/motioneye.conf" sc_meConfigExample="${sc_meVenvHome}/lib/python3.9/site-packages/motioneye/extra/motioneye.conf.sample" sc_meServiceFile="/etc/systemd/system/motioneye.service" sc_meSystemd="[Unit] Description=motionEye Server After=network.target local-fs.target remote-fs.target [Service] User=motion RuntimeDirectory=motioneye LogsDirectory=motioneye StateDirectory=motioneye ExecStart=${sc_meVenvHome}/bin/meyectl startserver -c /etc/motioneye/motioneye.conf Restart=on-abort [Install] WantedBy=multi-user.target" step_25_info() { echo "Upgrade $toolName"; } step_25_alias() { echo "upgrade"; } step_25() { exe service motioneye stop exe "${sc_mePip}" install --upgrade --force-reinstall --no-deps "${sq_meUrl}" exe service motioneye start } readonly sqr_minVersion=16 . /usr/local/bin/sequencer.sh