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