9

I build a lot of websites with Wordpress, and my initial setup is basically always the same :

  • Latest version of WP
  • Latest versions of about 5 plugins
  • My naked development theme

Instead of downloading/uploading these things separately and do that by hand each time I start a new project, I'd like to create a bash script that would do this :

  • Download the latest version of Wordpress
  • Unzip
  • Download the latest version of plugin X
  • Unzip to WP plugins folder
  • Download my naked theme
  • Unzip to themes folder

Now downloading the latest WP is easy (http://wordpress.org/latest.tar.gz), downloading my naked theme too, but I'm having trouble getting the latest version of a plugin, as they are not called latest.tar.gz but specifict names with the version (ex: wptouch.1.9.26.zip)

EDIT : So I'm wonderning now if it's possible to use cURL in my bash script to find the exact URL of the Current version of a plugin. The idea would be to fetch the page, and then find the value of the href that is in the paragraph just after the <h3>Current Version</h3>.

Here's an example, all plugin download pages on WP are like this :

<h3>Current Version</h3>
<p class="unmarked-list">
    <a href="http://downloads.wordpress.org/plugin/jetpack.1.1.2.zip">1.1.2</a>
</p>
4

To always get latest plugin take for example my plugin:

http://wordpress.org/extend/plugins/wordpress-file-monitor-plus/

the download link for the latest is:

http://downloads.wordpress.org/plugin/wordpress-file-monitor-plus.1.1.zip

but if you remove the version from the download link you always get the latest version:

http://downloads.wordpress.org/plugin/wordpress-file-monitor-plus.zip

EDIT: Have you considered keeping a folder of the latest wordpress and plugins unpacked? Then as soon as a new plugin or wordpress comes out you simply unpack that over what you have. Then your bash script just packages the whole lot to be used on an install.

  • 1
    Dammit, that was easy, thanks. Now I'm off bash scripting, I hope I can put something together. I'll post the result here. – mike23 May 13 '11 at 8:22
  • One question though, in your example wordpress-file-monitor-plus.zip is listed under "Development Version", that's not the same as the latest stable version, is it ? – mike23 May 13 '11 at 8:43
  • Oh I see. This maybe not the latest version... It might be what's currently latest in the trunk. Sorry I might have miss informed you. – Brady May 13 '11 at 9:38
  • 2
    I would go with SVN here. There you can checkout/export the tag with the highest number or just the trunk from every plugin. Same goes for the WordPress Core. – rofflox May 14 '11 at 12:52
  • 1
    Couldn't you just open http://plugins.svn.wordpress.org/plugin-name/trunk/readme.txt, parse out the Stable Tag: X line, then download http://downloads.wordpress.org/plugin/plugin-name.X.zip ? – Ian Dunn Jul 9 '11 at 21:21
1

Create the bash script:

touch wp_plugins_theme.sh

Make Executable:

chmod +x ./wp_plugins_theme.sh

Copy this into it:

#!/bin/bash
#
#  This script is to automate a common WP setup.
#
#   - Download the latest version of Wordpress
#   - Unzip
#   - Download the latest version of plugin X
#   - Unzip to WP plugins folder
#   - Download theme
#   - Unzip to themes folder

: ' Define Directory
'

# Change to your directory name
# Final site will be $PWD/$dirname/www/

dirname=ExampleWPPluginsTheme

# WordPress Directories used later

plugins=$PWD/$dirname/www/wp-content/plugins
themes=$PWD/$dirname/www/wp-content/themes

: ' Clear Example Dir
'

rm -rf $PWD/$dirname
mkdir -p $PWD/$dirname/www
cd $PWD/$dirname;

: ' Download the latest version of Wordpress
'

curl -OL "https://wordpress.org/latest.tar.gz"

: ' Unzip
'

tar -zxvf "./latest.tar.gz" -C 'www' --strip-components=1

: ' Download the latest version of plugin X
'

curl -OL "https://downloads.wordpress.org/plugin/query-monitor.latest-stable.zip"
curl -OL "https://downloads.wordpress.org/plugin/wp-optimize.latest-stable.zip"

: ' Unzip to WP plugins folder
'

tar -zxvf "./query-monitor.latest-stable.zip" -C $plugins
tar -zxvf "./wp-optimize.latest-stable.zip" -C $plugins

: ' Download theme
'

curl -OL "https://github.com/Automattic/_s/archive/master.zip"

: ' Unzip to themes folder
'

tar -zxvf "./master.zip" -C $themes

: ' Done
'

# List the folder contents

ls -la $PWD

Run the command

./wp_plugins_theme.sh
  • I know that this is old now but it's the closest one to the right answer which should simply be https://downloads.wordpress.org/plugin/plugin-name.latest-stable.zip – Sledge Hammer May 2 '18 at 17:44
0

I created a bash script to update Wordpress using subversion as they recommend.

#!/bin/bash
# usage: upgrade_wordpress.sh X.X.X
# http://codex.wordpress.org/Installing/Updating_WordPress_with_Subversion

# http://stackoverflow.com/a/699613/327074
die () {
    echo >&2 "$@"
    exit 1
}

# check that there is one argument
[ "$#" -eq 1 ] || die "usage: upgrade_wordpress.sh X.X.X"
# http://stackoverflow.com/a/2220646/327074
response=$(curl --write-out %{http_code} --silent --output /dev/null http://core.svn.wordpress.org/tags/$1/)
# check that the tag repository exists, i.e. returns a HTTP 200 status code
[ "$response" -eq 200 ] || die "Couldn't find Wordpress version, http error: $response"
# Take a backup
mysqldump -u root -p wordpress > wordpress_upgrade_to_$1_bak.sql
# Updating to a New Stable Version
cd /path/to/wordpress/dir/
svn sw http://core.svn.wordpress.org/tags/$1/ .

I've modified this to do the installation. This second script is untested but it should get you started. You will need to write your own create_wordpress_database_and_user.sql - but you didn't ask for that in the question anyway, so maybe you can ignore it.

#!/bin/bash
# usage: install_wordpress.sh X.X.X /path/to/wordpress/dir
# http://codex.wordpress.org/Installing/Updating_WordPress_with_Subversion

# http://stackoverflow.com/a/699613/327074
die () {
    echo >&2 "$@"
    exit 1
}
# check that there are two arguments
[ "$#" -eq 2 ] || die "usage: install_wordpress.sh X.X.X /path/to/wordpress/dir"
# http://stackoverflow.com/a/2220646/327074
response=$(curl --write-out %{http_code} --silent --output /dev/null http://core.svn.wordpress.org/tags/$1/)
# check that the tag repository exists, i.e. returns a HTTP 200 status code
[ "$response" -eq 200 ] || die "Could not find Wordpress version, http error: $response"
# create directory if needed
if [ ! -d $2 ]; then
    mkdir $2
fi
# Install the database
mysql -u root -p < create_wordpress_database_and_user.sql
# Checking out stable version
cd $2
svn co http://core.svn.wordpress.org/tags/$1/ .
0

I have been using git clone as a sort of poor mans bash.

The WordPress git is updated every 30 minutes so I clone it into my own repo with my own plugins/themes or just pull directly from it.

The whole thing is pretty fast, in fact it is only about 2 lines, and the only thing I have to do manually is create the local DB and edit the config.php. It can be a bit tricky making sure you update WordPress to the latest version if you want to do it every 30minutes, but I typically only use the stable version, and keep the dev version in another environment.

It looks like this:

mkdir wordpress-project
git clone ..url-to-my-wordpress-base 

The other downside is that it is a bit hard to get plugins from the actual WordPress repo through git, it is possible to do it, using the git svn command but I find it's not easy to work with, yet.

0

I have created a bash script to install wordpress.

This script will automate the following:

  • Downlaod and install Wordpress automatically
  • Create Default Users with passwords
  • Install all default plugins
  • Install the default or custom theme by zip url you mostly used.

You can find script on github.com

https://github.com/jeoga/wordpress_install_bash_script

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.