This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
cozy-init
executable file
·51 lines (43 loc) · 1.63 KB
/
cozy-init
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
#!/bin/bash
set -e
# Remove old CouchDB admin
if [ "$(tail -n1 /etc/couchdb/local.ini | awk '{ print $1 }')" != ";admin" ]; then
sed -i '$ d' /etc/couchdb/local.ini
fi
if [ "$NODE_ENV" == "development" ]; then
# In development: ensure that DS will not start with CouchDB credentials
rm -f /etc/cozy/couchdb.login
else
# In production: configure a new CouchDB admin
new_admin=$(pwgen -1)
new_password=$(pwgen -1)
echo "$new_admin = $new_password" >> /etc/couchdb/local.ini
echo "$new_admin" > /etc/cozy/couchdb.login
echo "$new_password" >> /etc/cozy/couchdb.login
fi
supervisorctl restart couchdb
# Reset controller token
pwgen -1 > /etc/cozy/controller.token
chown cozy-home /etc/cozy/controller.token
chmod 700 /etc/cozy/controller.token
supervisorctl restart cozy-controller
# Regenerate SSL certificates
if [ "$DISABLE_SSL" == "true" ]; then
rm -f /etc/nginx/sites-enabled/cozy-ssl
ln -sf /etc/nginx/sites-available/cozy /etc/nginx/sites-enabled/
else
rm -f /etc/nginx/sites-enabled/cozy
ln -sf /etc/nginx/sites-available/cozy-ssl /etc/nginx/sites-enabled/
if [ -z "$DOMAIN" ]; then
DOMAIN=localhost
fi
openssl dhparam -out /etc/cozy/dh2048.pem -outform PEM -2 2048
openssl req -x509 -nodes -newkey rsa:2048 -keyout /etc/cozy/server.key -out /etc/cozy/server.crt -days 3650 -subj "/CN=$DOMAIN"
chown cozy:cozy /etc/cozy/server.key
chmod 600 /etc/cozy/server.key
fi
supervisorctl restart nginx
# Restart cozy-controller when CouchDB is available
while ! curl -s 127.0.0.1:5984; do sleep 5; done
cozy-monitor restart-cozy-stack
rm -f /etc/supervisor/conf.d/cozy-init.conf