Support https in blog URLs
[dotclear.git] / createBlog-dev.sh
CommitLineData
22ff3cf1
RB
1#!/bin/bash
2
3# Usage:
4# ./createBlog.sh type owner
5# type = user | connected | group-member | group-admin
6# * user: this is a blog for a user
7# * connected: this is a blog for a group, all connected users can post
8# * group-member: this is a blog for a group, all the members of the group can post
9# * group-admin: this is a blog for a group, only group admins can post
10# owner = name of the owner
11# * user blog: forlife of the owner of the blog
12# * group blog: 'diminutif' of the group (from X.net database)
13# url = full url of the blog (e.g http://group.blog-x.org/).
14
15# WARNING: The script generates a .htaccess. The rewrite base might be edited to match
16# the installation. Default value is based on a blog-farm of the form
17# http://$owner.base.url/
18
19# Once the blog has been installed and the .htaccess set-up, you can go on the administration
20# page of the blog at baseurl/admin/
21#
22# Their, go to the section 'Widget' and add (by drag-n-drop) the widgets 'Auth X.org' and 'Copyright'.
23# (should be set up by default in near future).
24
25# The blog will be created at :
26# ~/dev/blogs/$owner
27# It will be available at
28# http://dev.blog-x.org/~$USER/$owner
29
30# HELPERS
31
32usage() {
33 echo "Usage: $0 -t TYPE -o OWNER
34
35 where :
36 TYPE = user | connected | group-member | group-admin is the type of the blog
37 OWNER if the owner of the blog (user hruid or group diminutif)
38 "
39 exit $1;
40}
41
42die() {
43 echo $1
44 exit 1
45}
46
47
48# GETOPT
49
50TEMP=`getopt -n $0 -o ht:o: -- "$@"`
51
52RET=$?
53
54if [ $RET != 0 ]; then
55 usage $RET
56fi
57
58eval set -- "$TEMP"
59
60TYPE=""
61OWNER=""
62VHOST=0
63
64while true ; do
65 case "$1" in
66 -h)
67 usage 0
68 ;;
69 -t)
70 TYPE=$2;
71 if [[ "${TYPE}" != "user" && "${TYPE}" != "group-member" && "${TYPE}" != "group-admin" && "${TYPE}" != "connected" ]]; then
72 echo -e "ERROR: TYPE must be one of: user | group-member | group-admin | connected\n";
73 usage 1
74 fi
75 shift 2;
76 ;;
77 -o)
78 OWNER=$2;
79 shift 2;
80 ;;
81 --)
82 shift;
83 break;
84 ;;
85 *)
86 echo -e "ERROR: Invalid argument '$1'\n"
87 usage 1
88 ;;
89 esac
90done
91
92if [[ "x${TYPE}" == "x" || "x${OWNER}" == "x" ]]; then
93 echo -e "ERROR: Missing one of -t or -o options.\n"
94 usage 1
95fi
96
97URL="http://dev.blog-x.org/~${USER}/${OWNER}/"
98BASEURL=`echo "${URL}" | sed -r 's,http://[^/]+/,/,'`
99
100echo "Creating blog with :
101 TYPE = ${TYPE}
102 OWNER = ${OWNER}
103 URL = ${URL}
104 BASEURL = ${BASEURL}
105"
106
107apache_group=www-data
108rootpath=${HOME}/dev/blogs/
109templatepath=dotclear
110
7df5b665 111serviceurl="http://dev.blog-x.org/default/xorgservice/createBlog"
22ff3cf1 112
7df5b665
RB
113CALLED="$serviceurl?owner=${OWNER}&type=${TYPE}&url=${URL}&baseurl=${BASEURL}"
114echo "Calling $CALLED"
115( wget "$CALLED" -O - 2> /dev/null | grep 'blog created' ) || die "Blog creation failed"
22ff3cf1 116
7df5b665 117( cd $rootpath && mkdir -p $OWNER ) || die "Can't create the repository for the blog ($rootpath/$OWNER)"
22ff3cf1 118
7df5b665 119cd $rootpath/$OWNER
22ff3cf1
RB
120for i in admin db inc index.php locales plugins themes; do
121 ln -s $rootpath/$templatepath/$i || die "Can't add path to $i"
122done
123mkdir -p "$rootpath/$templatepath/public/$OWNER"
124chgrp -R "$apache_group" "$rootpath/$templatepath/public/$OWNER"
125chmod g+wr "$rootpath/$templatepath/public/$OWNER"
126ln -s $rootpath/$templatepath/public/$OWNER public
127
128( cat <<EOF
129RewriteEngine On
130RewriteBase ${BASEURL}
131RewriteCond %{REQUEST_FILENAME} !-f
132RewriteCond %{REQUEST_FILENAME} !-d
133RewriteRule (.*) index.php/\$1
134RewriteRule ^index.php\$ index.php/
135SetEnv DC_BLOG_ID $OWNER
136EOF
137) > .htaccess