This repository has been archived by the owner on Apr 21, 2021. It is now read-only.
forked from netsec-ethz/scion-coord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scion_install_script.sh
executable file
·207 lines (170 loc) · 5.45 KB
/
scion_install_script.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
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
#!/bin/bash
set -e
shopt -s nullglob
usage="$(basename "$0") [-p PATCH_DIR] [-g GEN_DIR] [-v VPN_CONF_PATH] \
[-s SCION_SERVICE] [-z SCION_VI_SERVICE] [-a ALIASES_FILE] [-c]
where:
-p PATCH_DIR apply patches from PATCH_DIR on cloned repo
-g GEN_DIR path to gen directory to be used
-v VPN_CONF_PATH path to OpenVPN configuration file
-s SCION_SERVICE path to SCION service file
-z SCION_VI_SERVICE path to SCION-viz service file
-a ALIASES_FILE adds useful command aliases in specified file
-c do not destroy user context on logout"
while getopts ":p:g:v:s:z:ha:c" opt; do
case $opt in
p)
patch_dir=$OPTARG
;;
g)
gen_dir=$OPTARG
;;
v)
vpn_config_file=$OPTARG
;;
s)
scion_service_path=$OPTARG
;;
z)
scion_viz_service=$OPTARG
;;
h)
echo "Displaying help:" >&2
echo "$usage" >&2
exit 1
;;
a)
aliases_file=$OPTARG
;;
c)
keep_user_context=true
;;
\?)
echo "Invalid option: -$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
echo "$usage" >&2
exit 1
;;
esac
done
echo "Starting SCION installation..."
# Check if we are running on correct Ubuntu system
if [ -f /etc/os-release ]
then
. /etc/os-release
if [[ $NAME == "Ubuntu" && $VERSION_ID == 16.04* ]] ; then
echo "We are running on $NAME version $VERSION_ID seems okay"
else
echo "ERROR! We are not running on Ubuntu 16.04 system, shutting down!" >&2
exit 1
fi
else
echo "ERROR! This script can only be run on Ubuntu 16.04" >&2
exit 1
fi
sudo apt-get -y update
sudo apt-get -y install git
echo 'export GOPATH="$HOME/go"' >> ~/.profile
echo 'export PATH="$HOME/.local/bin:$GOPATH/bin:/usr/local/go/bin:$PATH"' >> ~/.profile
echo 'export SC="$GOPATH/src/github.com/netsec-ethz/scion"' >> ~/.profile
echo 'export PYTHONPATH="$SC/python:$SC"' >> ~/.profile
source ~/.profile
mkdir -p "$GOPATH"
mkdir -p "$GOPATH/src/github.com/netsec-ethz"
cd "$GOPATH/src/github.com/netsec-ethz"
git config --global url.https://github.com/.insteadOf [email protected]:
git clone --recursive -b scionlab [email protected]:netsec-ethz/netsec-scion scion
cd scion
# Check if there is a patch directory
if [[ ( ! -z ${patch_dir+x} ) && -d ${patch_dir} ]]
then
echo "Applying patches:"
patch_files="$patch_dir/*.patch"
for f in $patch_files;
do
echo -e "\t$f"
git apply "$f"
done
git_username=$(git config user.name || true)
# We need to have git user in order to commit
if [ -z "$git_username" ]
then
echo "GIT user credentials not set, configuring defaults"
git config --global user.name "Scion User"
git config --global user.email "[email protected]"
fi
git commit -am "Applied platform dependent patches"
echo "Finished applying patches"
fi
bash -c 'yes | GO_INSTALL=true ./env/deps'
sudo cp docker/zoo.cfg /etc/zookeeper/conf/zoo.cfg
# Add cron script which removes old zk logs
sudo bash -c 'cat > /etc/cron.daily/zookeeper << CRON1
#! /bin/sh
/usr/share/zookeeper/bin/zkCleanup.sh -n 3
CRON1'
sudo chmod 755 /etc/cron.daily/zookeeper
# Check if gen directory exists
if [[ ( ! -z ${gen_dir+x} ) && -d ${gen_dir} ]]
then
echo "Gen directory is specified! Using content from there!"
cp -r "$gen_dir" .
else
echo "Gen directory is NOT specified! Generating local (Tiny) topology!"
./scion.sh topology -c topology/Tiny.topo
fi
cd sub
git clone [email protected]:netsec-ethz/scion-viz
cd scion-viz/python/web
pip3 install --user --require-hashes -r requirements.txt
python3 ./manage.py migrate
# Should we add aliases
if [[ (! -z ${aliases_file} ) ]]
then
echo "Adding aliases to $aliases_file"
echo "alias cdscion='cd $SC'" >> "$aliases_file"
echo "alias checkbeacons='tail -f $SC/logs/bs*.DEBUG'" >> "$aliases_file"
fi
if [[ ( ! -z ${vpn_config_file+x} ) && -r ${vpn_config_file} ]]
then
echo "VPN configuration specified! Configuring it!"
sudo apt-get -y install openvpn
sudo cp "$vpn_config_file" /etc/openvpn/client.conf
sudo chmod 600 /etc/openvpn/client.conf
sudo systemctl start openvpn@client
sudo systemctl enable openvpn@client
fi
if [[ ( ! -z ${scion_service_path+x} ) && -r ${scion_service_path} ]]
then
echo "Registering SCION as startup service"
cp "$scion_service_path" tmp.service
# We need to replace template user with current username
sed -i "s/_USER_/$USER/g" tmp.service
sudo cp tmp.service /etc/systemd/system/scion.service
sudo systemctl enable scion.service
sudo systemctl start scion.service
rm tmp.service
else
echo "SCION systemd service file not specified! SCION won't run automatically on startup."
fi
if [[ ( ! -z ${scion_viz_service+x} ) && -r ${scion_viz_service} ]]
then
echo "Registering SCION-viz as startup service"
cp "$scion_viz_service" tmp.service
# We need to replace template user with current username
sed -i "s/_USER_/$USER/g" tmp.service
sudo cp tmp.service /etc/systemd/system/scion-viz.service
sudo systemctl enable scion-viz.service
sudo systemctl start scion-viz.service
rm tmp.service
else
echo "SCION-viz systemd service file not specified! SCION-viz won't run automatically on startup."
fi
if [[ $keep_user_context = true ]]
then
sudo sh -c 'echo \"RemoveIPC=no\" >> /etc/systemd/logind.conf'
fi