commit f78b030c72daa495a97b94ca7e555cc0f4dcf815
Author: espiv <servers@espiv.net>
Date:   Mon Dec 29 01:41:07 2014 +0200

    Add mirror class
    
    Creates necessary configuration files for nginx/apache2 and adds
    a new cron entry for syncing.

diff --git a/manifests/mirror.pp b/manifests/mirror.pp
new file mode 100644
index 0000000..660ae0c
--- /dev/null
+++ b/manifests/mirror.pp
@@ -0,0 +1,41 @@
+#
+# Don't include this class directly, use either
+# tails::mirror::nginx or tails::mirror::apache2
+#
+# This class creates the cron rsync entry and the mirror
+# path
+
+class tails::mirror (
+  $ensure='present',
+  $mirror_path='/var/www/tails-mirror/',
+) {
+
+  if !defined(Package['rsync']) {
+    package { 'rsync': ensure => $ensure }
+  }
+
+  if $ensure == 'present' {
+    $dir_ensure = 'directory'
+  } elsif $ensure == 'absent' {
+    $dir_ensure = 'absent'
+  }
+
+  file { $mirror_path :
+    ensure  => $dir_ensure,
+    mode    => '0755',
+    owner   => 'www-data',
+    group   => 'www-data',
+    force   => true,
+    content => template('tails/mirror/mirror_cron.erb'),
+  }
+
+  file { '/etc/cron.d/tails' :
+    ensure  => $ensure,
+    mode    => '0644',
+    owner   => root,
+    group   => root,
+    content => template('tails/mirror/mirror_cron.erb'),
+    require => File[$mirror_path]
+  }
+
+}
diff --git a/manifests/mirror/apache2.pp b/manifests/mirror/apache2.pp
new file mode 100644
index 0000000..5ff4bf3
--- /dev/null
+++ b/manifests/mirror/apache2.pp
@@ -0,0 +1,39 @@
+#
+# Notes:
+# It does not uninstall package apache2.2-bin when ensure is
+# set to absent in case it's also used by other vhosts.
+# Notifying service apache2 is commented out since it's not
+# required as a dependency
+
+class tails::mirror::apache2 (
+  $ensure = 'present',
+  $mirror_path='/var/www/tails-mirror/',
+  $admin_mail = '',
+) {
+
+  class {'tails::mirror':
+    ensure      => $ensure,
+    mirror_path => $mirror_path
+  }
+
+  if !defined(Package['apache2.2-bin']) {
+    package { 'apache2.2-bin': ensure => 'present' }
+  }
+
+  # mirror file
+  file { '/etc/apache2/sites-available/dl.amnesia.boum.org':
+    ensure  => $ensure,
+    mode    => '0644',
+    owner   => root,
+    group   => root,
+    content => template('tails/mirror/apache/dl.amnesia.boum.org.erb'),
+  }
+
+  file { '/etc/apache2/sites-enabled/dl.amnesia.boum.org':
+    ensure  => 'link',
+    target  => '/etc/apache2/sites-available/dl.amnesia.boum.org',
+    require => File['/etc/apache2/sites-available/dl.amnesia.boum.org'],
+    #notify  => Service['apache2'],
+  }
+
+}
diff --git a/manifests/mirror/nginx.pp b/manifests/mirror/nginx.pp
new file mode 100644
index 0000000..75f68a1
--- /dev/null
+++ b/manifests/mirror/nginx.pp
@@ -0,0 +1,40 @@
+#
+# Notes:
+# Installs package nginx-light which might conflict with some already
+# installed nginx flavor. Change package name if needed.
+# This class does not uninstall package nginx-light when ensure is
+# set to absent in case it's also used by other vhosts.
+# Notifying service nginx is commented out since it's not
+# required as a dependency
+
+class tails::mirror::nginx (
+  $ensure = 'present',
+  $mirror_path='/var/www/tails-mirror/',
+) {
+
+  class {'tails::mirror':
+    ensure      => $ensure,
+    mirror_path => $mirror_path
+  }
+
+  if !defined(Package['nginx-light']) {
+    package { 'nginx-light': ensure => 'present' }
+  }
+
+  # mirror file
+  file { '/etc/nginx/sites-available/dl.amnesia.boum.org':
+    ensure  => $ensure,
+    mode    => '0644',
+    owner   => root,
+    group   => root,
+    content => template('tails/mirror/nginx/dl.amnesia.boum.org.erb'),
+    require => Package['nginx-light']
+  }
+
+  file { '/etc/nginx/sites-enabled/dl.amnesia.boum.org':
+    ensure  => 'link',
+    target  => '/etc/nginx/sites-available/dl.amnesia.boum.org',
+    require => File['/etc/nginx/sites-available/dl.amnesia.boum.org'],
+    #notify  => Service['nginx'],
+  }
+}
diff --git a/templates/mirror/apache/dl.amnesia.boum.org.erb b/templates/mirror/apache/dl.amnesia.boum.org.erb
new file mode 100644
index 0000000..5db6abd
--- /dev/null
+++ b/templates/mirror/apache/dl.amnesia.boum.org.erb
@@ -0,0 +1,15 @@
+<VirtualHost *:80>
+   ServerName dl.amnesia.boum.org
+   <% if @admin_mail -%>
+   ServerAdmin <%= @admin_mail %>
+   <% end -%>
+
+   DocumentRoot <%= @mirror_path %>
+   <Directory <%= @mirror_path %> >
+      Options Indexes
+      AllowOverride None
+      IndexIgnore README.html
+      IndexOptions FancyIndexing FoldersFirst IgnoreCase NameWidth=50
+      IndexOrderDefault Descending Date
+   </Directory>
+</VirtualHost>
diff --git a/templates/mirror/mirror_cron.erb b/templates/mirror/mirror_cron.erb
new file mode 100644
index 0000000..a4f0b4d
--- /dev/null
+++ b/templates/mirror/mirror_cron.erb
@@ -0,0 +1 @@
+15 * * * * root rsync -aPHrt --delete rsync.torproject.org::amnesia-archive <%= @mirror_path %>
diff --git a/templates/mirror/nginx/dl.amnesia.boum.org.erb b/templates/mirror/nginx/dl.amnesia.boum.org.erb
new file mode 100644
index 0000000..27ef056
--- /dev/null
+++ b/templates/mirror/nginx/dl.amnesia.boum.org.erb
@@ -0,0 +1,21 @@
+server {
+    server_name dl.amnesia.boum.org;
+    listen 80; ## listen for ipv4; this line is default and implied
+    <% if @ipaddress6 -%>
+    listen [::]:80 ipv6only=on; ## listen for ipv6
+    <% end -%>
+
+    root <%= @mirror_path %>;
+    access_log     off;
+
+    location = /favicon.ico {
+      return 204;
+      access_log     off;
+      log_not_found  off;
+    }
+
+    location / {
+        index index.html;
+        autoindex  on;
+    }
+}
