-
Notifications
You must be signed in to change notification settings - Fork 2
/
start.sh
executable file
·106 lines (88 loc) · 3.45 KB
/
start.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
#!/bin/bash
set -eu
echo "Create base folders"
mkdir -p /app/data /run/apache2 /run/proftpd /run/app /run/cron
if ! [ -f /app/data/.initialized ]; then
echo "Fresh installation start"
# Setup commands here
echo "Copying crontab file"
cp /app/code/crontab /app/data/
echo "Copying crontab file finished"
echo "Copying Friendica code"
cp -rf /app/code/friendica /app/data/public
echo "Copying Friendica code finished"
echo "Automatic installation start"
cd /app/data/public/
bin/console autoinstall
cd /app/data
echo "Automatic Installation done"
touch /app/data/.initialized
echo "Fresh installation done"
fi
# cleanup for old apache2-app.conf
rm -f /app/data/apache2-app.conf
if [ ! -f "/app/data/php.ini" ]; then
cp /etc/php/7.0/apache2/php.ini.orig /app/data/php.ini
else
crudini --set /app/data/php.ini Session session.gc_probability 1
crudini --set /app/data/php.ini Session session.gc_divisor 100
fi
# SFTP_PORT can be unset to disable SFTP
disable_sftp="false"
if [[ -z "${SFTP_PORT:-}" ]]; then
echo "SSH disabled"
SFTP_PORT=29418 # arbitrary port to keep sshd happy
disable_sftp="true"
else
sed -e "s,##SERVER_NAME,${APP_DOMAIN}," \
-e "s/##SFTP_PORT/${SFTP_PORT}/" \
-e "s,##LDAP_URL,${LDAP_URL},g" \
-e "s/##LDAP_BIND_DN/${LDAP_BIND_DN}/g" \
-e "s/##LDAP_BIND_PASSWORD/${LDAP_BIND_PASSWORD}/g" \
-e "s/##LDAP_USERS_BASE_DN/${LDAP_USERS_BASE_DN}/g" \
-e "s/##LDAP_UID/$(id -u www-data)/g" \
-e "s/##LDAP_GID/$(id -g www-data)/g" \
/app/code/proftpd.conf.template > /run/proftpd/proftpd.conf
if [[ -f /app/data/public/index.php ]]; then
sed -e "s,^sftp -P.*public/$,sftp -P ${SFTP_PORT} ${APP_DOMAIN}:public/," \
-i /app/data/public/index.php
fi
fi
if [[ ! -f "/app/data/sftpd/ssh_host_ed25519_key" ]]; then
echo "Generating ssh host keys"
mkdir -p /app/data/sftpd
ssh-keygen -qt rsa -N '' -f /app/data/sftpd/ssh_host_rsa_key
ssh-keygen -qt dsa -N '' -f /app/data/sftpd/ssh_host_dsa_key
ssh-keygen -qt ecdsa -N '' -f /app/data/sftpd/ssh_host_ecdsa_key
ssh-keygen -qt ed25519 -N '' -f /app/data/sftpd/ssh_host_ed25519_key
else
echo "Reusing existing host keys"
fi
chmod 0600 /app/data/sftpd/*_key
chmod 0644 /app/data/sftpd/*.pub
## Generate apache config. PMA is disabled based on SFTP config
if [[ "${disable_sftp}" == "true" ]]; then
echo "PMA disabled"
sed '/.*PMA BEGIN/,/.*PMA END/d' /app/code/apache2-app.conf > /run/apache2/app.conf
else
sed -e "s@AuthLDAPURL .*@AuthLDAPURL ${LDAP_URL}/${LDAP_USERS_BASE_DN}?username??(objectclass=user)@" \
-e "s@AuthLDAPBindDN .*@AuthLDAPBindDN ${LDAP_BIND_DN}@" \
-e "s@AuthLDAPBindPassword .*@AuthLDAPBindPassword ${LDAP_BIND_PASSWORD}@" \
/app/code/apache2-app.conf > /run/apache2/app.conf
fi
## hook for custom start script in /app/data/run.sh
if [ -f "/app/data/run.sh" ]; then
/bin/bash /app/data/run.sh
fi
## configure in-container Crontab
if [ -f "/app/data/crontab" ]; then
# http://www.gsp.com/cgi-bin/man.cgi?section=5&topic=crontab
if ! (env; cat /app/data/crontab; echo -e '\nMAILTO=""') | crontab -u www-data -; then
echo "Error importing crontab. Continuing anyway"
else
echo "Imported crontab"
fi
fi
chown -R www-data:www-data /app/data /run/apache2 /run/proftpd /run/app
echo "Starting supervisord"
exec /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Friendica