summaryrefslogtreecommitdiff
path: root/localikiwikicreatesite
diff options
context:
space:
mode:
Diffstat (limited to 'localikiwikicreatesite')
-rwxr-xr-xlocalikiwikicreatesite110
1 files changed, 82 insertions, 28 deletions
diff --git a/localikiwikicreatesite b/localikiwikicreatesite
index 8014722..5602456 100755
--- a/localikiwikicreatesite
+++ b/localikiwikicreatesite
@@ -19,7 +19,7 @@ set -e
PRG=$(basename "$0")
-TEMP=$(getopt -s sh -o d:s:fh -l domain:,srcdomain:,force,help -n "$PRG" -- "$@")
+TEMP=$(getopt -s sh -o d:s:o:b:fh -l domain:,srcdomain:,origin:,branch:,force,help -n "$PRG" -- "$@")
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
eval set -- "$TEMP"
@@ -30,6 +30,8 @@ fi
gitsrcuri="http://source.jones.dk"
domain="${domain:-example.com}"
srcdomain="$srcdomain"
+origin="$origin"
+branch="$branch"
force="$force"
showhelp() {
@@ -45,12 +47,17 @@ Options:
If SRCHOST is a shortname: FQDN is HOST.SRCDOMAIN.
If SRCHOST is omitted: FQDN is source.SRCDOMAIN.
(default: ${srcdomain:-$domain without any leading www.})
+ -o, --origin Clone Git repositories from origin as skeleton
+ (default: ${origin:-do not clone.})
+ -b, --branch Use this branch of cloned Git repository
+ (default: ${branch:-Git default})
-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
+ $PRG -d example.com -o git://source.jones.dk/ikiwiki wiki
EOF
}
@@ -60,24 +67,47 @@ exit1() {
exit 1
}
+git_setenv_work() {
+ set -e
+
+ targetdir="$1"
+ shift
+
+ export GIT_WORK_TREE="$targetdir"
+ export GIT_DIR="$targetdir/.git"
+}
+
+git_unsetenv() {
+ unset GIT_WORK_TREE
+ unset GIT_DIR
+}
+
git_init_pub() {
repo="$DESTSRCDIR/$1.git"
+# export GIT_WORK_TREE="$repo"
+ export GIT_DIR="$repo"
+
mkdir -p $repo
- (cd $repo
git --bare init --shared
- )
+
+ chmod +x $repo/hooks/post-update
+
+ git_unsetenv
}
git_init_work() {
+ set -e
+
repo="$DESTSRCDIR/$1.git"
targetdir="$2"
shift 2
- (cd $targetdir
+ git_setenv_work "$targetdir"
+
git init
for ignore in "$@"; do
- echo "$1" >> .gitignore
+ echo "$1" >> $targetdir/.gitignore
done
git add .
git commit -m "initial commit"
@@ -85,14 +115,16 @@ git_init_work() {
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
git push --all
- )
- chmod +x $repo/hooks/post-update
+
+ git_unsetenv
}
while true ; do
case "$1" in
-d|--domain) domain="$2"; shift 2;;
-s|--srcdomain) srcdomain="$2"; shift 2;;
+ -o|--origin) origin="$2"; shift 2;;
+ -b|--branch) branch="$2"; shift 2;;
-f|--force) force="1"; shift;;
-h|--help) showhelp; exit 0;;
--) shift; break;;
@@ -122,25 +154,41 @@ DESTSRCDIR=~/public_websites/$srchost
git_init_pub "$project"
git_init_pub "${project}_content"
+## Create initial basedir
+if [ -n "$origin" ]; then
+ git clone $origin $CFGDIR
+ git_setenv_work "$CFGDIR"
+ if [ -n "$branch" ]; then
+ git branch -f "$branch" "origin/$branch"
+ git checkout "$branch"
+ fi
+ git config remote.origin.url "$DESTSRCDIR/$project.git"
+ git push --all
+ git_unsetenv
+else
+ mkdir -p $CFGDIR
+ cp /usr/share/doc/ikiwiki/html/ikiwiki.setup $CFGDIR
+fi
+
+## Init working RCS repositories
+if [ -n "$origin" ]; then
+ make -C $CFGDIR
+else
+ git_init_work "$project" "$CFGDIR" "/content"
+fi
+
## Create initial content
-mkdir -p $SRCDIR
-cat <<'EOF' >$SRCDIR/index.mdwn
+if ! [ -e $SRCDIR ]; then
+ mkdir -p $SRCDIR
+ cat <<'EOF' >$SRCDIR/index.mdwn
Welcome to your new wiki.
All wikis are supposed to have a <a href="../sandbox/">SandBox</a>,
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"
+fi
## Adjust backend to actual paths, and enable Git post-update wrapper
# TODO: Rewrite as semi-generic functions:
@@ -165,13 +213,14 @@ perl -0 -pi -e '
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_setenv_work "$CFGDIR"
git add ikiwiki.setup
git commit -m "Adjust ikiwiki.setup to use actual paths, and add+enable Git post-update hooks"
-)
+git_unsetenv
## Add Makefile for further customization
-cat <<EOF >$CFGDIR/Makefile
+if ! [ -e $CFGDIR/Makefile ]; then
+ cat <<EOF >$CFGDIR/Makefile
#underlays = basewiki smiley templates
underlays = templates
#locale = danish
@@ -186,12 +235,17 @@ all: \$(underlays)
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"
-)
+ git_setenv_work "$CFGDIR"
+ git add Makefile
+ git commit -m "Setup local paths"
+ git_unsetenv
+fi
-ikiwiki --verbose $SRCDIR $DESTDIR --url=http://"$host" --setup $CFGDIR/ikiwiki.setup
-(cd $CFGDIR
+if [ -n "$origin" ]; then
+ make -C $CFGDIR install
+else
+ ikiwiki --verbose $SRCDIR $DESTDIR --url=http://"$host" --setup $CFGDIR/ikiwiki.setup
+fi
+git_setenv_work "$CFGDIR"
git push
-)
+git_unsetenv