Skip to content

Commit

Permalink
Fix issue #520
Browse files Browse the repository at this point in the history
  • Loading branch information
roleoroleo committed Sep 20, 2023
1 parent bee5173 commit 2dbfab0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 45 deletions.
62 changes: 33 additions & 29 deletions src/static/static/home/yi-hack/script/clean_records.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
2 changes: 2 additions & 0 deletions src/www/httpd/cgi-bin/camera_settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/www/httpd/cgi-bin/getlastrecordedsnapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ 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;
fi
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
Expand All @@ -82,17 +82,17 @@ 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;
fi
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
Expand Down
16 changes: 8 additions & 8 deletions src/www/httpd/cgi-bin/getlastrecordedvideo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ 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;
fi
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
Expand All @@ -84,17 +84,17 @@ 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;
fi
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
Expand Down

0 comments on commit 2dbfab0

Please sign in to comment.