-
Notifications
You must be signed in to change notification settings - Fork 2
/
dnsManager.sh
executable file
·98 lines (76 loc) · 2.43 KB
/
dnsManager.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
###############################################################################
#
# Init and basic checks part
#
###############################################################################
DNSMANAGER_DIR="`dirname $0`"
cd ${DNSMANAGER_DIR}
[[ $? -ne 0 ]] && echo "Unable to change directory to: ${DNSMANAGER_DIR}" && exit 1
# Load all the env
[[ ! -e "${DNSMANAGER_DIR}/etc/vars" ]] && echo "failed to load vars file" && exit 1
source ${DNSMANAGER_DIR}/etc/vars
[[ ! -e "${DNSMANAGER_DIR}/libs/functions" ]] && echo "Unable to load functions file" && exit 1
source ${DNSMANAGER_DIR}/libs/functions
###############################################################################
#
# Main
#
###############################################################################
DNSMANAGER_ACTION="$1"
DNSMANAGER_DOMAIN="$2"
if [[ ${DNSMANAGER_ACTION} == 'setupAccount' ]]
then
_printStep "Setup your env"
_gandi_setupAccount
_printStep "Setup done"
exit 0
fi
_check_virtualEnv
source ${DNSMANAGER_VIRTUALENV_ACTIVATE}
[[ $? -ne 0 ]] && _fatal "Problem to load the virtual env"
case ${DNSMANAGER_ACTION} in
listDomains)
_printStep "List all registered domains:"
_gandi_listDomains
_printStep "List done"
;;
updateDomainZone)
if [[ -z ${DNSMANAGER_DOMAIN} ]]
then
_printRed "You forget to specify a domain name"
_printRed "\tUsage: $0 updateDomainZone domain_name"
_help
fi
_printStep "Update DNS zone ${DNSMANAGER_DOMAIN}"
_gandi_updateDomainZone "${DNSMANAGER_DOMAIN}"
_printStep "Update done, check new file: ${DOMAIN_ZONE_DIR}/${DNSMANAGER_DOMAIN}.txt"
_gandi_getLastDomainZone "${DNSMANAGER_DOMAIN}"
_printStep "Please don't forget to commit your changes"
echo -e "\tsuggestion:"
echo -e "\t\t\tgit add ${DOMAIN_ZONE_DIR}/${DNSMANAGER_DOMAIN}.txt"
echo -e "\t\t\tgit commit -m '${DNSMANAGER_DOMAIN} :: update/delete/add entries'"
;;
getLastDomainZone)
if [[ -z ${DNSMANAGER_DOMAIN} ]]
then
_printRed "You forget to specify a domain name"
_printRed "\tUsage: $0 getLastDomainZone domain_name"
_help
fi
_printStep "Dump zone for ${DNSMANAGER_DOMAIN}"
_gandi_getLastDomainZone "${DNSMANAGER_DOMAIN}"
if [[ $? -eq 0 ]]
then
_printStep "Dump done, check new file: ${DOMAIN_ZONE_DIR}/${DNSMANAGER_DOMAIN}.txt"
git diff ${DOMAIN_ZONE_DIR}/${DNSMANAGER_DOMAIN}.txt
else
_printStep "Dump done, but you already got the latest version"
exit 1
fi
;;
*)
_help
;;
esac
exit 0