-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall
executable file
·219 lines (186 loc) · 6.07 KB
/
install
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
#!/bin/bash
#set -e
#set -x
source /etc/opt/copilot
readonly PROG_DIR=$(readlink -m $(dirname $0))
temporary_fixes () {
echo dnsmasq-base hold |dpkg --set-selections
}
# ==== OS ====
update_os() {
apt-get -y update
apt-get -y upgrade
}
# ==== CO-PILOT BASE ====
install_co-pilot_deps() {
# usbmount auto-mounts usb sticks
apt-get -y install usbmount
}
setup_copilot_env() {
if grep -Fxq "COPILOT_PROFILE_CONFIG_DIRECTORY" /etc/environment
then
echo "Copilot environment already configured. Skipping..."
else
# Create global environment variable for copilot to use
echo "COPILOT_PROFILE_CONFIG_DIRECTORY=${COPILOT_PROFILE_CONFIG_DIRECTORY}" >> /etc/environment
echo "COPILOT_TEMPORARY_CONFIG_DIRECTORY=${COPILOT_TEMPORARY_CONFIG_DIRECTORY}" >> /etc/environment
echo "COPILOT_DEFAULT_CONFIG_DIRECTORY=${COPILOT_DEFAULT_CONFIG_DIRECTORY}" >> /etc/environment
fi
}
# ==== FLASK ====
install_flask_deps() {
#Install Flask dependencies
apt-get -y install python-dev
apt-get -y install curl
apt-get -y install python2.7-dev
apt-get -y install python-pysqlite2
apt-get -y install python-pip
# Add pip to path
export PATH="/usr/local/bin:$PATH"
# Bcrypt Dependencies
apt-get -y install build-essential
#apt-get -y install libffi-dev
}
install_flask() {
#install flask & WTForms
pip install flask
pip install flask-wtf
pip install SQLAlchemy
pip install Flask-SQLAlchemy
pip install flask-bcrypt
pip install Flask-Login
}
setup_flask_env() {
# # Get rid of the application root in the bp_config
# sed -i '/^APPLICATION_ROOT.*/d' $COPILOT_DIR/instance/bp_config.py
set RANDFILE="/tmp/.rnd"
if grep -Fxq "CSRF_SESSION_KEY" $COPILOT_DIR/instance/config.py
then
# Add a random CSRF session key.
local CSRF=$(openssl rand -base64 32)
sed -i "s/^\(CSRF_SESSION_KEY\s=\s\).*$/\1\"${CSRF}\"/" $COPILOT_DIR/instance/config.py
sed -i "s/^\(CSRF_SESSION_KEY\s=\s\).*$/\1\"${CSRF}\"/" $COPILOT_DIR/instance/bp_config.py
else
echo "Random copilot CSRF secret already set. Skipping..."
fi
if grep -Fxq "SECRET_KEY" $COPILOT_DIR/instance/config.py
then
# Add a random secret key for signing cookies
local SECRET=$(openssl rand -base64 32)
sed -i "s/^\(SECRET_KEY\s=\s\).*$/\1\"${SECRET}\"/" $COPILOT_DIR/instance/config.py
sed -i "s/^\(SECRET_KEY\s=\s\).*$/\1\"${SECRET}\"/" $COPILOT_DIR/instance/bp_config.py
else
echo "Random copilot secret key already set. Skipping..."
fi
}
# ==== WSGI ====
install_wsgi() {
apt-get -y install nginx supervisor
pip install gunicorn
apt-get -y install python-pip
pip install watchdog
}
setup_wsgi() {
setup_nginx
setup_supervisor
}
setup_nginx() {
if [[ -a "/etc/nginx/sites-enabled/default" ]]
then
rm /etc/nginx/sites-enabled/default
service nginx start
cp $COPILOT_DIR/templates/nginx_sites /etc/nginx/sites-available/copilot
ln -s /etc/nginx/sites-available/copilot /etc/nginx/sites-enabled/copilot
#enable
update-rc.d nginx enable
service nginx restart
else
echo "Nginx already setup. Skipping..."
fi
}
setup_supervisor() {
if grep -Fxq "PLUGIN_DIR_REPLACE_STRING" /etc/supervisor/conf.d/supervisord.conf
then
# replace the various environment variables with the actual value of the vars
# Using @ as the sed seperator so that we don't get errors when using double quotes
cat $COPILOT_DIR/templates/supervisor \
| sed "s@PLUGIN_DIR_REPLACE_STRING@${COPILOT_PLUGINS_DIRECTORY}@" \
| sed "s@COPILOT_PROFILE_DIR_REPLACE_STRING@${COPILOT_PROFILE_CONFIG_DIRECTORY}@" \
| sed "s@COPILOT_TEMP_DIR_REPLACE_STRING@${COPILOT_TEMPORARY_CONFIG_DIRECTORY}@" \
| sed "s@COPILOT_DEFAULT_DIR_REPLACE_STRING@${COPILOT_DEFAULT_CONFIG_DIRECTORY}@" \
> /etc/supervisor/conf.d/supervisord.conf
#enable
update-rc.d supervisor enable
else
echo "Supervisor already setup. Skipping...."
fi
}
# ==== AVAHI ====
install_avahi() {
apt-get -y install avahi-daemon
update-rc.d avahi-daemon enable
service avahi-daemon restart
}
# ==== PLUGINS ====
install_plugins() {
echo "Installing plugins."
if grep -Fxq "COPILOT_PLUGINS_DIRECTORY" /etc/environment
then
echo "Plugins already added to environment. Skipping..."
else
# Create global environment variable for copilot to use
echo "COPILOT_PLUGINS_DIRECTORY=${COPILOT_PLUGINS_DIRECTORY}" >> /etc/environment
fi
cd "${COPILOT_PLUGINS_DIRECTORY}"
cd plugins
for path in "${COPILOT_PLUGINS_DIRECTORY}"plugins/*; do
[ -d "${path}" ] || continue # if not a directory, skip
dirname="$(basename "${path}")"
echo "Beginning install of plugin $dirname"
# Run installation script
if [ -a "${path}"/install ]; then
"$path"/install
fi
# Add supervisor configs to supervisor
if [ -a "$path"/supervisor.conf ]; then
# replace COPILOT_PLUGINS_DIRECTORY with the actual value of the var
# Using @ as the sed seperator so that we don't get errors when using double quotes
cat "$path"/supervisor.conf \
| sed "s@COPILOT_PLUGINS_DIRECTORY@${COPILOT_PLUGINS_DIRECTORY}@" \
>> /etc/supervisor/conf.d/supervisord.conf
fi
echo "Plugin $dirname installed"
done
echo "All plugins installed"
}
dependencies() {
# lack of entropy slows installing massively
apt-get install -y haveged
install_flask_deps
}
install() {
#create setup directory
mkdir -p $SETUP_DIR
#Create website Directory
mkdir -p $WEB_DIR
setup_copilot_env
setup_flask_env
install_avahi
install_flask
install_wsgi
install_avahi
}
setup() {
setup_wsgi
}
main() {
update_os
dependencies
install
setup
cd $COPILOT_DIR
install_plugins
cd $PROG_DIR
touch "${INSTALL_FLAG}"
}
main