tool=${tool%/*}
. "$tool"/lib/rule.sh
. "$tool"/etc/vm.sh
+export TRACE=1
rule_help () { # SYNTAX: [--hidden]
local hidden; [ ${1:+set} ] || hidden=set
git config --replace branch.master.merge refs/remotes/master
local tool
tool=$(cd "$tool"; cd -)
- sudo ln -fns "$tool"/vm_hosted /usr/local/sbin/
- sudo ln -fns "$tool"/vm_hosted /usr/local/sbin/vm
+ install -m 770 /dev/stdin .git/hooks/post-update <<-EOF
+ #!/bin/sh -efux
+ case \$1 in
+ (refs/remotes/master)
+ cd ..
+ git --git-dir=\$PWD/.git checkout -f -B master remotes/master
+ git --git-dir=\$PWD/.git clean -f -d -x
+ ;;
+ esac
+ EOF
)
}
rule_git_reset () {
)
}
+rule_adduser () {
+ local user="$1"; shift
+ getent passwd "$user" >/dev/null ||
+ sudo adduser "$@" "$user"
+ }
rule_apt_get_install () { # SYNTAX: $package
- sudo DEBIAN_FRONTEND=noninteractive apt-get install "$@"
+ sudo DEBIAN_FRONTEND=noninteractive apt-get install --yes "$@"
}
rule_dpkg_reconfigure () { # SYNTAX: $package
sudo DEBIAN_FRONTEND=noninteractive dpkg-reconfigure "$@"
. /etc/profile
}
-rule_apache2_configure () {
+rule_apache2_configure () { # XXX: cette règle n'est pas testée/mise-à-jour
local -; set +f
rule apt_get_install \
apache2-mpm-itk \
# 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
+ sudo rm -rf \
+ /etc/apache2/site.d
+ sudo install -d -m 770 -o www -g www \
+ /etc/apache2 \
+ /etc/apache2/site.d \
+ /etc/apache2/x509.d
cat /dev/stdin "$tool"/etc/apache2/apache2.conf <<-EOF |
ServerName "$vm_fqdn"
EOF
/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 domain <<-EOF
- ${conf%\/VirtualHost\.conf}
- EOF
- assert 'test "${port:+set}"'
- assert 'test "${domain:+set}"'
- local site="$port.$domain"
- case $port in
- (443)
+ local site=${conf%/VirtualHost.conf}
+ case $site in
+ (*-tls)
local hint="run vm_remote apache2_key_send before"
assert "sudo test -f /etc/apache2/site.d/\"$site\"/x509/key.pem" hint
- sudo install -d -m 770 -o www."$site" -g www."$site" \
+ sudo install -d -m 770 -o www-"$site" -g www-"$site" \
/etc/apache2 \
/etc/apache2/site.d/"$site" \
- /etc/apache2/site.d/"$site"/x509 \
- /etc/apache2/site.d/"$site"/x509/ca \
- /etc/apache2/site.d/"$site"/x509/empty \
- /etc/apache2/site.d/"$site"/x509/rvk \
- /etc/apache2/site.d/"$site"/x509/usr
+ /etc/apache2/x509.d/"$site" \
+ /etc/apache2/x509.d/"$site"/ca \
+ /etc/apache2/x509.d/"$site"/empty \
+ /etc/apache2/x509.d/"$site"/rvk \
+ /etc/apache2/x509.d/"$site"/usr
sudo install -m 664 -o www -g www \
- "$tool"/var/pub/x509/"$site"/crt.self-signed.pem \
- /etc/apache2/site.d/"$site"/x509/crt.self-signed.pem
- #sudo install -m 664 -o www."$site" -g www."$site" \
+ "$tool"/var/pub/x509/"$site"/crt.self-signed.pem \
+ /etc/apache2/x509.d/"$site"/crt.self-signed.pem
+ #sudo install -m 664 -o www-"$site" -g www-"$site" \
# "$tool"/var/pub/x509/"$site"/rvk.pem \
- # /etc/apache2/site.d/"$site"/x509/rvk.pem
+ # /etc/apache2/x509.d/"$site"/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"/x509/ca/crt.pem
+ /etc/apache2/x509.d/"$site"/ca/crt.pem
sudo install -m 664 -o www -g www \
- "$tool"/var/pub/x509/"$site"/crt.pem \
- /etc/apache2/site.d/"$site"/x509/crt.pem
+ "$tool"/var/pub/x509/"$site"/crt.pem \
+ /etc/apache2/x509.d/"$site"/crt.pem
;;
esac
- case $port in
- (80)
- cat <<-EOF
- <VirtualHost *:$port>
- AssignUserID www.$site www.$site
- CustomLog "|/usr/sbin/rotatelogs /home/www/log/$site/apache2/access/%Y-%m-%d.log 86400 60" Combined
- #CustomLog "/dev/null" Combined
- DocumentRoot /home/www/pub/$site
- ErrorLog "|/usr/sbin/rotatelogs /home/www/log/$site/apache2/error/%Y-%m-%d.log 86400 60"
- #ErrorLog "/dev/null"
- ServerName $domain
- LogLevel Warn
- $(cat "$tool"/etc/apache2/site.d/"$site"/VirtualHost.conf)
- </VirtualHost>
- EOF
- ;;
- (443)
+ case $site in
+ (*-tls)
cat <<-EOF
<IfModule mod_ssl.c>
<VirtualHost *:$port>
- AssignUserID www.$site www.$site
+ AssignUserID www-$site www-$site
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/apache2/access/%Y-%m-%d.log 86400 60" Combined
ErrorLog "|/usr/sbin/rotatelogs /home/www/log/$site/apache2/error/%Y-%m-%d.log 86400 60"
#ErrorLog "/dev/null"
LogLevel Warn
- ServerName $domain
- SSLCACertificateFile /etc/apache2/site.d/$site/x509/crt.self-signed.pem
- SSLCACertificatePath /etc/apache2/site.d/$site/x509/usr/
- #SSLCARevocationFile /etc/apache2/site.d/$site/x509/rvk.pem
- SSLCADNRequestFile /etc/apache2/site.d/$site/x509/crt.self-signed.pem
- SSLCADNRequestPath /etc/apache2/site.d/$site/x509/empty/
+ SSLCACertificateFile /etc/apache2/x509.d/$site/crt.self-signed.pem
+ SSLCACertificatePath /etc/apache2/x509.d/$site/usr/
+ #SSLCARevocationFile /etc/apache2/x509.d/$site/rvk.pem
+ SSLCADNRequestFile /etc/apache2/x509.d/$site/crt.self-signed.pem
+ SSLCADNRequestPath /etc/apache2/x509.d/$site/empty/
# NOTE: ne publie pas les certificats d’utilisateur-ice-s acceptés
- SSLCARevocationPath /etc/apache2/site.d/$site/x509/rvk/
- SSLCertificateChainFile /etc/apache2/site.d/$site/x509/ca/crt.pem
- SSLCertificateFile /etc/apache2/site.d/$site/x509/crt.pem
- SSLCertificateKeyFile /etc/apache2/site.d/$site/x509/key.pem
+ SSLCARevocationPath /etc/apache2/x509.d/$site/rvk/
+ SSLCertificateChainFile /etc/apache2/x509.d/$site/ca/crt.pem
+ SSLCertificateFile /etc/apache2/x509.d/$site/crt.pem
+ SSLCertificateKeyFile /etc/apache2/x509.d/$site/key.pem
SSLCipherSuite AES+RSA+SHA256
SSLEngine On
SSLInsecureRenegotiation Off
</IfModule>
EOF
;;
+ (*)
+ cat <<-EOF
+ <VirtualHost *:$port>
+ AssignUserID www-$site www-$site
+ CustomLog "|/usr/sbin/rotatelogs /home/www/log/$site/apache2/access/%Y-%m-%d.log 86400 60" Combined
+ #CustomLog "/dev/null" Combined
+ DocumentRoot /home/www/pub/$site
+ ErrorLog "|/usr/sbin/rotatelogs /home/www/log/$site/apache2/error/%Y-%m-%d.log 86400 60"
+ #ErrorLog "/dev/null"
+ LogLevel Warn
+ $(cat "$tool"/etc/apache2/site.d/"$site"/VirtualHost.conf)
+ </VirtualHost>
+ EOF
+ ;;
esac |
sudo install -m 660 -o root -g root /dev/stdin \
/etc/apache2/site.d/"$site"/VirtualHost.conf
sudo ln -fns \
../site.d/"$site"/VirtualHost.conf \
/etc/apache2/sites-available/"$site"
- sudo install -d -m 770 -o www."$site" -g www."$site" \
+ sudo install -d -m 770 -o www-"$site" -g www-"$site" \
/home/www/log/"$site" \
/home/www/log/"$site"/apache2
sudo ln -fns \
/etc/apache2/site.d/"$site" \
/home/www/etc/apache2/"$site"
test -e /home/www/pub/"$site" ||
- sudo install -d -m 770 -o www."$site" -g www."$site" \
+ sudo install -d -m 2770 -o www-"$site" -g www-"$site" \
/home/www/pub/"$site"
- getent passwd www."$site" >/dev/null ||
- sudo adduser \
+ rule adduser www-"$site"
--disabled-password \
--group \
--no-create-home \
--home /home/www/pub/"$site" \
--shell /bin/false \
- --system \
- www."$site"
- #sudo setfacl -m u:"www.$site":--x \
+ --system
+ #sudo setfacl -m u:"www-$site":--x \
# /home/www/ \
# /home/www/pub/ \
# /home/www/pub/"$site"/
- #sudo setfacl -m d:u:"www.$site":rwx \
+ #sudo setfacl -m d:u:"www-$site":rwx \
# "$home"/pub/www/"$site"/
test ! -r "$tool"/etc/apache2/site.d/"$site"/configure.sh ||
. "$tool"/etc/apache2/site.d/"$site"/configure.sh
}
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
+ deb http://ftp.rezopole.net/debian $vm_lsb_name main
EOF
- sudo install -m 660 -o root -g root /dev/stdin /etc/apt/$vm_lsb_name-backports.list <<-EOF
- #deb http://backports.debian.org/debian-backports $vm_lsb_name-backports main contrib non-free
+ sudo install -m 660 -o root -g root /dev/stdin /etc/apt/sources.list.d/$vm_lsb_name-backports.list <<-EOF
+ deb http://ftp.rezopole.net/debian $vm_lsb_name-backports main
EOF
sudo install -m 660 -o root -g root /dev/stdin /etc/apt/preferences <<-EOF
Package: *
Pin: release a=$vm_lsb_name
- Pin-Priority: 170
+ Pin-Priority: 200
Package: *
Pin: release a=$vm_lsb_name-backports
- Pin-Priority: 200
+ Pin-Priority: 170
EOF
sudo apt-get update
rule apt_get_install apticron
local hint="run vm_remote dovecot_key_send before"
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/$vm_domainname/imap/crt+crl.self-signed.pem \
- /etc/dovecot/$vm_domainname/imap/x509/crt+crl.self-signed.pem
+ "$tool"/var/pub/x509/imap."$vm_domainname"/crt+crl.self-signed.pem \
+ /etc/dovecot/"$vm_domainname"/imap/x509/crt+crl.self-signed.pem
sudo install -d -m 770 -o root -g root \
/etc/skel/etc/mail \
/etc/skel/etc/sieve
$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 \
sudo update-initramfs -u
}
rule_gitolite_configure () {
- local user=git
sudo debconf-set-selections <<-EOF
- gitolite gitolite/gituser string $user
+ gitolite gitolite/gituser string git
gitolite gitolite/adminkey string
- gitolite gitolite/gitdir string /home/$user
+ gitolite gitolite/gitdir string /home/git
EOF
rule apt_get_install gitolite
- getent passwd "$user" >/dev/null ||
- sudo adduser \
+ rule adduser git \
--disabled-password \
--group \
+ --home /home/git \
--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" \
+ --system
+ sudo chfn --full-name git git
+ rule adduser log-git \
+ --disabled-login \
+ --disabled-password \
+ --group \
+ --home /home/git/log \
+ --shell /bin/false \
+ --system
+ rule adduser git-data \
+ --disabled-login \
+ --disabled-password \
+ --group \
+ --home /home/git/pub \
+ --shell /bin/false \
+ --system
+ sudo adduser git git-data
+ sudo install -d -m 770 -o git -g git \
/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
+ /home/git/etc \
+ /home/git/etc/ssh
+ sudo install -d -m 751 -o git -g git \
+ /home/git
+ sudo install -d -m 2770 -o git-data -g git-data \
+ /home/git/pub
+ sudo install -d -m 1771 -o git -g git \
+ /home/git/log
+ sudo install -d -m 2770 -o git -g log-git \
+ /home/git/log/gitolite \
+ /home/git/log/gitolite/perf
+ sudo install -d -m 3771 -o git -g git \
+ /home/git/hooks
+ sudo ln -fns /etc/gitolite /home/git/etc/gitolite
+ sudo ln -fns /etc/gitweb /home/git/etc/gitweb
+ sudo ln -fns etc/gitolite/gitolite.rc /home/git/.gitolite.rc
+ sudo ln -fns etc/ssh /home/git/.ssh
+ sudo install -m 770 -o git -g git /dev/stdin \
+ /home/git/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';
\$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";
#\$GL_WILDREPOS_DEFPERMS = 'R @all';
\$GL_WILDREPOS_PERM_CATS = "READERS WRITERS";
\$HTPASSWD_FILE = "";
- \$PROJECTS_LIST = \$ENV{HOME} . "/projects.list";
+ \$PROJECTS_LIST = \$ENV{HOME} . "/etc/gitweb/projects.list";
\$REPO_BASE = "pub";
\$REPO_UMASK = 0007;
\$RSYNC_BASE = "";
\$SVNSERVE = "";
#\$UPDATE_CHAINS_TO = "hooks/update.secondary";
- #\$WEB_INTERFACE = "gitweb";
+ \$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"
+ sudo install -m 600 -o git -g git \
+ "$tool"/var/pub/ssh/git.key \
+ /home/git/etc/ssh/git.pub
+ sudo -u git \
+ GL_RC=/home/git/etc/gitolite/gitolite.rc \
+ GIT_AUTHOR_NAME=git \
+ gl-setup -q /home/git/etc/ssh/git.pub git
local d
for d in doc logs src
- do test ! -d "$home"/etc/gitolite/"$d" ||
- rmdir "$home"/etc/gitolite/"$d"
+ do test ! -d /home/git/etc/gitolite/"$d" ||
+ rmdir /home/git/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
+ sudo service tmpfs restart
}
rule_locales_configure () {
sudo debconf-set-selections <<-EOF
}
rule_mysql_configure () {
rule apt_get_install mysql-server-5.5
- sudo service mysql restart
+ rule adduser mysql \
+ --disabled-login \
+ --disabled-password \
+ --group \
+ --home /home/mysql \
+ --shell /bin/false \
+ --system
+ rule adduser mysql-data \
+ --disabled-login \
+ --disabled-password \
+ --group \
+ --home /home/mysql/data \
+ --no-create-home \
+ --shell /bin/false \
+ --system
+ sudo usermod --home /home/mysql mysql
+ sudo adduser mysql mysql-data
+ sudo install -m 644 -o mysql -g mysql \
+ "$tool"/etc/mysql/my.cnf \
+ /etc/mysql/my.cnf
+ sudo install -d -m 751 -o mysql -g mysql \
+ /home/mysql
+ sudo rm -rf /etc/mysql
+ sudo install -d -m 750 -o mysql -g mysql \
+ /etc/mysql \
+ /home/mysql/etc
+ sudo ln -fns \
+ /etc/mysql \
+ /home/mysql/etc/mysql
+ if sudo test ! -d /home/mysql/data
+ then
+ sudo install -d -m 750 -o mysql -g mysql-data \
+ /home/mysql/data
+ sudo -u mysql mysql_install_db \
+ --datadir=/home/mysql/data \
+ --no-defaults
+ fi
+ sudo service tmpfs restart
+ sudo insserv -r mysql
+ sudo chmod ugo-x /etc/init.d/mysql
+ case $(sudo sv status mysql || true) in
+ (''|run:*|*"s, normally up;"*)
+ sudo sv restart mysql
+ case $(sudo inotifywait -e create -- /run/mysqld/sock/) in
+ ("/run/mysqld/sock/ CREATE mysql")
+ # NOTE:
+ # - ajoute l'accès par socket Unix à mysql
+ # - ajoute les droits de super-utilisateur à mysql
+ # - supprime l'accès par mot-de-passe à root
+ # - supprime les bases de données de l'utilisateurice anonyme
+ # - supprime l'utilisateurice anonyme
+ # NOTE: mémo :
+ # GRANT USAGE ON *.* TO 'root'@'*' IDENTIFIED WITH auth_socket;
+ # CREATE USER 'root'@'localhost' IDENTIFIED WITH auth_socket;
+ # UPDATE mysql.user SET Password='' WHERE user='root';
+ # DELETE FROM mysql.user WHERE user = 'root' AND host NOT IN ('localhost', '127.0.0.1', '::1');
+ sudo mysql -u root --batch --verbose <<-EOF
+ DELETE FROM mysql.user WHERE user = 'root' and plugin = '';
+ GRANT ALL PRIVILEGES ON *.* TO 'mysql'@'localhost' IDENTIFIED WITH auth_socket;
+ UPDATE mysql.user SET grant_priv='Y',super_priv='Y' WHERE user='mysql';
+ DELETE FROM mysql.db WHERE user = '';
+ DELETE FROM mysql.user WHERE user = '';
+ FLUSH PRIVILEGES;
+ EOF
+ ;;
+ esac
+ esac
+ }
+rule_mysql_db_add () { # SYNTAX: $user $db
+ sudo -u mysql mysql --batch <<-EOF
+ DROP DATABASE IF EXISTS $db;
+ CREATE DATABASE $db CHARACTER SET utf8 COLLATE utf8_general_ci;
+ GRANT ALL PRIVILEGES ON $base.* TO '$user'@'localhost' IDENTIFIED WITH auth_socket;
+ FLUSH PRIVILEGES;
+ EOF
+ }
+rule_mysql_user_add () { # SYNTAX: $user
+ sudo mysql -u mysql --batch <<-EOF || true
+ DROP USER '$user'@'localhost';
+ EOF
+ sudo mysql -u mysql --batch <<-EOF
+ CREATE USER '$user'@'localhost' IDENTIFIED WITH auth_socket;
+ EOF
}
rule_network_configure () {
sudo install -m 644 -o root -g root /dev/stdin /etc/hostname <<-EOF
$(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
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
+ /etc/nginx/site.d \
+ /etc/nginx/x509.d
sudo ln -fns \
/etc/nginx \
/home/www/etc/nginx
"$tool"/etc/nginx/conf.d/"$conf" \
/etc/nginx/conf.d/"$conf"
done
- for conf in "$tool"/etc/nginx/site.d/*/server.conf
+ for conf in "$tool"/etc/nginx/site.d/*/site.conf
do conf=${conf#"$tool"/etc/nginx/site.d/}
- local port domain
- IFS=. read -r port domain <<-EOF
- ${conf%\/server\.conf}
- EOF
- assert 'test "${port:+set}"'
- assert 'test "${domain:+set}"'
- local site="$port.$domain"
- getent passwd www."$site" >/dev/null ||
- sudo adduser \
+ local site="${conf%/site.conf}"
+ rule adduser www-"$site" \
--disabled-login \
--disabled-password \
--group \
- --home ~www-data/"$site" \
+ --home /home/www/pub/"$site" \
--shell /bin/false \
- --system \
- www."$site"
- getent passwd log."$site" >/dev/null ||
- sudo adduser \
+ --system
+ rule adduser log-www-"$site" \
--disabled-login \
--disabled-password \
--group \
+ --home /home/www/log/"$site"/nginx \
--shell /bin/false \
- --system \
- log."$site"
- sudo usermod --home ~www/log/"$site"/nginx log."$site"
+ --system
+ sudo install -d -m 771 -o log-www -g log-www \
+ /home/www/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 $domain;
- $(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 $domain;
- # 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 www."$site"
- test -e /home/www/pub/"$site" ||
- sudo install -d -m 3770 -o www."$site" -g www."$site" \
+ sudo install -d -m 770 -o www -g www \
+ /etc/nginx/x509.d/"$site"
+ test -L /home/www/pub/"$site" ||
+ sudo install -d -m 2770 -o www-"$site" -g www-"$site" \
/home/www/pub/"$site"
- sudo install -d -m 3770 -o log."$site" -g log."$site" \
- /home/www/log/"$site"/nginx
+ sudo adduser www-data www-"$site"
+ sudo adduser www-data log-www-"$site"
+ sudo install -m 660 -o www -g www \
+ "$tool"/etc/nginx/site.d/"$site"/local.conf \
+ /etc/nginx/site.d/"$site"/local.inc
+ sudo install -m 660 -o www -g www \
+ "$tool"/etc/nginx/site.d/"$site"/site.conf \
+ /etc/nginx/site.d/"$site"/site.inc
+ sudo install -m 660 -o www -g www /dev/stdin \
+ /etc/nginx/site.d/"$site"/server.conf <<-EOF
+ server {
+ 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;
+ include /etc/nginx/site.d/$site/local.inc;
+ include /etc/nginx/site.d/$site/site.inc;
+ }
+ EOF
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
+ sudo chmod ugo-x /etc/init.d/fcgiwrap
+ #sudo insserv --remove nginx
+ #sudo chmod ugo-x /etc/init.d/nginx
rule tmpfs_configure
+ sudo service php5-fpm restart
+ # NOTE: relance les processus du pool
+ # pour leur donner les droits
+ # 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 nsdc rebuild
+ sudo service nsd3 restart
+ }
rule_php5_fpm_configure () {
local -; set +f
rule apt_get_install \
php5-fpm \
php-apc
- getent passwd php5 >/dev/null ||
- sudo adduser \
+ rule adduser php5 \
--disabled-login \
--disabled-password \
--group \
+ --home /etc/php5/fpm \
--shell /bin/false \
- --system \
- php5
- local conf
+ --system
+ rule adduser log-php5 \
+ --disabled-login \
+ --disabled-password \
+ --group \
+ --home /home/www/log/php5/fpm \
+ --shell /bin/false \
+ --system
sudo ln -fns \
- /etc/php5-fpm \
+ /etc/php5/fpm \
/home/www/etc/php5
- sudo rm -f /etc/php5/fpm/pool.d/*
+ sudo rm -rf \
+ /etc/php5/fpm/conf.d \
+ /etc/php5/fpm/pool.d
+ sudo install -d -m 770 -o php5 -g php5 \
+ /etc/php5/fpm/conf.d \
+ /etc/php5/fpm/pool.d
+ sudo install -m 770 -o php5 -g php5 \
+ "$tool"/etc/php5/fpm/php-fpm.conf \
+ /etc/php5/fpm/php-fpm.conf
+ local conf
+ #for conf in "$tool"/etc/php5/fpm/conf.d/*.conf
+ # do conf=${conf#"$tool"/etc/php5/fpm/conf.d/}
+ # sudo install -m 660 -o php5 -g php5 \
+ # "$tool"/etc/php5/fpm/conf.d/"$conf" \
+ # /etc/php5/fpm/conf.d/"$conf"
+ # done
for conf in "$tool"/etc/php5/fpm/pool.d/*.conf
do conf=${conf#"$tool"/etc/php5/fpm/pool.d/}
- local port domain
- IFS=. read -r port domain <<-EOF
- ${conf%\.conf}
+ IFS=. read -r pool <<-EOF
+ ${conf%.conf}
EOF
- assert 'test "${port:+set}"'
- assert 'test "${domain:+set}"'
- local site="$port.$domain"
- getent passwd php5."$site" >/dev/null ||
- sudo adduser \
+ assert 'test "${pool:+set}"'
+ rule adduser php5-"$pool" \
+ --disabled-login \
+ --disabled-password \
+ --group \
+ --no-create-home \
+ --home /etc/php5/fpm/pool.d \
+ --shell /bin/false \
+ --system
+ rule adduser log-php5-"$pool" \
--disabled-login \
--disabled-password \
--group \
--no-create-home \
- --home ~www/pub/"$site" \
+ --home /home/www/log/php5/fpm/"$pool" \
--shell /bin/false \
- --system \
- php5."$site"
- sudo install -d -m 770 -o php5 -g php5 \
+ --system
+ sudo install -d -m 770 -o log-php5 -g log-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."$site" 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
+ sudo install -d -m 770 -o log-php5-"$pool" -g log-php5-"$pool" \
+ /home/www/log/php5/fpm/"$pool"
+ sudo install -m 660 -o php5 -g php5 /dev/stdin \
+ /etc/php5/fpm/pool.d/"$pool".conf <<-EOF
+ [$pool]
+ access.log = /home/www/log/php5/fpm/$pool/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
+ group = php5-$pool
#listen = 127.0.0.1:9000
+ listen = /run/php5/fpm/$pool
#listen.allowed_clients = 127.0.0.1
+ listen.group = www-data
+ listen.mode = 0660
+ #listen.owner = www-data
listen.backlog = -1
pm = dynamic
pm.max_children = 5
request_terminate_timeout = 120s
rlimit_core = unlimited
rlimit_files = 131072
- slowlog = /home/www/log/$site/php5/fpm/slow.log
- user = $php5_user
+ slowlog = /home/www/log/php5/fpm/$pool/slow.log
+ user = php5-$pool
$(cat "$tool"/etc/php5/fpm/pool.d/"$conf")
EOF
- sudo install -m 664 -o root -g root \
+ sudo install -m 664 -o php5 -g php5 \
"$tool"/etc/php5/fpm/php.ini \
/etc/php5/fpm/php.ini
+ case $(sudo sv status php5-"$pool") in
+ (run:*) sudo sv restart php5-"$pool"
+ esac
done
rule tmpfs_configure
sudo service php5-fpm restart
../crt+crl.self-signed.pem \
/etc/postfix/$vm_domainname/smtpd/x509/ca/crt.pem
sudo install -m 400 -o root -g root \
- "$tool"/var/pub/x509/smptd.$vm_domainname/crt+crl.self-signed.pem \
+ "$tool"/var/pub/x509/smtpd.$vm_domainname/crt+crl.self-signed.pem \
/etc/postfix/$vm_domainname/smtpd/x509/crt+crl.self-signed.pem
sudo install -m 400 -o root -g root \
- "$tool"/var/pub/x509/smptd.$vm_domainname/crt.pem \
+ "$tool"/var/pub/x509/smtpd.$vm_domainname/crt.pem \
/etc/postfix/$vm_domainname/smtpd/x509/crt.pem
sudo install -m 400 -o root -g root \
- "$tool"/var/pub/x509/smptd.$vm_domainname/crt+ca.pem \
+ "$tool"/var/pub/x509/smtpd.$vm_domainname/crt+ca.pem \
/etc/postfix/$vm_domainname/smtpd/x509/crt+ca.pem
sudo install -m 400 -o root -g root \
- "$tool"/var/pub/x509/smptd.$vm_domainname/crt+crl.self-signed.pem \
+ "$tool"/var/pub/x509/smtpd.$vm_domainname/crt+crl.self-signed.pem \
/etc/postfix/$vm_domainname/smtpd/x509/crt+crl.self-signed.pem
sudo install -m 660 -o root -g root \
"$tool"/etc/postfix/$vm_domainname/header_checks \
abuse: root
admin: root
contact: root
+ mailer-daemon: root
postmaster: root
root: $(getent group sudo | cut -f 4 -d : | tr , ' ')
EOF
sudo service postfix restart
}
rule_postgresql_configure () {
+ # DOC: http://wiki.postgresql.org/wiki/Shared_Database_Hosting
rule apt_get_install postgresql-9.1
- if [ ! -d /var/lib/postgresql/9.1/ ]; then
- pg_createcluster -u postgres --start 9.1 main
- fi
- sudo install -m 660 -o root -g root \
- "$tool"/etc/postgresql/9.1/main/postgresql.conf \
- /etc/postgresql/9.1/main/postgresql.conf
- sudo service postgresql restart
+ rule adduser postgres \
+ --disabled-login \
+ --disabled-password \
+ --group \
+ --home /home/postgresql \
+ --shell /bin/false \
+ --system
+ rule adduser postgres-data \
+ --disabled-login \
+ --disabled-password \
+ --group \
+ --home /home/postgresql/data \
+ --no-create-home \
+ --shell /bin/false \
+ --system
+ sudo usermod --home /home/postgresql postgres
+ sudo adduser postgres postgres-data
+ sudo rm -rf \
+ /etc/postgresql
+ sudo install -d -m 750 -o postgres -g postgres \
+ /home/postgresql \
+ /home/postgresql/etc \
+ /etc/postgresql \
+ /etc/postgresql/9.1 \
+ /etc/postgresql/9.1/main
+ sudo ln -fns \
+ /etc/postgresql \
+ /home/postgresql/etc/postgresql
+ sudo install -d -m 751 -o postgres -g postgres \
+ /home/postgresql/log \
+ /home/postgresql/log/9.1
+ sudo service tmpfs restart
+ if sudo test ! -d /home/postgresql/data
+ then
+ sudo install -d -m 750 -o postgres -g postgres \
+ /home/postgresql/data
+ (
+ cd /
+ sudo -u postgres pg_createcluster \
+ --datadir=/home/postgresql/data \
+ --logfile=/home/postgresql/log/9.1/main \
+ --socketdir=/run/postgresql/sock \
+ --start 9.1 main
+ )
+ fi
+ sudo install -m 770 -o postgres -g postgres /dev/stdin \
+ /etc/postgresql/9.1/main/pg_hba.conf <<-EOF
+ local all postgres peer
+ local all all peer
+ EOF
+ sudo install -m 660 -o postgres -g postgres \
+ "$tool"/etc/postgresql/9.1/main/postgresql.conf \
+ /etc/postgresql/9.1/main/postgresql.conf
+ sudo insserv -r postgresql
+ sudo chmod ugo-x /etc/init.d/postgresql
+ case $(sudo sv status postgres || true) in
+ (''|run:*|*"s, normally up;"*)
+ sudo sv restart postgres
+ (
+ cd /
+ case $(sudo inotifywait -e create -- /run/postgresql/sock/) in
+ ("/run/postgresql/sock/ CREATE .s.PGSQL."*)
+ # NOTE:
+ # - supprime l'accès au schéma public depuis public,
+ # de sorte à ce que les différents utilisateurices
+ # ne voient pas leurs bases de données entre-elleux ;
+ # - ajoute le support de PL/PGSQL.
+ sudo -u postgres psql template1 -f - <<-EOF
+ REVOKE ALL ON DATABASE template1 FROM public;
+ REVOKE ALL ON SCHEMA public FROM public;
+ GRANT ALL ON SCHEMA public TO postgres;
+ CREATE LANGUAGE plpgsql;
+ EOF
+ # NOTE:
+ # - supprime l'accès à la liste des bases données
+ # et utilisateurices depuis public.
+ sudo -u postgres psql template1 -f - <<-EOF
+ REVOKE ALL ON pg_auth_members FROM public;
+ REVOKE ALL ON pg_authid FROM public;
+ REVOKE ALL ON pg_database FROM public;
+ REVOKE ALL ON pg_group FROM public;
+ REVOKE ALL ON pg_roles FROM public;
+ REVOKE ALL ON pg_settings FROM public;
+ REVOKE ALL ON pg_tablespace FROM public;
+ REVOKE ALL ON pg_user FROM public;
+ EOF
+ ;;
+ esac
+ )
+ ;;
+ esac
+ }
+rule_postgresql_db_add () { # SYNTAX: $db $db_user
+ local db="$1" db_user="$2"
+ sudo -u postgresql psql template1 -f - <<-EOF
+ CREATE ROLE $db NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT NOLOGIN;
+ CREATE ROLE $db_user NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT LOGIN ENCRYPTED;
+ GRANT $db TO $db_user;
+ CREATE DATABASE $db WITH OWNER=$db_user;
+ REVOKE ALL ON DATABASE $db FROM public;
+ EOF
+ }
+rule_postgresql_db_user_add () { # SYNTAX: $db $user
+ local db="$1" user="$2"
+ sudo -u postgresql psql template1 -f - <<-EOF
+ CREATE ROLE $user NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT LOGIN ENCRYPTED;
+ GRANT USAGE ON SCHEMA public TO $user;
+ GRANT CONNECT,TEMPORARY ON DATABASE $db TO $user;
+ GRANT $db TO $user;
+ EOF
}
rule_openerp_configure () {
sudo install -m 660 -o root -g root /dev/stdin /etc/apt/sources.list.d/openerp.list <<-EOF
"$tool"/etc/skel/etc/mail/delivery.procmailrc \
/etc/skel/etc/mail/delivery.procmailrc
}
-rule_runit_configure () {
+rule_runit_configure () { # SYNTAX: $service
rule apt_get_install runit
local -; set +f
- rm -f /etc/service/*
- # NOTE: runsvdir éteindra les services qui n'apparaîtront plus ici.
- for sv in "$tool"/etc/sv/*
- do sv=${sv#"$tool"/etc/sv/}
+ for sv in ${1-/etc/service/*}
+ # NOTE: stoppe les services en retenant leur status de départ
+ do sv=$(basename "$sv")
+ local sv_hash=$(printf %s "$sv" | sha1sum | cut -f 1 -d ' ')
+ local sv_status
+ IFS= read -r sv_status_$sv_hash <<-EOF
+ $(sudo sv status "$sv")
+ EOF
+ sudo rm -f /etc/service/"$sv"
+ done
+ for sv in ${1-"$tool"/etc/sv/*}
+ # NOTE: configure et (re-)démarre les services
+ do sv=$(basename "$sv")
+ local sv_hash=$(printf %s "$sv" | sha1sum | cut -f 1 -d ' ')
sudo install -d -m 770 -o root -g root \
/etc/sv/"$sv"
sudo install -m 770 -o root -g root \
"$tool"/etc/sv/"$sv"/log/run \
/etc/sv/"$sv"/log/run
fi
- if test ! -x "$tool"/etc/sv/"$sv"/configure ||
- "$tool"/etc/sv/"$sv"/configure
- then
- ln -fns ../sv/"$sv" /etc/service/"$sv"
- sv restart "$sv"
- fi
+ test ! -r "$tool"/etc/sv/"$sv"/configure.sh ||
+ . "$tool"/etc/sv/"$sv"/configure.sh
+ sudo ln -fns ../sv/"$sv" /etc/service/"$sv"
+ eval local sv_status=\"\${sv_status_$sv_hash-}\"
+ case $sv_status in
+ ("") true;;
+ (run:*) sudo sv restart "$sv";;
+ esac
done
}
rule_ssh_configure () {
/etc/ssh/ssh_host_ecdsa_key \
/etc/ssh/ssh_host_ecdsa_key.pub
# NOTE: clefs générées par Debian
- sudo install -m 644 -o root -g root /dev/stdin /etc/ssh/sshd_config <<-EOF
- Port 22
- ListenAddress $vm_ipv4
- #ListenAddress ::
- Protocol 2
+ sudo install -m 644 -o root -g root /dev/stdin /etc/ssh/sshd_config <<-EOF
+ AcceptEnv LANG LC_*
+ AuthorizedKeysFile %h/etc/ssh/authorized_keys
+ ChallengeResponseAuthentication no
+ ClientAliveInterval 0
Compression yes
+ DebianBanner no
+ GSSAPIAuthentication no
HostKey /etc/ssh/ssh_host_rsa_key
- UsePrivilegeSeparation yes
+ HostbasedAuthentication no
+ IgnoreRhosts yes
+ IgnoreUserKnownHosts no
+ KerberosAuthentication no
KeyRegenerationInterval 3600
- ServerKeyBits 768
- SyslogFacility AUTH
+ Port 22
+ ListenAddress 127.0.0.1
+ ListenAddress $vm_ipv4
LogLevel INFO
LoginGraceTime 120
+ PasswordAuthentication no
+ PermitEmptyPasswords no
PermitRootLogin yes
- StrictModes yes
- RSAAuthentication yes
+ PrintLastLog yes
+ PrintMotd no
+ Protocol 2
PubkeyAuthentication yes
- AuthorizedKeysFile %h/etc/ssh/authorized_keys
- IgnoreRhosts yes
+ RSAAuthentication yes
RhostsRSAAuthentication no
- HostbasedAuthentication no
- IgnoreUserKnownHosts no
- PermitEmptyPasswords no
- ChallengeResponseAuthentication no
- PasswordAuthentication no
- KerberosAuthentication no
- GSSAPIAuthentication no
- X11Forwarding no
- X11DisplayOffset 10
- PrintMotd no
- DebianBanner no
- PrintLastLog yes
- TCPKeepAlive yes
- ClientAliveInterval 0
- AcceptEnv LANG LC_*
+ ServerKeyBits 768
+ StrictModes yes
Subsystem sftp /usr/lib/openssh/sftp-server
+ SyslogFacility AUTH
+ TCPKeepAlive yes
UsePAM yes
+ UsePrivilegeSeparation yes
+ X11DisplayOffset 10
+ X11Forwarding no
+ EOF
+ sudo install -m 644 -o root -g root /dev/stdin /etc/ssh/ssh_config <<-EOF
+ Host *
+ #Compression yes
+ #CompressionLevel 9
+ #ControlMaster auto
+ #ControlPath ~/var/run/ssh/sock/%h-%p-%r
+ GSSAPIAuthentication no
+ GSSAPIDelegateCredentials no
+ HashKnownHosts yes
+ IdentityFile ~/etc/ssh/id_dsa
+ IdentityFile ~/etc/ssh/id_rsa
+ IdentityFile ~/etc/ssh/identity
+ SendEnv LANG LC_*
+ StrictHostKeyChecking ask
+ UserKnownHostsFile ~/etc/ssh/known_hosts
EOF
sudo service ssh restart
}
"$tool"/etc/init.d/tmpfs \
/etc/init.d/tmpfs
sudo update-rc.d tmpfs defaults
+ sudo service tmpfs restart
}
rule_time_configure () {
sudo install -m 644 -o root -g root /dev/stdin /etc/timezone <<-EOF
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
- getent passwd "$user" >/dev/null ||
- sudo adduser --disabled-password "$user"
+ rule adduser "$user" --disabled-password
# 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
done
}
rule_user_configure () {
+ rule apt_get_install bash-completion
sudo install -m 660 -o root -g root /dev/stdin \
/etc/adduser.conf <<-EOF
ADD_EXTRA_GROUPS=1
LAST_SYSTEM_UID=999
LAST_UID=29999
LETTERHOMES=no
- NAME_REGEX="^[a-z][-a-z0-9_.]*\$"
+ NAME_REGEX="^[a-z][-a-z0-9_]*\$"
QUOTAUSER="" # TODO: init
SETGID_HOME=no
SKEL=/etc/skel
USERGROUPS=yes
USERS_GID=100
EOF
- }
-rule_user_admin_add () { # SYNTAX: $user
- rule user_configure
- local user=$1
- getent passwd "$user" >/dev/null ||
- sudo adduser --disabled-password "$user"
- eval local home\; home="~$user"
- sudo adduser "$user" sudo
- 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_admin_configure
- }
-rule_user_admin_configure () {
- rule initramfs_configure
- rule user_root_configure
- }
-rule_user_configure () {
sudo install -d -m 750 -o root -g root \
/etc/skel \
/etc/skel/etc \
("\$SUDO_USER L "*) /usr/bin/passwd \$SUDO_USER;; esac
EOF
sudo install -m 640 -o root -g root /dev/stdin /etc/sudoers.d/etckeeper-unclean <<-EOF
- %sudo ALL=(ALL) NOPASSWD: /usr/sbin/etckeeper unclean
+ %sudo ALL=(ALL) NOPASSWD: /usr/bin/etckeeper unclean
EOF
sudo install -m 640 -o root -g root /dev/stdin /etc/sudoers.d/env_keep <<-EOF
Defaults env_keep = " \\
"$tool"/etc/screenrc \
/etc/screenrc
}
+rule_user_admin_add () { # SYNTAX: $user
+ rule user_configure
+ local user=$1
+ rule adduser "$user" --disabled-password
+ eval local home\; home="~$user"
+ sudo adduser "$user" sudo
+ 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_admin_configure
+ }
+rule_user_admin_configure () {
+ rule initramfs_configure
+ rule user_root_configure
+ }
rule_user_root_configure () {
sudo install -d -m 750 -o root -g root \
/root/etc \
$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
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
rule sysctl_configure
rule user_configure
rule mail_configure
- #rule apache2_configure
- rule nginx_configure
- rule php5_fpm_configure
rule gitolite_configure
+ rule www_configure
+ rule php5_fpm_configure
+ rule nginx_configure
+ #rule apache2_configure
+ rule nsd3_configure
rule runit_configure
}