Browse Source

inadyn confile file variable

Bob Mottram 7 years ago
parent
commit
a3e6ce965c
1 changed files with 28 additions and 27 deletions
  1. 28
    27
      src/freedombone-utils-dns

+ 28
- 27
src/freedombone-utils-dns View File

41
 
41
 
42
 INADYN_REPO="https://github.com/bashrc/inadyn"
42
 INADYN_REPO="https://github.com/bashrc/inadyn"
43
 INADYN_COMMIT='fadbe17f520d337dfb8d69ee4bf1fcaa23fce0d6'
43
 INADYN_COMMIT='fadbe17f520d337dfb8d69ee4bf1fcaa23fce0d6'
44
+INADYN_CONFIG_FILE=/etc/inadyn.conf
44
 
45
 
45
 # web site used to obtain the external IP address of the system
46
 # web site used to obtain the external IP address of the system
46
 GET_IP_ADDRESS_URL="checkip.two-dns.de"
47
 GET_IP_ADDRESS_URL="checkip.two-dns.de"
95
         'http://httpbin.org/ip')
96
         'http://httpbin.org/ip')
96
 
97
 
97
 function update_inadyn_config {
98
 function update_inadyn_config {
98
-    if [ ! -f /etc/inadyn.conf ]; then
99
+    if [ ! -f "${INADYN_CONFIG_FILE}" ]; then
99
         return
100
         return
100
     fi
101
     fi
101
 
102
 
103
         return
104
         return
104
     fi
105
     fi
105
 
106
 
106
-    if ! grep -q "$DDNS_PROVIDER" /etc/inadyn.conf; then
107
+    if ! grep -q "$DDNS_PROVIDER" "${INADYN_CONFIG_FILE}"; then
107
         # store any previous aliases
108
         # store any previous aliases
108
-        grep 'alias ' /etc/inadyn.conf > /tmp/inadyn_aliases
109
+        grep 'alias ' "${INADYN_CONFIG_FILE}" > /tmp/inadyn_aliases
109
 
110
 
110
         # remove entry for any previous ddns
111
         # remove entry for any previous ddns
111
-        sed -i '/system /,$d' /etc/inadyn.conf
112
+        sed -i '/system /,$d' "${INADYN_CONFIG_FILE}"
112
 
113
 
113
         # add the new provider
114
         # add the new provider
114
         { echo '';
115
         { echo '';
115
           echo "system $DDNS_PROVIDER";
116
           echo "system $DDNS_PROVIDER";
116
           echo '  ssl';
117
           echo '  ssl';
117
-          echo "  checkip-url $GET_IP_ADDRESS_URL /"; } >> /etc/inadyn.conf
118
+          echo "  checkip-url $GET_IP_ADDRESS_URL /"; } >> "${INADYN_CONFIG_FILE}"
118
         if [ "$DDNS_USERNAME" ]; then
119
         if [ "$DDNS_USERNAME" ]; then
119
-            echo "  username $DDNS_USERNAME" >> /etc/inadyn.conf
120
+            echo "  username $DDNS_USERNAME" >> "${INADYN_CONFIG_FILE}"
120
         fi
121
         fi
121
         if [ "$DDNS_PASSWORD" ]; then
122
         if [ "$DDNS_PASSWORD" ]; then
122
-            echo "  password $DDNS_PASSWORD" >> /etc/inadyn.conf
123
+            echo "  password $DDNS_PASSWORD" >> "${INADYN_CONFIG_FILE}"
123
         fi
124
         fi
124
 
125
 
125
         if [ -f /tmp/inadyn_aliases ]; then
126
         if [ -f /tmp/inadyn_aliases ]; then
126
-            cat /tmp/inadyn_aliases >> /etc/inadyn.conf
127
+            cat /tmp/inadyn_aliases >> "${INADYN_CONFIG_FILE}"
127
             rm /tmp/inadyn_aliases
128
             rm /tmp/inadyn_aliases
128
         fi
129
         fi
129
     else
130
     else
130
         # change username/password for an existing provider
131
         # change username/password for an existing provider
131
         if [ "$DDNS_USERNAME" ]; then
132
         if [ "$DDNS_USERNAME" ]; then
132
-            if grep -q "  username " /etc/inadyn.conf; then
133
-                sed -i "s|  username .*|  username $DDNS_USERNAME|g" /etc/inadyn.conf
133
+            if grep -q "  username " "${INADYN_CONFIG_FILE}"; then
134
+                sed -i "s|  username .*|  username $DDNS_USERNAME|g" "${INADYN_CONFIG_FILE}"
134
             else
135
             else
135
-                echo "  username $DDNS_USERNAME" >> /etc/inadyn.conf
136
+                echo "  username $DDNS_USERNAME" >> "${INADYN_CONFIG_FILE}"
136
             fi
137
             fi
137
         fi
138
         fi
138
         if [ "$DDNS_PASSWORD" ]; then
139
         if [ "$DDNS_PASSWORD" ]; then
139
-            if grep -q "  password " /etc/inadyn.conf; then
140
-                sed -i "s|  password .*|  password $DDNS_PASSWORD|g" /etc/inadyn.conf
140
+            if grep -q "  password " "${INADYN_CONFIG_FILE}"; then
141
+                sed -i "s|  password .*|  password $DDNS_PASSWORD|g" "${INADYN_CONFIG_FILE}"
141
             else
142
             else
142
-                echo "  password $DDNS_PASSWORD" >> /etc/inadyn.conf
143
+                echo "  password $DDNS_PASSWORD" >> "${INADYN_CONFIG_FILE}"
143
             fi
144
             fi
144
         fi
145
         fi
145
     fi
146
     fi
197
     if [[ "$DDNS_PROVIDER" == 'none' ]]; then
198
     if [[ "$DDNS_PROVIDER" == 'none' ]]; then
198
         return
199
         return
199
     fi
200
     fi
200
-    if [ ! -f /etc/inadyn.conf ]; then
201
-        echo $'Unable to find inadyn configuration file /etc/inadyn.conf'
201
+    if [ ! -f "${INADYN_CONFIG_FILE}" ]; then
202
+        echo $'Unable to find inadyn configuration file "${INADYN_CONFIG_FILE}"'
202
         exit 5745
203
         exit 5745
203
     fi
204
     fi
204
-    if ! grep -q "$DDNS_PROVIDER" /etc/inadyn.conf; then
205
+    if ! grep -q "$DDNS_PROVIDER" "${INADYN_CONFIG_FILE}"; then
205
         { echo '';
206
         { echo '';
206
           echo "system $DDNS_PROVIDER";
207
           echo "system $DDNS_PROVIDER";
207
           echo '  ssl';
208
           echo '  ssl';
208
-          echo "  checkip-url $GET_IP_ADDRESS_URL /"; } >> /etc/inadyn.conf
209
+          echo "  checkip-url $GET_IP_ADDRESS_URL /"; } >> "${INADYN_CONFIG_FILE}"
209
         if [ $DDNS_USERNAME ]; then
210
         if [ $DDNS_USERNAME ]; then
210
-            echo "  username $DDNS_USERNAME" >> /etc/inadyn.conf
211
+            echo "  username $DDNS_USERNAME" >> "${INADYN_CONFIG_FILE}"
211
         fi
212
         fi
212
         if [ $DDNS_PASSWORD ]; then
213
         if [ $DDNS_PASSWORD ]; then
213
-            echo "  password $DDNS_PASSWORD" >> /etc/inadyn.conf
214
+            echo "  password $DDNS_PASSWORD" >> "${INADYN_CONFIG_FILE}"
214
         fi
215
         fi
215
     fi
216
     fi
216
 
217
 
217
-    if ! grep -q "$CURRENT_DDNS_DOMAIN" /etc/inadyn.conf; then
218
-        echo "  alias $CURRENT_DDNS_DOMAIN" >> /etc/inadyn.conf
218
+    if ! grep -q "$CURRENT_DDNS_DOMAIN" "${INADYN_CONFIG_FILE}"; then
219
+        echo "  alias $CURRENT_DDNS_DOMAIN" >> "${INADYN_CONFIG_FILE}"
219
     fi
220
     fi
220
-    chmod 600 /etc/inadyn.conf
221
+    chmod 600 "${INADYN_CONFIG_FILE}"
221
     systemctl restart inadyn
222
     systemctl restart inadyn
222
     systemctl daemon-reload
223
     systemctl daemon-reload
223
 }
224
 }
