-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall
executable file
·222 lines (181 loc) · 5.45 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
220
221
222
#!/bin/bash
#set -e
#set -x
readonly PROG_DIR=$(readlink -m $(dirname $0))
readonly COPILOT_DIR=/home/www/copilot
readonly WEB_DIR=/home/www
readonly SETUP_DIR=/tmp/setup
readonly TESTING=false
# ==== HARDWARE ====
prepare_devices() {
#TODO remove the temporary fix that address' a bug introduced in https://github.com/OpenInternet/co-pilot/issues/59
# watch https://github.com/OpenInternet/co-pilot/issues/60 for when this can be removed.
#To remove this temporary fix delete the call to temporary_fixes below, remove the temporary_fixes function, and uncoment apt-get -y install dnsmasq
temporary_fixes
#Currently only BBB has specific preparation needs
local kernel=$(uname -mrs)
if [[ $kernel == *"bone"* ]]; then
#Prepare the beagle bone black
prep_bbb
fi
}
prep_bbb() {
rm -rf /var/lib/apt/lists
apt-get -y update
apt-get -y --force-yes install kali-archive-keyring
}
temporary_fixes () {
echo dnsmasq-base hold |dpkg --set-selections
}
# ==== OS ====
update_os() {
apt-get -y update
apt-get -y upgrade
}
# ==== CO-PILOT BASE ====
install_copilot() {
cp -fr $PROG_DIR $COPILOT_DIR
}
install_co-pilot_deps() {
#usbmount auto-mounts usb sticks
apt-get -y install usbmount
}
setup_copilot_db() {
mkdir -p /var/lib/copilot
mkdir -p /var/lib/copilot/profiles
}
# ==== 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
# Instal pip
curl https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py | python -
curl https://bootstrap.pypa.io/get-pip.py | python -
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() {
cd $WEB_DIR
mkdir $COPILOT_DIR/instance
local SECRET=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
if [[ $TESTING = true ]]; then
cp $COPILOT_DIR/templates/testing_config.py $COPILOT_DIR/instance/config.py
cp $COPILOT_DIR/templates/testing_config.py $COPILOT_DIR/instance/bp_config.py
else
cp $COPILOT_DIR/templates/base_config.py $COPILOT_DIR/instance/config.py
cp $COPILOT_DIR/templates/base_config.py $COPILOT_DIR/instance/bp_config.py
fi
# Get rid of the application root in the bp_config
sed -i '/^APPLICATION_ROOT.*/d' $COPILOT_DIR/instance/bp_config.py
# Add a random CSRF session key.
local CSRF=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
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
# Add a random secret key for signing cookies
local SECRET=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
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
cd $PROG_DIR
}
# ==== 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() {
service nginx start
rm /etc/nginx/sites-enabled/default
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
}
setup_supervisor() {
cp $COPILOT_DIR/templates/supervisor /etc/supervisor/conf.d/supervisord.conf
#enable
update-rc.d supervisor enable
}
# ==== AVAHI ====
install_avahi() {
apt-get -y install avahi-daemon
update-rc.d avahi-daemon enable
service avahi-daemon restart
}
setup_avahi() {
echo "copilot" > /etc/hostname
/etc/init.d/hostname.sh start
sed -i 's/127.0.0.1\s*kali/127.0.0.1\tcopilot/' /etc/hosts
service networking restart
}
# ==== PLUGINS ====
install_plugins() {
echo "Installing plugins."
for path in "$COPILOT_DIR"/copilot/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
cat "$path"/supervisor.conf >> /etc/supervisor/conf.d/supervisord.conf
fi
echo "Plugin $dirname installed"
done
echo "All plugins installed"
}
dependencies() {
install_co-pilot_deps
install_flask_deps
}
install() {
#create setup directory
mkdir -p $SETUP_DIR
#Create website Directory
mkdir -p $WEB_DIR
install_copilot
setup_copilot_db
setup_flask_env
install_avahi
install_flask
install_wsgi
install_avahi
}
setup() {
setup_wsgi
setup_avahi
}
main() {
prepare_devices
update_os
dependencies
install
setup
cd $COPILOT_DIR
install_plugins
cd $PROG_DIR
}
main