5005b594299efa63e45f4381c4dfc786a871eaa6
[joid.git] / ci / clean.sh
1 #!/bin/bash
2
3 set -ex
4
5 jujuver=`juju --version`
6
7 if [[ "$jujuver" > "2" ]]; then
8     if [ ! -d labconfig.yaml ]; then
9         cp ~/joid_config/labconfig.yaml ./labconfig.yaml || true
10         if [ -d $HOME/joid_config/deployconfig.yaml ]; then
11             cp ~/joid_config/deployconfig.yaml ./deployconfig.yaml || true
12         else
13             python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
14         fi
15     fi
16 else
17     if [ ! -d environments.yaml ]; then
18         cp ~/joid_config/environments.yaml ./environments.yaml || true
19         cp ~/.juju/environments.yaml ./environments.yaml || true
20     fi
21 fi
22
23
24 if [[ "$jujuver" > "2" ]]; then
25     controllername=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
26     cloudname=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployconfig.yaml`
27     juju destroy-controller $controllername --destroy-all-models -y || true
28 #    juju kill-controller $controllername --timeout 10s -y || true
29     rm -rf precise
30     rm -rf trusty
31     rm -rf xenial
32     rm -rf ~/joid_config/admin-openrc
33     sleep 10
34     sudo sysctl -w vm.drop_caches=3
35 elif [ -d $HOME/.juju/environments ]; then
36     echo " " > status.txt
37     juju status  &>>status.txt || true
38     if [ "$(grep -c "environment is not bootstrapped" status.txt )" -ge 1 ]; then
39         echo " environment is not bootstrapped ..."
40     else
41         echo " environment is bootstrapped ..."
42         jujuenv=`juju status | grep environment | cut -d ":" -f 2`
43         juju destroy-environment $jujuenv  -y || true
44     fi
45     rm -rf precise
46     rm -rf trusty
47     rm -rf xenial
48     rm -rf $HOME/.juju/j*
49     rm -rf $HOME/.juju/.deployer-store-cache
50     rm -rf $HOME/.juju/environments
51     rm -rf $HOME/.juju/ssh
52     sudo sysctl -w vm.drop_caches=3
53 fi