#!/bin/bash # # mkpmwiki 0.2: cria uma nova instancia do pmwiki # feedback: rhatto at riseup.net | gpl # # This is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or any later version. # # This software is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., 59 Temple # Place - Suite 330, Boston, MA 02111-1307, USA # # # section 1: default procedures # TMP="/tmp" MKSITE_BASE="/etc/mksite" CONF="$MKSITE_BASE/mksite.conf" MESSAGES="/usr/share/mksite/mksite.messages" LOCKFILE="$TMP/mksite.lock" HELPER_FUNCTIONS="/usr/libexec/mksite/mksite-helper" # plugin definitions PLUGIN_NAME="pmwiki" USE_VERSION="0" USE_DATABASE="0" if [ -f "$HELPER_FUNCTIONS" ]; then source $HELPER_FUNCTIONS mksite_checks else echo Fatal error: function file not found, aborting. echo Erro fatal: arquivo de funcoes nao encontrado, abortando. exit 1 fi # # section 2: plugin specific functions # function usage { echo "usage: `basename $0` project [-n wikiname]" } function set_folder { if [ "$1" == "wiki" ]; then echo $HOME/$USER/wiki else echo $HOME/$USER/wiki/$1 fi } function set_url { if [ "$1" != "$DOCROOT" ]; then echo $USER.$DOMAIN/$1 else echo $USER.$DOMAIN fi } function create_config_file { # usage: create_config_file local folder url folder="`set_folder $1`" url="`set_url $1`" # write field.php; its important not to close with "?>" echo "" > $folder/field.php echo " $folder/local/config.php echo "\$ScriptUrl = \"$url\";" >> $folder/local/config.php echo "\$EnablePathInfo = 1;" >> $folder/local/config.php echo "?>" >> $folder/local/config.php echo "Order Deny,Allow" > $folder/local/.htaccess echo "Deny from all" >> $folder/local/.htaccess echo "Options +FollowSymLinks " > $folder/.htaccess echo "RewriteEngine on" >> $folder/.htaccess echo "RewriteRule ^/?$ $url/Main/HomePage [R=permanent,QSA,L]" >> $folder/.htaccess echo "RewriteRule ^([^/a-z].*) field.php?n=\$1 [QSA,L]" >> $folder/.htaccess ( cd $folder && ln -s field.php index.php ) chown $APACHE_USER.$APACHE_GROUP $folder chown $APACHE_USER.$USER $folder/local/config.php chmod 460 $folder/local/config.php } function update_config { # update the configurations of each wiki instance installed for $USER local wiki folder url for wiki in `mksite_eval_param $MKSITE_BASE/sites/$USER $PLUGIN_NAME_UPPER`; do folder="`set_folder $wiki`" url="`set_url $wiki`" # TODO: check regexp # adjust .htaccess sed -e '/RewriteRule \^\/\?\$/d' $folder/.htaccess > $folder/.htaccess.tmp echo "RewriteRule ^/?$ $url/Main/HomePage [R=permanent,QSA,L]" >> $folder/.htaccess.tmp mv $folder/.htaccess.tmp $folder/.htaccess # TODO: check regexp # adjust settings.php sed -e '/\$ScriptUrl = /d' $folder/local/config.php > $folder/local/config.php.tmp echo "\$ScriptUrl = \"$url\";" >> $folder/local/config.php.tmp mv $folder/local/config.php.tmp $folder/local/config.php done } function write_config_file { # salva as alteracoes no arquivo de configuracao do sitio local tmpfile wiki tmpfile="$TMP/$USER-conf.tmp" wiki="`mksite_eval_param $MKSITE_BASE/sites/$USER $PLUGIN_NAME_UPPER | sed -e "s/$INSTANCE_NAME//g" -e 's/ //g'`" echo "$PLUGIN_NAME_UPPER=\"$wiki $INSTANCE_NAME\"" >> $tmpfile mv $tmpfile $MKSITE_BASE/sites/$USER mksite_write_config_file } function check_instance_installed { # check if the instance is installed # should return INSTALLED="installed" if its installed :P local folder # wikis sao instaladados em $HOME/$USER/wiki/ folder="`set_folder $INSTANCE_NAME`" # check if the instance is installed if [ -f "$folder/settings.php" ]; then INSTALLED="installed" fi } function create_folders { # cria a pasta local folder folder="`set_folder $INSTANCE_NAME`" mkdir -p $folder/local if [ "$INSTANCE_NAME" == "wiki" ]; then # symlink so it can be reached via http://wiki.project.org/$USER ln -s $folder $PLUGIN_DIR/$USER fi } function create_contrib_folders { local folder folder="`set_folder $INSTANCE_NAME`" ( cd $folder && ln -s field.php index.php ) # TODO: $USER como dono de $folder, $APACHE_USER.$APACHE_GROUP soh onde for necessario chown $APACHE_USER.$APACHE_GROUP $folder } # # section 3: main procedure # mksite_init $*