-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-entrypoint.sh
executable file
·75 lines (65 loc) · 2.02 KB
/
docker-entrypoint.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
#!/bin/bash
# get the current active timezone.
TZ=$(date | awk -F' ' '{print $5}')
# check if the timezone should be changed
if [ -n "$CONTAINER_TIMEZONE" ] && [ "$CONTAINER_TIMEZONE" != "$TZ" ]; then
ln -sf "/usr/share/zoneinfo/$CONTAINER_TIMEZONE" /etc/localtime && \
echo "$CONTAINER_TIMEZONE" > /etc/timezone && date
echo "Setting container timezone to: $CONTAINER_TIMEZONE"
fi
echo "Creating calibre user"
if ! grep -Eq ":$PGROUP:" /etc/group
then
groupadd -g "$PGROUP" calibre
fi
useradd -M -N -u "$PUSER" -g "$PGROUP" calibre
echo "Changing application owner"
chown -R "$PUSER:$PGROUP" /calibre-web
if ! gosu calibre test -w /calibre-web
then
echo "Error: Was not able to write in application folder"
exit 1
fi
if [[ ! -f /config/app.db ]]
then
echo "Initialize application configuration"
cp /calibre-web/dockerinit/app.db /config/app.db
fi
if [[ ! -f /config/gdrive.db ]]
then
echo "Initialize gdrive configuration"
cp /calibre-web/dockerinit/gdrive.db /config/gdrive.db
fi
echo "Changing configuration owner"
chown -R "$PUSER:$PGROUP" /config
chmod -R o+rwx /config
if ! gosu calibre test -w /config/app.db -a -w /config/gdrive.db
then
echo "Error: Was not able to write config databases"
exit 1
fi
if [[ ! -f /books/metadata.db ]]
then
echo "Initialize Library"
cp /calibre-web/dockerinit/metadata.db /books/metadata.db
fi
if [[ ! -r /books/metadata.db ]]
then
chown "$PUSER:$PGROUP" /books/metadata.db
fi
if [[ ! -f /books/metadata_db_prefs_backup.json ]]
then
echo "Initialize Library configuration"
cp /calibre-web/dockerinit/metadata_db_prefs_backup.json /books/metadata_db_prefs_backup.json
fi
if [[ ! -r /books/metadata_db_prefs_backup.json ]]
then
chown "$PUSER:$PGROUP" /books/metadata_db_prefs_backup.json
fi
if ! gosu calibre test -w /books/metadata.db -a -w /books/metadata_db_prefs_backup.json
then
echo "Error: Was not able to write application databases"
exit 1
fi
echo "Starting Calibre Web"
gosu "$PUSER:$PGROUP" bash -c "python /calibre-web/cps.py -p /config/app.db -g /config/gdrive.db"