Skip to content

Instantly share code, notes, and snippets.

@jhaus
Created December 4, 2010 05:59
Show Gist options
  • Save jhaus/727961 to your computer and use it in GitHub Desktop.
Save jhaus/727961 to your computer and use it in GitHub Desktop.
install wordpress automatically via: http://codex.wordpress.org install wordpress automatic via: Installing_Multiple_Blogs#Multiple_Install_Automation
#!/bin/sh -x
# script by Stephanie Booth aka bunny http://stephanie-booth.com/ to install wordpress automatically (geeky, but useful for mass installs), with help from many people: drauh, io_error, zedrdave, roddie... and all those I've forgotten to mention.
# variables: $1 whatever, $2 wp_user, $3 wp_pass, $4 root password
# prerequisites: an existing mysql db, and a root password
# care! .htaccess is not generated, needs to be done manually, by clicking on "Update Permalinks" in Options once everything is installed
# todo: add themes, check plugin list, make wrapper script for multiple installs, prepare php patch template for options and common stuff, see if the script can edit the vhost conf files for mass installs, prepare alternate version for French, add bilingual plugin and maybe cache. Add an extra user to the WP install. Also an alternate version for upgrading the school blogs.
# set database name to user name and other stuff (config)
d="wp" # database name
pass=$4 # your mysql root password
rkuser="rkuser" # user with privs on ref karma tables
rkpass="rkpass" # password for above user
url="http://test.swissblogs.com" # this will change a lot depending what you are using the script for, basically it's the url the blog will have
title="Mon weblog de test" # your title here
u=$2 # the mysql user
p=$3 # the mysql user's password
adminmail="edublogs@gmail.com" # administrator e-mail for the weblog
directory="wordpress" # name of the directory the wordpress install will live in
# files to wget
wpress="http://wordpress.org/latest.tar.gz"
# testing -- comment this out if you're starting on a clean system
sudo rm -rf wordpress
# do dirty mysql stuff first
echo GRANT ALL PRIVILEGES ON $d.* to \'$u\'@\'%\' IDENTIFIED BY \'$p\' WITH GRANT OPTION\; | mysql -u root -p$pass
# clean previously installed stuff -- comment this out if you're starting on a clean system
cat <<EOF | mysql -u root -p$pass
USE $d;
DROP TABLE $2_categories, $2_comments, $2_linkcategories, $2_links, $2_post2cat, $2_options, $2_posts, $2_postmeta, $2_users;
EOF
# with that we have a user which can install wordpress
# get wordpress, untar, config
wget -O mywordpress.tar.gz $wpress
tar -xzf mywordpress.tar.gz
rm mywordpress.tar.gz
mv wordpress $directory
cd $directory
touch .htaccess
chmod 777 .htaccess
cat wp-config-sample.php | sed -e "s/_NAME.*$/_NAME\', \'$d\'\);/" | \
sed -e "s/_USER.*$/_USER\', \'$u\'\);/" | \
sed -e "s/wp_/$2_/" | \
sed -e "s/_PASSWORD.*$/_PASSWORD\', \'$p\'\);/" > wp-config.php
# get plugin manager in there
chmod -R 777 wp-content
cd wp-content
wget http://wp-plugins.net/wp-plugin-mgr.zip
unzip wp-plugin-mgr.zip
mv wp-plugin-mgr-plugin/put_into_wp-root/wp-plugin-mgr.php ../
mv wp-plugin-mgr-plugin/wp-plugin-mgr-plugin.php plugins
rm -rf wp-plugin-mgr*
# get ref karma
wget http://wp-plugins.net/downloads/ref-karma.zip
unzip ref-karma.zip
mv ref-karma/* ./
rm -rf ref-karma
rm -rf __MACOSX
rm ref-karma.zip
cat rk_settings_sample.php | sed -e "s/_NAME.*$/_NAME\', \'$d\'\);/" | \
sed -e "s/_USER.*$/_USER\', \'$rkuser\'\);/" | \
sed -e "s/_PASSWORD.*$/_PASSWORD\', \'$rkpass\'\);/" | \
sed -e "s/_configure.*$/_configure = false;/" | \
sed -e "s/_config_pwd.*$/_config_pwd = \"spamaway\";/" | \
sed -e "s/_blacklist\ =.*$/_blacklist = true;/" | \
sed -e "s/rumplestiltskin/whatever/" > rk_settings.php
# we want backup
mkdir backup
chmod o+w backup
touch backup/index.html
cd plugins
wget http://boren.nu/downloads/wp_backup.tar.gz
tar -xzvf wp_backup.tar.gz
mv wp_backup/backuprestore* ./
rm -rf wp_backup*
# install wordpress (a few wgets)
wget -q $url/wp-admin/install.php?step=1
wget -q $url/wp-admin/install.php?step=2
# spam karma, quick!
wget -O spam-karma2.zip http://wp-plugins.net/downloads/sk2_pre_alpha.zip
unzip spam-karma2.zip
rm spam-karma2.zip
# more dirty sql (set options, fix privs so that the current user can only do stuff on his tables -- allows different people to live side-by-side in the same db, sharing RK)
cat <<EOF | mysql -u root -p$pass
USE $d;
UPDATE $2_users SET user_pass = MD5( 'admin' ) , user_firstname = 'Stephanie', user_lastname = 'Booth', user_email = 'edublogs@gmail.com' WHERE ID = '1';
UPDATE $2_options SET option_value = '$adminmail' where option_name = 'admin_email';
UPDATE $2_options SET option_value = '/categories' where option_name = 'category_base';
UPDATE $2_options SET option_value = '$title' where option_name = 'blogname';
UPDATE $2_options SET option_value = 'j.m.Y' where option_name = 'date_format';
UPDATE $2_options SET option_value = 'H:i' where option_name = 'time_format';
UPDATE $2_options SET option_value = '/archives/%year%/%monthnum%/%day%/%postname%/' where option_name = 'permalink_structure';
UPDATE $2_options SET option_value = 'http://rpc.technorati.com/rpc/ping\nhttp://rpc.pingomatic.com/\nhttp://www.weblogues.com/RPC/\nhttp://topicexchange.com/RPC2' where option_name = 'ping_sites';
INSERT INTO test1_options ( option_id , blog_id , option_name , option_can_override , option_type , option_value , option_width , option_height , option_description , option_admin_level , autoload )
VALUES (
'', '0', 'active_plugins', 'Y', '1', 'a:8:{i:0;s:0:"";i:1;s:27:"SK2/spam_karma_2_plugin.php";i:2;s:17:"backuprestore.php";i:3;s:14:"bunny-tags.php";i:4;s:12:"markdown.php";i:5;s:24:"wp-plugin-mgr-plugin.php";i:6;s:16:"wp-theme-mgr.php";i:7;s:19:"wp_freeze_users.php";}', '20', '8', '', '1', 'yes'
);
EOF
# error in here
cat <<EOF | mysql -u root -p$pass
USE $d;
REVOKE ALL PRIVILEGES ON * . * FROM '$2'@ '%';
REVOKE ALL PRIVILEGES ON $d . * FROM '$2'@ '%';
REVOKE GRANT OPTION ON $d . * FROM '$2'@ '%';
EOF
# error in here too
cat <<EOF | mysql -u root -p$pass
USE $d;
GRANT CREATE , CREATE TEMPORARY TABLES ON $d . * TO '$2'@'%';
GRANT SELECT , INSERT , UPDATE , DELETE , CREATE , DROP , REFERENCES , INDEX , ALTER ON $d . $2_comments, $d . $2_posts, $d . $2_categories, $d . $2_post2cat, $d . $2_options, $d . $2_linkcategories, $d . $2_links, $d . $2_postmeta, $d . $2_users TO '$2'@'%'
WITH GRANT OPTION ;
EOF
# here comes the plugin manager
cd ../..
cat wp-plugin-mgr.php | sed -e "s/get_currentuserinfo();/get_currentuserinfo(); \$user_level=8;/" > wp-plugin-mgr.php.tmp
mv wp-plugin-mgr.php.tmp wp-plugin-mgr.php
wget -q $url/wp-plugin-mgr.php
# 1-click install some plugins
wget -q $url/wp-plugin-mgr.php?oneclick_id=120 # theme manager
wget -q $url/wp-plugin-mgr.php?oneclick_id=98 # bunny's technorati tags
# put security back in place
cat wp-plugin-mgr.php | sed -e "s/get_currentuserinfo(); \$user_level=8;/get_currentuserinfo();/" > wp-plugin-mgr.php.tmp
mv wp-plugin-mgr.php.tmp wp-plugin-mgr.php
# plugin options page bug
cd wp-admin
wget -O bugfix.zip http://ericanderson.us/wp-content/ea.us/files/wordpress-1-5-menu-header-fix.zip
unzip -o bugfix.zip
rm bugfix.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment