#!/bin/bash -e usage() { cat < " DB_PASSWORD fi LENGTH="50" while [ "${n:=1}" -le "$LENGTH" ] do SECRET_KEY="$SECRET_KEY${MATRIX:$(($RANDOM%${#MATRIX})):1}" let n+=1 done if [ ! $DB_DB ]; then DB_NAME=$NAME else DB_NAME=$DB_DB fi # Write the config file for wordpress (umask 0027; cat > $CONFIG_FILE << EOF EOF ) chgrp www-data "${CONFIG_FILE}" echo $CONFIG_FILE written } create() { # Create the database and user # Wordpress's install.php creates the tables btw if [ ! $DB_DB ]; then MYSQLCOMMAND="mysql -u $DB_USER -p -h $DB_HOST" $MYSQLCOMMAND < $BACKUPFILE && echo Wrote $BACKUPFILE } destroy() { # The destroy method need root to be able to drop databases and such. # People using complex setups with remote servers probably know how to # cleanup after the user any way. if [ ! -e /etc/mysql/debian.cnf ]; then echo "Default mysql settings not available. Manual clean up is required." exit 1 fi echo Destroying $NAME prompt mysql /etc/mysql/debian.cnf <&2 ; exit 1 ;; esac done shift $(($OPTIND - 1)) if [ "$(id -u)" != "0" ] then echo "You must be root to use this script." exit 1 fi DOMAIN=$(echo $1 | tr "[:upper:]" "[:lower:]") CONTENT="/var/lib/wordpress/wp-content" if [ $DOMAIN ] ; then ping -c 1 `echo $DOMAIN | sed 's/:[0-9]\+//'` || exit 1 else usage exit 0 fi CONFIG_FILE=/etc/wordpress/config-$DOMAIN.php if [ ! $NAME ] ; then NAME=$(echo $DOMAIN | sed 's,\.,,g;s,-,,g') echo Constructed database name and user: $NAME from $DOMAIN fi if [ ${#NAME} -gt 16 ]; then echo "$NAME is longer than MySQL's limit of 16 characters. Please specify a shorter one." exit 1 fi if [ ! $DB_HOST ]; then DB_HOST="localhost" fi if [ $BACKUP ] ; then backup exit 0 fi if [ $DESTROY ] ; then destroy exit 0 fi checkforexistingsetup create