summaryrefslogtreecommitdiff
path: root/localikiwikicreatesite
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2008-02-13 12:56:17 +0000
committerJonas Smedegaard <dr@jones.dk>2008-02-13 12:56:17 +0000
commit95ca5495b4a2a932fb841360fb3c294b064e9779 (patch)
tree06be6b1df86839ead394b3b76dda6434f2c22f2f /localikiwikicreatesite
parentf806f9612a297970d0e8cc25e5014af89cef3cff (diff)
Add copyright header, and getopt parsing. Require project as input, and resolve hostnames from that if omitted. Use project as basename in Git repository names.
Diffstat (limited to 'localikiwikicreatesite')
-rwxr-xr-xlocalikiwikicreatesite108
1 files changed, 89 insertions, 19 deletions
diff --git a/localikiwikicreatesite b/localikiwikicreatesite
index 27cc00a..f3cea73 100755
--- a/localikiwikicreatesite
+++ b/localikiwikicreatesite
@@ -1,12 +1,83 @@
#!/bin/sh
-
+#
+# /usr/local/bin/localikiwikicreatesite
+# Copyright 2008 Jonas Smedegaard <dr@jones.dk>
+#
+# $Id: localikiwikicreatesite,v 1.10 2008-02-13 12:56:17 jonas Exp $
+#
+# Initialize ikiwiki site
+#
# Origin: http://ikiwiki.info/setup/
+#
set -e
-host=$1
-[ -z "$host" ] && echo "ERROR: Hostname must be supplied!" && exit 1
-srchost=${2:-source.$host}
+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 <<EOF
+Usage: $PRG [opts...] PROJECT [HOST [SRCHOST]]
+
+Options:
+ -d, --domain If HOST is a FQDN: Ignore the DOMAIN value.
+ If HOST is a shortname: FQDN is HOST.DOMAIN.
+ If HOST is omitted: FQDN is PROJECT.DOMAIN.
+ (default: $domain)
+ -s, --srcdomain If SRCHOST is a FQDN: Ignore the SRCDOMAIN value.
+ If SRCHOST is a shortname: FQDN is HOST.SRCDOMAIN.
+ If SRCHOST is omitted: FQDN is source.SRCDOMAIN.
+ (default: ${srcdomain:-$domain without any leading www.})
+ -f, --force Update without asking for confirmation
+ -h, --help This help text
+
+Examples:
+ $PRG -d example.com wiki
+ $PRG mysite www.example.com source.example.org
+EOF
+}
+
+exit1() {
+ echo >&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
@@ -15,8 +86,8 @@ DESTSRCDIR=~/public_websites/$srchost
## Init public RCS repositories
mkdir -p $DESTSRCDIR
-GIT_DIR=$DESTSRCDIR/content.git git --bare init --shared
-GIT_DIR=$DESTSRCDIR/backend.git git --bare init --shared
+GIT_DIR=$DESTSRCDIR/${project}_content.git git --bare init --shared
+GIT_DIR=$DESTSRCDIR/$project.git git --bare init --shared
## Create initial content
mkdir -p $SRCDIR
@@ -41,7 +112,7 @@ git init
echo /.ikiwiki > .gitignore
git add .
git commit -m "initial commit"
-git remote add origin $DESTSRCDIR/content.git
+git remote add origin $DESTSRCDIR/${project}_content.git
git config branch.master.merge refs/heads/master
git push --all
)
@@ -53,7 +124,7 @@ git init
echo /content > .gitignore
git add .
git commit -m "initial commit"
-git remote add origin $DESTSRCDIR/backend.git
+git remote add origin $DESTSRCDIR/$project.git
git config branch.master.merge refs/heads/master
git push --all
)
@@ -67,33 +138,32 @@ perl -pi -e '
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/content.git/hooks/post-update-backend'$3$4},;
+ 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-ikiwiki\n\n$1,' $DESTSRCDIR/content.git/hooks/post-update
-chmod +x $DESTSRCDIR/content.git/hooks/post-update
+perl -0 -pi -e 's,\n(exec\s[^\n]*),\nhooks/post-update-'"$project"'\n\n$1,' $DESTSRCDIR/${project}_content.git/hooks/post-update
+chmod +x $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 <<'EOF' >$CFGDIR/Makefile
+cat <<EOF >$CFGDIR/Makefile
#underlays = basewiki smiley templates
underlays = templates
#locale = danish
master = master
#master = master-LOCALE
-all: $(underlays)
+all: \$(underlays)
-$(underlays):
- mkdir $@
- cd $@ && git init
- cd $@ && git remote add -f -t $(master:LOCALE=$(locale)) -m $(master:LOCALE=$(locale)) origin http://source.jones.dk/ikiwiki_$@.git
- cd $@ && git merge origin
+\$(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
-echo /Makefile >> $CFGDIR/.gitignore
(
cd $CFGDIR
git add Makefile