+# GETOPT
+
+TEMP=`getopt -n $0 -o ht:o:u: -- "$@"`
+
+RET=$?
+
+if [ $RET != 0 ]; then
+ usage $RET
+fi
+
+eval set -- "$TEMP"
+
+TYPE=""
+OWNER=""
+URL=""
+VHOST=0
+
+while true ; do
+ case "$1" in
+ -h)
+ usage 0
+ ;;
+ -t)
+ TYPE=$2;
+ if [[ "${TYPE}" != "user" && "${TYPE}" != "group-member" && "${TYPE}" != "group-admin" && "${TYPE}" != "connected" ]]; then
+ echo -e "ERROR: TYPE must be one of: user | group-member | group-admin | connected\n";
+ usage 1
+ fi
+ shift 2;
+ ;;
+ -o)
+ OWNER=$2;
+ shift 2;
+ ;;
+ -u)
+ URL=$2;
+ if ! echo "${URL}" | grep -E "^https?://[^/]+/" > /dev/null; then
+ echo -e "ERROR: URL must be a full URL, e.g 'http://www.example.org/'\n";
+ usage 1
+ fi
+ shift 2;
+ ;;
+ --)
+ shift;
+ break;
+ ;;
+ *)
+ echo -e "ERROR: Invalid argument '$1'\n"
+ usage 1
+ ;;
+ esac
+done
+
+if [[ "x${TYPE}" == "x" || "x${OWNER}" == "x" || "x${URL}" == "x" ]]; then
+ echo -e "ERROR: Missing one of -t, -o or -u options.\n"
+ usage 1
+fi
+
+BASEURL=`echo "${URL}" | sed -r 's,https?://[^/]+/,/,'`
+
+echo "Creating blog with :
+ TYPE = ${TYPE}
+ OWNER = ${OWNER}
+ URL = ${URL}
+ BASEURL = ${BASEURL}
+"
+
+apache_group=www-data
+rootpath=/home/web/blogs
+templatepath=dotclear
+
+serviceurl="http://blog.polytechnique.org/xorgservice/createBlog"
+
+CALLED="$serviceurl?owner=${OWNER}&type=${TYPE}&url=${URL}&baseurl=${BASEURL}"
+echo "Calling $CALLED"
+( wget "$CALLED" -O - 2> /dev/null | grep 'blog created' ) || die "Blog creation failed"
+
+( cd $rootpath && mkdir -p $OWNER ) || die "Can't create the repository for the blog ($rootpath/$OWNER)"