Skip to content

Instantly share code, notes, and snippets.

@keichan34
Last active December 15, 2015 14:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keichan34/5275326 to your computer and use it in GitHub Desktop.
Save keichan34/5275326 to your computer and use it in GitHub Desktop.
A WordPress install script Adds version and language options
#!/bin/bash
language="default"
version="latest"
dl_url=""
while getopts l:v:u: opt; do
case $opt in
l)
language=$OPTARG
;;
v)
version=$OPTARG
;;
u)
dl_url=$OPTARG
;;
esac
done
shift $((OPTIND - 1))
echo "Installing $language language, version $version."
if [ -z "$1" ]; then
echo "Usage: $0 [-v <latest|nightly|code>] [-u URL] [-l <language code>] <name of WordPress install>"
exit 1
fi
if [ -e "$1" ]; then
echo "Pathspec '$1' exists."
exit 1
fi
wordpresstemp="wordpress-latest-$RANDOM"
zipfile="$wordpresstemp.zip"
uri="http://wordpress.org/latest.zip"
if [ "$version" = "nightly" ]; then
uri="http://wordpress.org/nightly-builds/wordpress-latest.zip"
else
uri="http://wordpress.org/wordpress-$version.zip"
fi
if [ "$language" != "default" ]; then
if [ "$version" = "latest" ]; then
filename="latest-$language.zip"
else
filename="wordpress-$version-$language.zip"
fi
uri="http://ja.wordpress.org/$filename"
fi
if [ "$dl_url" != "" ]; then
uri="$dl_url"
fi
echo "Downloading WordPress from $uri..."
curl "$uri" > $zipfile
unzip $zipfile -d "$wordpresstemp"/ &> /dev/null
if [ $? -ne 0 ]; then
echo "Sorry, there was a problem with the archive. The version / language combination may not be valid."
rm -r $zipfile "$wordpresstemp"
exit 1
fi
rm $zipfile
mv "$wordpresstemp"/wordpress "$1"
rm -r "$wordpresstemp"
echo "Created a new WordPress install in '$1'!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment