#!/bin/bash # # pmwiki management script. # SITES="<%= scope.lookupvar('pmwiki::sites_folder') %>" BASE="<%= scope.lookupvar('pmwiki::www_folder') %>" # Check for existing installations function pmwiki_check_existing { if [ -e "$BASE/pmwiki-$1" ]; then echo "Folder $BASE/pmwiki-$1 already exists, skipping." exit 1 fi } # Deploy a fresh pmwiki tree function pmwiki_deploy { if [ "$#" != "1" ]; then new="`lynx -dump http://www.pmwiki.org/pub/pmwiki/ 2> /dev/null | grep ".tgz$" | grep -v latest | sed -e 's/^.*-//' | head -1`" if [ -z "$new" ]; then echo "Unable to determine latest release, please specify it manually:" echo "Usage: `basename $0` deploy " else new="`basename $new .tgz`" fi else new="$1" fi # Setup cd $BASE pmwiki_check_existing $new # Deploy a fresh pmwiki tree wget http://pmwiki.org/pub/pmwiki/pmwiki-$new.tgz wget http://pmwiki.org/pub/pmwiki/i18n/i18n-all.zip tar zxvf pmwiki-$new.tgz && rm pmwiki-$new.tgz ( cd pmwiki-$new && unzip -o ../i18n-all.zip && rm $_ ) if [ ! -e "pmwiki-$new/index.php" ]; then ( cd pmwiki-$new && ln -s pmwiki.php index.php ) fi chown -R root.root pmwiki-$new/ } # Upgrade a pmwiki instance using upstream source function pmwiki_upgrade { if [ "$#" != "2" ]; then echo "Usage: `basename $0` upgrade " exit 1 fi # Setup old="$1" new="$2" extra_folders="" pmwiki_check_existing $new cd $BASE cp -a pmwiki-$old pmwiki-$old.backup # Deploy a fresh pmwiki tree pmwiki_deploy $new # Copy files for file in .htaccess index.php farmconfig.php local config.php wiki.d; do if [ -e "pmwiki-$old/$file" ]; then cp -a pmwiki-$old/$file pmwiki-$new/ fi done for extra_folder in $extra_folders; do if [ -d ../pmwiki-$old/$extra_folder ]; then cp -Rp ../pmwiki-$old/$extra_folder . fi done # Themes and cookbook rsync -av pmwiki-$old/cookbook/ pmwiki-$new/cookbook rsync -av --exclude=pmwiki --exclude=print pmwiki-$old/pub/skins/ pmwiki-$new/pub/skins/ # Change symlink to point to the new location cd $BASE ; rm -f wiki && ln -s pmwiki-$new wiki # Done echo "Audit: `du -hs pmwiki-$old`" echo "Audit: `du -hs pmwiki-$new`" echo "Check procedure and remove pmwiki-$old once you make sure that everything is fine." } # Install a pmwiki instance function pmwiki_install { local site="$1" if [ -z "$site" ]; then echo "Usage: `basename $0` install " exit 1 fi if [ ! -d "$BASE/wiki" ]; then echo "Please deploy pmwiki first" exit 1 fi if [ ! -d "$SITES/$site" ]; then echo "Please configure site $site first" exit 1 fi if [ -e "$SITES/$site/wiki/field.php" ]; then echo "Looks like $site wiki is already installed" exit 1 fi # Create folder structure ( mkdir -p $SITES/$site/wiki/{local,uploads,wiki.d,cookbook} cd $SITES/$site/wiki ln -s field.php index.php chown $site. wiki.d touch local/config.php chown root.$site local/config.php ) # Setup dispatcher echo '' > $SITES/$site/wiki/field.php # Setup redirections cat > $SITES/$site/wiki/.htaccess <<-EOF Options +FollowSymLinks RewriteEngine on RewriteRule ^/?$ https://$site.<%= domain %>/Main/HomePage [R=permanent,QSA,L] RewriteRule ^([^/a-z].*) field.php?n=\$1 [QSA,L] EOF # Setup config file cat > $SITES/$site/wiki/local/config.php <<-EOF "; \$EnablePathInfo = 1; EOF } # Main procedure if [ -z "$1" ]; then echo "Usage: `basename $0` [arguments]" exit 1 elif [ "$1" == "deploy" ]; then shift pmwiki_deploy $* elif [ "$1" == "upgrade" ]; then shift pmwiki_upgrade $* elif [ "$1" == "install" ]; then shift pmwiki_install $* fi