Blame Extras/Moin/create-wikifarm-instance.sh

4c79b5
#!/bin/bash
4c79b5
# moinmoin-postinstall.sh
4c79b5
# MoinMoin 1.5 wikifarm instance installation script.
4c79b5
#
4c79b5
# The CentOS Artwork SIG.
4c79b5
# http://wiki.centos.org/ArtWork
4c79b5
4c79b5
4c79b5
4c79b5
# ---------------------------------------------------------
4c79b5
# Begin Configuration Section
4c79b5
4c79b5
# First Wiki Site Name. This is the name shown in the browser 
4c79b5
# title bar.
4c79b5
WIKISITENAME="mywiki"
4c79b5
4c79b5
# Your Domain Name (without the trailing slash).
4c79b5
MYDOMAIN="localdomain"
4c79b5
4c79b5
# Name of the Wiki Front Page.
4c79b5
WIKIFRONTPAGE="FrontPage"
4c79b5
4c79b5
# Directory name where the wiki instance will be copied.
4c79b5
WIKILOCATION=/var/www/
4c79b5
4c79b5
# Instance Name.
4c79b5
WIKIINSTANCE="wikifarm"
4c79b5
4c79b5
# Alias name used to access wiki static files. This value
4c79b5
# should be different from $WIKIALIAS above.
4c79b5
WIKIURLPREFIX="staticfiles"
4c79b5
4c79b5
# Wiki Super User. Add your WikiUserName here.
4c79b5
WIKISUPERUSER="YourName"
4c79b5
4c79b5
# Do you want to restrict the edit actions ?  (yes|no).
4c79b5
# 
4c79b5
# a) If `yes' only the wiki superuser, and those listed into
4c79b5
# EditGroup and AdminGroup pages will be able to edit pages
4c79b5
# on your wiki. After this script is run, we suggest to:
4c79b5
#
4c79b5
#    1. Register the superuser. For example:
4c79b5
#	Login > UserPreferences > Create Profile
4c79b5
#    2. Create a EditGroup page.
4c79b5
#    3. Add registered user names into EditGroup page.
4c79b5
#
4c79b5
#       At this point those users listed in EditGroup will
4c79b5
#       be able to edit pages on your wiki. If you need to
4c79b5
#       grant admin rights to other people then create the
4c79b5
#       AdminGroup page and add register users names into
4c79b5
#       it. After that they will have admin rights.
4c79b5
#
4c79b5
#       More info about acl can be found at
4c79b5
#       http://localhost/wiki/HelpOnAccessControlLists once
4c79b5
#       you have installed the wiki.
4c79b5
# 
4c79b5
# b) If `no' all users will be able to edit your wiki. Even
4c79b5
# if they haven't a user register on it.
4c79b5
WIKIRESTRICTEDIT="no"
4c79b5
4c79b5
# Mail
4c79b5
WIKIMAILSMARTHOST=""
4c79b5
WIKIMAILFROM=""
4c79b5
WIKIMAILLOGIN=""
4c79b5
4c79b5
# Language.
4c79b5
WIKILANGUAGE="en"
4c79b5
4c79b5
# Basic installation Prefix.
4c79b5
PREFIX=/usr
4c79b5
4c79b5
# Share directory name.
4c79b5
SHARE=$PREFIX/share/moin/
4c79b5
4c79b5
# User & Group used by your web server.
4c79b5
USER=apache
4c79b5
GROUP=$USER
4c79b5
4c79b5
# End of Configuration section
4c79b5
# ---------------------------------------------------------
4c79b5
4c79b5
4c79b5
# Copy files
4c79b5
#
4c79b5
# Here we create directories and copy files into the
4c79b5
# instance.
4c79b5
#
4c79b5
cd $WIKILOCATION
4c79b5
mkdir -p ${WIKIINSTANCE}/cgi-bin/
4c79b5
mkdir -p ${WIKIINSTANCE}/${WIKISITENAME}.${MYDOMAIN}/
4c79b5
cp -r ${SHARE}data/* ${WIKIINSTANCE}/${WIKISITENAME}.${MYDOMAIN}/
4c79b5
cp -r ${SHARE}data ${WIKIINSTANCE}/
4c79b5
cp -r ${SHARE}htdocs $WIKIINSTANCE
4c79b5
cp -r ${SHARE}underlay $WIKIINSTANCE
4c79b5
cp ${SHARE}server/moin.cgi ${WIKIINSTANCE}/cgi-bin/
4c79b5
4c79b5
4c79b5
# Fix PATH in moin.cgi file
4c79b5
#
4c79b5
sed -i -e "
4c79b5
        s/\/path\/to\/wikiconfig/\/var\/www\/${WIKIINSTANCE}\/cgi-bin/
4c79b5
        s/\/path\/to\/farmconfig/\/var\/www\/${WIKIINSTANCE}\/cgi-bin\/farmconfig/
4c79b5
        " ${WIKILOCATION}${WIKIINSTANCE}/cgi-bin/moin.cgi
4c79b5
4c79b5
4c79b5
# Apache Configuration
4c79b5
#
4c79b5
# Here we create the apache configuration file. By default
4c79b5
# the wiki will be accessed through the `wiki' apache alias.
4c79b5
# Virtual domains are also included but commented by
4c79b5
# default.
4c79b5
cat <<APACHECONF > /etc/httpd/conf.d/${WIKIINSTANCE}.conf
4c79b5
# Apache web server configuration for MoinMoin wiki.
4c79b5
#
4c79b5
# Created by moinmoin-postinstall-wikifarm.sh.
4c79b5
4c79b5
<VirtualHost *:80>
4c79b5
   ServerName ${WIKISITENAME}.${MYDOMAIN}/
4c79b5
   ServerAdmin webmaster@${MYDOMAIN}
4c79b5
   ErrorLog logs/wiki-${WIKISITENAME}.error_log
4c79b5
   CustomLog logs/wiki-${WIKISITENAME}.access_log common   
4c79b5
   Alias /${WIKIURLPREFIX} "${WIKILOCATION}${WIKIINSTANCE}/htdocs/"
4c79b5
   Alias /favicon.ico "${WIKILOCATION}${WIKIINSTANCE}/favicon.ico"
4c79b5
   ScriptAlias / "${WIKILOCATION}${WIKIINSTANCE}/cgi-bin/moin.cgi/"
4c79b5
</VirtualHost>
4c79b5
APACHECONF
4c79b5
4c79b5
# MoinMoin Configuration - farmconfig.py
4c79b5
#
4c79b5
# Here is a copy and paste from original farmconfig.py file
4c79b5
# in the moin-1.5.7-1.el5.rf package. Some additions were
4c79b5
# included in the secutiry section to make it configurablen
4c79b5
# between 1) an everyone editable wiki 2) a just Superuser,
4c79b5
# EditGroup, and AdminGroup editable wiki.
4c79b5
cat <<WIKICONFIG > ${WIKIINSTANCE}/cgi-bin/farmconfig.py 
4c79b5
# -*- coding: iso-8859-1 -*-
4c79b5
# IMPORTANT! This encoding (charset) setting MUST be correct! If you live in a
4c79b5
# western country and you don't know that you use utf-8, you probably want to
4c79b5
# use iso-8859-1 (or some other iso charset). If you use utf-8 (a Unicode
4c79b5
# encoding) you MUST use: coding: utf-8
4c79b5
# That setting must match the encoding your editor uses when you modify the
4c79b5
# settings below. If it does not, special non-ASCII chars will be wrong.
4c79b5
4c79b5
"""
4c79b5
    MoinMoin - Configuration for a wiki farm
4c79b5
4c79b5
    If you run a single wiki only, you can keep the "wikis" list "as is"
4c79b5
    (it has a single rule mapping all requests to mywiki.py).
4c79b5
4c79b5
    Note that there are more config options than you'll find in
4c79b5
    the version of this file that is installed by default; see
4c79b5
    the module MoinMoin.multiconfig for a full list of names and their
4c79b5
    default values.
4c79b5
4c79b5
    Also, the URL http://moinmoin.wikiwikiweb.de/HelpOnConfiguration has
4c79b5
    a list of config options.
4c79b5
"""
4c79b5
4c79b5
4c79b5
# Wikis in your farm --------------------------------------------------
4c79b5
4c79b5
# If you run multiple wikis, you need this list of pairs (wikiname, url
4c79b5
# regular expression). moin processes that list and tries to match the
4c79b5
# regular expression against the URL of this request - until it matches.
4c79b5
# Then it loads the <wikiname>.py config for handling that request.
4c79b5
4c79b5
# Important:
4c79b5
#  * the left part is the wikiname enclosed in double quotes
4c79b5
#  * the left part must be a valid python module name, so better use only
4c79b5
#    lower letters "a-z" and "_". Do not use blanks or "-" there!!!
4c79b5
#  * the right part is the url re, use r"..." for it
4c79b5
#  * the right part does NOT include "http://" nor "https://" at the beginning
4c79b5
#  * in the right part ".*" means "everything". Just "*" does not work like
4c79b5
#    for filenames on the shell / commandline, you must use ".*" as it is a RE.
4c79b5
#  * in the right part, "^" means "beginning" and "$" means "end"
4c79b5
4c79b5
wikis = [
4c79b5
    # Standalone server needs the port e.g. localhost:8000
4c79b5
    # Twisted server can now use the port, too.
4c79b5
    
4c79b5
    # wikiname,     url regular expression (no protocol)
4c79b5
    # ---------------------------------------------------------------
4c79b5
    #("mywiki",  r".*"),   # this is ok for a single wiki
4c79b5
4c79b5
    # for multiple wikis, do something like this:
4c79b5
    #("moinmoin",    r"^moinmoin.wikiwikiweb.de/.*$"),
4c79b5
    #("moinmaster",  r"^moinmaster.wikiwikiweb.de/.*$"),
4c79b5
4c79b5
    ("${WIKISITENAME}",		r"^${WIKISITENAME}.${MYDOMAIN}/.*$"),
4c79b5
]
4c79b5
4c79b5
4c79b5
# Common configuration for all wikis ----------------------------------
4c79b5
4c79b5
# Everything that should be configured the same way should go here,
4c79b5
# anything else that should be different should go to the single wiki's
4c79b5
# config.
4c79b5
# In that single wiki's config, we will use the class FarmConfig we define
4c79b5
# below as the base config settings and only override what's different.
4c79b5
#
4c79b5
# In exactly the same way, we first include MoinMoin's Config Defaults here -
4c79b5
# this is to get everything to sane defaults, so we need to change only what
4c79b5
# we like to have different:
4c79b5
4c79b5
from MoinMoin.multiconfig import DefaultConfig
4c79b5
4c79b5
# Now we subclass this DefaultConfig. This means that we inherit every setting
4c79b5
# from the DefaultConfig, except those we explicitely define different.
4c79b5
4c79b5
class FarmConfig(DefaultConfig):
4c79b5
4c79b5
    # Critical setup  ---------------------------------------------------
4c79b5
4c79b5
    # Misconfiguration here will render your wiki unusable. Check that
4c79b5
    # all directories are accessible by the web server or moin server.
4c79b5
4c79b5
    # If you encounter problems, try to set data_dir and data_underlay_dir
4c79b5
    # to absolute paths.
4c79b5
4c79b5
    # Where your mutable wiki pages are. You want to make regular
4c79b5
    # backups of this directory.
4c79b5
    #data_dir = '${WIKILOCATION}${WIKIINSTANCE}/data/'
4c79b5
4c79b5
    # Where read-only system and help page are. You might want to share
4c79b5
    # this directory between several wikis. When you update MoinMoin,
4c79b5
    # you can safely replace the underlay directory with a new one. This
4c79b5
    # directory is part of MoinMoin distribution, you don't have to
4c79b5
    # backup it.
4c79b5
    data_underlay_dir = '${WIKILOCATION}${WIKIINSTANCE}/underlay/'
4c79b5
4c79b5
    # Location of your STATIC files (css/png/js/...) - you must NOT use the
4c79b5
    # same for invoking moin.cgi (or, in general, the moin code).
4c79b5
    # url_prefix must be '/wiki' for Twisted and standalone servers.
4c79b5
    # For CGI, it should match your Apache Alias setting.
4c79b5
    url_prefix = '/${WIKIURLPREFIX}'
4c79b5
4c79b5
4c79b5
    # Security ----------------------------------------------------------
4c79b5
4c79b5
    # This is checked by some rather critical and potentially harmful actions,
4c79b5
    # like despam or PackageInstaller action:
4c79b5
    #superuser = [u"${WIKISUPERUSER}", ]
4c79b5
4c79b5
    # IMPORTANT: grant yourself admin rights! replace YourName with
4c79b5
    # your user name. See HelpOnAccessControlLists for more help.
4c79b5
    # All acl_rights_xxx options must use unicode [Unicode]
4c79b5
    #acl_rights_default = u"All:read"
4c79b5
    #acl_rights_before  = u"${WIKISUPERUSER}:read,write,delete,revert,admin" \\
4c79b5
    #			 u"AdminGroup:read,write,delete,revert,admin" \\
4c79b5
    #			 u"EditGroup:read,write,delete,revert"
4c79b5
4c79b5
    # Link spam protection for public wikis (uncomment to enable).
4c79b5
    # Needs a reliable internet connection.
4c79b5
    #from MoinMoin.util.antispam import SecurityPolicy
4c79b5
4c79b5
4c79b5
    # Mail --------------------------------------------------------------
4c79b5
4c79b5
    # Configure to enable subscribing to pages (disabled by default)
4c79b5
    # or sending forgotten passwords.
4c79b5
4c79b5
    # SMTP server, e.g. "mail.provider.com" (None to disable mail)
4c79b5
    #mail_smarthost = "${WIKIMAILSMARTHOST}"
4c79b5
4c79b5
    # The return address, e.g u"Jürgen Wiki <noreply@mywiki.org>" [Unicode]
4c79b5
    #mail_from = u"${WIKIMAILFROM}"
4c79b5
4c79b5
    # "user pwd" if you need to use SMTP AUTH
4c79b5
    #mail_login = "${WIKIMAILLOGIN}"
4c79b5
4c79b5
4c79b5
    # User interface ----------------------------------------------------
4c79b5
4c79b5
    # Add your wikis important pages at the end. It is not recommended to
4c79b5
    # remove the default links.  Leave room for user links - don't use
4c79b5
    # more than 6 short items.
4c79b5
    # You MUST use Unicode strings here, but you need not use localized
4c79b5
    # page names for system and help pages, those will be used automatically
4c79b5
    # according to the user selected language. [Unicode]
4c79b5
    navi_bar = [
4c79b5
        # If you want to show your page_front_page here:
4c79b5
        #u'%(page_front_page)s',
4c79b5
        u'RecentChanges',
4c79b5
        u'FindPage',
4c79b5
        u'HelpContents',
4c79b5
    ]
4c79b5
4c79b5
4c79b5
    # You must use Unicode strings here [Unicode]
4c79b5
    page_category_regex = u'^Category[A-Z]'
4c79b5
    page_dict_regex = u'[a-z]Dict$'
4c79b5
    page_group_regex = u'[a-z]Group$'
4c79b5
    page_template_regex = u'[a-z]Template$'
4c79b5
4c79b5
    # Content options ---------------------------------------------------
4c79b5
4c79b5
    # Show users hostnames in RecentChanges
4c79b5
    show_hosts = 1
4c79b5
4c79b5
    # Show the interwiki name (and link it to page_front_page) in the Theme,
4c79b5
    # nice for farm setups or when your logo does not show the wiki's name.
4c79b5
    show_interwiki = 1
4c79b5
    #logo_string = u''
4c79b5
4c79b5
    # Enable graphical charts, requires gdchart.
4c79b5
    #chart_options = {'width': 600, 'height': 300}
4c79b5
WIKICONFIG
4c79b5
4c79b5
# Copy First Wiki Configuration file.
4c79b5
#
4c79b5
cat <<WIKICONFIG > ${WIKIINSTANCE}/cgi-bin/${WIKISITENAME}.py
4c79b5
# -*- coding: iso-8859-1 -*-
4c79b5
# IMPORTANT! This encoding (charset) setting MUST be correct! If you live in a
4c79b5
# western country and you don't know that you use utf-8, you probably want to
4c79b5
# use iso-8859-1 (or some other iso charset). If you use utf-8 (a Unicode
4c79b5
# encoding) you MUST use: coding: utf-8
4c79b5
# That setting must match the encoding your editor uses when you modify the
4c79b5
# settings below. If it does not, special non-ASCII chars will be wrong.
4c79b5
4c79b5
"""
4c79b5
This is a sample config for a wiki that is part of a wiki farm and uses
4c79b5
farmconfig for common stuff. Here we define what has to be different from
4c79b5
the farm's common settings.
4c79b5
"""
4c79b5
4c79b5
# we import the FarmConfig class for common defaults of our wikis:
4c79b5
from farmconfig import FarmConfig
4c79b5
4c79b5
# now we subclass that config (inherit from it) and change what's different:
4c79b5
class Config(FarmConfig):
4c79b5
4c79b5
    # basic options (you normally need to change these)
4c79b5
    sitename = u'${WIKISITENAME}' # [Unicode]
4c79b5
    interwikiname = '${WIKISITENAME}'
4c79b5
4c79b5
    # name of entry page / front page [Unicode], choose one of those:
4c79b5
4c79b5
    # a) if most wiki content is in a single language
4c79b5
    #page_front_page = u"MyStartingPage"
4c79b5
4c79b5
    # b) if wiki content is maintained in many languages
4c79b5
    page_front_page = u"${WIKIFRONTPAGE}"
4c79b5
4c79b5
    logo_string = u'MoinMoin Logo'
4c79b5
4c79b5
    # The default theme anonymous or new users get
4c79b5
    theme_default = 'modern'
4c79b5
4c79b5
    # Language options --------------------------------------------------
4c79b5
    
4c79b5
    # See http://moinmoin.wikiwikiweb.de/ConfigMarket for configuration in 
4c79b5
    # YOUR language that other people contributed.
4c79b5
    
4c79b5
    # The main wiki language, set the direction of the wiki pages
4c79b5
    language_default = '${WIKILANGUAGE}'
4c79b5
4c79b5
    data_dir = '${WIKILOCATION}${WIKIINSTANCE}/${WIKISITENAME}.${MYDOMAIN}/'
4c79b5
WIKICONFIG
4c79b5
4c79b5
# Uncomment some options in the farmconfig.py file if ...
4c79b5
if [ "$WIKISUPERUSER" != "" ]; then
4c79b5
4c79b5
	sed -i -e '
4c79b5
		/#superuser/s/#//
4c79b5
		s/YourName/'$WIKISUPERUSER'/' ${WIKIINSTANCE}/cgi-bin/farmconfig.py
4c79b5
4c79b5
fi
4c79b5
4c79b5
if [ "$WIKIRESTRICTEDIT" = "yes" ]; then
4c79b5
4c79b5
	sed -i -r -e '
4c79b5
		/#acl_rights_before/s/#//
4c79b5
		/#acl_rights_default/s/#//
4c79b5
		/#[\t ]*u"EditGroup/s/#//
4c79b5
		/#[\t ]*u"AdminGroup/s/#//' ${WIKIINSTANCE}/cgi-bin/farmconfig.py
4c79b5
4c79b5
fi
4c79b5
4c79b5
if [ "$WIKIMAILSMARTHOST" != "" ]; then
4c79b5
4c79b5
	sed -i -e '
4c79b5
		/#mail_smarthost/s/#//' ${WIKIINSTANCE}/cgi-bin/farmconfig.py
4c79b5
4c79b5
fi
4c79b5
4c79b5
if [ "$WIKIMAILFROM" != "" ];then
4c79b5
4c79b5
	sed -i -e '
4c79b5
		/#mail_from/s/#//' ${WIKIINSTANCE}/cgi-bin/farmconfig.py
4c79b5
4c79b5
fi
4c79b5
4c79b5
if [ "$WIKIMAILLOGIN" != "" ];then
4c79b5
 
4c79b5
	sed -i -e '
4c79b5
		/#mail_login/s/#//' ${WIKIINSTANCE}/cgi-bin/farmconfig.py
4c79b5
4c79b5
fi
4c79b5
4c79b5
# File Permissions
4c79b5
#
4c79b5
# Here we set the file permissons to the created and copied
4c79b5
# files.
4c79b5
#
4c79b5
chown -R $USER.$GROUP $WIKIINSTANCE
4c79b5
chmod -R ug=rwx $WIKIINSTANCE
4c79b5
chmod -R o-rwx $WIKIINSTANCE
4c79b5
cd $WIKIINSTANCE
4c79b5
chown -R $USER.$GOUP cgi-bin 
4c79b5
chmod -R ug=rx cgi-bin
4c79b5
chmod -R o-rwx cgi-bin
4c79b5
4c79b5
4c79b5
# Last Message
4c79b5
#
4c79b5
less <
4c79b5
4c79b5
------------------------------------------------------------
4c79b5
	     *** WIKIFARM INSTANCE CREATED *** 
4c79b5
------------------------------------------------------------
4c79b5
4c79b5
   To finish the installation do the following:
4c79b5
4c79b5
	1. Restart the Web Server (service httpd restart)
4c79b5
4c79b5
	2. Open your browser and try the address:
4c79b5
	http://${WIKISITENAME}.${MYDOMAIN}/"
4c79b5
4c79b5
------------------------------------------------------------
4c79b5
	      *** HOWTO CREATE NEW WIKIS  *** 
4c79b5
------------------------------------------------------------
4c79b5
4c79b5
  To create new wikis into the farm check the following
4c79b5
  steps:
4c79b5
4c79b5
  	1. Update your farmconfig.py file adding the new
4c79b5
	wiki definition. Ex.
4c79b5
4c79b5
	("mywiki2",    r"^mywiki2.${MYDOMAIN}/.*$"),
4c79b5
4c79b5
	2. Create a directory to store your new wiki data.
4c79b5
	Ex.
4c79b5
	
4c79b5
	mkdir ${WIKILOCATION}${WIKIINSTANCE}/mywiki2.${MYDOMAIN}/
4c79b5
4c79b5
	3. Copy the content of data directory into the
4c79b5
	recently created directory. Ex.: 
4c79b5
4c79b5
	cp -rv ${WIKILOCATION}${WIKIINSTANCE}/data/* \\
4c79b5
	${WIKILOCATION}${WIKIINSTANCE}/mywiki2.${MYDOMAIN}/
4c79b5
4c79b5
	4. Create a copy of your cgi-bin/mywiki.py into
4c79b5
	cgi-bin/mywiki2.py. Then modify mywiki2 with the new
4c79b5
	and specific configuration, related to the second
4c79b5
	wiki. Ex.:
4c79b5
4c79b5
	sitename = u'mywiki2' # [Unicode]
4c79b5
	interwikiname = 'mywiki2'
4c79b5
	data_dir = '/var/www/wikifarm/mywiki2.${MYDOMAIN}/'
4c79b5
		
4c79b5
4c79b5
------------------------------------------------------------
4c79b5
		   *** GET TROUBLES ? ***
4c79b5
------------------------------------------------------------
4c79b5
4c79b5
   If you get some error when try to reach your wiki through
4c79b5
   the web browser, check the following:
4c79b5
4c79b5
	1. Add in your DNS or HOSTS file a record to your
4c79b5
	wiki address. For example, if your domain is
4c79b5
	${MYDOMAIN} and your wiki is in a host with the ip
4c79b5
	192.168.0.1, and you want a wiki address like
4c79b5
	http://${WIKISITENAME}.${MYDOMAIN}/ it is possible
4c79b5
	that you should add a related CNAME record into your
4c79b5
	DNS to your new wiki address, something like the
4c79b5
	following:
4c79b5
4c79b5
   	${WIKISITENAME}.${MYDOMAIN}.	IN CNAME	${MYDOMAINl}.
4c79b5
4c79b5
	Remeber to do a 'service named restart' after
4c79b5
	changes.
4c79b5
4c79b5
	2. Check Virtual Domain configuration in your Apache
4c79b5
	server. It is possible that it is disabled so enable
4c79b5
	it by uncomenting a line like the following:
4c79b5
4c79b5
	NameVirtualHost *:80
4c79b5
4c79b5
	3. It is possible that you want something in
4c79b5
	http://${MYDOMAIN}/ other than the error that
4c79b5
	sometimes appears there after you get your wiki
4c79b5
	working into virtual domains. So you should create a
4c79b5
	virtual domain for that address too and change the
4c79b5
	DocumentoRoot param to wherever you want to load at
4c79b5
	that moment.
4c79b5
4c79b5
	If you are still in troubles, you can write to:
4c79b5
	<alain.reguera@gmail.com>. 
4c79b5
	
4c79b5
	Other way ...
4c79b5
	
4c79b5
   Enjoy your installed wikifarm :).
4c79b5
4c79b5
LASTMESSAGE