-
Notifications
You must be signed in to change notification settings - Fork 10
/
albums-for-web.sh
executable file
·77 lines (62 loc) · 2 KB
/
albums-for-web.sh
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
#!/bin/bash
## Make globally available with:
# sudo ln -s ~/Desktop/www/shell-scripts/albums-for-web.sh /usr/local/bin/albums-for-web
# sudo chmod a+x /usr/local/bin/albums-for-web
# https://github.com/Janis-Rullis-IT/shell-scripts/issues/2#issuecomment-608466590
# Define error reporting level, file seperator, and init direcotry.
function init(){
set -Eeuo pipefail; # set -o xtrace;
IFS=$'\n\t'
DIR=$PWD;
ROOT_DIR="$(dirname "${DIR}")";
echo "" > "${DIR}/albums-for-web.log";
}
init
echo "== Prepare multiple image albums for publishing in the web - make responsive images, generate videos, HTML, XML, JSON ==
Example
albums-for-web
";
# #3 Get the total image count and pass it to the HTML generator.
FOUND_SCRIPTS=`find . -maxdepth 2 -name 'gen.sh'`
FOUND_SCRIPTS_ARR=($FOUND_SCRIPTS)
FOUND_SCRIPT_CNT=${#FOUND_SCRIPTS_ARR[@]}
PROCESSED_DIR="${DIR}/Processed";
GROUP_FORMATS[0]='html';
GROUP_FORMATS[1]='xml';
GROUP_FORMATS[2]='mp4';
# #4 Will store processed albums here.
if [[ ! -d $PROCESSED_DIR ]]; then
mkdir $PROCESSED_DIR;
echo "Created $PROCESSED_DIR";
fi
for i in "${!FOUND_SCRIPTS_ARR[@]}"
do
f=${FOUND_SCRIPTS_ARR[$i]};
dir=$(dirname $f);
echo $dir >> "${DIR}/albums-for-web.log";
cd "${dir}";
if [[ -r 'renamed' ]]; then
echo "Skipping because there's already a generated content." >> "${DIR}/albums-for-web.log";
else
./gen.sh
echo "Completed." >> "${DIR}/albums-for-web.log";
fi
cd ${DIR};
# #4 Move the album to Processed.
mv "${dir}" "${PROCESSED_DIR}";
done
# #4 Group HTML, XML, videos.
for GROUP_FORMAT in ${GROUP_FORMATS[@]}; do
GROUP_FORMAT_DIR="${PROCESSED_DIR}/${GROUP_FORMAT}";
if [[ ! -d $GROUP_FORMAT_DIR ]]; then
mkdir $GROUP_FORMAT_DIR;
echo "Created ${GROUP_FORMAT_DIR}";
fi
for f in `find ${PROCESSED_DIR}/. -type f -name "*.${GROUP_FORMAT}"`
do
echo $f;
# #4 https://stackoverflow.com/a/9392784
cp -n "${f}" "${GROUP_FORMAT_DIR}/.";
done
done
echo "Done! See ${DIR}/albums-for-web.log";