This repository has been archived by the owner on Oct 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathupgrade_infrastructure_step1_build.sh
executable file
·167 lines (147 loc) · 4.07 KB
/
upgrade_infrastructure_step1_build.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
#!/bin/bash
# Copyright 2018 ETH Zurich
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
export LC_ALL=C
GITREPO="origin"
GITBRANCH="scionlab"
BACKUPBRANCH="backup_upgrade1"
#MAKECHANGES=0
# This script should be run on each of the ASes that are part of the infrastructure.
# Ideally called with ansible or forallASes -f
usage="$(basename $0) [-b branchname]
where:
-b branchname: Upgrade to branchname. Default value is scionlab"
while getopts ":b:h" opt; do
case $opt in
h)
echo "$usage"
exit 0
;;
b)
GITBRANCH="$OPTARG"
;;
\?)
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 "Using branch $GITBRANCH"
# check we have $SC, and gen folder
if [ ! -d "$SC" ]; then
echo "SC folder not found. SC=$SC"
exit 1
fi
cd "$SC"
if [ ! -d "gen" ]; then
echo "gen folder not found"
exit 1
fi
# check we can sudo
sudo -S echo a >/dev/null </dev/null && success=1 || success=0
if [ $success != 1 ]; then
echo "sudo failed"
exit 1
fi
currentref=$(git rev-parse --abbrev-ref --symbolic-full-name @{u})
if [ "$currentref" != "${GITREPO}/${GITBRANCH}" ]; then
echo "Not currently using reference ${GITREPO}/${GITBRANCH}, but $currentref"
exit 1
fi
output=$(git remote update) && success=1 || success=0
if [ $success != 1 ]; then
echo "Error updating remote: $output"
exit 1
fi
output=$(git fetch "$GITREPO" "$GITBRANCH" 2>&1) && success=1 || success=0
if [ $success != 1 ]; then
echo "Error fetching branch: $output"
exit 1
fi
if [ $(git rev-parse HEAD) != $(git rev-parse "$GITREPO/$GITBRANCH") ]; then
if git branch | grep "$BACKUPBRANCH"; then
echo "Branch $BACKUPBRANCH exists already. Aborting."
exit 1
fi
fi
if [ "$MAKECHANGES" != 1 ]; then
echo "Read only. Quitting now"
exit 0
fi
echo "All checks OK."
########################################################## MODIFYING THE AS HERE ###############
output=$(git stash) && success=1 || success=0
if [ $success != 1 ]; then
echo "SCION stash failed:"
echo "$output"
exit 1
fi
output=$(./scion.sh stop 2>&1) && success=1 || success=0
if [ $success != 1 ]; then
echo "SCION stop failed:"
echo "$output"
exit 1
fi
output=$(./supervisor/supervisor.sh shutdown 2>&1) && success=1 || success=0
if [ $success != 1 ]; then
echo "SCION supervisor shutdown failed:"
echo "$output"
# exit 1
fi
# Only
if [ $(git rev-parse HEAD) != $(git rev-parse "$GITREPO/$GITBRANCH") ]; then
git branch "$BACKUPBRANCH"
output=$(git reset --hard "$GITREPO/$GITBRANCH" 2>&1) && success=1 || success=0
if [ $success != 1 ]; then
echo "Problem updating copy:"
echo "$output"
exit 1
fi
fi
output=$(git stash pop) && success=1 || success=0
if [ $success != 1 ]; then
echo "SCION stash failed:"
echo "$output"
fi
echo "Updated"
echo "Install dependencies"
# because upgrading to SCIONLab 2019-01 will fail if installed, remove it:
sudo apt-get remove -y parallel >/dev/null
output=$(yes | ./env/deps 2>&1) && success=1 || success=0
if [ $success != 1 ]; then
echo "SCION deps failed:"
echo "$output"
exit 1
fi
echo "Starting build."
output=$(./scion.sh clean 2>&1) && success=1 || success=0
if [ $success != 1 ]; then
echo "SCION clean failed:"
echo "$output"
# exit 1
fi
output=$(./scion.sh build 2>&1) && success=1 || success=0
if [ $success != 1 ]; then
echo "SCION build failed:"
echo "$output"
exit 1
fi
echo "done."