Use ${VAR} syntax

This commit is contained in:
Calin Crisan 2019-01-12 17:34:21 +02:00
parent 8642911d60
commit 484d7c23be
11 changed files with 129 additions and 124 deletions

View File

@ -1,5 +1,5 @@
#!/bin/bash
mkdir -p /var/lib/samba/private
echo -e "$PASSWORD\n$PASSWORD\n" | /usr/bin/smbpasswd -a admin -s > /dev/null
echo -e "${PASSWORD}\n${PASSWORD}\n" | /usr/bin/smbpasswd -a admin -s > /dev/null

View File

@ -2,10 +2,10 @@
test -f /etc/proftpd.conf || exit 0
test -n "$OS_VERSION" || source /etc/init.d/base
test -n "$OS_DEBUG" || source /etc/init.d/conf
test -n "${OS_VERSION}" || source /etc/init.d/base
test -n "${OS_DEBUG}" || source /etc/init.d/conf
test "$OS_NETWORKLESS" == "true" && exit 0
test "${OS_NETWORKLESS}" == "true" && exit 0
start() {
msg_begin "Starting proftpd"

View File

@ -2,10 +2,10 @@
test -f /etc/samba/smb.conf || exit 0
test -n "$OS_VERSION" || source /etc/init.d/base
test -n "$OS_DEBUG" || source /etc/init.d/conf
test -n "${OS_VERSION}" || source /etc/init.d/base
test -n "${OS_DEBUG}" || source /etc/init.d/conf
test "$OS_NETWORKLESS" == "true" && exit 0
test "${OS_NETWORKLESS}" == "true" && exit 0
start() {
mkdir -p /var/log/samba

View File

@ -11,20 +11,20 @@ MEYEWATCH_DISABLE="false"
DEV_V4L_BY_ID="/dev/v4l/by-id/"
MEDIA_DIR="/data/output"
test -n "$OS_VERSION" || source /etc/init.d/base
test -n "${OS_VERSION}" || source /etc/init.d/base
prepare_conf $CONF $SYS_CONF $BOOT_CONF
prepare_conf ${CONF} ${SYS_CONF} ${BOOT_CONF}
test -f "$CONF" || exit 0
test -f "${CONF}" || exit 0
test -r $WATCH_CONF && source $WATCH_CONF
test -r ${WATCH_CONF} && source ${WATCH_CONF}
opts=$(cat "$CONF" | while read line; do echo "--$line"; done)
port=$(echo "$opts" | grep -oE 'port [[:digit:]]+' | cut -d ' ' -f 2)
opts=$(cat "${CONF}" | while read line; do echo "--${line}"; done)
port=$(echo "${opts}" | grep -oE 'port [[:digit:]]+' | cut -d ' ' -f 2)
responsive() {
curl -m 2 --head http://127.0.0.1:$port &>/dev/null && return 0 || return 1
curl -m 2 --head http://127.0.0.1:${port} &>/dev/null && return 0 || return 1
}
watch() {
@ -34,10 +34,10 @@ watch() {
if responsive; then
count=0
else
if [ $count -lt $MEYEWATCH_TIMEOUT ]; then
count=$(($count + 5))
if [ ${count} -lt ${MEYEWATCH_TIMEOUT} ]; then
count=$((${count} + 5))
else
logger -t motioneye -s "not responding for $MEYEWATCH_TIMEOUT seconds, rebooting"
logger -t motioneye -s "not responding for ${MEYEWATCH_TIMEOUT} seconds, rebooting"
reboot
fi
fi
@ -47,39 +47,39 @@ watch() {
find_persistent_device() {
device=$1
if ! [ -d $DEV_V4L_BY_ID ]; then
echo $device
if ! [ -d ${DEV_V4L_BY_ID} ]; then
echo ${device}
return
fi
for p in $DEV_V4L_BY_ID/*; do
if [ $(realpath "$p") == $device ]; then
echo $p | sed 's#//*#/#g'
for p in ${DEV_V4L_BY_ID}/*; do
if [ $(realpath "${p}") == ${device} ]; then
echo ${p} | sed 's#//*#/#g'
return
fi
done
echo $device
echo ${device}
}
add_mmal_cameras() {
vcgencmd=$(which vcgencmd)
if [ -z "$vcgencmd" ]; then
if [ -z "${vcgencmd}" ]; then
return 1
fi
camera=$($vcgencmd get_camera 2>/dev/null)
if [ "$camera" != "supported=1 detected=1" ]; then
camera=$(${vcgencmd} get_camera 2>/dev/null)
if [ "${camera}" != "supported=1 detected=1" ]; then
return 1
fi
output_dir="/data/output/camera1/"
loc="/config/add/?_username=admin"
device="vc.ril.camera"
body="{\"path\": \"$device\", \"proto\": \"mmal\"}"
signature=$(echo -n "POST:$loc:$body:" | sha1sum | cut -d ' ' -f 1)
body="{\"path\": \"${device}\", \"proto\": \"mmal\"}"
signature=$(echo -n "POST:${loc}:${body}:" | sha1sum | cut -d ' ' -f 1)
curl -s -m 60 --data "$body" "http://127.0.0.1:$port$loc&_signature=$signature" > /dev/null
curl -s -m 60 --data "${body}" "http://127.0.0.1:${port}${loc}&_signature=${signature}" > /dev/null
return 0
}
@ -88,20 +88,20 @@ add_v4l2_cameras() {
index=1
for device in $(ls /dev/video* 2>/dev/null); do
# filter out devices that don't look like cameras
if ! v4l2-ctl -d $device --list-formats-ext 2>/dev/null | grep -oE '[[:digit:]]+x[[:digit:]]+' &>/dev/null; then
if ! v4l2-ctl -d ${device} --list-formats-ext 2>/dev/null | grep -oE '[[:digit:]]+x[[:digit:]]+' &>/dev/null; then
continue
fi
output_dir="/data/output/camera$index/"
output_dir="/data/output/camera${index}/"
loc="/config/add/?_username=admin"
device=$(find_persistent_device $device)
body="{\"path\": \"$device\", \"proto\": \"v4l2\"}"
signature=$(echo -n "POST:$loc:$body:" | sha1sum | cut -d ' ' -f 1)
device=$(find_persistent_device ${device})
body="{\"path\": \"${device}\", \"proto\": \"v4l2\"}"
signature=$(echo -n "POST:${loc}:${body}:" | sha1sum | cut -d ' ' -f 1)
curl -s -m 60 --data "$body" "http://127.0.0.1:$port$loc&_signature=$signature" > /dev/null
index=$(($index + 1))
curl -s -m 60 --data "${body}" "http://127.0.0.1:${port}${loc}&_signature=${signature}" > /dev/null
index=$((${index} + 1))
done
if [ $index -gt 1 ]; then
if [ ${index} -gt 1 ]; then
return 0
else
return 1
@ -111,8 +111,8 @@ add_v4l2_cameras() {
start() {
msg_begin "Starting motioneye"
mkdir -p $MEDIA_DIR
meyectl startserver -b -c $CONF -l
mkdir -p ${MEDIA_DIR}
meyectl startserver -b -c ${CONF} -l
count=0
while true; do
@ -122,22 +122,22 @@ start() {
break
fi
if [ $count -gt $MEYEWATCH_TIMEOUT ]; then
if [ ${count} -gt ${MEYEWATCH_TIMEOUT} ]; then
msg_fail
test "$MEYEWATCH_DISABLE" == "false" && reboot
test "${MEYEWATCH_DISABLE}" == "false" && reboot
return 1
fi
count=$(($count + 1))
count=$((${count} + 1))
done
# add connected camera(s) with default settings
if responsive && ! [ -f $MOTION_CONF ]; then
if responsive && ! [ -f ${MOTION_CONF} ]; then
add_mmal_cameras || add_v4l2_cameras
sync
fi
if [ "$MEYEWATCH_DISABLE" == "false" ]; then
if [ "${MEYEWATCH_DISABLE}" == "false" ]; then
watch &
fi
@ -146,7 +146,7 @@ start() {
stop() {
msg_begin "Stopping motioneye"
meyectl stopserver -c $CONF &>/dev/null
meyectl stopserver -c ${CONF} &>/dev/null
test $? == 0 && msg_done || msg_fail
ps | grep motioneye | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill
}

View File

@ -1,5 +1,5 @@
#!/bin/bash
test "$MEYE_USERNAME" == "admin" || exit 0
PASSWORD="$MEYE_PASSWORD" /usr/sbin/adminpasswd
test "${MEYE_USERNAME}" == "admin" || exit 0
PASSWORD="${MEYE_PASSWORD}" /usr/sbin/adminpasswd

View File

@ -3,14 +3,14 @@
MOTIONEYE_CONF_DIR="/data/etc/"
test -n "$OS_VERSION" || source /etc/init.d/base
test -n "${OS_VERSION}" || source /etc/init.d/base
enabled() {
test $(ls -1 $MOTIONEYE_CONF_DIR/thread-*.conf 2>/dev/null| wc -l) == 1 || return 1
test $(ls -1 ${MOTIONEYE_CONF_DIR}/thread-*.conf 2>/dev/null| wc -l) == 1 || return 1
grep '# @proto mjpeg' $MOTIONEYE_CONF_DIR/thread-1.conf &>/dev/null || return 1
grep '# @proto mjpeg' ${MOTIONEYE_CONF_DIR}/thread-1.conf &>/dev/null || return 1
grep -E '# @url http://(.*)127.0.0.1:' $MOTIONEYE_CONF_DIR/thread-1.conf &>/dev/null || return 1
grep -E '# @url http://(.*)127.0.0.1:' ${MOTIONEYE_CONF_DIR}/thread-1.conf &>/dev/null || return 1
return 0
}

View File

@ -6,8 +6,9 @@ MOTIONEYE_CONF=/data/etc/motioneye.conf
STREAMEYE_CONF=/data/etc/streameye.conf
STREAMEYE_LOG=/var/log/streameye.log
test -r $RASPIMJPEG_CONF || exit 1
test -r $STREAMEYE_CONF || exit 1
test -r ${RASPIMJPEG_CONF} || exit 1
test -r ${STREAMEYE_CONF} || exit 1
watch() {
count=0
@ -22,33 +23,33 @@ watch() {
function start() {
pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1)
if [ -n "$pid" ]; then
if [ -n "${pid}" ]; then
return
fi
raspimjpeg_opts=""
while read line; do
if echo "$line" | grep false &>/dev/null; then
if echo "${line}" | grep false &>/dev/null; then
continue
fi
if echo "$line" | grep true &>/dev/null; then
line=$(echo $line | cut -d ' ' -f 1)
if echo "${line}" | grep true &>/dev/null; then
line=$(echo ${line} | cut -d ' ' -f 1)
fi
raspimjpeg_opts="$raspimjpeg_opts --$line"
done < $RASPIMJPEG_CONF
raspimjpeg_opts="${raspimjpeg_opts} --${line}"
done < ${RASPIMJPEG_CONF}
source $STREAMEYE_CONF
streameye_opts="-p $PORT"
if [ -n "$CREDENTIALS" ] && [ "$AUTH" = "basic" ]; then
streameye_opts="$streameye_opts -a basic -c $CREDENTIALS"
source ${STREAMEYE_CONF}
streameye_opts="-p ${PORT}"
if [ -n "${CREDENTIALS}" ] && [ "${AUTH}" = "basic" ]; then
streameye_opts="${streameye_opts} -a basic -c ${CREDENTIALS}"
fi
if [ -r $MOTIONEYE_CONF ] && grep 'log-level debug' $MOTIONEYE_CONF >/dev/null; then
raspimjpeg_opts="$raspimjpeg_opts -d"
streameye_opts="$streameye_opts -d"
if [ -r ${MOTIONEYE_CONF} ] && grep 'log-level debug' ${MOTIONEYE_CONF} >/dev/null; then
raspimjpeg_opts="${raspimjpeg_opts} -d"
streameye_opts="${streameye_opts} -d"
fi
raspimjpeg.py $raspimjpeg_opts 2>$RASPIMJPEG_LOG | streameye $streameye_opts &>$STREAMEYE_LOG &
raspimjpeg.py ${raspimjpeg_opts} 2>${RASPIMJPEG_LOG} | streameye ${streameye_opts} &>${STREAMEYE_LOG} &
}
function stop() {
@ -57,17 +58,17 @@ function stop() {
# stop the raspimjpeg process
pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1)
if [ -z "$pid" ]; then
if [ -z "${pid}" ]; then
return
fi
kill -HUP "$pid" &>/dev/null
kill -HUP "${pid}" &>/dev/null
count=0
while kill -0 "$pid" &>/dev/null && [ $count -lt 5 ]; do
while kill -0 "${pid}" &>/dev/null && [ ${count} -lt 5 ]; do
sleep 1
count=$(($count + 1))
count=$((${count} + 1))
done
kill -KILL "$pid" &>/dev/null || true
kill -KILL "${pid}" &>/dev/null || true
}
case "$1" in

View File

@ -1,15 +1,16 @@
#!/bin/sh
motioneye_conf_dir="/data/etc/"
MOTIONEYE_CONF_DIR="/data/etc/"
test -n "$OS_VERSION" || source /etc/init.d/base
test -n "${OS_VERSION}" || source /etc/init.d/base
enabled() {
test $(ls -1 $motioneye_conf_dir/thread-*.conf 2>/dev/null| wc -l) == 1 || return 1
test $(ls -1 ${MOTIONEYE_CONF_DIR}/thread-*.conf 2>/dev/null| wc -l) == 1 || return 1
grep '# @proto mjpeg' $motioneye_conf_dir/thread-1.conf &>/dev/null || return 1
grep '# @proto mjpeg' ${MOTIONEYE_CONF_DIR}/thread-1.conf &>/dev/null || return 1
grep -E '# @url http://(.*)127.0.0.1:' $motioneye_conf_dir/thread-1.conf &>/dev/null || return 1
grep -E '# @url http://(.*)127.0.0.1:' ${MOTIONEYE_CONF_DIR}/thread-1.conf &>/dev/null || return 1
return 0
}

View File

@ -6,8 +6,9 @@ MOTIONEYE_CONF=/data/etc/motioneye.conf
STREAMEYE_CONF=/data/etc/streameye.conf
STREAMEYE_LOG=/var/log/streameye.log
test -r $RASPIMJPEG_CONF || exit 1
test -r $STREAMEYE_CONF || exit 1
test -r ${RASPIMJPEG_CONF} || exit 1
test -r ${STREAMEYE_CONF} || exit 1
watch() {
count=0
@ -22,33 +23,33 @@ watch() {
function start() {
pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1)
if [ -n "$pid" ]; then
if [ -n "${pid}" ]; then
return
fi
raspimjpeg_opts=""
while read line; do
if echo "$line" | grep false &>/dev/null; then
if echo "${line}" | grep false &>/dev/null; then
continue
fi
if echo "$line" | grep true &>/dev/null; then
line=$(echo $line | cut -d ' ' -f 1)
if echo "${line}" | grep true &>/dev/null; then
line=$(echo ${line} | cut -d ' ' -f 1)
fi
raspimjpeg_opts="$raspimjpeg_opts --$line"
done < $RASPIMJPEG_CONF
raspimjpeg_opts="${raspimjpeg_opts} --${line}"
done < ${RASPIMJPEG_CONF}
source $STREAMEYE_CONF
streameye_opts="-p $PORT"
if [ -n "$CREDENTIALS" ] && [ "$AUTH" = "basic" ]; then
streameye_opts="$streameye_opts -a basic -c $CREDENTIALS"
source ${STREAMEYE_CONF}
streameye_opts="-p ${PORT}"
if [ -n "${CREDENTIALS}" ] && [ "${AUTH}" = "basic" ]; then
streameye_opts="${streameye_opts} -a basic -c ${CREDENTIALS}"
fi
if [ -r $MOTIONEYE_CONF ] && grep 'log-level debug' $MOTIONEYE_CONF >/dev/null; then
raspimjpeg_opts="$raspimjpeg_opts -d"
streameye_opts="$streameye_opts -d"
if [ -r ${MOTIONEYE_CONF} ] && grep 'log-level debug' ${MOTIONEYE_CONF} >/dev/null; then
raspimjpeg_opts="${raspimjpeg_opts} -d"
streameye_opts="${streameye_opts} -d"
fi
raspimjpeg.py $raspimjpeg_opts 2>$RASPIMJPEG_LOG | streameye $streameye_opts &>$STREAMEYE_LOG &
raspimjpeg.py ${raspimjpeg_opts} 2>${RASPIMJPEG_LOG} | streameye ${streameye_opts} &>${STREAMEYE_LOG} &
}
function stop() {
@ -57,17 +58,17 @@ function stop() {
# stop the raspimjpeg process
pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1)
if [ -z "$pid" ]; then
if [ -z "${pid}" ]; then
return
fi
kill -HUP "$pid" &>/dev/null
kill -HUP "${pid}" &>/dev/null
count=0
while kill -0 "$pid" &>/dev/null && [ $count -lt 5 ]; do
while kill -0 "${pid}" &>/dev/null && [ ${count} -lt 5 ]; do
sleep 1
count=$(($count + 1))
count=$((${count} + 1))
done
kill -KILL "$pid" &>/dev/null || true
kill -KILL "${pid}" &>/dev/null || true
}
case "$1" in

View File

@ -1,15 +1,16 @@
#!/bin/sh
motioneye_conf_dir="/data/etc/"
MOTIONEYE_CONF_DIR="/data/etc/"
test -n "$OS_VERSION" || source /etc/init.d/base
test -n "${OS_VERSION}" || source /etc/init.d/base
enabled() {
test $(ls -1 $motioneye_conf_dir/thread-*.conf 2>/dev/null| wc -l) == 1 || return 1
test $(ls -1 ${MOTIONEYE_CONF_DIR}/thread-*.conf 2>/dev/null| wc -l) == 1 || return 1
grep '# @proto mjpeg' $motioneye_conf_dir/thread-1.conf &>/dev/null || return 1
grep '# @proto mjpeg' ${MOTIONEYE_CONF_DIR}/thread-1.conf &>/dev/null || return 1
grep -E '# @url http://(.*)127.0.0.1:' $motioneye_conf_dir/thread-1.conf &>/dev/null || return 1
grep -E '# @url http://(.*)127.0.0.1:' ${MOTIONEYE_CONF_DIR}/thread-1.conf &>/dev/null || return 1
return 0
}

View File

@ -6,8 +6,9 @@ MOTIONEYE_CONF=/data/etc/motioneye.conf
STREAMEYE_CONF=/data/etc/streameye.conf
STREAMEYE_LOG=/var/log/streameye.log
test -r $RASPIMJPEG_CONF || exit 1
test -r $STREAMEYE_CONF || exit 1
test -r ${RASPIMJPEG_CONF} || exit 1
test -r ${STREAMEYE_CONF} || exit 1
watch() {
count=0
@ -22,33 +23,33 @@ watch() {
function start() {
pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1)
if [ -n "$pid" ]; then
if [ -n "${pid}" ]; then
return
fi
raspimjpeg_opts=""
while read line; do
if echo "$line" | grep false &>/dev/null; then
if echo "${line}" | grep false &>/dev/null; then
continue
fi
if echo "$line" | grep true &>/dev/null; then
line=$(echo $line | cut -d ' ' -f 1)
if echo "${line}" | grep true &>/dev/null; then
line=$(echo ${line} | cut -d ' ' -f 1)
fi
raspimjpeg_opts="$raspimjpeg_opts --$line"
done < $RASPIMJPEG_CONF
raspimjpeg_opts="${raspimjpeg_opts} --${line}"
done < ${RASPIMJPEG_CONF}
source $STREAMEYE_CONF
streameye_opts="-p $PORT"
if [ -n "$CREDENTIALS" ] && [ "$AUTH" = "basic" ]; then
streameye_opts="$streameye_opts -a basic -c $CREDENTIALS"
source ${STREAMEYE_CONF}
streameye_opts="-p ${PORT}"
if [ -n "${CREDENTIALS}" ] && [ "${AUTH}" = "basic" ]; then
streameye_opts="${streameye_opts} -a basic -c ${CREDENTIALS}"
fi
if [ -r $MOTIONEYE_CONF ] && grep 'log-level debug' $MOTIONEYE_CONF >/dev/null; then
raspimjpeg_opts="$raspimjpeg_opts -d"
streameye_opts="$streameye_opts -d"
if [ -r ${MOTIONEYE_CONF} ] && grep 'log-level debug' ${MOTIONEYE_CONF} >/dev/null; then
raspimjpeg_opts="${raspimjpeg_opts} -d"
streameye_opts="${streameye_opts} -d"
fi
raspimjpeg.py $raspimjpeg_opts 2>$RASPIMJPEG_LOG | streameye $streameye_opts &>$STREAMEYE_LOG &
raspimjpeg.py ${raspimjpeg_opts} 2>${RASPIMJPEG_LOG} | streameye ${streameye_opts} &>${STREAMEYE_LOG} &
}
function stop() {
@ -57,17 +58,17 @@ function stop() {
# stop the raspimjpeg process
pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1)
if [ -z "$pid" ]; then
if [ -z "${pid}" ]; then
return
fi
kill -HUP "$pid" &>/dev/null
kill -HUP "${pid}" &>/dev/null
count=0
while kill -0 "$pid" &>/dev/null && [ $count -lt 5 ]; do
while kill -0 "${pid}" &>/dev/null && [ ${count} -lt 5 ]; do
sleep 1
count=$(($count + 1))
count=$((${count} + 1))
done
kill -KILL "$pid" &>/dev/null || true
kill -KILL "${pid}" &>/dev/null || true
}
case "$1" in