-
Notifications
You must be signed in to change notification settings - Fork 4
/
main_destroy_script.sh
executable file
·72 lines (65 loc) · 2.71 KB
/
main_destroy_script.sh
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
#
# set -x
export vm_group_name="VITC-USR-OSEHRA"
# Get the id for Common resources vnet.
ad_vm_name="VITC-C-DC1"
common_rg="VITC-Common-RG"
common_vnet="VITC-Common-RG-vnet"
ME=$(basename "$0")
print_usage ()
{
printf "\n"
printf "Usage: "
printf "\t%s [OPTIONS]\n" "$ME"
printf "Available options\n\n"
printf " -h | --help : Print help text\n"
printf " -a | --ad-name : Name of the Domain Controller 1 VM, Default: $ad_vm_name\n"
printf " -c | --common-vent <COMMON VNET NAME> : Name of the Common VNET where the Domain Controllers are located, Default: $common_vnet\n"
printf " -e | --enterprise : Flag to add a sandbox to an Enterprise setup\n"
printf " -g | --group <GROUP NAME> : Name of sandbox resource group (default: $vm_group_name), Default: $vm_group_name\n"
printf " -r | --common-rg <COMMON RG NAME> : Name of the Common Resource group where the Domain Controllers are located, Default: $common_rg\n"
printf "\n\n"
}
while [[ $1 =~ ^- ]]; do
case $1 in
-h | --help ) print_usage
exit 0
;;
-a | --ad-name ) shift
ad_vm_name=$1
;;
-c | --common-vnet ) shift
common_vnet=$1
;;
-e | --enterprise ) shift
enterprise=true
;;
-g | --group ) shift
group_name=$1
;;
-r | --common-rg ) shift
common_rg=$1
;;
* ) echo "Unknown option $1"
print_usage
exit 1
esac
shift
done
az cloud set --name AzureCloud
if [ $(az account list &> /dev/null | grep -c id) -eq 0 ]; then
az login
fi
if [[ $group_name ]]; then
vm_group_name="VITC-USR-${group_name}"
fi
if [[ $enterprise ]]; then
# Delete peer from common to us
echo "Removing peering to Common VNET"
az network vnet peering delete -g $common_rg -n common-to-consumer-${vm_group_name} --vnet-name $common_vnet > /dev/null
echo "Removing Organiztion from Domain"
./scripts/adRemove.sh $common_rg $ad_vm_name $group_name > /dev/null
fi
echo "Removing resource group"
az group delete --name $vm_group_name --yes > /dev/null