234
     if [[ "$DDNS_PROVIDER" == 'none' ]]; then
235
     if [[ "$DDNS_PROVIDER" == 'none' ]]; then
235
         return
236
         return
236
     fi
237
     fi
237
-    if [ ! -f /etc/inadyn.conf ]; then
238
-        echo $'Unable to find inadyn configuration file /etc/inadyn.conf'
238
+    if [ ! -f "${INADYN_CONFIG_FILE}" ]; then
239
+        echo $'Unable to find inadyn configuration file "${INADYN_CONFIG_FILE}"'
239
         exit 5745
240
         exit 5745
240
     fi
241
     fi
241
-    if grep -q "$CURRENT_DDNS_DOMAIN" /etc/inadyn.conf; then
242
+    if grep -q "$CURRENT_DDNS_DOMAIN" "${INADYN_CONFIG_FILE}"; then
242
         systemctl stop inadyn
243
         systemctl stop inadyn
243
-        sed -i "/alias $CURRENT_DDNS_DOMAIN/d" /etc/inadyn.conf
244
+        sed -i "/alias $CURRENT_DDNS_DOMAIN/d" "${INADYN_CONFIG_FILE}"
244
         systemctl start inadyn
245
         systemctl start inadyn
245
         systemctl daemon-reload
246
         systemctl daemon-reload
246
     fi
247
     fi