#!/bin/sh # # /usr/local/bin/localikiwikicreatesite # Copyright 2008 Jonas Smedegaard # # $Id: localikiwikicreatesite,v 1.12 2008-02-13 15:26:54 jonas Exp $ # # Initialize ikiwiki site # # Origin: http://ikiwiki.info/setup/ # set -e PRG=$(basename "$0") TEMP=$(getopt -s sh -o d:s:fh -l domain:,srcdomain:,force,help -n "$PRG" -- "$@") if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi eval set -- "$TEMP" if [ -f /etc/local/ikiwiki.cfg ]; then . /etc/local/ikiwiki.cfg fi gitsrcuri="http://source.jones.dk" domain="${domain:-example.com}" srcdomain="$srcdomain" force="$force" showhelp() { cat <&2 "Error: $1" echo >&2 "Exiting..." exit 1 } while true ; do case "$1" in -d|--domain) domain="$1"; shift 2;; -s|--srcdomain) srcdomain="$1"; shift 2;; -f|--force) force="1"; shift;; -h|--help) showhelp; exit 0;; --) shift; break;; *) exit1 "Internal error!";; esac done # Resolve FQDNs project="$1" [ -n "$project" ] || exit1 "ERROR: Project name must be supplied!" host="$2" [ -n "$host" ] || host="$project" echo "$host" | grep -q '\.' || host="$host.$domain" srchost="$3" [ -n "$srchost" ] || srchost="source" if echo "$srchost" | grep -qv '\.'; then [ -n "$srcdomain" ] || srcdomain=$(echo "$host" | sed 's/^www\.//') srchost="$srchost.$srcdomain" fi SRCDIR=~/private_webdata/$host/content CFGDIR=~/private_webdata/$host DESTDIR=~/public_websites/$host DESTSRCDIR=~/public_websites/$srchost ## Init public RCS repositories mkdir -p $DESTSRCDIR/${project}.git $DESTSRCDIR/${project}_content.git (cd $DESTSRCDIR/${project}_content.git git --bare init --shared ) (cd $DESTSRCDIR/${project}.git git --bare init --shared ) ## Create initial content mkdir -p $SRCDIR cat <<'EOF' >$SRCDIR/index.mdwn Welcome to your new wiki. All wikis are supposed to have a SandBox, so this one does too. ---- This wiki is powered by [ikiwiki](http://ikiwiki.info). EOF #ikiwiki --verbose $SRCDIR $DESTDIR --url=http://"$host" ## Create initial backend mkdir -p $CFGDIR cp /usr/share/doc/ikiwiki/html/ikiwiki.setup $CFGDIR ## Init content RCS (cd $SRCDIR git init echo /.ikiwiki > .gitignore git add . git commit -m "initial commit" git remote add origin $DESTSRCDIR/${project}_content.git git config branch.master.merge refs/heads/master git push --all chmod +x $DESTSRCDIR/${project}_content.git/hooks/post-update ) ## Init backend RCS (cd $CFGDIR git init echo /content > .gitignore git add . git commit -m "initial commit" git remote add origin $DESTSRCDIR/$project.git git config branch.master.merge refs/heads/master git push --all chmod +x $DESTSRCDIR/${project}.git/hooks/post-update ) ## Adjust backend to actual paths, and enable Git post-update wrapper perl -pi -e ' s,^(\s*)#?(srcdir\s*=>\s*")[^"]*("\,\s*),$1$2'$SRCDIR'$3,; s,^(\s*)#?(destdir\s*=>\s*")[^"]*("\,\s*),$1$2'$DESTDIR'$3,; s,^(\s*)#?(url\s*=>\s*")[^"]*("\,\s*),$1$2http://'$host'$3,; s,^(\s*)#?(cgiurl\s*=>\s*")([^"]*)("\,\s*),$1#$2$3$4,; s,^(\s*)#?(rcs\s*=>\s*")(git)("\,\s*),$1$2$3$4,; ' $CFGDIR/ikiwiki.setup perl -0 -pi -e ' s,#{([\s#]*The git post-update wrapper[^}]*\s*)#(\s*wrapper =>\s*")[^"]*("\,\s*[^}]*)#(\s*wrappermode =>[^}]*)#},{$1$2'$DESTSRCDIR/${project}_content.git/hooks/post-update-$project'$3$4},; ' $CFGDIR/ikiwiki.setup perl -0 -pi -e 's,\n(exec\s[^\n]*),\nhooks/post-update-'"$project"'\n\n$1,' $DESTSRCDIR/${project}_content.git/hooks/post-update (cd $CFGDIR git add ikiwiki.setup git commit -m "Adjust ikiwiki.setup to use actual paths, and add+enable Git post-update hooks" ) ## Add Makefile for further customization cat <$CFGDIR/Makefile #underlays = basewiki smiley templates underlays = templates #locale = danish master = master #master = master-LOCALE all: \$(underlays) \$(underlays): mkdir \$@ cd \$@ && git init cd \$@ && git remote add -f -t \$(master:LOCALE=\$(locale)) -m \$(master:LOCALE=\$(locale)) origin $gitsrcuri/${project}_\$@.git cd \$@ && git merge origin EOF (cd $CFGDIR git add Makefile git commit -m "Setup local paths" ) ikiwiki --verbose $SRCDIR $DESTDIR --url=http://"$host" --setup $CFGDIR/ikiwiki.setup (cd $CFGDIR git push )