#!/bin/bash toolName=motioneye # Supporting tools dependencies (ffmpeg and motion) toolDeps="ffmpeg libmariadb3 libpq5 libmicrohttpd12" # Motioneye dependencies toolDeps+=" python-pip python-dev libssl-dev libcurl4-openssl-dev libjpeg-dev libz-dev" toolCfgDir="/etc/motioneye" SEQ_OSNAME= SEQ_DISTNAME= # Get script working directory # (when called from a different directory) WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )" CONFIG=0 #CONFIG_FILE_NAME="${toolName}.cfg" #CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example" seq_config() { ## e.g. to source a config file manually: #. "$CONFIG_FILE" ## or to use sequencer api: #initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE" #if [ $? -eq 0 ] ; then # CONFIG=1 #fi if [ "$(which lsb_release)" == "" ] ; then warning -e "Cannot detect OS. Assuming Ubuntu" SEQ_OSNAME="Ubuntu" else SEQ_OSNAME=$(lsb_release -is) SEQ_DISTNAME=$(lsb_release -cs) fi if [ "$SEQ_OSNAME" == "" ] ; then warning -e "Error dedecting OS. Assuming Ubuntu" SEQ_OSNAME="Ubuntu" fi info "Detected OS: $SEQ_OSNAME $SEQ_DISTNAME" } step_1_info() { echo "Install $toolName dependencies"; } step_1_alias() { echo "install"; } step_1() { local aptOption= local pyVersion=$(python -V 2>&1) if [[ ! "$pyVersion" =~ \ 2\.[7-9]+ ]] ; then error -e "Motioneye requires python version 2.7 but $pyVersion was found." return 1 fi exe apt update endReturn "Updating apt repositories failed" if quiet ; then aptOption="-y" else aptOption="" fi exe apt install $toolDeps $aptOption } step_2_info() { echo "Download recommended motion version"; } step_2() { local motionUrl= if [ "$SEQ_OSNAME" == "Raspbian" ]; then motionUrl="https://github.com/Motion-Project/motion/releases/download/release-4.2.2/pi_${SEQ_DISTNAME}_motion_4.2.2-1_armhf.deb" elif [ "$SEQ_OSNAME" == "Ubuntu" ]; then motionUrl="https://github.com/Motion-Project/motion/releases/download/release-4.2.2/${SEQ_DISTNAME}_motion_4.2.2-1_amd64.deb" fi if [ "$motionUrl" == "" ]; then warning "Unsupported OS" return 1 fi exe wget -O "$motionDownload" $motionUrl endReturn "Download motion failed" } motionDownload="/tmp/motion.deb" step_3_info() { echo "Install downloaded motion version"; } step_3() { if [ ! -f "$motionDownload" ]; then info "No downloaded motion found attempting download" step 2 fi exe dpkg -i "$motionDownload" endReturn "Installing motion failed" } step_4_info() { echo "Upgrade python pip"; } step_4_alias() { echo "upgradepip"; } step_4() { exe pip install --upgrade pip endReturn "Upgrading pip failed" } step_5_info() { echo "Install $toolName"; } step_5() { exe pip install motioneye endReturn "Installing $toolName failed" } step_6_info() { echo "Prepare configuration directory $toolCfgDir"; } step_6() { exe mkdir -p /etc/motioneye saveReturn $? exe cp "$motioneyeConfigSource" "$motioneyeConfigTarget" saveReturn $? endReturn "Creating first configuration failed" } motioneyeConfigSource="/usr/local/share/motioneye/extra/motioneye.conf.sample" motioneyeConfigTarget="/etc/motioneye/motioneye.conf" step_7_info() { echo "Create media directory $motioneyeMediaDir"; } step_7() { exe mkdir -p "$motioneyeMediaDir" } motioneyeMediaDir="/var/lib/motioneye" step_8_info() { echo "Create $toolName service"; } step_8() { exe cp "$motioneyeServiceSource" "$motioneyeServiceTarget" endReturn "Creating service failed" exe systemctl daemon-reload exe systemctl enable motioneye exe systemctl start motioneye } motioneyeServiceSource="/usr/local/share/motioneye/extra/motioneye.systemd-unit-local" motioneyeServiceTarget="/etc/systemd/system/motioneye.service" step_20_info() { echo "Upgrade $toolName"; } step_20_alias() { echo "upgrade"; } step_20() { step "upgradepip" exe pip install motioneye --upgrade endReturn "Upgrading $toolName failed" exe systemctl restart motioneye } readonly sqr_minVersion=16 . /usr/local/bin/sequencer.sh