#!/bin/sh # # /usr/local/bin/localikiwikicreatesite # Copyright 2008 Jonas Smedegaard # # $Id: localikiwikicreatesite,v 1.18 2008-06-03 11:20:16 jonas Exp $ # # Initialize ikiwiki site # # Origin: http://ikiwiki.info/setup/ # # TODO: Explicitly replace ~ with $HOME for shell use, and $ENV{'HOME'} for Perl # TODO: Quote variables everywhere # TODO: Implement --verbose option # TODO: Check for name collision and ask (except when --force is enabled) # 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 } git_init_pub() { repo="$DESTSRCDIR/$1.git" mkdir -p $repo (cd $repo git --bare init --shared ) } git_init_work() { repo="$DESTSRCDIR/$1.git" targetdir="$2" shift 2 (cd $targetdir git init for ignore in "$@"; do echo "$1" >> .gitignore done git add . git commit -m "initial commit" git remote add origin $repo git config branch.master.remote origin git config branch.master.merge refs/heads/master git push --all ) chmod +x $repo/hooks/post-update } 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 "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/$project/content CFGDIR=~/private_webdata/$project DESTDIR=~/public_websites/$host DESTSRCDIR=~/public_websites/$srchost ## Init public RCS repositories git_init_pub "$project" git_init_pub "${project}_content" ## 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 working RCS repositories git_init_work "$project" "$CFGDIR" "/content" git_init_work "${project}_content" "$SRCDIR" "/.ikiwiki" ## Adjust backend to actual paths, and enable Git post-update wrapper # TODO: Rewrite as semi-generic functions: #perl_param_enable_set "$CFGDIR/ikiwiki.setup" "srcdir" "$SRCDIR" #perl_param_enable_set "$CFGDIR/ikiwiki.setup" "destdir" "$DESTDIR" #perl_param_enable_set "$CFGDIR/ikiwiki.setup" "url" "$host" #perl_param_disable "$CFGDIR/ikiwiki.setup" "cgiurl" #perl_param_match_enable "$CFGDIR/ikiwiki.setup" "rcs" "git" #perl_section_match_enable_param_set "$CFGDIR/ikiwiki.setup" "git post-update wrapper" "wrapper" "$DESTSRCDIR/${project}_content.git/hooks/post-update-$project" #perl_section_match_enable_param_match_enable "$CFGDIR/ikiwiki.setup" "git post-update wrapper" "wrappermode" "06755" #shell_line_match_enable_appendlinebefore "$DESTSRCDIR/${project}_content.git/hooks/post-update" "^exec" "hooks/post-update-$project\n" 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 )