-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup
executable file
·126 lines (95 loc) · 2.6 KB
/
setup
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
#!/bin/bash
# File name for generating SSL certificates (dev-only)
site=board.portal2.local
# File name of gzip'd database dump
dbname=iverborg_leaderboard
# Configuration files:
# .env > used by docker
# .config.json -> used by the server (mounted by docker)
create_config_and_env()
{
echo "[+] creating .config.json and .env file"
cp -n .config.example.json .config.json
cp -n .env.example .env
}
# Mounted log files.
# access.log -> apache vhosts access log
# error.log -> apache erro log
# debug.txt -> debug output by the server
create_logs()
{
echo "[+] creating logs in docker/logs"
mkdir -p docker/logs
touch docker/logs/access.log docker/logs/error.log docker/logs/debug.txt
}
# Other mounted volumes.
# docker/volumes/cache -> cache files used by the server
# docker/volumes/demos -> uploaded demo files
# docker/volumes/sessions -> user sessions used by the server
create_volumes()
{
echo "[+] creating volumes in docker/volumes"
mkdir -p docker/volumes docker/volumes/cache docker/volumes/demos docker/volumes/sessions
}
# Self-signed certificate for development only.
create_ssl_cert()
{
if [ -f "docker/ssl/$site.crt" ];
then
echo "[+] skipped generating certificate"
return
fi
if ! command -v mkcert &> /dev/null ;
then
echo "[-] mkcert does not seem to be installed. failed to generate ssl certificates"
else
echo "[+] generating certificate in docker/ssl"
mkdir -p "docker/ssl"
if ! err=$(mkcert -cert-file docker/ssl/$site.crt -key-file docker/ssl/$site.key $site 2>&1) ;
then
echo $err
fi
fi
}
# Database dump.
create_db()
{
echo "[+] extracting database dump to docker/initdb"
echo "USE $dbname;" > docker/initdb/_init.sql
gunzip -c data/leaderboard.gz >> docker/initdb/_init.sql
}
# Set permissions for www-data for all mounted volumes.
set_permissions()
{
echo "[+] setting permissions for all volumes"
sudo chown -R www-data:www-data \
./docker/logs/debug.txt \
./docker/volumes/cache \
./docker/volumes/demos \
./docker/volumes/sessions
}
# Development server only.
setup_dev()
{
echo "[+] setup for development..."
create_config_and_env
create_logs
create_volumes
create_ssl_cert
create_db
echo "[+] done"
}
# Prodcution server only.
setup_prod()
{
echo "[+] setup for production..."
create_config_and_env
create_logs
create_volumes
create_db
echo "[+] done"
}
case $1 in
dev) setup_dev ;;
* ) echo "usage: ./setup <dev>" ;;
esac