-
Notifications
You must be signed in to change notification settings - Fork 7
/
docker-entrypoint.sh
111 lines (95 loc) · 3.11 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
set -e
run_as() {
if [ "$(id -u)" = 0 ]; then
su -p www-data -s /bin/sh -c "$1"
else
sh -c "$1"
fi
}
# version_greater A B returns whether A > B
version_greater() {
[ "$(printf '%s\n' "$@" | sort -t '.' -n -k1,1 -k2,2 -k3,3 | head -n 1)" != "$1" ]
}
wait_for_db() {
until nc -z -v -w60 "${SPIP_DB_HOST}" "3306"; do
echo "Waiting for database ready..."
sleep 5
done
}
installed_version="0.0.0"
image_version="0.0.1"
if [ -f "/var/www/html/ecrire/inc_version.php" ]; then
installed_version=$(grep -i /var/www/html/ecrire/inc_version.php -e '\$spip_version_branche =' | cut -d '=' -f 2 | cut -d ';' -f 1 | cut -d "'" -f 2 | cut -d '"' -f 2)
image_version=$(grep -i /usr/src/spip/ecrire/inc_version.php -e '\$spip_version_branche =' | cut -d '=' -f 2 | cut -d ';' -f 1 | cut -d "'" -f 2 | cut -d '"' -f 2)
fi
echo $installed_version
echo $image_version
if version_greater "$installed_version" "$image_version"; then
echo "Can't start SPIP because the version of the data ($installed_version) is higher than the docker image version ($image_version) and downgrading is not supported. Are you sure you have pulled the newest image version?"
exit 1
fi
# Reconfigure php.ini
# set PHP.ini settings for SPIP
( \
echo 'display_errors=Off'; \
echo 'error_log=/var/log/apache2/php.log'; \
echo "max_execution_time=${PHP_MAX_EXECUTION_TIME}"; \
echo "memory_limit=${PHP_MEMORY_LIMIT}"; \
echo "post_max_size=${PHP_POST_MAX_SIZE}"; \
echo "upload_max_filesize=${PHP_UPLOAD_MAX_FILESIZE}"; \
echo "date.timezone=${PHP_TIMEZONE}"; \
) > /usr/local/etc/php/conf.d/spip.ini
if version_greater "$image_version" "$installed_version"; then
echo >&2 "SPIP upgrade in $PWD - copying now..."
if [ "$(ls -A)" ]; then
echo >&2 "WARNING: $PWD is not empty"
fi
tar cf - --one-file-system -C /usr/src/spip . | tar xf -
echo >&2 "Complete! SPIP has been successfully copied to $PWD"
echo >&2 "Create plugins, libraries and template directories"
mkdir -p plugins/auto
mkdir -p lib
mkdir -p squelettes
mkdir -p tmp/{dump,log,upload}
chown -R www-data:www-data plugins lib squelettes tmp
if [ ! -e .htaccess ]; then
cp -p htaccess.txt .htaccess
chown www-data:www-data .htaccess
fi
# Upgrade SPIP
if [ -f config/connect.php ]; then
spip core:maj:bdd
spip plugins:maj:bdd
fi
fi
# Install SPIP
if [ ${SPIP_DB_SERVER} = "mysql" ]; then
wait_for_db
fi
if [[ ! -e config/connect.php && ${SPIP_AUTO_INSTALL} = 1 ]]; then
# Wait for mysql before install
# cf. https://docs.docker.com/compose/startup-order/
run_as "spip install \
--db-server ${SPIP_DB_SERVER} \
--db-host ${SPIP_DB_HOST} \
--db-login ${SPIP_DB_LOGIN} \
--db-pass ${SPIP_DB_PASS} \
--db-database ${SPIP_DB_NAME} \
--db-prefix ${SPIP_DB_PREFIX} \
--adresse-site ${SPIP_SITE_ADDRESS} \
--admin-nom ${SPIP_ADMIN_NAME} \
--admin-login ${SPIP_ADMIN_LOGIN} \
--admin-email ${SPIP_ADMIN_EMAIL} \
--admin-pass ${SPIP_ADMIN_PASS}" || true
fi
# Default mes_options
if [ ! -e config/mes_options.php ]; then
/bin/cat << MAINEOF > config/mes_options.php
<?php
if (!defined("_ECRIRE_INC_VERSION")) return;
\$GLOBALS['spip_header_silencieux'] = 1;
?>
MAINEOF
fi
exec "$@"