forked from billw2/pikrellcam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_archive-still
executable file
·98 lines (80 loc) · 2.47 KB
/
_archive-still
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
# Move stills into an archive directory.
# Calling format from pikrellcam or a at-commands script:
# archive-still [day|still.jpg] yyyy-mm-dd $a $m $P $G
#
# Which pikrellcam expands into:
# archive-still day yyyy-mm-dd archive-dir media-dir FIFO LOG
# or
# archive-still still.jpg yyyy-mm-dd archive-dir media-dir FIFO LOG
# If $1 is the string "day", move all stills for the day yyyy-mm-dd into
# the archive directory archive-dir/yyyy/mm/dd/stills
# Otherwise, $1 should be a jpg still and it
# is moved into the archive directory.
DAY_FLAG=$1
STILL=$1
DATE=$2
ARCHIVE_DIR=$3
MEDIA_DIR=$4
FIFO=$5
LOG_FILE=$6
if [ "$DATE" == "yesterday" ]
then
DATE=`date --date="yesterday" +'%F'`
elif [ "$DATE" == "today" ]
then
DATE=`date --date="today" +'%F'`
fi
LEN=${#DATE}
if [[ "$LEN" -ne "10" ]]
then
echo " archive-still bad date string: $DATE" >> $LOG_FILE
exit 1
fi
# From DATE arg: yyyy-mm-dd, DATE_PATH is: yyyy/mm/dd
YEAR=`expr substr $DATE 1 4`
MONTH=`expr substr $DATE 6 2`
DAY=`expr substr $DATE 9 2`
DATE_PATH=$YEAR/$MONTH/$DAY
ARCHIVE_STILLS_PATH=$ARCHIVE_DIR/$DATE_PATH/stills
ARCHIVE_THUMBS_PATH=$ARCHIVE_STILLS_PATH/.thumbs
YEAR=`expr substr $DATE 1 4`
MONTH=`expr substr $DATE 6 2`
DAY=`expr substr $DATE 9 2`
create_dir()
{
DIR=$1
if [ ! -d $DIR ]
then
mkdir $DIR
sudo chown :www-data $DIR
sudo chmod 775 $DIR
fi
}
create_dir $ARCHIVE_DIR/$YEAR
create_dir $ARCHIVE_DIR/$YEAR/$MONTH
create_dir $ARCHIVE_DIR/$YEAR/$MONTH/$DAY
create_dir $ARCHIVE_STILLS_PATH
if [ ! -d $ARCHIVE_STILLS_PATH ]
then
echo " archive-still could not create archive directory: $ARCHIVE_STILLS_PATH" >> $LOG_FILE
exit 1
fi
create_dir $ARCHIVE_THUMBS_PATH
if [ "$DAY_FLAG" == "day" ]
then
echo " archive-still day $DATE to $ARCHIVE_DIR/$DATE_PATH" >> $LOG_FILE
mv $MEDIA_DIR/stills/*${DATE}*.jpg $ARCHIVE_STILLS_PATH
mv $MEDIA_DIR/stills/.thumbs/*${DATE}*.th.jpg $ARCHIVE_THUMBS_PATH
else
echo " archive-still $STILL to $ARCHIVE_DIR/$DATE_PATH" >> $LOG_FILE
mv $MEDIA_DIR/stills/$STILL $ARCHIVE_STILLS_PATH
THUMB_JPEG=${STILL%.jpg}.th.jpg
mv $MEDIA_DIR/stills/.thumbs/$THUMB_JPEG $ARCHIVE_THUMBS_PATH
fi
# Cleanup in case no files were moved so archive page won't show dangling links
#
find $ARCHIVE_THUMBS_PATH -maxdepth 0 -empty -exec rmdir $ARCHIVE_THUMBS_PATH \;
find $ARCHIVE_STILLS_PATH -maxdepth 0 -empty -exec rmdir $ARCHIVE_STILLS_PATH \;
ARCHIVE_DATE_PATH=$ARCHIVE_DIR/$DATE_PATH
find $ARCHIVE_DATE_PATH -maxdepth 0 -empty -exec rmdir $ARCHIVE_DATE_PATH \;