-
Notifications
You must be signed in to change notification settings - Fork 0
/
stativa.sh
66 lines (55 loc) · 2.01 KB
/
stativa.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
#/bin/sh
for i in "$@"; do
case $i in
-c=*|--config=*)
CONFIG_PATH="${i#*=}"
shift # past argument=value
;;
*)
# unknown option
;;
esac
done
if [ ! -n "$CONFIG_PATH" ]; then
echo "You need to provide config path"
exit;
fi
export SUB_TITLE=$(grep title $CONFIG_PATH | cut -d '=' -f 2)
IMAGES_DIRECTORY=$(grep imagesDirectory $CONFIG_PATH | cut -d '=' -f 2)
TEMPLATES=$(grep templates $CONFIG_PATH | cut -d '=' -f 2)
export SUB_ENCRYPTED=$(grep encrypted $CONFIG_PATH | cut -d '=' -f 2)
if [ ! -n "$IMAGES_DIRECTORY" ]; then
SHOULD_USE_CONFIG_PATH_AS_IMAGES_DIRECTORY=$(grep configPathAsImageDirectory $CONFIG_PATH | cut -d '=' -f 2)
if [ ! -n "$SHOULD_USE_CONFIG_PATH_AS_IMAGES_DIRECTORY" ]; then
echo "You need to provide images directory in which index.html will be created"
exit;
fi
echo "Using config dirname as images directory"
IMAGES_DIRECTORY=$(dirname $CONFIG_PATH)
fi
export SUB_OUTPUT_INDEX="$IMAGES_DIRECTORY/index.html"
[ -f $SUB_OUTPUT_INDEX ] && rm $SUB_OUTPUT_INDEX
# Create array of images before cration of index.html
IMAGES_IDS=$(ls $IMAGES_DIRECTORY)
if [ -n "$SUB_ENCRYPTED" ]; then
echo "Removing images with .gpg extension"
rm $IMAGES_DIRECTORY/*.gpg
IMAGES_IDS=$(ls $IMAGES_DIRECTORY)
stty -echo
printf "Password: "
read GPG_PASSWORD
stty echo
printf "\n"
for fileToEncrypt in $IMAGES_IDS; do
echo encrypting $fileToEncrypt
gpg --output $IMAGES_DIRECTORY/$fileToEncrypt.gpg --cipher-algo AES256 --symmetric --batch --yes --passphrase $GPG_PASSWORD $IMAGES_DIRECTORY/$fileToEncrypt
done
IMAGES_IDS=$(ls -1 $IMAGES_DIRECTORY | grep gpg) # This is a dirty fix to get .gpg extension. Find and ls are really bad for that
fi
touch $SUB_OUTPUT_INDEX
export SUB_IMAGES_IDS="$(echo $IMAGES_IDS | xargs)"
export SUB_ALL_IMAGES="$(echo $IMAGES_IDS | xargs)"
for template in $TEMPLATES; do
export SUB_IMAGES_IDS="$(envsubst '$SUB_IMAGES_IDS,$SUB_ALL_IMAGES,$SUB_OUTPUT_INDEX,$SUB_ENCRYPTED' < $template | sh)"
echo $SUB_IMAGES_IDS
done