summaryrefslogtreecommitdiffstats
path: root/ci/clean.sh
blob: 0cd207616967fd4150f4fc24f20db48af680207f (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
#!/bin/bash

set -ex

if [ ! -d environments.yaml ]; then
    cp ~/joid_config/environments.yaml ./environments.yaml || true
    cp ~/.juju/environments.yaml ./environments.yaml || true
fi

jujuver=`juju --version`

if [[ "$jujuver" > "2" ]]; then
    controllername=`awk 'NR==1{print $2}' environments.yaml`
    cloudname=`awk 'NR==1{print $2}' environments.yaml`
    juju kill-controller $controllername --timeout 10s -y || true
    rm -rf precise
    rm -rf trusty
    rm -rf xenial
    sudo sysctl -w vm.drop_caches=3
elif [ -d $HOME/.juju/environments ]; then
    echo " " > status.txt
    juju status  &>>status.txt || true
    if [ "$(grep -c "environment is not bootstrapped" status.txt )" -ge 1 ]; then
        echo " environment is not bootstrapped ..."
    else
        echo " environment is bootstrapped ..."
        jujuenv=`juju status | grep environment | cut -d ":" -f 2`
        juju destroy-environment $jujuenv  -y || true
    fi
    rm -rf precise
    rm -rf trusty
    rm -rf xenial
    rm -rf $HOME/.juju/j*
    rm -rf $HOME/.juju/.deployer-store-cache
    rm -rf $HOME/.juju/environments
    rm -rf $HOME/.juju/ssh
    sudo sysctl -w vm.drop_caches=3
fi