cron_bash 1.67 KB
Newer Older
pierre_f's avatar
pierre_f committed
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
#!/bin/bash

# cron pouvant servir au cas ou la foinctionnalite n est pas intergre a alternc

PUBLIC_IP="`awk -F'"' '/^PUBLIC_IP/ {print $2}' /etc/alternc/local.sh`"

if [ -d "/var/alternc/bind/zones" ]
then
 BINDDIR="/var/alternc/bind/zones"
fi
if [ -d "/var/lib/alternc/bind/zones" ]
then
 BINDDIR="/var/lib/alternc/bind/zones"
fi
BINDRELOAD=0

while read domaine gesmx gesdns
do
 # for debug 
 #echo $domaine $gesmx $gesdns 
 if [ $gesdns -eq 0 ]
 then
  sed -i '/^autodiscover/d' $BINDDIR/$domaine
  sed -i '/^autoconfig/d' $BINDDIR/$domaine
 else
  if [ $gesmx -eq 0 ]
  then
   sed -i '/^autodiscover/d' $BINDDIR/$domaine
   sed -i '/^autoconfig/d' $BINDDIR/$domaine
  else
   ZNSERIAL="`awk '/; serial/ {print $1}' $BINDDIR/$domaine`"
   NEWZNSERIAL=$((ZNSERIAL+1))
   # for debug
   #echo $ZNSERIAL $NEWZNSERIAL $BINDDIR
   if [ `grep "^autodiscover " $BINDDIR/$domaine | wc -l` -ge 1 ]
   then
    echo -e "autodiscover IN A $PUBLIC_IP" >> /dev/null
   else
    echo -e "autodiscover IN A $PUBLIC_IP" >> $BINDDIR/$domaine
    sed -i '/; serial[ \t]*$/ s/'$ZNSERIAL'/'$NEWZNSERIAL'/' $BINDDIR/$domaine
   fi
   if [ `grep "^autoconfig " $BINDDIR/$domaine | wc -l` -ge 1 ]
   then
    echo -e "autoconfig IN A $PUBLIC_IP" >> /dev/null
   else
    echo -e "autoconfig IN A $PUBLIC_IP" >> $BINDDIR/$domaine
    sed -i '/; serial[ \t]*$/ s/'$ZNSERIAL'/'$NEWZNSERIAL'/' $BINDDIR/$domaine
   fi
  fi
 fi
if [ `awk '/; serial/ {print $1}' $BINDDIR/$domaine` -gt $ZNSERIAL ]
then
 BINDRELOAD=$((BINDRELOAD+1))
fi
done < <(mysql --defaults-file=/etc/alternc/my.cnf -e "select domaine,gesmx,gesdns from domaines;" alternc | grep -v \| | tail --lines=+2)

if [ $BINDRELOAD -ne 0 ]
then
 /usr/sbin/rndc reload
fi