summaryrefslogtreecommitdiff
path: root/bin/lut.sh
blob: 01903e20f103d7c1fdd1a21bc39149cdb1f1ffa1 (plain)
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
#!/bin/bash -x
# This script lives in the lut provider and should be run from there

provider_dir=`pwd`
platform_git=https://leap.se/git/leap_platform
cli_git=https://leap.se/git/leap_cli
from_version=$1
to_version=$2

#workdir=`mktemp -d`
workdir='/tmp/lut'
platform_link="${workdir}/leap_platform"

# note: the following is an ugly way to set the cli version it is based on
# the fact that the second number in the platform version is the second
# number of the cli version, with a prepended 1. For example, if the
# platform version in 0.8.2, then the cli version is 1.8.
if [ "$1" == 'develop' ]; then
    cli_fromver='develop'
else
    cli_fromver=1.${1:2:1}
fi

if [ "$2" == 'develop' ]; then
    cli_tover='develop'
else
    cli_tover=1.${2:2:1}
fi

if [ "$1" == 'develop' -a "$2" == 'develop' ]; then
    echo 'wut'
    exit 9000
fi

cli_from=${workdir}/cli_${cli_fromver}
cli_to=${workdir}/cli_${cli_tover}


# If you hit control-c or kill the process, stop the VMs
killed () {

    leap vm stop upgrade
    echo "VMs stopped, but not removed. Will still incur charges, please remove them if you are not using them anymore."
    cleanup 3
}

trap "{ killed ; }" TERM INT ABRT QUIT

help () {
    cat <<EOF
Usage lut <from version> <to version>

This script will setup leap platform, leap cli, for the versions required and
perform an upgrade test using leap vm credentials stored in cloud.json.

Note: the cloud.json file is encrypted with git-crypt. You need to decrypt it
first, just do once: apt install git-crypt and then git-crypt unlock.

EOF
}

check_version () {
    git ls-remote --refs --heads --tags --exit-code $1 $2
    if [ $? -ne 0 ]; then
        echo "unknown <version>: $2 for $1, please use a tag from git tag -l, or specify a branch"
        cleanup 2
    fi
}

get_platform () {
    echo "Setup platform, version $2"
    git clone $1 ${workdir}/platform_${2} --branch $2
    if [ $? -ne 0 ]; then
        echo "Setup failed"
        cleanup 2
    fi
}

get_cli () {
    echo "Setup leap_cli"
    git clone $cli_git $cli_from --branch $cli_fromver
    git clone $cli_git $cli_to --branch $cli_tover

    cd $cli_from
    rake build
    bundle --path vendor/bundle

    cd $cli_to
    rake build
    bundle --path vendor/bundle
}

switch () {
    rm -f $platform_link
    ln -s platform_${1} $platform_link
}

cleanup () {
#    leap vm stop upgrade
#    rm -rf $workdir
    exit $1
}

start_nodes () {
    echo "Starting all the VMs, you should go do something else now, this will take a while..."
    # monarch: monitor, tor hidden service, webapp
    leap vm add monarch
    # dogface: couchdb/soledad
    leap vm add dogface
    # hairstreak: mx
    leap vm add hairstreak
    # checkerspot: openvn, need a gateway address to do openvpn, disabled
    # spicebush: static node, with hidden service, disabled because static service is not tested
    # leap vm add spicebush
    # cloak: tor exit
    leap vm add cloak
    # swallowtail: singlenode
    leap vm add swallowtail
}

deploy () {
    $1/bin/leap -v2 --yes deploy $2

    if [ $? -ne 0 ]; then
        cleanup 1
    else
        echo "$2 environment deployed with $1 version of platform"
    fi
}

case "$1" in
    -h | -help | --help )
	help
	exit
	;;
esac

if [ $# -ne 2 ]; then
    help
else
    leap vm rm upgrade
    leap vm rm singlenode
    rm -rf $workdir
    check_version $platform_git $from_version
    check_version $platform_git $to_version
    get_platform $platform_git $from_version
    get_platform $platform_git $to_version
    get_cli
    cd $provider_dir
    switch $to_version
    start_nodes
    # because 0.8 doesn't have the right support, we need
    # to use the new version to do the node init
    # switch $from_version
    # $cli_from/bin/leap -v2 node init upgrade
    $cli_to/bin/leap -v2 node init upgrade
    if [ $? -ne 0 ]; then
        cleanup 1
    else
        echo "Multi-node environment initialized with old platform"
    fi

    $cli_to/bin/leap -v2 node init singlenode
    if [ $? -ne 0 ]; then
        cleanup 1
    else
        echo "Single-node environment initialized with old platform"
    fi

    # 0.8 hack, remove after 0.9 release
    switch $from_version
    deploy $cli_from upgrade
    $cli_from/bin/leap test --continue upgrade
    deploy $cli_from singlenode
    $cli_from/bin/leap test --continue singlenode

    switch $to_version
    deploy $cli_to upgrade
    $cli_to/bin/leap test --continue upgrade
    deploy $cli_to singlenode
    $cli_to/bin/leap test --continue singlenode
   
    cleanup 0
fi