aboutsummaryrefslogtreecommitdiffstats
path: root/modules/blog
diff options
context:
space:
mode:
Diffstat (limited to 'modules/blog')
-rw-r--r--modules/blog/manifests/init.pp114
-rw-r--r--modules/blog/templates/.htaccess10
-rwxr-xr-xmodules/blog/templates/backup_blog-db.sh23
-rwxr-xr-xmodules/blog/templates/backup_blog-files.sh24
-rw-r--r--modules/blog/templates/blogs_vhosts.conf16
-rwxr-xr-xmodules/blog/templates/check_new-blog-post.sh43
6 files changed, 186 insertions, 44 deletions
diff --git a/modules/blog/manifests/init.pp b/modules/blog/manifests/init.pp
index ab7f9ec0..c89a8168 100644
--- a/modules/blog/manifests/init.pp
+++ b/modules/blog/manifests/init.pp
@@ -1,41 +1,97 @@
-#TODO:
-# - add the creation of the user 'blog' in puppet
class blog {
- package { 'mysql':
- ensure => installed
- }
+ class base {
+ $blog_domain = "blog.${::domain}"
+ $blog_location = "/var/www/vhosts/${blog_domain}"
+ $blog_db_backupdir = '/var/lib/backups/blog_db'
+ $blog_files_backupdir = '/var/lib/backups/blog_files'
+ $blog_newpost_email_to = "i18n-reports@ml.${::domain}"
+ $blog_newpost_email_from = "Mageia Blog bot <blog@${::domain}>"
- package { 'wget':
- ensure => installed
+ user { 'blog':
+ groups => apache,
+ comment => 'Mageia Blog bot',
+ home => '/var/lib/blog',
}
+ }
- include apache::mod_php
+ class files_bots inherits base {
+if versioncmp($::lsbdistrelease, '9') < 0 {
+ package { ['php-mysqlnd',
+ 'php-ldap',
+ 'unzip',
+ 'nail']: }
+} else {
+ package { ['php-mysqlnd',
+ 'php-ldap',
+ 'unzip',
+ 's-nail']: }
+}
+
+ mga_common::local_script { 'check_new-blog-post.sh':
+ content => template('blog/check_new-blog-post.sh'),
+ }
+
+ cron { 'Blog bot':
+ user => 'blog',
+ minute => '*/15',
+ command => '/usr/local/bin/check_new-blog-post.sh',
+ require => Mga_common::Local_script['check_new-blog-post.sh'],
+ }
+
+ include apache::mod::php
+
+ apache::vhost::base { "${blog_domain}":
+ location => $blog_location,
+ content => template('blog/blogs_vhosts.conf'),
+ }
+
+ apache::vhost::base { "ssl_${blog_domain}":
+ use_ssl => true,
+ vhost => $blog_domain,
+ location => $blog_location,
+ content => template('blog/blogs_vhosts.conf'),
+ }
- package { 'php-mysql':
- ensure => installed
- }
+ file { $blog_location:
+ ensure => directory,
+ owner => apache,
+ group => apache,
+ }
+ }
+
+ class db_backup inherits base {
+ file { $blog_db_backupdir:
+ ensure => directory,
+ }
+ mga_common::local_script { 'backup_blog-db.sh':
+ content => template('blog/backup_blog-db.sh'),
+ }
- file { "check_new-blog-post":
- path => "/usr/local/bin/check_new-blog-post.sh",
- ensure => present,
- owner => blog,
- group => blog,
- mode => 755,
- content => template("blog/check_new-blog-post.sh")
- }
+ cron { "Backup DB (blog)":
+ user => root,
+ hour => '23',
+ minute => '42',
+ command => '/usr/local/bin/backup_blog-db.sh',
+ require => Mga_common::Local_script['backup_blog-db.sh'],
+ }
+ }
- file { "/var/lib/blog":
+ class files_backup inherits base {
+ file { $blog_files_backupdir:
ensure => directory,
- owner => blog,
- group => blog,
- mode => 644,
}
- cron { blog:
- user => blog,
- minute => '*/15',
- command => "/usr/local/bin/check_new-blog-post.sh",
- require => File["check_new-blog-post"]
- }
+ mga_common::local_script { 'backup_blog-files.sh':
+ content => template('blog/backup_blog-files.sh'),
+ }
+
+ cron { 'Backup files (blog)':
+ user => root,
+ hour => '23',
+ minute => '42',
+ command => '/usr/local/bin/backup_blog-files.sh',
+ require => Mga_common::Local_script['backup_blog-files.sh'],
+ }
+ }
}
diff --git a/modules/blog/templates/.htaccess b/modules/blog/templates/.htaccess
new file mode 100644
index 00000000..19bee3bd
--- /dev/null
+++ b/modules/blog/templates/.htaccess
@@ -0,0 +1,10 @@
+# BEGIN WordPress
+<IfModule mod_rewrite.c>
+RewriteEngine On
+RewriteBase /
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
+RewriteRule . /index.php [L]
+</IfModule>
+
+# END WordPress
diff --git a/modules/blog/templates/backup_blog-db.sh b/modules/blog/templates/backup_blog-db.sh
new file mode 100755
index 00000000..c497cb8f
--- /dev/null
+++ b/modules/blog/templates/backup_blog-db.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+# Initialization
+PATH_TO_FILE=${PATH_TO_FILE:-<%= blog_db_backupdir %>}
+[ ! -f $PATH_TO_FILE/count ] && echo 0 > $PATH_TO_FILE/count
+COUNT=$(cat "$PATH_TO_FILE/count")
+# Backup each locale DB
+for locale in de el en es fr it nl pl pt ro ru tr uk
+do
+ if [ ! -d $PATH_TO_FILE/$locale ]
+ then
+ /bin/mkdir $PATH_TO_FILE/$locale
+ fi
+ /usr/bin/mysqldump --add-drop-table -h localhost blog_$locale | bzip2 -c > $PATH_TO_FILE/$locale/mageia_$locale-$COUNT.bak.sql.bz2
+done
+# Check count file to have a week of backup in the directory
+if [ $COUNT -ne 6 ]
+then
+ COUNT=$(expr $COUNT + 1)
+else
+ COUNT="0"
+fi
+echo $COUNT > $PATH_TO_FILE/count
diff --git a/modules/blog/templates/backup_blog-files.sh b/modules/blog/templates/backup_blog-files.sh
new file mode 100755
index 00000000..e268ad2b
--- /dev/null
+++ b/modules/blog/templates/backup_blog-files.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+# Initialization
+PATH_TO_FILE=${PATH_TO_FILE:-<%= blog_files_backupdir %>}
+[ ! -f $PATH_TO_FILE/count ] && echo 0 > $PATH_TO_FILE/count
+COUNT=$(cat "$PATH_TO_FILE/count")
+# Backup each locale
+for locale in de el en es fr it nl pl pt ro ru sv tr uk
+do
+ if [ ! -d $PATH_TO_FILE/$locale ]
+ then
+ /bin/mkdir $PATH_TO_FILE/$locale
+ fi
+ # use relative paths to avoid "Removing leading `/' from member names'" warning
+ tar -C / -Jcf "$PATH_TO_FILE/$locale/$locale-$COUNT.tar.xz" "$(sed s,^/,, <<< "<%= blog_location %>/$locale")"
+done
+# Check count file to have a week of backup in the directory
+if [ $COUNT -ne 6 ]
+then
+ COUNT=$(expr $COUNT + 1)
+else
+ COUNT="0"
+fi
+echo $COUNT > $PATH_TO_FILE/count
diff --git a/modules/blog/templates/blogs_vhosts.conf b/modules/blog/templates/blogs_vhosts.conf
new file mode 100644
index 00000000..ff3c792f
--- /dev/null
+++ b/modules/blog/templates/blogs_vhosts.conf
@@ -0,0 +1,16 @@
+<Directory <%= blog_location %> >
+ Order deny,allow
+ Allow from All
+ AllowOverride All
+ Options FollowSymlinks
+ Options +Indexes
+</Directory>
+# Add a permanent redirection for 'pt' as it was 'pt-br' before
+# Add a permanent redirection for '/*' as it's now '/en/' for english blog
+# TO BE REMOVE in May, 1st (?)
+<IfModule mod_alias.c>
+ Redirect permanent /pt-br/ /pt/
+ Redirect permanent /wp-content/uploads/ /en/wp-content/uploads/
+ Redirect permanent /wp-includes/images/ /en/wp-includes/images/
+ RedirectMatch permanent ^/?$ /en/
+</IfModule>
diff --git a/modules/blog/templates/check_new-blog-post.sh b/modules/blog/templates/check_new-blog-post.sh
index c3183375..f2089a52 100755
--- a/modules/blog/templates/check_new-blog-post.sh
+++ b/modules/blog/templates/check_new-blog-post.sh
@@ -2,36 +2,49 @@
# Initialization
PATH_TO_FILE=${PATH_TO_FILE:-/var/lib/blog}
-/usr/bin/wget -qO $PATH_TO_FILE"/RSS_new" http://blog.mageia.org/?feed=rss2
-if [ -n $? ]
+/usr/bin/wget -qO $PATH_TO_FILE"/last_tmp" https://blog.mageia.org/en/?feed=rss2
+if [ $? -ne 0 ]
then
- exit 2
+ exit 2
fi
-# Check if RSS_old exists
-if [ ! -f $PATH_TO_FILE"/RSS_old" ]
+last_title=$(grep "title" $PATH_TO_FILE"/last_tmp" | head -n 2 | sed '1d' | sed 's/<title>//' | sed 's/<\/title>//' | sed 's/^[ \t]*//')
+last_pub=$(grep "pubDate" $PATH_TO_FILE"/last_tmp" | head -n 1 | sed 's/<pubDate>//' | sed 's/<\/pubDate>//' | sed 's/^[ \t]*//')
+last_creator=$(grep "creator" $PATH_TO_FILE"/last_tmp" | head -n 1 | sed 's/<dc:creator>//' | sed 's/<\/dc:creator>//' | sed 's/^[ \t]*//')
+echo -e "$last_title\n$last_pub\n$last_creator" > $PATH_TO_FILE"/last_tmp"
+
+# Check if 'last_entry' exists
+if [ ! -f $PATH_TO_FILE"/last_entry" ]
then
- /bin/mv -f $PATH_TO_FILE"/RSS_new" $PATH_TO_FILE"/RSS_old"
+ /bin/mv -f $PATH_TO_FILE"/last_tmp" $PATH_TO_FILE"/last_entry"
exit 1
fi
+# Add a date file for log
/bin/date +"%d:%m:%Y %H:%M" > $PATH_TO_FILE"/last_check"
# Check if a new blog post on EN needs to be translated on other blogs
-tmp_new=$(/bin/grep 'lastBuildDate' $PATH_TO_FILE"/RSS_new")
-tmp_old=$(/bin/grep 'lastBuildDate' $PATH_TO_FILE"/RSS_old")
+tmp_new=$(cat $PATH_TO_FILE"/last_tmp" | sed -n '1p')
+tmp_old=$(cat $PATH_TO_FILE"/last_entry" | sed -n '1p')
if [ "$tmp_old" = "$tmp_new" ]
then
# Nothing new
- echo "NO" >> $PATH_TO_FILE"/last_check"
+ tmp_new=$(cat $PATH_TO_FILE"/last_tmp" | sed -n '2p')
+ tmp_old=$(cat $PATH_TO_FILE"/last_entry" | sed -n '2p')
+ if [ "$tmp_old" != "$tmp_new" ]
+ then
+ # Modification on latest post
+ echo "YES - Modification" >> $PATH_TO_FILE"/last_check"
+ echo -e "The latest blog post has been modified and needs to be checked!\n\nTitle:\t$last_title\nAuthor:\t$last_creator\n-- \nMail sent by the script '$0' on `hostname`" | /bin/mail -r '<%= blog_newpost_email_from %>' -s "Modification of the latest entry on English Blog" <%= blog_newpost_email_to %>
+ echo $DATE
+ else
+ echo "NO" >> $PATH_TO_FILE"/last_check"
+ fi
else
# New post to translate
- cat $PATH_TO_FILE"/last_check" > $PATH_TO_FILE"/last_need_translation"
- new_post=$(grep "title" $PATH_TO_FILE"/RSS_new" | head -n 2 | sed '1d' | sed 's/<title>//' | sed 's/<\/title>//' | sed 's/^[ \t]*//')
- echo $new_post >> $PATH_TO_FILE"/last_need_translation"
- echo "YES" >> $PATH_TO_FILE"/last_check"
- echo -e "A new blog post is waiting for translation\n\"$new_post\"" | /bin/mail -s "New entry on English Blog" mageia-blogteam@mageia.org
+ echo "YES - New entry" >> $PATH_TO_FILE"/last_check"
+ echo -e "A new blog post is waiting for translation:\n\nTitle:\t$last_title\nAuthor:\t$last_creator\n-- \nMail sent by the script '$0' on `hostname`" | /bin/mail -r '<%= blog_newpost_email_from %>' -s "New entry on English Blog" <%= blog_newpost_email_to %>
echo $DATE
fi
# Clean tmp files and copy RSS_new to RSS_old
-/bin/mv -f $PATH_TO_FILE"/RSS_new" $PATH_TO_FILE"/RSS_old"
+/bin/mv -f $PATH_TO_FILE"/last_tmp" $PATH_TO_FILE"/last_entry"