Skip to content

Commit

Permalink
ALARM: Fix tabs, spaces and used function files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank van der Stad committed Jan 15, 2018
1 parent 176fba2 commit 8c7149d
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 76 deletions.
53 changes: 13 additions & 40 deletions src/home/yi-hack-v3/script/alarm.sh
Original file line number Diff line number Diff line change
@@ -1,51 +1,24 @@
#!/bin/sh

# Copyright 2018 Vladimir Dronnikov
# Additional enhancements: Frank van der Stad
# Copyright 2018 Vladimir Dronnokov & Frank van der Stad

This comment has been minimized.

Copy link
@dvv

dvv Jan 15, 2018

Dronnikov

# GPL
source ./include_functions.sh

CONF_FILE="/yi-hack-v3/etc/system.conf"

if [ -d "/usr/yi-hack-v3" ]; then
YI_HACK_V3_PREFIX="/usr"
elif [ -d "/home/yi-hack-v3" ]; then
YI_HACK_V3_PREFIX="/home"
fi

get_config()
{
key=$1
grep $1 $YI_HACK_V3_PREFIX$CONF_FILE | cut -d "=" -f2
}
CAMERA_NAME=`more $YI_HACK_V3_PREFIX/yi-hack-v3/etc/hostname`;

TELEGRAM_BOT_TOKEN=$(get_config TELEGRAM_BOT_TOKEN)
TELEGRAM_CHAT_ID=$(get_config TELEGRAM_CHAT_ID)
TELEGRAM_SILENT=0

CAMERA_NAME=`more $YI_HACK_V3_PREFIX/yi-hack-v3/etc/hostname`;

curl() {
LD_LIBRARY_PATH=/tmp/sd /tmp/sd/curl -k -q $@
}

photo() {
cp $1 /tmp/sd/record/last.jpg
curl -F photo="@$1" "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendPhoto?chat_id=${TELEGRAM_CHAT_ID}&caption=$2&disable_notification=${TELEGRAM_SILENT}"
}

video() {
cp $1 /tmp/sd/record/last.mp4
curl -F video="@$1" "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendVideo?chat_id=${TELEGRAM_CHAT_ID}&caption=$2&disable_notification=${TELEGRAM_SILENT}"
}

# This part is copyright 2018 Vladimir Dronnikov
# GPL
ALARM=0
while true; do
test -r /tmp/sd/record/tmp.mp4.tmp && REC=1 || REC=0
if [ "$REC" != "$ALARM" ]; then
ALARM="$REC"
[ "n$ALARM" == "n0" ] && rm /tmp/temp.jpg /tmp/temp.mp4
fi
[ -r /tmp/motion.jpg -a ! -r /tmp/temp.jpg ] && cp /tmp/motion.jpg /tmp/temp.jpg && echo JPG ready && photo /tmp/temp.jpg "Photo from $CAMERA_NAME"
[ -r /tmp/motion.mp4 -a ! -r /tmp/temp.mp4 ] && cp /tmp/motion.mp4 /tmp/temp.mp4 && echo MP4 ready && video /tmp/temp.mp4 "Video from $CAMERA_NAME"
sleep 1
test -r /tmp/sd/record/tmp.mp4.tmp && REC=1 || REC=0
if [ "$REC" != "$ALARM" ]; then
ALARM="$REC"
[ "n$ALARM" == "n0" ] && rm /tmp/temp.jpg /tmp/temp.mp4
fi
[ -r /tmp/motion.jpg -a ! -r /tmp/temp.jpg ] && cp /tmp/motion.jpg /tmp/temp.jpg && echo JPG ready && photo /tmp/temp.jpg "Photo from $CAMERA_NAME"
[ -r /tmp/motion.mp4 -a ! -r /tmp/temp.mp4 ] && cp /tmp/motion.mp4 /tmp/temp.mp4 && echo MP4 ready && video /tmp/temp.mp4 "Video from $CAMERA_NAME"
sleep 1
done
45 changes: 45 additions & 0 deletions src/home/yi-hack-v3/script/include_functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh
# Copyright 2018 Frank van der Stad
# GPL
CONF_FILE="/yi-hack-v3/etc/system.conf"

if [ -d "/usr/yi-hack-v3" ]; then
YI_HACK_V3_PREFIX="/usr"
elif [ -d "/home/yi-hack-v3" ]; then
YI_HACK_V3_PREFIX="/home"
fi

get_config() {
key=$1
grep $1 $YI_HACK_V3_PREFIX$CONF_FILE | cut -d "=" -f2
}

curl() {
LD_LIBRARY_PATH=/tmp/sd /tmp/sd/curl -k -q $@
}

photo() {
message=$(urlencode $2)
cp $1 /tmp/sd/record/last.jpg
if [ ! -z "$TELEGRAM_BOT_TOKEN" ]
then
curl -F photo="@$1" "https://api.telegram.org/bot${TELEGRAM_BOT_
fi
}
video() {
message=$(urlencode $2)
cp $1 /tmp/sd/record/last.mp4
if [ ! -z "$TELEGRAM_BOT_TOKEN" ]
then
curl -F video="@$1" "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/s
fi
}




