| | 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 | |
| | 32 | usage() { |
| | 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 | |
| | 42 | die() { |
| | 43 | echo $1 |
| | 44 | exit 1 |
| | 45 | } |
| | 46 | |
| | 47 | |
| | 48 | # GETOPT |
| | 49 | |
| | 50 | TEMP=`getopt -n $0 -o ht:o: -- "$@"` |
| | 51 | |
| | 52 | RET=$? |
| | 53 | |
| | 54 | if [ $RET != 0 ]; then |
| | 55 | usage $RET |
| | 56 | fi |
| | 57 | |
| | 58 | eval set -- "$TEMP" |
| | 59 | |
| | 60 | TYPE="" |
| | 61 | OWNER="" |
| | 62 | VHOST=0 |
| | 63 | |
| | 64 | while 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 |
| | 90 | done |
| | 91 | |
| | 92 | if [[ "x${TYPE}" == "x" || "x${OWNER}" == "x" ]]; then |
| | 93 | echo -e "ERROR: Missing one of -t or -o options.\n" |
| | 94 | usage 1 |
| | 95 | fi |
| | 96 | |
| | 97 | URL="http://dev.blog-x.org/~${USER}/${OWNER}/" |
| | 98 | BASEURL=`echo "${URL}" | sed -r 's,http://[^/]+/,/,'` |
| | 99 | |
| | 100 | echo "Creating blog with : |
| | 101 | TYPE = ${TYPE} |
| | 102 | OWNER = ${OWNER} |
| | 103 | URL = ${URL} |
| | 104 | BASEURL = ${BASEURL} |
| | 105 | " |
| | 106 | |
| | 107 | apache_group=www-data |
| | 108 | rootpath=${HOME}/dev/blogs/ |
| | 109 | templatepath=dotclear |
| | 110 | |
| | 111 | serviceurl="http://dev.blog-x.org/default/xorgservice/createBlog" |
| | 112 | |
| | 113 | CALLED="$serviceurl?owner=${OWNER}&type=${TYPE}&url=${URL}&baseurl=${BASEURL}" |
| | 114 | echo "Calling $CALLED" |
| | 115 | ( wget "$CALLED" -O - 2> /dev/null | grep 'blog created' ) || die "Blog creation failed" |
| | 116 | |
| | 117 | ( cd $rootpath && mkdir -p $OWNER ) || die "Can't create the repository for the blog ($rootpath/$OWNER)" |
| | 118 | |
| | 119 | cd $rootpath/$OWNER |
| | 120 | for i in admin db inc index.php locales plugins themes; do |
| | 121 | ln -s $rootpath/$templatepath/$i || die "Can't add path to $i" |
| | 122 | done |
| | 123 | mkdir -p "$rootpath/$templatepath/public/$OWNER" |
| | 124 | chgrp -R "$apache_group" "$rootpath/$templatepath/public/$OWNER" |
| | 125 | chmod g+wr "$rootpath/$templatepath/public/$OWNER" |
| | 126 | ln -s $rootpath/$templatepath/public/$OWNER public |
| | 127 | |
| | 128 | ( cat <<EOF |
| | 129 | RewriteEngine On |
| | 130 | RewriteBase ${BASEURL} |
| | 131 | RewriteCond %{REQUEST_FILENAME} !-f |
| | 132 | RewriteCond %{REQUEST_FILENAME} !-d |
| | 133 | RewriteRule (.*) index.php/\$1 |
| | 134 | RewriteRule ^index.php\$ index.php/ |
| | 135 | SetEnv DC_BLOG_ID $OWNER |
| | 136 | EOF |
| | 137 | ) > .htaccess |