151 lines
4.0 KiB
Bash
Executable File
151 lines
4.0 KiB
Bash
Executable File
#!/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"
|
|
|
|
step_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
|
|
echoerr " [W] Cannot detect OS. Assuming Ubuntu"
|
|
SEQ_OSNAME="Ubuntu"
|
|
else
|
|
SEQ_OSNAME=$(lsb_release -is)
|
|
SEQ_DISTNAME=$(lsb_release -cs)
|
|
fi
|
|
|
|
if [ "$SEQ_OSNAME" == "" ] ; then
|
|
echoerr " [W] Error dedecting OS. Assuming Ubuntu"
|
|
SEQ_OSNAME="Ubuntu"
|
|
fi
|
|
|
|
echo " [I] Detected OS: $SEQ_OSNAME $SEQ_DISTNAME"
|
|
}
|
|
|
|
step_1_info() { echo "Install $toolName dependencies"; }
|
|
step_1_alias() { ALIAS="install"; }
|
|
step_1() {
|
|
local aptOption=
|
|
|
|
local pyVersion=$(python -V 2>&1)
|
|
if [[ ! "$pyVersion" =~ \ 2\.[7-9]+ ]] ; then
|
|
echoerr " [E] Motioneye requires python version 2.7 but $pyVersion was found."
|
|
return 1
|
|
fi
|
|
|
|
exe apt update
|
|
endReturn -o $? "Updating apt repositories failed"
|
|
|
|
if [ $QUIET -ne 0 ] ; 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
|
|
echo " [W] Unsupported OS"
|
|
return 1
|
|
fi
|
|
|
|
exe wget -O "$motionDownload" $motionUrl
|
|
endReturn -o $? "Download motion failed"
|
|
}
|
|
motionDownload="/tmp/motion.deb"
|
|
|
|
step_3_info() { echo "Install downloaded motion version"; }
|
|
step_3() {
|
|
if [ ! -f "$motionDownload" ]; then
|
|
echo " [I] No downloaded motion found attempting download"
|
|
step 2
|
|
fi
|
|
|
|
exe dpkg -i "$motionDownload"
|
|
endReturn -o $? "Installing motion failed"
|
|
}
|
|
|
|
step_4_info() { echo "Upgrade python pip"; }
|
|
step_4_alias() { ALIAS="upgradepip"; }
|
|
step_4()
|
|
{
|
|
exe pip install --upgrade pip
|
|
endReturn -o $? "Upgrading pip failed"
|
|
}
|
|
|
|
step_5_info() { echo "Install $toolName"; }
|
|
step_5() {
|
|
exe pip install motioneye
|
|
endReturn -o $? "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 -o $? "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() { ALIAS="upgrade"; }
|
|
step_20() {
|
|
step "upgradepip"
|
|
exe pip install motioneye --upgrade
|
|
endReturn -o $? "Upgrading $toolName failed"
|
|
exe systemctl restart motioneye
|
|
}
|
|
|
|
VERSION_SEQREV=11
|
|
. /usr/local/bin/sequencer.sh
|