summaryrefslogtreecommitdiff
path: root/bin/lut.sh
blob: 4a2d436ee2ab683517333e5bc112d57267345463 (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
#!/bin/sh -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"
platform_from=${workdir}/platform_$1
platform_to=${workdir}/platform_$1
cli_from=${workdir}/cli_master
cli_to=${workdir}/cli_develop


# 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."
}

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 () {
    cli_dir=${workdir}/cli_$2
    echo "Setup leap_cli"
    git clone $cli_git $cli_dir --branch $2
    cd $cli_dir
    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
}

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

if [ $# -ne 2 ]; then
    help
else
    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 $cli_git master
    get_cli $cli_git develop
    cd $provider_dir
    ln -s platform_$from_version $platform_link

do stuff
   
    switch $to_version

do new stuff
   
    cleanup 0
fi