-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·144 lines (115 loc) · 3.43 KB
/
setup.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
# Script for setting up Open Carbon Map application
# Code snippets taken from internet and credited where relevant
# 2020
# Workaround for problem with bash on OSX not supporting -i flag on read
# https://stackoverflow.com/questions/22634065/bash-read-command-does-not-accept-i-parameter-on-mac-any-alternatives
function readinput() {
local CLEAN_ARGS=""
default=''
prompt=''
while [[ $# -gt 0 ]]; do
local i="$1"
case "$i" in
"-i")
default="$2"
shift
shift
;;
"-p")
prompt="$2"
shift
shift
;;
*)
input=$1
shift
;;
esac
done
read -p "$prompt [$default]: " tempinput
eval $input="${tempinput:-$default}"
}
echo "Creating folders for GIS and data files"
mkdir app/BEIS
mkdir app/subregions
readinput -e -p "Domain name to be used" -i "localhost" domain
echo "Website will be run on ${domain}"
echo "Creating Nginx config file"
echo "# Open Carbon Map Nginx conf file
# v1.0.0
# 19th November, 2020
upstream opencarbonmap {
server unix://${PWD}/opencarbonmap.sock;
}
server {
listen 80;
server_name ${domain};
location / {
proxy_pass http://opencarbonmap;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header Host \$host;
proxy_redirect off;
}
location /static/ {
alias ${PWD}/app/static/;
}
}
" > nginx/nginx_server.conf
echo "Creating gunicorn config file"
mkdir gunicorn
echo "[Unit]
Description=gunicorn daemon for Open Carbon Map
After=network.target
[Service]
User=www-data
Group=www-data
WorkingDirectory=${PWD}/app
Environment="PATH=${PWD}/venv/bin"
ExecStart=${PWD}/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:${PWD}/opencarbonmap.sock carbonmap.wsgi:application
[Install]
WantedBy=multi-user.target
" > gunicorn/gunicorn.service
echo "Database setup"
readinput -e -p "Name of new Postgres database to be used for Open Carbon Map system" -i "opencarbonmap" postgres_dbname
readinput -e -p "Name of new Postgres database user to be used for Open Carbon Map application" -i "opencarbonmapuser" postgres_username
read -p "Password for new Postgres database user (Note: password will be hidden): " -s postgres_password; echo
echo "Creating Django dev environment file"
echo "DJANGO_ALLOWED_HOSTS=${domain} 127.0.0.1 [::1]
PUBLICDOMAIN=http://${domain}:8000/
SECURE_SSL_REDIRECT=0
DEBUG=1
DATABASE=postgres
SQL_ENGINE=django.contrib.gis.db.backends.postgis
SQL_DATABASE=${postgres_dbname}
SQL_USER=${postgres_username}
SQL_PASSWORD=${postgres_password}
SQL_HOST=localhost
SQL_PORT=5432
POSTGRES_USER=\${SQL_USER}
POSTGRES_PASSWORD=\${SQL_PASSWORD}
POSTGRES_DB=\${SQL_DATABASE}" > app/.env.dev
echo "Creating Django prod environment file"
echo "DJANGO_ALLOWED_HOSTS=${domain} 127.0.0.1 [::1]
PUBLICDOMAIN=https://${domain}/
SECURE_SSL_REDIRECT=0
DEBUG=0
DATABASE=postgres
SQL_ENGINE=django.contrib.gis.db.backends.postgis
SQL_DATABASE=${postgres_dbname}
SQL_USER=${postgres_username}
SQL_PASSWORD=${postgres_password}
SQL_HOST=localhost
SQL_PORT=5432
POSTGRES_USER=\${SQL_USER}
POSTGRES_PASSWORD=\${SQL_PASSWORD}
POSTGRES_DB=\${SQL_DATABASE}" > app/.env.prod
echo "Adding SECRET_KEY to environment files"
python3 addsecretkey.py
ln -s .env.dev app/.env
echo "Installing node modules"
cd app/frontend/
npm install
echo "Compiling frontend app"
npm run build
cd ../../
echo "Core application set up complete, ready for server init or Docker to be run"