Migrating to php 5.3
[dotclear.git] / createBlog.sh
1 #!/bin/sh -x
2
3 # Usage:
4 # ./createBlog.sh type owner baseurl
5 # type = user | group-member | group-admin
6 # * user: this is a blog for a user
7 # * group-member: this is a blog for a group, all the members of the group can post
8 # * group-admin: this is a blog for a group, only group admins can post
9 # owner = name of the owner
10 # * user blog: forlife of the owner of the blog
11 # * group blog: 'diminutif' of the group (from X.net database)
12 # url = full url of the blog (e.g http://group.blog-x.org/).
13
14 # WARNING: The script generates a .htaccess. The rewrite base might be edited to match
15 # the installation. Default value is based on a blog-farm of the form
16 # http://$owner.base.url/
17
18 # Once the blog has been installed and the .htaccess set-up, you can go on the administration
19 # page of the blog at baseurl/admin/
20 #
21 # Their, go to the section 'Widget' and add (by drag-n-drop) the widgets 'Auth X.org' and 'Copyright'.
22 # (should be set up by default in near future).
23
24 type=$1
25 owner=$2
26 url=$3
27 apache_group=www-data
28 rootpath=/home/web/blogs
29 templatepath=dotclear
30 baseurl=/
31 serviceurl="http://blog.polytechnique.org/xorgservice/createBlog"
32
33 die() {
34 echo $1
35 exit 1
36 }
37
38 ( wget "$serviceurl?owner=$owner&type=$type&url=$3" -O - 2> /dev/null | grep 'blog created' ) || die "Blog creation failed"
39
40 ( cd $rootpath && mkdir $owner ) || die "Can't create the repository for the blog"
41
42 cd $owner
43 for i in admin db inc index.php locales plugins themes; do
44 ln -s $rootpath/$templatepath/$i || die "Can't add path to $i"
45 done
46 mkdir -p "$rootpath/$templatepath/public/$owner"
47 chgrp -R "$apache_group" "$rootpath/$templatepath/public/$owner"
48 chmod g+wr "$rootpath/$templatepath/public/$owner"
49 ln -s $rootpath/$templatepath/public/$owner public
50
51 ( cat <<EOF
52 RewriteEngine On
53 RewriteBase $baseurl
54 RewriteCond %{REQUEST_FILENAME} !-f
55 RewriteCond %{REQUEST_FILENAME} !-d
56 RewriteRule (.*) index.php/\$1
57 RewriteRule ^index.php\$ index.php/
58 SetEnv DC_BLOG_ID $owner
59 EOF
60 ) > .htaccess