}
rule_apt_get_install () { # SYNTAX: $package
- case $(dpkg -s "$1" 2>/dev/null | grep '^Status: ') in
- ("Status: install ok installed");;
- (*)
- test ! -x /usr/bin/etckeeper ||
- ! sudo etckeeper unclean ||
- warn "/etc unclean: etckeeper may force you to \`etckeeper commit'; then you can run your $0 command again."
- sudo apt-get install "$@";;
- esac
+ sudo DEBIAN_FRONTEND=noninteractive apt-get install "$@"
+ }
+rule_dpkg_reconfigure () { # SYNTAX: $package
+ sudo DEBIAN_FRONTEND=noninteractive dpkg-reconfigure "$@"
}
rule__chrooted_configure () { # NOTE: est-ce bien utile à un moment ?
. /etc/profile
}
+rule_apache2_configure () {
+ local -; set +f
+ rule apt_get_install \
+ apache2-mpm-itk \
+ libapache2-mod-php5
+ # VOIR: http://serverfault.com/questions/383526/how-do-i-select-which-apache-mpm-to-use/383634#383634
+ # VOIR: http://jkroon.blogs.uls.co.za/it/security/using-php-fpm-and-mod_proxy_fcgi-to-optimize-and-secure-lamp-servers
+ # NOTE: apache2-mpm-itk semble le plus sécurisé,
+ # car on est certain que tout est exécuté avec les uid/gid
+ # assignés au VirtualHost/Directory/Location
+ # néamoins il se peut qu'une combinaison du genre :
+ # apache2-mpm-{worker,event} + mod_proxy_fcgi + apache2-suexec-custom + php-fpm
+ # soit plus performante (threads et pas forks),
+ # cependant l'usage de suexec impose des forks il semble..
+ # et mod_proxy_fcgi n'apparaît que dans apache 2.4 ;
+ # donc pour l'instant : apache2-mpm-itk
+ rule www_configure
+ cat /dev/stdin "$tool"/etc/apache2/apache2.conf <<-EOF |
+ ServerName "$vm_fqdn"
+ EOF
+ sudo install -m 660 -o root -g root /dev/stdin \
+ /etc/apache2/apache2.conf
+ sudo install -m 660 -o root -g root \
+ "$tool"/etc/apache2/envvars \
+ /etc/apache2/envvars
+ sudo install -m 660 -o root -g root \
+ "$tool"/etc/apache2/httpd.conf \
+ /etc/apache2/httpd.conf
+ #sudo install -m 660 -o root -g root /dev/stdin \
+ # /etc/apache2/suexec/www-data <<-EOF
+ # /home
+ # pub/www/cgi
+ # EOF
+ sudo install -m 660 -o root -g root \
+ "$tool"/etc/apache2/ports.conf \
+ /etc/apache2/ports.conf
+ sudo a2enmod actions
+ sudo a2enmod headers
+ sudo a2enmod rewrite
+ sudo a2enmod ssl
+ sudo a2enmod userdir
+ local conf
+ sudo a2dissite "*"
+ sudo ln -fns \
+ /etc/apache2 \
+ /home/www/etc/apache2
+ for conf in "$tool"/etc/apache2/site.d/*/VirtualHost.conf
+ do conf=${conf#"$tool"/etc/apache2/site.d/}
+ local port site
+ IFS=. read -r port site <<-EOF
+ ${conf%\/VirtualHost\.conf}
+ EOF
+ assert 'test "${site:+set}"'
+ assert 'test "${port:+set}"'
+ local site_user="$user.$port.$site"
+ local site_dir="$user.$port.$site"
+ case $port in
+ (443)
+ local hint="run vm_remote apache2_key_send before"
+ assert "sudo test -f /etc/apache2/site.d/\"$site_dir\"/x509/key.pem" hint
+ sudo install -d -m 770 -o "$user" -g "$user" \
+ /etc/apache2 \
+ /etc/apache2/site.d/"$site_dir" \
+ /etc/apache2/site.d/"$site_dir"/x509 \
+ /etc/apache2/site.d/"$site_dir"/x509/ca \
+ /etc/apache2/site.d/"$site_dir"/x509/empty \
+ /etc/apache2/site.d/"$site_dir"/x509/rvk \
+ /etc/apache2/site.d/"$site_dir"/x509/usr
+ sudo install -m 664 -o www -g www \
+ "$tool"/var/pub/x509/"$site"/crt.self-signed.pem \
+ /etc/apache2/site.d/"$site_dir"/x509/crt.self-signed.pem
+ #sudo install -m 664 -o "$user" -g "$user" \
+ # "$tool"/var/pub/x509/"$site"/rvk.pem \
+ # /etc/apache2/site.d/"$site_dir"/x509/rvk.pem
+ sudo install -m 664 -o www -g www \
+ "$tool"/var/pub/x509/"$site"/ca/crt.self-signed.pem \
+ /etc/apache2/site.d/"$site_dir"/x509/ca/crt.pem
+ sudo install -m 664 -o www -g www \
+ "$tool"/var/pub/x509/"$site"/crt.pem \
+ /etc/apache2/site.d/"$site_dir"/x509/crt.pem
+ ;;
+ esac
+ case $port in
+ (80)
+ cat <<-EOF
+ <VirtualHost *:$port>
+ AssignUserID $site_user $site_user
+ CustomLog "|/usr/sbin/rotatelogs /home/www/log/$site_dir/apache2/access/%Y-%m-%d.log 86400 60" Combined
+ #CustomLog "/dev/null" Combined
+ DocumentRoot /home/www/pub/$site_dir
+ ErrorLog "|/usr/sbin/rotatelogs /home/www/log/$site_dir/apache2/error/%Y-%m-%d.log 86400 60"
+ #ErrorLog "/dev/null"
+ ServerName $site
+ LogLevel Warn
+ $(cat "$tool"/etc/apache2/site.d/"$site_dir"/VirtualHost.conf)
+ </VirtualHost>
+ EOF
+ ;;
+ (443)
+ cat <<-EOF
+ <IfModule mod_ssl.c>
+ <VirtualHost *:$port>
+ AssignUserID $site_user $site_user
+ BrowserMatch "MSIE [2-6]" ssl-unclean-shutdown nokeepalive downgrade-1.0 force-response-1.0
+ BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
+ CustomLog "|/usr/sbin/rotatelogs /home/www/log/$site_dir/apache2/access/%Y-%m-%d.log 86400 60" Combined
+ #CustomLog "/dev/null" Combined
+ DocumentRoot /home/www/pub/$site_dir
+ ErrorLog "|/usr/sbin/rotatelogs /home/www/log/$site_dir/apache2/error/%Y-%m-%d.log 86400 60"
+ #ErrorLog "/dev/null"
+ LogLevel Warn
+ ServerName $site
+ SSLCACertificateFile /etc/apache2/site.d/$site_dir/x509/crt.self-signed.pem
+ SSLCACertificatePath /etc/apache2/site.d/$site_dir/x509/usr/
+ #SSLCARevocationFile /etc/apache2/site.d/$site_dir/x509/rvk.pem
+ SSLCADNRequestFile /etc/apache2/site.d/$site_dir/x509/crt.self-signed.pem
+ SSLCADNRequestPath /etc/apache2/site.d/$site_dir/x509/empty/
+ # NOTE: ne publie pas les certificats d’utilisateur-ice-s acceptés
+ SSLCARevocationPath /etc/apache2/site.d/$site_dir/x509/rvk/
+ SSLCertificateChainFile /etc/apache2/site.d/$site_dir/x509/ca/crt.pem
+ SSLCertificateFile /etc/apache2/site.d/$site_dir/x509/crt.pem
+ SSLCertificateKeyFile /etc/apache2/site.d/$site_dir/x509/key.pem
+ SSLCipherSuite AES+RSA+SHA256
+ SSLEngine On
+ SSLInsecureRenegotiation Off
+ SSLOptions +StrictRequire +OptRenegotiate +StdEnvVars
+ SSLProtocol -All +TLSv1
+ #SSLRenegBufferSize 262144
+ SSLSessionCacheTimeout 1200
+ SSLStrictSNIVHostCheck On
+ SSLUserName SSL_CLIENT_S_DN_CN
+ SSLVerifyClient None
+ SSLVerifyDepth 1
+ $(cat "$tool"/etc/apache2/site.d/"$site_dir"/VirtualHost.conf)
+ </VirtualHost>
+ </IfModule>
+ EOF
+ ;;
+ esac |
+ sudo install -m 660 -o root -g root /dev/stdin \
+ /etc/apache2/site.d/"$site_dir"/VirtualHost.conf
+ sudo ln -fns \
+ ../site.d/"$site_dir"/VirtualHost.conf \
+ /etc/apache2/sites-available/"$site_dir"
+ sudo install -d -m 770 -o "$user" -g "$user" \
+ /home/www/log/"$site_dir" \
+ /home/www/log/"$site_dir"/apache2
+ sudo ln -fns \
+ /etc/apache2/site.d/"$site_dir" \
+ /home/www/etc/apache2/"$site_dir"
+ test -e /home/www/pub/"$site_dir" ||
+ sudo install -d -m 770 -o "$user" -g "$user" \
+ /home/www/pub/"$site_dir"
+ getent passwd "$site_user" >/dev/null ||
+ sudo adduser \
+ --disabled-password \
+ --group \
+ --no-create-home \
+ --home /home/www/pub/"$site_dir" \
+ --shell /bin/false \
+ --system \
+ "$site_user"
+ sudo setfacl -m u:"$site_user":--x \
+ /home/www/ \
+ /home/www/pub/ \
+ /home/www/pub/"$site_dir"/
+ sudo setfacl -m d:u:"$site_user":rwx \
+ "$home"/pub/www/"$site_dir"/
+ test ! -r "$tool"/etc/apache2/site.d/"$site_dir"/configure.sh ||
+ . "$tool"/etc/apache2/site.d/"$site_dir"/configure.sh
+ test -e /etc/apache2/sites-enabled/"$site_dir" ||
+ sudo a2ensite "$site_dir"
+ done
+ sudo service apache2 restart
+ }
rule_apt_configure () {
sudo install -m 660 -o root -g root /dev/stdin /etc/apt/sources.list <<-EOF
deb http://ftp.fr.debian.org/debian $vm_lsb_name main contrib non-free
Pin: release a=$vm_lsb_name-backports
Pin-Priority: 200
EOF
- sudo install -m 660 -o root -g root /dev/stdin /etc/apt/sources.list.d/openerp.list <<-EOF
- deb http://nightly.openerp.com/trunk/nightly/deb/ ./
- EOF
sudo apt-get update
rule apt_get_install apticron
sudo install -m 644 -o root -g root /dev/stdin /etc/apticron/apticron.conf <<-EOF
EOF
}
rule_boot_configure () {
- warn "lors de l'installation Debian, surtout n'installer GRUB sur AUCUN disque proposé !"
+ #warn "lors de l'installation Debian, surtout n'installer GRUB sur AUCUN disque proposé !"
+ sudo debconf-set-selections <<-EOF
+ grub-pc grub-pc/install_devices multiselect
+ EOF
rule apt_get_install grub-pc
sudo install -d -m 644 -o root -g root /boot/grub
rule apt_get_install linux-image-$vm_arch
EOF
sudo update-grub2 # NOTE: prend en compte /boot/grub/device.map
rule initramfs_configure
+ rule apt_get_install molly-guard
+ sudo install -m 644 -o root -g root /dev/stdin /etc/molly-guard/rc <<-EOF
+ ALWAYS_QUERY_HOSTNAME=true
+ # NOTE: une alternative est de dire à sudo de conserver les SSH_*
+ # néamoins demander tout le temps n'est pas trop contraignant
+ # et davantage sécurisant.
+ EOF
}
rule_dovecot_configure () {
rule apt_get_install dovecot-imapd dovecot-managesieved dovecot-sieve
local hint="run vm_remote dovecot_key_send before"
- assert "test -f /etc/dovecot/$vm_domainname/imap/x509/key.pem" hint
+ assert "sudo test -f /etc/dovecot/\"$vm_domainname\"/imap/x509/key.pem" hint
sudo install -m 400 -o root -g root \
- "$tool"/var/pub/x509/service/imap/crt+crl.self-signed.pem \
+ "$tool"/var/pub/x509/$vm_domainname/imap/crt+crl.self-signed.pem \
/etc/dovecot/$vm_domainname/imap/x509/crt+crl.self-signed.pem
sudo install -d -m 770 -o root -g adm \
/etc/skel/etc/mail \
LABEL=${vm_lvm_lv}_boot /boot ext2 defaults 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
- tmpfs /tmp tmpfs rw,nosuid,nodev,auto,size=200m,nr_inodes=1000k,mode=1777,noatime,nodiratime 0 0
/dev/mapper/${vm_lvm_lv}_root_deciphered / ext4 defaults,errors=remount-ro,acl,barrier=1,noatime 0 1
/dev/mapper/${vm_lvm_lv}_var_deciphered /var ext4 defaults,errors=remount-ro,acl,barrier=1,noatime 0 1
/dev/mapper/${vm_lvm_lv}_home_deciphered /home ext4 defaults,errors=remount-ro,acl,barrier=1,noatime,usrquota,grpquota 0 0
${vm_lvm_lv}_home_deciphered /dev/$vm_lvm_vg/${vm_lvm_lv}_home ${vm_lvm_lv}_root_deciphered luks,lvm=$vm_lvm_vg,keyscript=/lib/cryptsetup/scripts/decrypt_derived
${vm_lvm_lv}_swap_deciphered /dev/$vm_lvm_vg/${vm_lvm_lv}_swap ${vm_lvm_lv}_root_deciphered luks,lvm=$vm_lvm_vg,keyscript=/lib/cryptsetup/scripts/decrypt_derived
EOF
- sudo install -m 644 -o root -g root /dev/stdin /etc/sysctl.d/local-swap.conf <<-EOF
- vm.swappiness = 10 # NOTE: n'utilise le swap qu'en cas d'absolue nécessité
- vm.vfs_cache_pressure=50
+ sudo install -m 644 -o root -g root /dev/stdin /etc/default/tmpfs <<-EOF
+ LOCK_SIZE=5242880 # NOTE: 5MiB
+ RAMLOCK=yes
+ RAMSHM=yes
+ RAMTMP=yes
+ RUN_SIZE=10%
+ SHM_SIZE=
+ TMP_MODE=1777,nr_inodes=1000k,noatime
+ TMP_OVERFLOW_LIMIT=1024
+ # NOTE: mount tmpfs on /tmp if there is less than the limit size (in kiB)
+ # on the root filesystem (overriding RAMTMP).
+ TMP_SIZE=200m
+ TMPFS_SIZE=20%VM
EOF
+ sudo install -m 775 -o root -g root \
+ "$tool"/etc/init.d/tmpfs \
+ /etc/init.d/tmpfs
+ sudo update-rc.d tmpfs defaults
}
rule_initramfs_configure () {
sudo install -m 644 -o root -g root /dev/stdin /etc/initramfs-tools/initramfs.conf <<-EOF
# NOTE: clefs générées par Debian
sudo update-initramfs -u
}
+rule_gitolite_configure () {
+ local user=git
+ sudo debconf-set-selections <<-EOF
+ gitolite gitolite/gituser string $user
+ gitolite gitolite/adminkey string
+ gitolite gitolite/gitdir string /home/$user
+ EOF
+ rule apt_get_install gitolite
+ getent passwd "$user" >/dev/null ||
+ sudo adduser \
+ --disabled-password \
+ --group \
+ --shell /bin/bash \
+ --system \
+ "$user"
+ sudo chfn --full-name "$user" "$user"
+ eval local home\; home="~$user"
+ sudo install -d -m 770 -o "$user" -g "$user" \
+ /etc/gitolite \
+ "$home"/etc \
+ "$home"/etc/ssh \
+ "$home"/pub \
+ "$home"/log \
+ "$home"/log/gitolite \
+ "$home"/log/gitolite/perf
+ sudo ln -fns /etc/gitolite "$home"/etc/gitolite
+ sudo ln -fns etc/gitolite/gitolite.rc "$home"/.gitolite.rc
+ sudo ln -fns etc/ssh "$home"/.ssh
+ sudo install -m 770 -o "$user" -g "$user" /dev/stdin \
+ "$home"/etc/gitolite/gitolite.rc <<-EOF
+ #\$ADMIN_POST_UPDATE_CHAINS_TO = "hooks/post-update.secondary";
+ #\$BIG_INFO_CAP = 20;
+ #\$ENV{GL_SLAVES} = 'gitolite@server2 gitolite@server3';
+ # NOTE: Please use single quotes, not double quotes.
+ #\$GITWEB_URI_ESCAPE = 0;
+ \$GIT_PATH = "";
+ #\$GL_ADC_PATH = "";
+ \$GL_ADMINDIR = \$ENV{HOME} . "/etc/gitolite";
+ #\$GL_ALL_INCLUDES_SPECIAL = 0;
+ #\$GL_ALL_READ_ALL = 0;
+ \$GL_BIG_CONFIG = 0;
+ \$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_HOSTNAME = "git.$vm_domainname";
+ # NOTE: read doc/mirroring.mkd COMPLETELY before setting this.
+ #\$GL_HTTP_ANON_USER = "mob";
+ \$GL_KEYDIR = "\$GL_ADMINDIR/keydir";
+ \$GL_LOGT = \$ENV{HOME} . "/log/gitolite/%y-%m-%d.log";
+ #\$GL_NICE_VALUE = 0;
+ \$GL_NO_CREATE_REPOS = 0;
+ \$GL_NO_DAEMON_NO_GITWEB = 0;
+ \$GL_NO_SETUP_AUTHKEYS = 0;
+ \$GL_PACKAGE_CONF = "/usr/share/gitolite/conf";
+ \$GL_PACKAGE_HOOKS = "/usr/share/gitolite/hooks";
+ #\$GL_PERFLOGT = \$ENV{HOME} . "/log/gitolite/perf/%y-%m-%d.log";
+ #\$GL_REF_OR_FILENAME_PATT = qr(^[0-9a-zA-Z][0-9a-zA-Z._\\@/+ :,-]*\$);
+ \$GL_SITE_INFO = "git.$vm_domainname";
+ #\$GL_SLAVE_MODE = 0;
+ \$GL_WILDREPOS = 0;
+ #\$GL_WILDREPOS_DEFPERMS = 'R @all';
+ \$GL_WILDREPOS_PERM_CATS = "READERS WRITERS";
+ \$HTPASSWD_FILE = "";
+ \$PROJECTS_LIST = \$ENV{HOME} . "/projects.list";
+ \$REPO_BASE = "pub";
+ \$REPO_UMASK = 0007;
+ \$RSYNC_BASE = "";
+ \$SVNSERVE = "";
+ #\$UPDATE_CHAINS_TO = "hooks/update.secondary";
+ #\$WEB_INTERFACE = "gitweb";
+ 1;
+ EOF
+ sudo install -m 770 -o "$user" -g "$user" /dev/stdin \
+ "$home"/etc/gitweb/gitweb.conf <<-EOF
+ \$commit_oneline_message_width = 70;
+ \$default_projects_order = 'age';
+ \$default_text_plain_charset = 'UTF-8';
+ @diff_opts = ();
+ \$favicon = "img/git-favicon.png";
+ \$git_temp = "/run/shm/gitweb";
+ \$home_footer = "/etc/gitweb/cgi/home-footer.cgi.inc";
+ \$home_header = "/etc/gitweb/cgi/home-header.cgi.inc";
+ \$home_link = "/";
+ \$home_link_str = 'dépôts';
+ \$home_th_age = 'activité';
+ \$home_th_descr = 'description';
+ \$home_th_owner = 'contact';
+ \$home_th_project = 'dépôt';
+ \$javascript = "js/gitweb.js";
+ \$logo = "img/git-logo.png";
+ \$my_uri = "";
+ \$projectroot = "../git";
+ \$projects_list = "/etc/gitolite/projects.list";
+ \$projects_list_description_width = 42;
+ \$projects_list_owner_width = 15;
+ \$search_str = "Filtre :";
+ \$site_footer = "/home/fai/pub/www/git.autogeree.net/cgi/site-footer.bin";
+ \$site_header = undef;
+ \$site_name = "git.$vm_domainname";
+ \$space_to_nbsp = 0;
+ @stylesheets = ("css/gitweb.css");#
+ \$untabify_tabstop = 2;
+ EOF
+ sudo install -m 600 -o "$user" -g "$user" \
+ "$tool"/var/pub/ssh/"$user".key \
+ "$home"/etc/ssh/"$user".pub
+ sudo -u "$user" \
+ GL_RC="$home"/etc/gitolite/gitolite.rc \
+ GIT_AUTHOR_NAME="$user" \
+ gl-setup -q "$home"/etc/ssh/"$user".pub "$user"
+ local d
+ for d in doc logs src
+ do test ! -d "$home"/etc/gitolite/"$d" ||
+ rmdir "$home"/etc/gitolite/"$d"
+ done
+ rule apt_get_install gitweb highlight
+ #sudo sv restart spawn-fcgi.git.80.git.heureux-cyclage.org
+ #sudo sv restart git-daemon.git.9418
+ }
rule_locale_configure () {
- sudo install -m 644 -o root -g root /dev/stdin /etc/locale.gen <<-EOF
- fr_FR.UTF-8 UTF-8
+ sudo debconf-set-selections <<-EOF
+ locales locales/default_environment_locale select None
+ locales locales/locales_to_be_generated multiselect fr_FR.UTF-8 UTF-8
EOF
- sudo update-locale
+ rule dpkg_reconfigure locales
}
rule_login_configure () {
- grep -q '^hvc0$' /etc/securetty ||
- sudo install -m 644 -o root -g root /dev/stdin /etc/securetty <<-EOF
- $(cat /etc/securetty)
- hvc0
- EOF
- grep -q '^xvc0$' /etc/securetty ||
- sudo install -m 644 -o root -g root /dev/stdin /etc/securetty <<-EOF
- $(cat /etc/securetty)
- xvc0
- EOF
sudo install -m 644 -o root -g root /dev/stdin /etc/inittab <<-EOF
# /etc/inittab: init(8) configuration.
$(cat /etc/pam.d/common-session)
session optional pam_umask.so
EOF
+ grep -q '^hvc0$' /etc/securetty ||
+ sudo install -m 644 -o root -g root /dev/stdin /etc/securetty <<-EOF
+ $(cat /etc/securetty)
+ hvc0
+ EOF
+ grep -q '^xvc0$' /etc/securetty ||
+ sudo install -m 644 -o root -g root /dev/stdin /etc/securetty <<-EOF
+ $(cat /etc/securetty)
+ xvc0
+ EOF
}
-rule_procmail_configure () {
- rule apt_get_install procmail
- sudo install -d -m 770 -o root -g adm \
- /etc/skel/etc/mail \
- /etc/skel/var/cache/mail \
- /etc/skel/var/log/mail \
- /etc/skel/var/mail
- sudo install -m 660 -o root -g adm \
- "$tool"/etc/skel/etc/mail/delivery.procmailrc \
- /etc/skel/etc/mail/delivery.procmailrc
+rule_mail_configure () {
+ rule postfix_configure
+ rule postgrey_configure
+ rule procmail_configure
+ rule dovecot_configure
}
-rule_postgrey_configure () {
- rule apt_get_install postgrey
- sudo service postgrey restart
+rule_mysql_configure () {
+ rule apt_get_install mysql-server-5.5
+ sudo service mysql restart
+ }
+rule_network_configure () {
+ sudo install -m 644 -o root -g root /dev/stdin /etc/hostname <<-EOF
+ $vm
+ EOF
+ grep -q " $vm\$" /etc/hosts ||
+ sudo install -m 644 -o root -g root /dev/stdin /etc/hosts <<-EOF
+ $(cat /etc/hosts)
+ 127.0.0.1 $vm_fqdn $vm
+ EOF
+ sudo install -m 644 -o root -g root /dev/stdin /etc/network/interfaces <<-EOF
+ auto lo
+ iface lo inet loopback
+
+ auto eth0=grenode
+ iface grenode inet static
+ address $vm_ipv4
+ gateway $vm_ipv4 # NOTE: proxy_arp sur la passerelle permet d'utiliser la même adresse
+ network $vm_ipv4
+ broadcast $vm_ipv4
+ netmask 255.255.255.255
+ mtu 1300
+ # NOTE: il y a besoin de ça en l'état actuel du réseau de Grenode
+ # car la MTU des tunnels GRE/IPsec entre les routeurs de Grenode l'impose.
+ #
+ # root@ateliers:~# ping -M do -c 1 -s \$((1500-20-8-200)) soupirail.grenode.net
+ # PING soupirail.grenode.net (91.216.110.1) 1272(1300) bytes of data.
+ # 1280 bytes from soupirail.grenode.net (91.216.110.1): icmp_req=1 ttl=63 time=18.0 ms
+ #
+ # --- soupirail.grenode.net ping statistics ---
+ # 1 packets transmitted, 1 received, 0% packet loss, time 0ms
+ # rtt min/avg/max/mdev = 18.027/18.027/18.027/0.000 ms
+ # root@ateliers:~# ping -M do -c 1 -s \$((1500-20-8-200+1)) soupirail.grenode.net
+ # PING soupirail.grenode.net (91.216.110.1) 1273(1301) bytes of data.
+ # From estran.grenode.net (91.216.110.6) icmp_seq=1 Frag needed and DF set (mtu = 1300)
+ #
+ # --- soupirail.grenode.net ping statistics ---
+ # 0 packets transmitted, 0 received, +1 errors
+ post-up ip address add $vm_ipv4/32 dev \$IFACE
+ pre-down ip address delete $vm_ipv4/32 dev \$IFACE
+ EOF
+ }
+rule_www_configure () {
+ getent passwd www >/dev/null ||
+ sudo adduser \
+ --disabled-login \
+ --disabled-password \
+ --group \
+ --home /home/www \
+ --shell /bin/false \
+ --system \
+ www
+ sudo adduser \
+ --disabled-login \
+ --disabled-password \
+ --group \
+ --home ~www/log \
+ --shell /bin/false \
+ --system \
+ log.www
+ #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
+ rule www_configure
+ sudo rm -rf \
+ /etc/nginx/conf.d \
+ /etc/nginx/site.d
+ sudo install -d -m 770 -o www -g www \
+ /etc/nginx \
+ /etc/nginx/conf.d \
+ /etc/nginx/site.d
+ sudo ln -fns \
+ /etc/nginx \
+ /home/www/etc/nginx
+ sudo install -m 660 -o www -g www \
+ "$tool"/etc/nginx/nginx.conf \
+ /etc/nginx/nginx.conf
+ local conf
+ for conf in "$tool"/etc/nginx/conf.d/*.conf
+ do conf=${conf#"$tool"/etc/nginx/conf.d/}
+ sudo install -m 660 -o www -g www \
+ "$tool"/etc/nginx/conf.d/"$conf" \
+ /etc/nginx/conf.d/"$conf"
+ done
+ for conf in "$tool"/etc/nginx/site.d/*/server.conf
+ do conf=${conf#"$tool"/etc/nginx/site.d/}
+ local port site
+ IFS=. read -r port site <<-EOF
+ ${conf%\/server\.conf}
+ EOF
+ assert 'test "${port:+set}"'
+ assert 'test "${site:+set}"'
+ site="$port.$site"
+ getent passwd www."$site" >/dev/null ||
+ sudo adduser \
+ --disabled-login \
+ --disabled-password \
+ --group \
+ --home ~www-data/"$site" \
+ --shell /bin/false \
+ --system \
+ www."$site"
+ getent passwd log."$site" >/dev/null ||
+ sudo adduser \
+ --disabled-login \
+ --disabled-password \
+ --group \
+ --shell /bin/false \
+ --system \
+ log."$site"
+ sudo usermod --home ~www/log/"$site"/nginx log."$site"
+ sudo install -d -m 770 -o www -g www \
+ /etc/nginx/site.d/"$site"
+ case $port in
+ (443)
+ local hint="run vm_remote nginx_key_send before"
+ assert "sudo test -f /etc/nginx/\"$site\"/x509/key.pem" hint
+ sudo install -m 664 -o www -g www \
+ "$tool"/var/pub/x509/"$site"/crt+ca.pem \
+ /etc/nginx/site.d/"$site"/x509/crt.pem
+ ;;
+ esac
+ case $port in
+ (80)
+ cat <<-EOF
+ server {
+ listen $port;
+ access_log /home/www/log/$site/nginx/access.log main;
+ error_log /home/www/log/$site/nginx/error.log warn;
+ root /home/www/pub/$site;
+ server_name $site;
+ $(cat "$tool"/etc/nginx/site.d/"$site"/server.conf)
+ }
+ EOF
+ ;;
+ (443)
+ cat <<-EOF
+ server {
+ listen $port;
+ access_log /home/www/log/$site/nginx/access.log main;
+ error_log /home/www/log/$site/nginx/error.log warn;
+ keepalive_timeout 70;
+ root /home/www/pub/$site;
+ server_name $site;
+ # DOC: http://wiki.nginx.org/HttpSslModule
+ ssl on;
+ ssl_certificate /home/www/etc/nginx/site.d/$site/x509/crt.pem;
+ ssl_certificate_key /home/www/etc/nginx/site.d/$site/x509/key.pem;
+ ssl_ciphers HIGH:!ADH:!MD5;
+ ssl_prefer_server_ciphers on;
+ ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
+ ssl_session_cache shared:SSL:10m;
+ $(cat "$tool"/etc/nginx/site.d/"$site"/server.conf)
+ }
+ EOF
+ ;;
+ esac |
+ sudo install -m 660 -o www -g www /dev/stdin \
+ /etc/nginx/site.d/"$site"/server.conf
+ adduser www-data "$site"
+ test -e /home/www/pub/"$site" ||
+ sudo install -d -m 3770 -o "$site" -g "$site" \
+ /home/www/pub/"$site"
+ sudo install -d -m 3770 -o log."$site" -g log."$site" \
+ /home/www/log/"$site"/nginx
+ test ! -r "$tool"/etc/nginx/site.d/"$site"/configure.sh ||
+ . "$tool"/etc/nginx/site.d/"$site"/configure.sh
+ done
+ rule apt_get_install spawn-fcgi fcgiwrap
+ sudo insserv --remove fcgiwrap
+ rule tmpfs_configure
+ sudo service nginx restart
+ }
+rule_php5_fpm_configure () {
+ local -; set +f
+ rule apt_get_install \
+ php5-fpm \
+ php-apc
+ getent passwd php5 >/dev/null ||
+ sudo adduser \
+ --disabled-login \
+ --disabled-password \
+ --group \
+ --shell /bin/false \
+ --system \
+ php5
+ local conf
+ sudo ln -fns \
+ /etc/php5-fpm \
+ /home/www/etc/php5
+ sudo rm -f /etc/php5/fpm/pool.d/*
+ for conf in "$tool"/etc/php5/fpm/pool.d/*.conf
+ do conf=${conf#"$tool"/etc/php5/fpm/pool.d/}
+ local port site
+ IFS=. read -r port site <<-EOF
+ ${conf%\.conf}
+ EOF
+ assert 'test "${port:+set}"'
+ assert 'test "${site:+set}"'
+ site="$port.$site"
+ getent passwd php5"$site" >/dev/null ||
+ sudo adduser \
+ --disabled-login \
+ --disabled-password \
+ --group \
+ --no-create-home \
+ --home ~www/pub/"$site" \
+ --shell /bin/false \
+ --system \
+ php5."$site"
+ sudo install -d -m 770 -o php5 -g php5 \
+ /home/www/log/php5 \
+ /home/www/log/php5/fpm
+ sudo install -d -m 770 -o log."$site" -g log."$site" \
+ /home/www/log/"$site"
+ sudo adduser php5."$user" www."$site"
+ sudo install -m 660 -o root -g root /dev/stdin \
+ /etc/php5/fpm/pool.d/"$conf" <<-EOF
+ [php5.$site]
+ access.log = /home/www/log/$site/php5/fpm/access.log
+ catch_workers_output = yes
+ chdir = /
+ env[HOSTNAME] = \$HOSTNAME
+ env[TEMP] = /tmp
+ env[TMPDIR] = /tmp
+ env[TMP] = /tmp
+ group = www-data
+ listen = /run/nginx/fastcgi/php5.$site
+ #listen = 127.0.0.1:9000
+ #listen.allowed_clients = 127.0.0.1
+ listen.backlog = -1
+ pm = dynamic
+ pm.max_children = 5
+ pm.max_requests = 200
+ pm.max_spare_servers = 4
+ pm.min_spare_servers = 2
+ pm.start_servers = 3
+ pm.status_path = /status
+ request_slowlog_timeout = 5s
+ request_terminate_timeout = 120s
+ rlimit_core = unlimited
+ rlimit_files = 131072
+ slowlog = /home/www/log/$site/php5/fpm/slow.log
+ user = $php5_user
+ $(cat "$tool"/etc/php5/fpm/pool.d/"$conf")
+ EOF
+ sudo install -m 664 -o root -g root \
+ "$tool"/etc/php5/fpm/php.ini \
+ /etc/php5/fpm/php.ini
+ done
+ rule tmpfs_configure
+ sudo service php5-fpm restart
}
rule_postfix_configure () {
local hint="run vm_remote postfix_key_send before"
assert "test -f /etc/postfix/$vm_domainname/smtpd/x509/key.pem" hint
- warn "lors de l'installation Debian, ne sélectionner aucune configuration pour postfix"
+ #warn "lors de l'installation Debian, ne sélectionner aucune configuration pour postfix"
+ sudo debconf-set-selections <<-EOF
+ postfix postfix/main_mailer_type select No configuration
+ EOF
rule apt_get_install postfix
sudo install -m 640 -o root -g root /dev/stdin /etc/postfix/.gitignore <<-EOF
*.db
../crt+crl.self-signed.pem \
/etc/postfix/$vm_domainname/smtpd/x509/ca/crt.pem
sudo install -m 400 -o root -g root \
- var/pub/x509/service/smtpd/crt+crl.self-signed.pem \
+ "$tool"/var/pub/x509/$vm_domainname/smtpd/crt+crl.self-signed.pem \
/etc/postfix/$vm_domainname/smtpd/x509/crt+crl.self-signed.pem
sudo install -m 400 -o root -g root \
- var/pub/x509/service/smtpd/crt.pem \
+ "$tool"/var/pub/x509/$vm_domainname/smtpd/crt.pem \
/etc/postfix/$vm_domainname/smtpd/x509/crt.pem
sudo install -m 400 -o root -g root \
- var/pub/x509/service/smtpd/crt+root.pem \
- /etc/postfix/$vm_domainname/smtpd/x509/crt+root.pem
+ "$tool"/var/pub/x509/$vm_domainname/smtpd/crt+ca.pem \
+ /etc/postfix/$vm_domainname/smtpd/x509/crt+ca.pem
sudo install -m 400 -o root -g root \
- var/pub/x509/service/smtpd/crt+crl.self-signed.pem \
+ "$tool"/var/pub/x509/$vm_domainname/smtpd/crt+crl.self-signed.pem \
/etc/postfix/$vm_domainname/smtpd/x509/crt+crl.self-signed.pem
sudo install -m 660 -o root -g root \
- etc/postfix/$vm_domainname/header_checks \
- /etc/postfix/$vm_domainname/header_checks
- sudo install -m 664 -o root -g root \
- etc/postfix/aliases \
- /etc/postfix/aliases
+ "$tool"/etc/postfix/$vm_domainname/header_checks \
+ /etc/postfix/$vm_domainname/header_checks
+ sudo install -m 664 -o root -g root /dev/stdin \
+ /etc/postfix/aliases <<-EOF
+ # See man 5 aliases for format
+ abuse: root
+ admin: root
+ contact: root
+ postmaster: root
+ root: $(getent group sudo | cut -f 4 -d : | tr , ' ')
+ EOF
sudo newaliases -oA/etc/postfix/aliases
- cat /dev/stdin etc/postfix/main.cf <<-EOF |
+ cat /dev/stdin "$tool"/etc/postfix/main.cf <<-EOF |
mydomain = $vm_domainname
myorigin = \$mydomain
myhostname = $vm_hostname.\$mydomain
sudo install -m 664 -o root -g root /dev/stdin \
/etc/postfix/main.cf
sudo install -m 664 -o root -g root \
- etc/postfix/master.cf \
- /etc/postfix/master.cf
+ "$tool"/etc/postfix/master.cf \
+ /etc/postfix/master.cf
sudo install -m 660 -o root -g root \
- etc/postfix/$vm_domainname/smtp/x509/policy \
- /etc/postfix/$vm_domainname/smtp/x509/policy
+ "$tool"/etc/postfix/$vm_domainname/smtp/x509/policy \
+ /etc/postfix/$vm_domainname/smtp/x509/policy
sudo postmap hash:/etc/postfix/$vm_domainname/smtp/x509/policy
sudo install -m 660 -o root -g root \
- etc/postfix/$vm_domainname/smtp/header_checks \
- /etc/postfix/$vm_domainname/smtp/header_checks
+ "$tool"/etc/postfix/$vm_domainname/smtp/header_checks \
+ /etc/postfix/$vm_domainname/smtp/header_checks
sudo install -m 660 -o root -g root \
- etc/postfix/$vm_domainname/smtpd/sender_access \
- /etc/postfix/$vm_domainname/smtpd/sender_access
+ "$tool"/etc/postfix/$vm_domainname/smtpd/sender_access \
+ /etc/postfix/$vm_domainname/smtpd/sender_access
sudo postmap hash:/etc/postfix/$vm_domainname/smtpd/sender_access
sudo install -m 660 -o root -g root \
- etc/postfix/$vm_domainname/smtpd/client_blacklist \
- /etc/postfix/$vm_domainname/smtpd/client_blacklist
+ "$tool"/etc/postfix/$vm_domainname/smtpd/client_blacklist \
+ /etc/postfix/$vm_domainname/smtpd/client_blacklist
sudo postmap hash:/etc/postfix/$vm_domainname/smtpd/client_blacklist
sudo install -m 660 -o root -g root \
- etc/postfix/$vm_domainname/smtpd/relay_clientcerts \
- /etc/postfix/$vm_domainname/smtpd/relay_clientcerts
+ "$tool"/etc/postfix/$vm_domainname/smtpd/relay_clientcerts \
+ /etc/postfix/$vm_domainname/smtpd/relay_clientcerts
sudo postmap hash:/etc/postfix/$vm_domainname/smtpd/relay_clientcerts
sudo install -m 660 -o root -g root \
- etc/postfix/$vm_domainname/transport \
- /etc/postfix/$vm_domainname/transport
+ "$tool"/etc/postfix/$vm_domainname/transport \
+ /etc/postfix/$vm_domainname/transport
sudo postmap hash:/etc/postfix/$vm_domainname/transport
sudo install -m 660 -o root -g root \
- etc/postfix/$vm_domainname/virtual_alias \
- /etc/postfix/$vm_domainname/virtual_alias
+ "$tool"/etc/postfix/$vm_domainname/virtual_alias \
+ /etc/postfix/$vm_domainname/virtual_alias
sudo postmap hash:/etc/postfix/$vm_domainname/virtual_alias
sudo service postfix restart
}
-rule_mail_configure () {
- rule postfix_configure
- rule postgrey_configure
- rule procmail_configure
- rule dovecot_configure
+rule_postgresql_configure () {
+ rule apt_get_install postgresql-9.1
+ sudo service postgresql restart
}
-rule_network_configure () {
- sudo install -m 644 -o root -g root /dev/stdin /etc/hostname <<-EOF
- $vm
- EOF
- grep -q " $vm\$" /etc/hosts ||
- sudo install -m 644 -o root -g root /dev/stdin /etc/hosts <<-EOF
- $(cat /etc/hosts)
- 127.0.0.1 $vm_fqdn $vm
- EOF
- sudo install -m 644 -o root -g root /dev/stdin /etc/network/interfaces <<-EOF
- auto lo
- iface lo inet loopback
-
- auto eth0=grenode
- iface grenode inet static
- address $vm_ipv4
- gateway $vm_ipv4 # NOTE: proxy_arp sur la passerelle permet d'utiliser la même adresse
- network $vm_ipv4
- broadcast $vm_ipv4
- netmask 255.255.255.255
- mtu 1300
- # NOTE: il y a besoin de ça en l'état actuel du réseau de Grenode
- # car la MTU des tunnels GRE/IPsec entre les routeurs de Grenode l'impose.
- #
- # root@ateliers:~# ping -M do -c 1 -s \$((1500-20-8-200)) soupirail.grenode.net
- # PING soupirail.grenode.net (91.216.110.1) 1272(1300) bytes of data.
- # 1280 bytes from soupirail.grenode.net (91.216.110.1): icmp_req=1 ttl=63 time=18.0 ms
- #
- # --- soupirail.grenode.net ping statistics ---
- # 1 packets transmitted, 1 received, 0% packet loss, time 0ms
- # rtt min/avg/max/mdev = 18.027/18.027/18.027/0.000 ms
- # root@ateliers:~# ping -M do -c 1 -s \$((1500-20-8-200+1)) soupirail.grenode.net
- # PING soupirail.grenode.net (91.216.110.1) 1273(1301) bytes of data.
- # From estran.grenode.net (91.216.110.6) icmp_seq=1 Frag needed and DF set (mtu = 1300)
- #
- # --- soupirail.grenode.net ping statistics ---
- # 0 packets transmitted, 0 received, +1 errors
- post-up ip address add $vm_ipv4/32 dev \$IFACE
- pre-down ip address delete $vm_ipv4/32 dev \$IFACE
+rule_openerp_configure () {
+ sudo install -m 660 -o root -g root /dev/stdin /etc/apt/sources.list.d/openerp.list <<-EOF
+ deb http://nightly.openerp.com/trunk/nightly/deb/ ./
EOF
+ sudo apt-get update
+ rule apt_get_install openerp
+ }
+rule_postgrey_configure () {
+ rule apt_get_install postgrey
+ sudo service postgrey restart
+ }
+rule_procmail_configure () {
+ rule apt_get_install procmail
+ sudo install -d -m 770 -o root -g adm \
+ /etc/skel/etc/mail \
+ /etc/skel/var/cache/mail \
+ /etc/skel/var/log/mail \
+ /etc/skel/var/mail
+ sudo install -m 660 -o root -g adm \
+ "$tool"/etc/skel/etc/mail/delivery.procmailrc \
+ /etc/skel/etc/mail/delivery.procmailrc
}
rule_ssh_configure () {
ssh-keygen -F "$vm_fqdn" -f "$tool"/etc/openssh/known_hosts |
EOF
sudo service ssh restart
}
-rule_user_admin_add () { # SYNTAX: $user
+rule_sysctl_configure () {
+ local -; set +f
+ for conf in "$tool"/etc/sysctl.d/*.conf
+ do conf=${conf#"$tool"/etc/sysctl.d/}
+ sudo install -m 660 -o root -g root \
+ "$tool"/etc/sysctl.d/"$conf" \
+ /etc/sysctl.d/"$conf"
+ done
+ sudo sysctl --system
+ }
+rule_time_configure () {
+ sudo install -m 644 -o root -g root /dev/stdin /etc/timezone <<-EOF
+ Europe/Paris
+ EOF
+ sudo debconf-set-selections <<-EOF
+ tzdata tzdata/Areas select Europe
+ tzdata tzdata/Zones/Europe select Paris
+ EOF
+ rule dpkg_reconfigure tzdata
+ rule apt_get_install ntp
+ }
+rule_user_add () { # SYNTAX: $user
+ rule user_configure
local user=$1
id "$user" >/dev/null ||
sudo adduser --disabled-password "$user"
# NOTE: le mot-de-passe doit être initialisé par l'utilisateur à l'aide de passwd-init .
eval local home\; home="~$user"
+ sudo adduser "$user" users
+ sudo install -m 640 -o root -g root \
+ "$tool"/var/pub/ssh/"$user".key \
+ "$home"/etc/ssh/authorized_keys
+ local key; local -; set +f
+ for key in "$tool"/var/pub/openpgp/*.key
+ do sudo -u "$user" gpg --import - <"$key"
+ done
+ }
+rule_user_configure () {
+ true
+ }
+rule_user_admin_add () { # SYNTAX: $user
+ rule user_configure
+ local user=$1
+ id "$user" >/dev/null ||
+ sudo adduser --disabled-password "$user"
+ eval local home\; home="~$user"
sudo adduser "$user" sudo
+ sudo adduser "$user" users
sudo install -m 640 -o root -g root \
"$tool"/var/pub/ssh/"$user".key \
"$home"/etc/ssh/authorized_keys
local key; local -; set +f
for key in "$tool"/var/pub/openpgp/*.key
- do sudo -u "$user" gpg --import "$key"
+ do sudo -u "$user" gpg --import - <"$key"
done
rule user_admin_configure
}
rule user_root_configure
}
rule_user_configure () {
- sudo install -d -m 750 -o root -g adm \
+ sudo install -d -m 750 -o root -g root \
+ /etc/skel \
/etc/skel/etc \
+ /etc/skel/etc/gpg \
/etc/skel/etc/ssh
- sudo install -d -m 770 -o root -g adm \
- /etc/skel/etc/apache2 \
+ sudo install -d -m 770 -o root -g root \
/etc/skel/var \
- /etc/skel/var/log \
/etc/skel/var/cache \
- /etc/skel/var/cache/ssh
+ /etc/skel/var/log \
+ /etc/skel/var/run \
+ /etc/skel/var/run/ssh
sudo ln -fns etc/ssh /etc/skel/.ssh
sudo ln -fns etc/gpg /etc/skel/.gnupg
sudo install -m 640 -o root -g root /dev/stdin /etc/sudoers.d/passwd-init <<-EOF
'case \$(/usr/bin/passwd --status "\$SUDO_USER") in ("\$SUDO_USER L "*) /usr/bin/passwd \$SUDO_USER;; esac'
EOF
sudo install -m 644 -o root -g root \
- etc/bash.bashrc \
- /etc/bash.bashrc
+ "$tool"/etc/bash.bashrc \
+ /etc/bash.bashrc
sudo install -m 644 -o root -g root \
- etc/screenrc \
- /etc/screenrc
+ "$tool"/etc/screenrc \
+ /etc/screenrc
}
rule_user_root_configure () {
- sudo install -d -m 750 -o root -g adm \
+ sudo install -d -m 750 -o root -g root \
/root/etc \
- /root/etc/ssh \
- /root/etc/gpg
+ /root/etc/gpg \
+ /root/etc/ssh
sudo ln -fns etc/gpg /root/.gnupg
sudo ln -fns etc/ssh /root/.ssh
getent group sudo |
do sudo gpg --import "$key"
done
}
+rule_xinetd_configure () {
+ rule apt_get_install xinetd
+ local -; set +f
+ for conf in "$tool"/etc/xinetd.d/*
+ do conf=${conf#"$tool"/etc/xinetd.d/}
+ sudo install -m 660 -o root -g root \
+ "$tool"/etc/xinetd.d/"$conf" \
+ /etc/xinetd.d/"$conf"
+ done
+ sudo service xinetd restart
+ }
rule_configure () {
rule apt_configure
rule git_configure
rule etckeeper_configure
rule locale_configure
+ rule time_configure
rule network_configure
rule filesystem_configure
rule login_configure
rule ssh_configure
rule user_root_configure
rule boot_configure
+ rule sysctl_configure
rule user_configure
+ rule mail_configure
+ #rule apache2_configure
+ rule nginx_configure
+ rule php5_fpm_configure
+ rule gitolite_configure
+ rule xinetd_configure
}
rule_luks_key_change () {