urlencode() {
url=$(echo "$*" | sed -e 's/%/%25/g' -e 's/ /%20/g' -e 's/!/%21/g' -e 's/"/%22/g' -e 's/#/%23/g' -e 's/\$/%24/g' -e 's/\&/%26/g' -e 's/'\''/%27/g' -e 's/(/%28/g' -e 's/)/%29/g' -e 's/\*/%2a/g' -e 's/+/%2b/g' -e 's/,/%2c/g' -e 's/-/%2d/g' -e 's/\./%2e/g' -e 's/\//%2f/g' -e 's/:/%3a/g' -e 's/;/%3b/g' -e 's//%3e/g' -e 's/?/%3f/g' -e 's/@/%40/g' -e 's/\[/%5b/g' -e 's/\\/%5c/g' -e 's/\]/%5d/g' -e 's/\^/%5e/g' -e 's/_/%5f/g' -e 's/`/%60/g' -e 's/{/%7b/g' -e 's/|/%7c/g' -e 's/}/%7d/g' -e 's/~/%7e/g')
echo $url
}
39 changes: 12 additions & 27 deletions src/home/yi-hack-v3/script/last_motion.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,20 @@
#!/bin/sh

# Copyright 2018 Vladimir Dronnikov
# Additional enhancements: Frank van der Stad
# Copyright 2018 Vladimir Dronnokov & Frank van der Stad
# GPL

CONF_FILE="/yi-hack-v3/etc/system.conf"

if [ -d "/usr/yi-hack-v3" ]; then
YI_HACK_V3_PREFIX="/usr"
elif [ -d "/home/yi-hack-v3" ]; then
YI_HACK_V3_PREFIX="/home"
fi
source ./include_functions.sh

CAMERA_NAME=`more $YI_HACK_V3_PREFIX/yi-hack-v3/etc/hostname`;

photo() {
cp $1 /tmp/sd/record/last.jpg
}

video() {
cp $1 /tmp/sd/record/last.mp4
}

# This part is copyright 2018 Vladimir Dronnikov
# GPL
ALARM=0
while true; do
test -r /tmp/sd/record/tmp.mp4.tmp && REC=1 || REC=0
if [ "$REC" != "$ALARM" ]; then
ALARM="$REC"
[ "n$ALARM" == "n0" ] && rm /tmp/temp.jpg /tmp/temp.mp4
fi
[ -r /tmp/motion.jpg -a ! -r /tmp/temp.jpg ] && cp /tmp/motion.jpg /tmp/temp.jpg && echo JPG ready && photo /tmp/temp.jpg "Photo from $CAMERA_NAME"
[ -r /tmp/motion.mp4 -a ! -r /tmp/temp.mp4 ] && cp /tmp/motion.mp4 /tmp/temp.mp4 && echo MP4 ready && video /tmp/temp.mp4 "Video from $CAMERA_NAME"
sleep 1
test -r /tmp/sd/record/tmp.mp4.tmp && REC=1 || REC=0
if [ "$REC" != "$ALARM" ]; then
ALARM="$REC"
[ "n$ALARM" == "n0" ] && rm /tmp/temp.jpg /tmp/temp.mp4
fi
[ -r /tmp/motion.jpg -a ! -r /tmp/temp.jpg ] && cp /tmp/motion.jpg /tmp/temp.jpg && echo JPG ready && photo /tmp/temp.jpg "Photo from $CAMERA_NAME"
[ -r /tmp/motion.mp4 -a ! -r /tmp/temp.mp4 ] && cp /tmp/motion.mp4 /tmp/temp.mp4 && echo MP4 ready && video /tmp/temp.mp4 "Video from $CAMERA_NAME"
sleep 1
done
10 changes: 5 additions & 5 deletions src/home/yi-hack-v3/script/system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
CONF_FILE="/yi-hack-v3/etc/system.conf"

if [ -d "/usr/yi-hack-v3" ]; then
YI_HACK_V3_PREFIX="/usr"
YI_HACK_V3_PREFIX="/usr"
elif [ -d "/home/yi-hack-v3" ]; then
YI_HACK_V3_PREFIX="/home"
YI_HACK_V3_PREFIX="/home"
fi

get_config()
{
key=$1
grep $1 $YI_HACK_V3_PREFIX$CONF_FILE | cut -d "=" -f2
key=$1
grep $1 $YI_HACK_V3_PREFIX$CONF_FILE | cut -d "=" -f2
}

if [ -d "/usr/yi-hack-v3" ]; then
Expand All @@ -37,7 +37,7 @@ if [[ $(get_config FTPD) == "yes" ]] ; then
fi

if [[ $(get_config DROPBEAR) == "yes" ]] ; then
dropbear -R
dropbear -R
fi

if [ -f "/tmp/sd/yi-hack-v3/startup.sh" ]; then
Expand Down
8 changes: 4 additions & 4 deletions src/home/yi-hack-v3/script/system_init.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/sh

if [ -d "/usr/yi-hack-v3" ]; then
YI_HACK_V3_PREFIX="/usr"
YI_HACK_V3_PREFIX="/usr"
YI_PREFIX="/home"
UDHCPC_SCRIPT_DEST="/home/default.script"
elif [ -d "/home/yi-hack-v3" ]; then
YI_HACK_V3_PREFIX="/home"
YI_HACK_V3_PREFIX="/home"
YI_PREFIX="/home/app"
UDHCPC_SCRIPT_DEST="/home/app/script/default.script"
fi
Expand All @@ -30,8 +30,8 @@ fi
if [ ! -f $YI_PREFIX/cloudAPI_real ]; then
mv $YI_PREFIX/cloudAPI $YI_PREFIX/cloudAPI_real
cp $YI_HACK_V3_PREFIX/yi-hack-v3/cloudAPI $YI_PREFIX/
rm $UDHCPC_SCRIPT_DEST
cp $UDHCP_SCRIPT $UDHCPC_SCRIPT_DEST
rm $UDHCPC_SCRIPT_DEST
cp $UDHCP_SCRIPT $UDHCPC_SCRIPT_DEST
if [ -f $DHCP_SCRIPT_DEST ]; then
rm $DHCP_SCRIPT_DEST
cp $DHCP_SCRIPT $DHCP_SCRIPT_DEST
Expand Down

0 comments on commit 8c7149d

Please sign in to comment.