improvements for default virtual pod creation
[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/deployment.yaml ./deployment.yaml || true
10         cp ~/joid_config/labconfig.yaml ./labconfig.yaml || true
11         cp ~/joid_config/deployconfig.yaml ./deployconfig.yaml || true
12     fi
13 else
14     if [ ! -d environments.yaml ]; then
15         cp ~/joid_config/environments.yaml ./environments.yaml || true
16         cp ~/.juju/environments.yaml ./environments.yaml || true
17     fi
18 fi
19
20
21 if [[ "$jujuver" > "2" ]]; then
22     controllername=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployment.yaml`
23     cloudname=`awk 'NR==1{print substr($1, 1, length($1)-1)}' deployment.yaml`
24     juju kill-controller $controllername --timeout 10s -y || true
25     rm -rf precise
26     rm -rf trusty
27     rm -rf xenial
28     sleep 30
29     sudo sysctl -w vm.drop_caches=3
30 elif [ -d $HOME/.juju/environments ]; then
31     echo " " > status.txt
32     juju status  &>>status.txt || true
33     if [ "$(grep -c "environment is not bootstrapped" status.txt )" -ge 1 ]; then
34         echo " environment is not bootstrapped ..."
35     else
36         echo " environment is bootstrapped ..."
37         jujuenv=`juju status | grep environment | cut -d ":" -f 2`
38         juju destroy-environment $jujuenv  -y || true
39     fi
40     rm -rf precise
41     rm -rf trusty
42     rm -rf xenial
43     rm -rf $HOME/.juju/j*
44     rm -rf $HOME/.juju/.deployer-store-cache
45     rm -rf $HOME/.juju/environments
46     rm -rf $HOME/.juju/ssh
47     sudo sysctl -w vm.drop_caches=3
48 fi