#!/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 < 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 : $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 () { FAIL=0 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 & for job in `jobs -p` do wait $job || let "FAIL+=1" done if [ "$FAIL" == "0" ]; then echo "Nodes started successfully!" else echo "Something happened starting a node ($FAIL)!" cleanup 1 fi } 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