forked from tsgoff/docker-yourls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sh
245 lines (218 loc) · 7.68 KB
/
init.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/bin/sh
FILE=config.php
YOURLS_PATH=/usr/share/nginx/yourls/user/
SSL_PROTOCOLS_DEFAULT='TLSv1 TLSv1.1 TLSv1.2'
SSL_CIPHERS_DEFAULT='AES256+EECDH:AES256+EDH'
if [ -e /$YOURLS_PATH$FILE ]; then
echo "restart check: installed"
else
echo "starting installation"
if [ -z "$YOURLS_RELATIV_URL_ROOT" ]; then
echo "install in Document Root"
else
echo "path to yourls: $YOURLS_RELATIV_URL_ROOT"
/bin/mv /usr/share/nginx/yourls/ /usr/share/yourls/RWlzYW9iYWluZzBpZXNoCg
/bin/mkdir -p /usr/share/nginx/yourls/$YOURLS_RELATIV_URL_ROOT
/bin/mv /usr/share/nginx/RWlzYW9iYWluZzBpZXNoCg/* /usr/share/nginx/RWlzYW9iYWluZzBpZXNoCg/.??* /usr/share/nginx/yourls/$YOURLS_RELATIV_URL_ROOT
/bin/rm -rf /usr/share/nginx/RWlzYW9iYWluZzBpZXNoCg
YOURLS_PATH=/usr/share/nginx/owncloud/$YOURLS_RELATIV_URL_ROOT/config/
/bin/chown -R nginx:nginx /usr/share/nginx/yourls/
#/bin/echo "<?php header(\"Location: $YOURLS_RELATIV_URL_ROOT\"); die(); ?>" > /usr/share/nginx/yourls/index.php
fi
if [ -z "$YOURLS_SITE" ]; then
echo "no YOURLS_SITE name detected -> EXIT"
exit 1
else
echo "YOURLS_SITE name: $YOURLS_SITE"
fi
if [ -z "$DB_PREFIX" ]; then
echo "no DB_PREFIX found"
DB_PREFIX="yourls_"
else
echo "DB_PREFIX: $DB_PREFIX"
fi
if [ -z "$MYSQL_ENV_MYSQL_ROOT_PASSWORD" ]; then
echo "no linked mysql detected"
else
echo "linked mysql detected with container id $HOSTNAME and version $MYSQL_ENV_MYSQL_VERSION"
DB_TYPE=link_mysql
fi
if [ -z "$POSTGRES_ENV_POSTGRES_PASSWORD" ]; then
echo "no linked postgresql detected"
else
echo "linked postgresql detected with container id $HOSTNAME and version $POSTGRES_ENV_PG_VERSION"
DB_TYPE=link_postgresql
fi
if [ -z "$DB_HOST" ]; then
echo "no external mysql detected"
else
echo "external mysql detected"
DB_TYPE=ext_mysql
fi
/bin/mkdir /data
/bin/chown -R nginx:nginx /data
function fixperm {
/bin/chown nginx:nginx $YOURLS_PATH$FILE
}
case $DB_TYPE in
link_mysql)
echo 'using linked mysql'
MYSQL_HOST=`echo $MYSQL_NAME | /bin/awk -F "/" '{print $3}'`
echo "MySQL host is $MYSQL_HOST"
if [ -z "$MYSQL_USER" ]; then
echo "set MySQL user default to: root"
MYSQL_USER=root
fi
/bin/cat >$YOURLS_PATH$FILE <<EOL
<?php
define( 'YOURLS_DB_USER', '$MYSQL_USER' );
define( 'YOURLS_DB_PASS', '$MYSQL_ENV_MYSQL_ROOT_PASSWORD' );
define( 'YOURLS_DB_NAME', 'yourls' );
define( 'YOURLS_DB_HOST', '$MYSQL_HOST' );
define( 'YOURLS_DB_PREFIX', '$DB_PREFIX' );
define( 'YOURLS_SITE', '$YOURLS_SITE' );
define( 'YOURLS_HOURS_OFFSET', 0 );
define( 'YOURLS_LANG', '' );
define( 'YOURLS_UNIQUE_URLS', true );
define( 'YOURLS_PRIVATE', false );
define( 'YOURLS_DEBUG', false );
define( 'YOURLS_URL_CONVERT', 36 );
\$yourls_reserved_URL = array(
'reserved',
);
EOL
fixperm
;;
link_postgresql)
echo 'using linked postgresql'
POSTGRESQL_HOST=`echo $POSTGRES_NAME | /bin/awk -F "/" '{print $3}'`
echo "PostgreSQL host is $POSTGRESQL_HOST"
if [ -z "$POSTGRESQL_USER" ]; then
echo "set PostgreSQL user default to: postgres"
POSTGRESQL_USER=postgres
fi
if [ -z "$DB_NAME" ]; then
echo "set PostgreSQL Database Name to: postgres"
DB_NAME=postgres
fi
/bin/cat >$YOURLS_PATH$FILE <<EOL
<?php
define( 'YOURLS_DB_USER', '$POSTGRESQL_USER' );
define( 'YOURLS_DB_PASS', '$POSTGRES_ENV_POSTGRES_PASSWORD' );
define( 'YOURLS_DB_NAME', '$DB_NAME' );
define( 'YOURLS_DB_HOST', '$POSTGRESQL_HOST' );
define( 'YOURLS_DB_PREFIX', '$DB_PREFIX' );
define( 'YOURLS_SITE', '$YOURLS_SITE' );
define( 'YOURLS_HOURS_OFFSET', 0 );
define( 'YOURLS_LANG', '' );
define( 'YOURLS_UNIQUE_URLS', true );
define( 'YOURLS_PRIVATE', false );
define( 'YOURLS_DEBUG', false );
define( 'YOURLS_URL_CONVERT', 36 );
\$yourls_reserved_URL = array(
'reserved',
);
EOL
fixperm
;;
ext_mysql)
echo 'using external MYSQL DB'
/bin/cat >$YOURLS_PATH$FILE <<EOL
<?php
define( 'YOURLS_DB_USER', '$DB_USER' );
define( 'YOURLS_DB_PASS', '$DB_PASSWORD' );
define( 'YOURLS_DB_NAME', '$DB_NAME' );
define( 'YOURLS_DB_HOST', '$DB_HOST' );
define( 'YOURLS_DB_PREFIX', '$DB_PREFIX' );
define( 'YOURLS_SITE', '$YOURLS_SITE' );
define( 'YOURLS_HOURS_OFFSET', 0 );
define( 'YOURLS_LANG', '' );
define( 'YOURLS_UNIQUE_URLS', true );
define( 'YOURLS_PRIVATE', false );
define( 'YOURLS_DEBUG', false );
define( 'YOURLS_URL_CONVERT', 36 );
\$yourls_reserved_URL = array(
'reserved',
);
EOL
fixperm
;;
*)
echo "no database specified"
exit 1
esac
if [ -z "$FQDN" ]; then
echo "no fqdn"
FQDN="local.host"
else
echo "found fqdn $FQDN"
/bin/sed -i "s@server_name _@server_name $FQDN@g" /etc/nginx/conf.d/default.conf
fi
if [ -z "$SSL_SELFSIGNED" ]; then
echo "no SSL"
else
echo "generating selfsigned cert"
if [ -z "$SSL_PROTOCOLS" ]; then
echo "set default SSL protocol"
SSL_PROTOCOLS=$SSL_PROTOCOLS_DEFAULT
fi
if [ -z "$SSL_CIPHERS" ]; then
echo "set default SSL ciphers"
SSL_CIPHERS=$SSL_CIPHERS_DEFAULT
fi
/bin/mkdir /etc/nginx/ssl/
/bin/chown nginx:nginx /etc/nginx/ssl/
### <--
/usr/bin/openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt <<SSL
YourlsCity
$FQDN
SSL
### -->
/bin/cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/ssl.conf
/bin/sed -i "s@listen 80 default_server@listen 443@g" /etc/nginx/conf.d/ssl.conf
/bin/sed -i '/server_name/a\\n ssl on; \n\
ssl_certificate /etc/nginx/ssl/nginx.crt;\n ssl_certificate_key /etc/nginx/ssl/nginx.key;\n\
ssl_session_timeout 5m;\n\n ssl_protocols '"$SSL_PROTOCOLS"';\
ssl_ciphers '"$SSL_CIPHERS"';\
ssl_prefer_server_ciphers on;' /etc/nginx/conf.d/ssl.conf
fi
/bin/mv $YOURLS_PATH/plugins /data
ln -s /data/plugins/ $YOURLS_PATH/plugins
/bin/env >> /INSTALLED
set >> /INSTALLED
fi
/usr/sbin/php-fpm -F &
/usr/sbin/nginx -c /etc/nginx/nginx.conf
if [ ! -z "$YOURLS_PUB_DUMMY" ]; then
echo "creating public dummy site"
/bin/cat >$YOURLS_PATH/../index.php <<EOL
<html>
<head>
<title>hello world</title>
</head>
<body onload="history.go(-1);">
</body>
</html>
EOL
/bin/chown nginx:nginx $YOURLS_PATH/../index.php
fi
if [ -f /data/backup/config.php ]; then
echo "found backup file -> restore"
source /data/backup/yourls_env.conf
/bin/cp /data/backup/config.php $YOURLS_PATH/config.php
/bin/chown nginx:nginx $YOURLS_PATH/config.php
else
echo "create backup"
/bin/mkdir /data/backup && /bin/chown -R nginx:nginx $_
/bin/echo "YOURLS_PATH=$YOURLS_PATH" > /data/backup/yourls_env.conf && /bin/chown nginx:nginx /data/backup/yourls_env.conf
while [ ! -f "$YOURLS_PATH/config.php" ]
do
/bin/sleep 1
done
until /bin/grep phpass $YOURLS_PATH/config.php
do
/bin/sleep 1
done
/bin/cp $YOURLS_PATH/config.php /data/backup/ && /bin/chown nginx:nginx /data/backup/config.php
fi
wait