Commit | Line | Data |
---|---|---|
22ff3cf1 | 1 | #!/bin/bash |
0873522c | 2 | |
3bc366b1 RB |
3 | # Usage: |
4 | # ./createBlog.sh type owner baseurl | |
99c51f8f | 5 | # type = user | connected | group-member | group-admin |
3bc366b1 | 6 | # * user: this is a blog for a user |
99c51f8f | 7 | # * connected: this is a blog for a group, all connected users can post |
3bc366b1 RB |
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) | |
1804b740 | 13 | # url = full url of the blog (e.g http://group.blog-x.org/). |
3bc366b1 RB |
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 | |
1804b740 | 17 | # http://$owner.base.url/ |
3bc366b1 RB |
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 | ||
22ff3cf1 RB |
25 | |
26 | # HELPERS | |
27 | ||
28 | usage() { | |
29 | echo "Usage: $0 -t TYPE -o OWNER -u URL | |
30 | ||
31 | where : | |
32 | TYPE = user | connected | group-member | group-admin is the type of the blog | |
33 | OWNER if the owner of the blog (user hruid or group diminutif) | |
34 | URL is the URL of the blog | |
35 | " | |
36 | exit $1; | |
37 | } | |
0873522c FB |
38 | |
39 | die() { | |
40 | echo $1 | |
41 | exit 1 | |
42 | } | |
43 | ||
0873522c | 44 | |
22ff3cf1 RB |
45 | # GETOPT |
46 | ||
47 | TEMP=`getopt -n $0 -o ht:o:u: -- "$@"` | |
48 | ||
49 | RET=$? | |
50 | ||
51 | if [ $RET != 0 ]; then | |
52 | usage $RET | |
53 | fi | |
54 | ||
55 | eval set -- "$TEMP" | |
56 | ||
57 | TYPE="" | |
58 | OWNER="" | |
59 | URL="" | |
60 | VHOST=0 | |
61 | ||
62 | while true ; do | |
63 | case "$1" in | |
64 | -h) | |
65 | usage 0 | |
66 | ;; | |
67 | -t) | |
68 | TYPE=$2; | |
69 | if [[ "${TYPE}" != "user" && "${TYPE}" != "group-member" && "${TYPE}" != "group-admin" && "${TYPE}" != "connected" ]]; then | |
70 | echo -e "ERROR: TYPE must be one of: user | group-member | group-admin | connected\n"; | |
71 | usage 1 | |
72 | fi | |
73 | shift 2; | |
74 | ;; | |
75 | -o) | |
76 | OWNER=$2; | |
77 | shift 2; | |
78 | ;; | |
79 | -u) | |
80 | URL=$2; | |
1ac0ab8a | 81 | if ! echo "${URL}" | grep -E "^https?://[^/]+/" > /dev/null; then |
22ff3cf1 RB |
82 | echo -e "ERROR: URL must be a full URL, e.g 'http://www.example.org/'\n"; |
83 | usage 1 | |
84 | fi | |
85 | shift 2; | |
86 | ;; | |
87 | --) | |
88 | shift; | |
89 | break; | |
90 | ;; | |
91 | *) | |
92 | echo -e "ERROR: Invalid argument '$1'\n" | |
93 | usage 1 | |
94 | ;; | |
95 | esac | |
96 | done | |
97 | ||
98 | if [[ "x${TYPE}" == "x" || "x${OWNER}" == "x" || "x${URL}" == "x" ]]; then | |
99 | echo -e "ERROR: Missing one of -t, -o or -u options.\n" | |
100 | usage 1 | |
101 | fi | |
102 | ||
1ac0ab8a | 103 | BASEURL=`echo "${URL}" | sed -r 's,https?://[^/]+/,/,'` |
22ff3cf1 RB |
104 | |
105 | echo "Creating blog with : | |
106 | TYPE = ${TYPE} | |
107 | OWNER = ${OWNER} | |
108 | URL = ${URL} | |
109 | BASEURL = ${BASEURL} | |
110 | " | |
111 | ||
112 | apache_group=www-data | |
113 | rootpath=/home/web/blogs | |
114 | templatepath=dotclear | |
115 | ||
116 | serviceurl="http://blog.polytechnique.org/xorgservice/createBlog" | |
117 | ||
7df5b665 RB |
118 | CALLED="$serviceurl?owner=${OWNER}&type=${TYPE}&url=${URL}&baseurl=${BASEURL}" |
119 | echo "Calling $CALLED" | |
120 | ( wget "$CALLED" -O - 2> /dev/null | grep 'blog created' ) || die "Blog creation failed" | |
22ff3cf1 | 121 | |
7df5b665 | 122 | ( cd $rootpath && mkdir -p $OWNER ) || die "Can't create the repository for the blog ($rootpath/$OWNER)" |
0873522c | 123 | |
7df5b665 | 124 | cd $rootpath/$OWNER |
3bc366b1 | 125 | for i in admin db inc index.php locales plugins themes; do |
0873522c FB |
126 | ln -s $rootpath/$templatepath/$i || die "Can't add path to $i" |
127 | done | |
22ff3cf1 RB |
128 | mkdir -p "$rootpath/$templatepath/public/$OWNER" |
129 | chgrp -R "$apache_group" "$rootpath/$templatepath/public/$OWNER" | |
130 | chmod g+wr "$rootpath/$templatepath/public/$OWNER" | |
131 | ln -s $rootpath/$templatepath/public/$OWNER public | |
0873522c FB |
132 | |
133 | ( cat <<EOF | |
58266dd3 | 134 | RewriteEngine On |
22ff3cf1 | 135 | RewriteBase ${BASEURL} |
58266dd3 FB |
136 | RewriteCond %{REQUEST_FILENAME} !-f |
137 | RewriteCond %{REQUEST_FILENAME} !-d | |
138 | RewriteRule (.*) index.php/\$1 | |
139 | RewriteRule ^index.php\$ index.php/ | |
22ff3cf1 | 140 | SetEnv DC_BLOG_ID $OWNER |
0873522c FB |
141 | EOF |
142 | ) > .htaccess |