set -ex
 
-#juju-deployer -T -d
-juju destroy-environment demo-maas  -y
-rm -rf ~/.juju/j*
-rm -rf ~/.juju/environments
-rm -rf ~/.juju/ssh
-rm -rf ~/.juju/.deployer-store-cache
+if [ -d "~/.juju/environemnts" ]; then
+    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 ..."
+        juju destroy-environment demo-maas  -y
+        rm -rf ~/.juju/j*
+        rm -rf ~/.juju/.deployer-store-cache
+    fi
+    rm -rf ~/.juju/environments
+    rm -rf ~/.juju/ssh
+fi
 
 
        juju status > status.txt 
        if [ "$(grep -c "executing" status.txt )" -ge 1 ]; then
            echo " still executing the reltionship within charms ..."
-           if [ $timeoutiter -ge 60 ] then
+           if [ $timeoutiter -ge 60 ]; then
                retval=1
            fi
            timeoutiter=$((timeoutiter+1))