Ajout : vm_hosted : rule_unbound_configure .
[lhc/ateliers.git] / vm_hosted
index 874c3e8..134b539 100755 (executable)
--- a/vm_hosted
+++ b/vm_hosted
@@ -34,7 +34,7 @@ rule_git_configure () {
        git config --replace branch.master.merge refs/remotes/master
        local tool
        tool=$(cd "$tool"; cd -)
-       sudo install -m 770 /dev/stdin .git/hooks/post-update <<-EOF
+       install -m 770 /dev/stdin .git/hooks/post-update <<-EOF
                #!/bin/sh -efux
                case \$1 in
                 (refs/remotes/master)
@@ -470,10 +470,11 @@ rule_initramfs_configure () {
                        $users
                        EOF
                 do eval local home\; home="~$user"
-                       cat "$home"/etc/ssh/authorized_keys
+                       sudo cat "$home"/etc/ssh/authorized_keys
                 done
         done |
-       sudo install -m 644 -o root -g root /dev/stdin /etc/initramfs-tools/root/.ssh/authorized_keys
+       sudo install -m 644 -o root -g root /dev/stdin \
+        /etc/initramfs-tools/root/.ssh/authorized_keys
        sudo rm -f \
         /etc/initramfs-tools/root/.ssh/id_rsa.dropbear \
         /etc/initramfs-tools/root/.ssh/id_rsa.pub \
@@ -545,7 +546,7 @@ rule_gitolite_configure () {
                \$GL_CONF = "\$GL_ADMINDIR/conf/gitolite.conf";
                \$GL_CONF_COMPILED = "\$GL_ADMINDIR/conf/gitolite.conf.pm";
                #\$GL_GET_MEMBERSHIPS_PGM = "/usr/local/bin/expand-ldap-user-to-groups"
-               \$GL_GITCONFIG_KEYS = "hooks\\..* repo\\..*";
+               \$GL_GITCONFIG_KEYS = "gitweb\\..* hooks\\..*";
                #\$GL_HOSTNAME = "git.$vm_domainname";
                        # NOTE: read doc/mirroring.mkd COMPLETELY before setting this.
                #\$GL_HTTP_ANON_USER = "mob";
@@ -747,6 +748,10 @@ rule_network_configure () {
                $(cat /etc/hosts)
                127.0.0.1 $vm_fqdn $vm
                EOF
+       sudo install -m 644 -o root -g root /dev/stdin /etc/resolv.conf <<-EOF
+               search ${vm_host#*.}
+               nameserver ${vm_host_nameserver}
+               EOF
        sudo install -m 644 -o root -g root /dev/stdin /etc/network/interfaces <<-EOF
                auto lo
                iface lo inet loopback
@@ -779,34 +784,6 @@ rule_network_configure () {
                    pre-down  ip address delete $vm_ipv4/32 dev \$IFACE
                EOF
  }
-rule_www_configure () {
-       rule adduser www \
-        --disabled-login \
-        --disabled-password \
-        --group \
-        --home /home/www \
-        --shell /bin/false \
-        --system
-       rule adduser log-www \
-        --disabled-login \
-        --disabled-password \
-        --group \
-        --home /home/www/log \
-        --shell /bin/false \
-        --system
-       #sudo adduser www www-data
-       sudo adduser www log-www
-       #sudo adduser log log-www
-       usermod --home /home/www/pub www-data
-       sudo install -d -m 751 -o www -g www \
-        /home/www
-       sudo install -d -m 750 -o www -g www \
-        /home/www/etc
-       sudo install -d -m 1771 -o www-data -g www-data \
-        /home/www/pub
-       sudo install -d -m 1771 -o log-www -g log-www \
-        /home/www/log
- }
 rule_nginx_configure () {
        local -; set +f
        rule apt_get_install nginx
@@ -888,6 +865,48 @@ rule_nginx_configure () {
                #       de leurs groupes supplĂ©mentaires.
        sudo service nginx restart
  }
+rule_nsd3_configure () { # NOTE: DNS autoritaire uniquement
+       local -; set +f
+       rule apt_get_install nsd m4
+       sudo rm -rf \
+        /etc/nsd3/zone.d
+       sudo install -d -m 750 -o root -g nsd \
+        /etc/nsd3/zone.d
+       {
+               cat <<-EOF
+                       server:
+                               ip-address: $vm_ipv4
+                               ip4-only: yes
+                       EOF
+               cat "$tool"/etc/nsd3/nsd.conf
+               local conf
+               for conf in "$tool"/etc/nsd3/zone.d/*.conf
+                do conf=${conf#"$tool"/etc/nsd3/zone.d/}
+                       local domain=${conf%.conf}
+                       if test -e "$tool"/etc/nsd3/zone.d/"$domain".zone.m4
+                        then m4 \
+                                --define=ZONE_DOMAIN=$domain \
+                                --define=ZONE_SERIAL=$(cd "$tool" && git log -1 --format="%ct" -- etc/nsd3/zone.d/"$domain".zone.m4) \
+                                --define=VM_IP4=$vm_ipv4 \
+                                       "$tool"/etc/nsd3/zone.d/"$domain".zone.m4
+                        else cat "$tool"/etc/nsd3/zone.d/"$domain".zone
+                        fi |
+                       sudo install -m 440 -o root -g nsd /dev/stdin \
+                        /etc/nsd3/zone.d/"$domain".zone
+                       sudo install -m 440 -o root -g nsd \
+                        "$tool"/etc/nsd3/zone.d/"$conf" \
+                               /etc/nsd3/zone.d/"$conf"
+                       cat <<-EOF
+                               zone:
+                                       name: $domain
+                                       zonefile: /etc/nsd3/zone.d/$domain.zone
+                               EOF
+                done
+       } |
+       sudo install -m 640 -o root -g nsd /dev/stdin \
+        /etc/nsd3/nsd.conf
+       sudo service nsd3 restart
+ }
 rule_php5_fpm_configure () {
        local -; set +f
        rule apt_get_install \
@@ -1268,6 +1287,23 @@ rule_time_configure () {
        rule dpkg_reconfigure tzdata
        rule apt_get_install ntp
  }
+rule_unbound_configure () {
+       sudo apt-get install unbound m4
+       sudo install -m 644 -o root -g root /dev/stdin /etc/resolv.conf <<-EOF
+               search ${vm_host#*.}
+               nameserver 127.0.0.1
+               #nameserver ${vm_host_nameserver}
+               EOF
+       sudo install -m 440 -o unbound -g unbound \
+        "$tool"/etc/unbound/named.cache \
+        /etc/unbound/named.cache
+       m4 \
+        --define=OUTGOING_INTERFACE=$vm_ipv4 \
+        <"$tool"/etc/unbound/unbound.conf |
+       sudo install -m 440 -o unbound -g unbound /dev/stdin \
+        /etc/unbound/unbound.conf
+       sudo service unbound restart
+ }
 rule_user_add () { # SYNTAX: $user
        rule user_configure
        local user=$1
@@ -1385,7 +1421,7 @@ rule_user_root_configure () {
                        $users
                        EOF
                 do eval local home\; home="~$user"
-                       cat "$home"/etc/ssh/authorized_keys
+                       sudo cat "$home"/etc/ssh/authorized_keys
                 done
         done |
        sudo install -m 640 -o root -g root /dev/stdin /root/etc/ssh/authorized_keys
@@ -1394,6 +1430,34 @@ rule_user_root_configure () {
         do sudo gpg --import "$key"
         done
  }
+rule_www_configure () {
+       rule adduser www \
+        --disabled-login \
+        --disabled-password \
+        --group \
+        --home /home/www \
+        --shell /bin/false \
+        --system
+       rule adduser log-www \
+        --disabled-login \
+        --disabled-password \
+        --group \
+        --home /home/www/log \
+        --shell /bin/false \
+        --system
+       #sudo adduser www www-data
+       sudo adduser www log-www
+       #sudo adduser log log-www
+       usermod --home /home/www/pub www-data
+       sudo install -d -m 751 -o www -g www \
+        /home/www
+       sudo install -d -m 750 -o www -g www \
+        /home/www/etc
+       sudo install -d -m 1771 -o www-data -g www-data \
+        /home/www/pub
+       sudo install -d -m 1771 -o log-www -g log-www \
+        /home/www/log
+ }
 rule_configure () {
        rule apt_configure
        rule git_configure
@@ -1414,6 +1478,7 @@ rule_configure () {
        rule php5_fpm_configure
        rule nginx_configure
        #rule apache2_configure
+       rule nsd3_configure
        rule runit_configure
  }