-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
executable file
·77 lines (58 loc) · 2.18 KB
/
install.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
#!/bin/bash
# exit when any command fails
set -e
if [ ! -f .env ]; then
echo "Exiting: Could not find .env file!"
exit 1
fi
set -a
source .env
set +a
echo "Adding deploy user to server if necessary…"
# Add deploy user if it doesn’t already exist
id -u deploy >/dev/null 2>&1 || sudo useradd -m deploy
# set up ssh key from root to deploy
mkdir -p /home/deploy/.ssh
cp /root/.ssh/authorized_keys /home/deploy/.ssh/authorized_keys
chown -R deploy:deploy /home/deploy/.ssh
echo "Installing docker-compose…"
apt install -y docker-compose
echo "Setting up Letsencrypt…"
mkdir -p ./data/etc/letsencrypt
mkdir -p ./data/var/lib/letsencrypt
mkdir -p ./data/couchdb
sudo docker run -it --rm \
-p 80:80 -p 443:443 \
--name certbot \
-v "$PWD/data/etc/letsencrypt:/etc/letsencrypt" \
-v "$PWD/data/var/lib/letsencrypt:/var/lib/letsencrypt" \
certbot/certbot certonly \
--standalone -d "$DOMAIN" --email "$CERTBOT_EMAIL" \
--agree-tos --keep --non-interactive
# Concatenate the resulting certificate chain and the private key and write it to HAProxy's certificate file.
cd data/etc/letsencrypt/live/${DOMAIN}/
cat fullchain.pem privkey.pem > ../../../haproxy/haproxychain.pem
cd -
mv renew_certificate_job /etc/cron.d/renew_certificate_job
chmod +x renew-certificate.sh
echo "Starting Docker Containers…"
docker-compose up -d
until curl -s -X GET http://localhost:5984 | jq -e '.couchdb == "Welcome"' >/dev/null; do
echo "Waiting for CouchDB to start..."
sleep 2
done
echo "CouchDB is ready!"
echo "Setting up CouchDB…"
# Make sure docker hasn't stolen deploy’s directory
chown deploy /home/deploy/web
curl -X PUT http://"$COUCHDB_USER":"$COUCHDB_PASS"@localhost:5984/_users
curl -X PUT http://"$COUCHDB_USER":"$COUCHDB_PASS"@localhost:5984/_replicator
if [ "$ENABLE_CORS" = "true" ]; then
curl -X PUT http://"$COUCHDB_USER":"$COUCHDB_PASS"@localhost:5984/_node/nonode@nohost/_config/chttpd/enable_cors -d '"true"'
curl -X PUT http://"$COUCHDB_USER":"$COUCHDB_PASS"@localhost:5984/_node/nonode@nohost/_config/cors/origins -d "\"$ALLOWED_ORIGINS\""
fi
if [ "$COUCHDB_PATH" = "/" ]; then
COUCHDB_PATH=""
fi
echo "Running Fauxton at https://$DOMAIN${COUCHDB_PATH}/_utils/"
echo "All Done!"