forked from theckman/gapps-linode-dns
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gapps-linode-dns.sh
executable file
·131 lines (118 loc) · 3.44 KB
/
gapps-linode-dns.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env bash
####
# Copyright (c) 2012 Tim Heckman <timothy.heckman@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be included in all copies
# or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# **** IMPORTANT PLEASE READ THE FOLLOWING SECTION ****
# This script is not written by, nor maintained by, Linode. Nor is it affiliated
# with Linode directly in any way. Do not contact Linode to report any issues or
# file any bug reports regarding this script.
# **** IMPORTANT PLEASE READ THE PREVIOUS SECTION ****
####
MX_RECORDS=(
"ASPMX.L.GOOGLE.COM"
"ALT1.ASPMX.L.GOOGLE.COM"
"ALT2.ASPMX.L.GOOGLE.COM"
"ASPMX2.GOOGLEMAIL.COM"
"ASPMX3.GOOGLEMAIL.COM"
)
MX_PRIORITY=(
"10"
"20"
"20"
"30"
"30"
)
GAPPS_SPF="v=spf1%20include:_spf.google.com%20~all"
ARRLEN=`expr ${#MX_RECORDS[@]} - 1`
if hash curl 2>&-; then
CMD="curl -s"
else
if hash wget 2>&-; then
CMD="wget -qO-"
else
echo "Sorry, this script requires you to have curl or wget to continue!"
exit 1
fi
fi
/bin/cat <<EOF
####################
# Google Apps MX #
# Records Creation #
# Script #
####################
EOF
if [ -z "${LINODE_API_KEY}" ]; then
echo -n "Enter API key: "
read API_KEY
echo
else
API_KEY="${LINODE_API_KEY}"
fi
if [ -z "${GDOMAIN}" ]; then
echo -n "Enter your master domain name: "
read DOMAIN
echo
else
DOMAIN="${GDOMAIN}"
echo "Adding entries for ${DOMAIN}"
fi
API_URL="https://api.linode.com/?api_key=${API_KEY}\
&api_responseformat=json\
&api_action=domain.list"
DOMAIN_ID=`$CMD "${API_URL}" | sed -E 's/.*"DOMAINID":([0-9]+),.*"DOMAIN":"'"${DOMAIN}"'".*/\1/'`
if [ `echo -n "${DOMAIN_ID}" | sed -E 's/[0-9]+/1/'` != "1" ]; then
echo "Domain not found"
exit
fi
echo -n "Would you like to add a default SPF record for Google Apps [y/n]: "
read ADD_SPF
echo
echo "Creating MX records..."
echo
for ((i=0; i <= ARRLEN; i++))
do
API_URL="https://api.linode.com/\
?api_key=${API_KEY}\
&api_action=domain.resource.create\
&domainid=${DOMAIN_ID}\
&type=MX\
&target=${MX_RECORDS[i]}\
&priority=${MX_PRIORITY[i]}"
$CMD "${API_URL}"
echo
done
if [ "$ADD_SPF" == "y" -o "$ADD_SPF" == "Y" ]; then
echo
echo "Creating SPF record..."
echo
API_URL="https://api.linode.com/\
?api_key=${API_KEY}\
&api_action=domain.resource.create\
&domainid=${DOMAIN_ID}\
&type=TXT\
&target=${GAPPS_SPF}"
$CMD "${API_URL}"
echo
fi
echo
echo "Should be finished at this point (assuming no errors were generated from API calls)!"
echo "Please verify the created records within the Linode DNS Manager."
echo "<3 heckman"
exit 0