Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clones a MediaWiki database
#!/bin/sh
if [ $# -ne 2 ]; then
echo 1>&2 Usage: $0 firstdb lastdb
exit 1
fi
START=$1
END=$2
cd /Library/WebServer/Documents
for (( i = $START; i <= $END; i++ ))
do
NUM=`echo $i | awk '{ printf "%02d\n", $1}'` # print leading zeros in front of i
mkdir $NUM
cd $NUM
ln -s ../mediawiki/COPYING
ln -s ../mediawiki/FAQ
ln -s ../mediawiki/HISTORY
ln -s ../mediawiki/INSTALL
ln -s ../mediawiki/README
ln -s ../mediawiki/RELEASE-NOTES
ln -s ../mediawiki/UPGRADE
ln -s ../mediawiki/docs
ln -s ../mediawiki/extensions
ln -s ../mediawiki/img_auth.php
ln -s ../mediawiki/includes
ln -s ../mediawiki/index.php
ln -s ../mediawiki/install-utils.inc
ln -s ../mediawiki/languages
ln -s ../mediawiki/maintenance
ln -s ../mediawiki/math
ln -s ../mediawiki/profileinfo.php
ln -s ../mediawiki/redirect.php
ln -s ../mediawiki/redirect.phtml
ln -s ../mediawiki/skins
ln -s ../mediawiki/tests
ln -s ../mediawiki/thumb.php
ln -s ../mediawiki/trackback.php
ln -s ../mediawiki/wiki.phtml
mkdir images
sudo chown www:wheel images
cd ..
cat /Library/WebServer/Documents/00/LocalSettings.php | sed s/00/$NUM/ > /Library/WebServer/Documents/$NUM/LocalSettings.php
NAME=/Users/shawn/wiki/wikidb$START-$END.sql
DBNAME=wikidb$NUM
cat >> $NAME <<EOF
create database $DBNAME;
use $DBNAME;
source /Users/shawn/wiki/blankwiki.sql
GRANT DELETE,INSERT,SELECT,UPDATE ON $DBNAME.* TO 'wikiuser'@'%' IDENTIFIED BY 'wikipass';
GRANT DELETE,INSERT,SELECT,UPDATE ON $DBNAME.* TO 'wikiuser'@localhost IDENTIFIED BY 'wikipass';
GRANT DELETE,INSERT,SELECT,UPDATE ON $DBNAME.* TO 'wikiuser'@localhost.localdomain IDENTIFIED BY 'wikipass';
EOF
done
echo Run this command to create wikis:
echo "echo \"source $NAME\" | /usr/local/mysql/bin/mysql -u root -p"
echo Update the ReWrite rules and fix LocalSettings.php for proper urls:
echo sudo pico +444 /etc/httpd/httpd.conf
echo also add user to appropriate htaccess and htgroup files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment