diff --git a/src/static/static/home/yi-hack/script/clean_records.sh b/src/static/static/home/yi-hack/script/clean_records.sh index d656d1b..fd60c56 100755 --- a/src/static/static/home/yi-hack/script/clean_records.sh +++ b/src/static/static/home/yi-hack/script/clean_records.sh @@ -19,37 +19,41 @@ fi MAX_AVI_NUMBER=10 USED_SPACE_LIMIT=$((100-$1)) -cd /tmp/sd/record/timelapse -AVI_NUMBER=`ls -lt | grep .avi | awk 'END{print NR}'` -while [ "$AVI_NUMBER" -gt "$MAX_AVI_NUMBER" ] -do - OLD_FILE=`ls -lt | grep .avi | awk 'END{print}' | awk '{print $9}'` - if [ ! -z "$OLD_FILE" ]; then - echo "Deleting file $OLD_FILE" - rm -f $OLD_FILE - AVI_NUMBER=`ls -lt | grep .avi | awk 'END{print NR}'` - else - break - fi -done - -cd /tmp/sd/record -USED_SPACE=`df -h /tmp/sd/ | grep mmc | awk '{print $5}' | tr -d '%'` - -if [ -z "$USED_SPACE" ]; then - exit +if [ -d /tmp/sd/record/timelapse ]; then + cd /tmp/sd/record/timelapse + AVI_NUMBER=`ls -lr | grep .avi | awk 'END{print NR}'` + while [ "$AVI_NUMBER" -gt "$MAX_AVI_NUMBER" ] + do + OLD_FILE=`ls -lr | grep .avi | awk 'END{print}' | awk '{print $9}'` + if [ ! -z "$OLD_FILE" ]; then + echo "Deleting file $OLD_FILE" + rm -f $OLD_FILE + AVI_NUMBER=`ls -lr | grep .avi | awk 'END{print NR}'` + else + break + fi + done fi -while [ "$USED_SPACE" -gt "$USED_SPACE_LIMIT" ] -do - OLD_DIR=`ls -lt | grep -v tmp | grep -v timelapse | tail -n1 | awk '{print $9}'` - if [ ! -z "$OLD_DIR" ]; then - echo "Deleting dir $OLD_DIR" - rm -rf $OLD_DIR - else - break - fi +if [ -d /tmp/sd/record ]; then + cd /tmp/sd/record USED_SPACE=`df -h /tmp/sd/ | grep mmc | awk '{print $5}' | tr -d '%'` -done + + if [ -z "$USED_SPACE" ]; then + exit + fi + + while [ "$USED_SPACE" -gt "$USED_SPACE_LIMIT" ] + do + OLD_DIR=`ls -lr | grep -v tmp | grep -v timelapse | tail -n1 | awk '{print $9}'` + if [ ! -z "$OLD_DIR" ]; then + echo "Deleting dir $OLD_DIR" + rm -rf $OLD_DIR + else + break + fi + USED_SPACE=`df -h /tmp/sd/ | grep mmc | awk '{print $5}' | tr -d '%'` + done +fi echo "Done!" diff --git a/src/www/httpd/cgi-bin/camera_settings.sh b/src/www/httpd/cgi-bin/camera_settings.sh index c3c7b40..6abe67e 100755 --- a/src/www/httpd/cgi-bin/camera_settings.sh +++ b/src/www/httpd/cgi-bin/camera_settings.sh @@ -43,6 +43,8 @@ do if [ "$CONF" == "switch_on" ] ; then if [ "$VAL" == "no" ] ; then ipc_cmd -t off + sleep 1 + ipc_cmd -T # Stop current motion detection event else ipc_cmd -t on fi diff --git a/src/www/httpd/cgi-bin/getlastrecordedsnapshot.sh b/src/www/httpd/cgi-bin/getlastrecordedsnapshot.sh index 6b22cc7..d237168 100755 --- a/src/www/httpd/cgi-bin/getlastrecordedsnapshot.sh +++ b/src/www/httpd/cgi-bin/getlastrecordedsnapshot.sh @@ -56,7 +56,7 @@ if [ "$OLDNESS" -lt "0" ]; then if [ -f "/tmp/sd/record/tmp.mp4.tmp" ]; then # A file is being recorded, therefore, try to get it when it finished saving. # First, we get the last directory. - for f in `ls -At /tmp/sd/record | grep H`; do + for f in `ls -Ar /tmp/sd/record | grep H`; do if [ ${#f} == 14 ]; then DIRNAME="$f" break; @@ -64,14 +64,14 @@ if [ "$OLDNESS" -lt "0" ]; then done # Now we get the number of directories and files in the last modified directory. - FILECOUNT=`ls -At /tmp/sd/record/$DIRNAME | grep .jpg -c` - DIRCOUNT=`ls -At /tmp/sd/record/ | grep H -c` + FILECOUNT=`ls -Ar /tmp/sd/record/$DIRNAME | grep .jpg -c` + DIRCOUNT=`ls -Ar /tmp/sd/record/ | grep H -c` SLEEPCOUNT=0 - while [ "$FILECOUNT" -eq `ls -At /tmp/sd/record/$DIRNAME | grep .jpg -c` ]; do + while [ "$FILECOUNT" -eq `ls -Ar /tmp/sd/record/$DIRNAME | grep .jpg -c` ]; do if [ "$SLEEPCOUNT" -gt 800 ]; then # After 80 seconds, we break the wait. break; - elif [ "$DIRCOUNT" -lt `ls -At /tmp/sd/record/ | grep H -c` ]; then + elif [ "$DIRCOUNT" -lt `ls -Ar /tmp/sd/record/ | grep H -c` ]; then # If a new dir comes, we break the wait. break; fi @@ -82,7 +82,7 @@ if [ "$OLDNESS" -lt "0" ]; then fi -for f in `ls -At /tmp/sd/record | grep H`; do +for f in `ls -Ar /tmp/sd/record | grep H`; do if [ ${#f} == 14 ]; then DIRNAME="$f" break; @@ -90,9 +90,9 @@ for f in `ls -At /tmp/sd/record | grep H`; do done # In $DIRNAME we now has the last modified directory. -COUNT=`ls -At /tmp/sd/record/$DIRNAME | grep .jpg -c` +COUNT=`ls -Ar /tmp/sd/record/$DIRNAME | grep .jpg -c` IDX=1 -for f in `ls -At /tmp/sd/record/$DIRNAME | grep .jpg`; do +for f in `ls -Ar /tmp/sd/record/$DIRNAME | grep .jpg`; do if [ ${#f} == 12 ] || [ ${#f} == 14 ]; then IMGNAME="$f" if [ "$IDX" -ge "$OLDNESS" ]; then diff --git a/src/www/httpd/cgi-bin/getlastrecordedvideo.sh b/src/www/httpd/cgi-bin/getlastrecordedvideo.sh index 918fdf1..2df70d2 100755 --- a/src/www/httpd/cgi-bin/getlastrecordedvideo.sh +++ b/src/www/httpd/cgi-bin/getlastrecordedvideo.sh @@ -58,7 +58,7 @@ if [ "$OLDNESS" -lt "0" ]; then if [ -f "/tmp/sd/record/tmp.mp4.tmp" ]; then # A file is being recorded, therefore, try to get it when it finished saving. # First, we get the last directory. - for f in `ls -At /tmp/sd/record | grep H`; do + for f in `ls -Ar /tmp/sd/record | grep H`; do if [ ${#f} == 14 ]; then DIRNAME="$f" break; @@ -66,14 +66,14 @@ if [ "$OLDNESS" -lt "0" ]; then done # Now we get the number of directories and files in the last modified directory. - FILECOUNT=`ls -At /tmp/sd/record/$DIRNAME | grep .mp4 -c` - DIRCOUNT=`ls -At /tmp/sd/record/ | grep H -c` + FILECOUNT=`ls -Ar /tmp/sd/record/$DIRNAME | grep .mp4 -c` + DIRCOUNT=`ls -Ar /tmp/sd/record/ | grep H -c` SLEEPCOUNT=0 - while [ "$FILECOUNT" -eq `ls -At /tmp/sd/record/$DIRNAME | grep .mp4 -c` ]; do + while [ "$FILECOUNT" -eq `ls -Ar /tmp/sd/record/$DIRNAME | grep .mp4 -c` ]; do if [ "$SLEEPCOUNT" -gt 800 ]; then # After 80 seconds, we break the wait. break; - elif [ "$DIRCOUNT" -lt `ls -At /tmp/sd/record/ | grep H -c` ]; then + elif [ "$DIRCOUNT" -lt `ls -Ar /tmp/sd/record/ | grep H -c` ]; then # If a new dir comes, we break the wait. break; fi @@ -84,7 +84,7 @@ if [ "$OLDNESS" -lt "0" ]; then fi -for f in `ls -At /tmp/sd/record | grep H`; do +for f in `ls -Ar /tmp/sd/record | grep H`; do if [ ${#f} == 14 ]; then DIRNAME="$f" break; @@ -92,9 +92,9 @@ for f in `ls -At /tmp/sd/record | grep H`; do done # In $DIRNAME we now has the last modified directory. -COUNT=`ls -At /tmp/sd/record/$DIRNAME | grep .mp4 -c` +COUNT=`ls -Ar /tmp/sd/record/$DIRNAME | grep .mp4 -c` IDX=1 -for f in `ls -At /tmp/sd/record/$DIRNAME | grep .mp4`; do +for f in `ls -Ar /tmp/sd/record/$DIRNAME | grep .mp4`; do if [ ${#f} == 12 ] || [ ${#f} == 14 ]; then VIDNAME="$f" if [ "$IDX" -ge "$OLDNESS" ]; then