summaryrefslogtreecommitdiff
path: root/localikiwikicreatesite
blob: be6630a9208a84c3a7d4a0d924483ec1c6f06772 (plain)
  1. #!/bin/sh
  2. #
  3. # /usr/local/bin/localikiwikicreatesite
  4. # Copyright 2008 Jonas Smedegaard <dr@jones.dk>
  5. #
  6. # $Id: localikiwikicreatesite,v 1.12 2008-02-13 15:26:54 jonas Exp $
  7. #
  8. # Initialize ikiwiki site
  9. #
  10. # Origin: http://ikiwiki.info/setup/
  11. #
  12. set -e
  13. PRG=$(basename "$0")
  14. TEMP=$(getopt -s sh -o d:s:fh -l domain:,srcdomain:,force,help -n "$PRG" -- "$@")
  15. if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
  16. eval set -- "$TEMP"
  17. if [ -f /etc/local/ikiwiki.cfg ]; then
  18. . /etc/local/ikiwiki.cfg
  19. fi
  20. gitsrcuri="http://source.jones.dk"
  21. domain="${domain:-example.com}"
  22. srcdomain="$srcdomain"
  23. force="$force"
  24. showhelp() {
  25. cat <<EOF
  26. Usage: $PRG [opts...] PROJECT [HOST [SRCHOST]]
  27. Options:
  28. -d, --domain If HOST is a FQDN: Ignore the DOMAIN value.
  29. If HOST is a shortname: FQDN is HOST.DOMAIN.
  30. If HOST is omitted: FQDN is PROJECT.DOMAIN.
  31. (default: $domain)
  32. -s, --srcdomain If SRCHOST is a FQDN: Ignore the SRCDOMAIN value.
  33. If SRCHOST is a shortname: FQDN is HOST.SRCDOMAIN.
  34. If SRCHOST is omitted: FQDN is source.SRCDOMAIN.
  35. (default: ${srcdomain:-$domain without any leading www.})
  36. -f, --force Update without asking for confirmation
  37. -h, --help This help text
  38. Examples:
  39. $PRG -d example.com wiki
  40. $PRG mysite www.example.com source.example.org
  41. EOF
  42. }
  43. exit1() {
  44. echo >&2 "Error: $1"
  45. echo >&2 "Exiting..."
  46. exit 1
  47. }
  48. while true ; do
  49. case "$1" in
  50. -d|--domain) domain="$1"; shift 2;;
  51. -s|--srcdomain) srcdomain="$1"; shift 2;;
  52. -f|--force) force="1"; shift;;
  53. -h|--help) showhelp; exit 0;;
  54. --) shift; break;;
  55. *) exit1 "Internal error!";;
  56. esac
  57. done
  58. # Resolve FQDNs
  59. project="$1"
  60. [ -n "$project" ] || exit1 "ERROR: Project name must be supplied!"
  61. host="$2"
  62. [ -n "$host" ] || host="$project"
  63. echo "$host" | grep -q '\.' || host="$host.$domain"
  64. srchost="$3"
  65. [ -n "$srchost" ] || srchost="source"
  66. if echo "$srchost" | grep -qv '\.'; then
  67. [ -n "$srcdomain" ] || srcdomain=$(echo "$host" | sed 's/^www\.//')
  68. srchost="$srchost.$srcdomain"
  69. fi
  70. SRCDIR=~/private_webdata/$host/content
  71. CFGDIR=~/private_webdata/$host
  72. DESTDIR=~/public_websites/$host
  73. DESTSRCDIR=~/public_websites/$srchost
  74. ## Init public RCS repositories
  75. mkdir -p $DESTSRCDIR/${project}.git $DESTSRCDIR/${project}_content.git
  76. (cd $DESTSRCDIR/${project}_content.git
  77. git --bare init --shared
  78. )
  79. (cd $DESTSRCDIR/${project}.git
  80. git --bare init --shared
  81. )
  82. ## Create initial content
  83. mkdir -p $SRCDIR
  84. cat <<'EOF' >$SRCDIR/index.mdwn
  85. Welcome to your new wiki.
  86. All wikis are supposed to have a <a href="../sandbox/">SandBox</a>,
  87. so this one does too.
  88. ----
  89. This wiki is powered by [ikiwiki](http://ikiwiki.info).
  90. EOF
  91. #ikiwiki --verbose $SRCDIR $DESTDIR --url=http://"$host"
  92. ## Create initial backend
  93. mkdir -p $CFGDIR
  94. cp /usr/share/doc/ikiwiki/html/ikiwiki.setup $CFGDIR
  95. ## Init content RCS
  96. (cd $SRCDIR
  97. git init
  98. echo /.ikiwiki > .gitignore
  99. git add .
  100. git commit -m "initial commit"
  101. git remote add origin $DESTSRCDIR/${project}_content.git
  102. git config branch.master.merge refs/heads/master
  103. git push --all
  104. chmod +x $DESTSRCDIR/${project}_content.git/hooks/post-update
  105. )
  106. ## Init backend RCS
  107. (cd $CFGDIR
  108. git init
  109. echo /content > .gitignore
  110. git add .
  111. git commit -m "initial commit"
  112. git remote add origin $DESTSRCDIR/$project.git
  113. git config branch.master.merge refs/heads/master
  114. git push --all
  115. chmod +x $DESTSRCDIR/${project}.git/hooks/post-update
  116. )
  117. ## Adjust backend to actual paths, and enable Git post-update wrapper
  118. perl -pi -e '
  119. s,^(\s*)#?(srcdir\s*=>\s*")[^"]*("\,\s*),$1$2'$SRCDIR'$3,;
  120. s,^(\s*)#?(destdir\s*=>\s*")[^"]*("\,\s*),$1$2'$DESTDIR'$3,;
  121. s,^(\s*)#?(url\s*=>\s*")[^"]*("\,\s*),$1$2http://'$host'$3,;
  122. s,^(\s*)#?(cgiurl\s*=>\s*")([^"]*)("\,\s*),$1#$2$3$4,;
  123. s,^(\s*)#?(rcs\s*=>\s*")(git)("\,\s*),$1$2$3$4,;
  124. ' $CFGDIR/ikiwiki.setup
  125. perl -0 -pi -e '
  126. 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},;
  127. ' $CFGDIR/ikiwiki.setup
  128. perl -0 -pi -e 's,\n(exec\s[^\n]*),\nhooks/post-update-'"$project"'\n\n$1,' $DESTSRCDIR/${project}_content.git/hooks/post-update
  129. (cd $CFGDIR
  130. git add ikiwiki.setup
  131. git commit -m "Adjust ikiwiki.setup to use actual paths, and add+enable Git post-update hooks"
  132. )
  133. ## Add Makefile for further customization
  134. cat <<EOF >$CFGDIR/Makefile
  135. #underlays = basewiki smiley templates
  136. underlays = templates
  137. #locale = danish
  138. master = master
  139. #master = master-LOCALE
  140. all: \$(underlays)
  141. \$(underlays):
  142. mkdir \$@
  143. cd \$@ && git init
  144. cd \$@ && git remote add -f -t \$(master:LOCALE=\$(locale)) -m \$(master:LOCALE=\$(locale)) origin $gitsrcuri/${project}_\$@.git
  145. cd \$@ && git merge origin
  146. EOF
  147. (cd $CFGDIR
  148. git add Makefile
  149. git commit -m "Setup local paths"
  150. )
  151. ikiwiki --verbose $SRCDIR $DESTDIR --url=http://"$host" --setup $CFGDIR/ikiwiki.setup
  152. (cd $CFGDIR
  153. git push
  154. )