wp-update.sh

This was a script that expanded over time. The basic purpose was to provide a crontab that would update WordPress. I believe WordPress has some auto-updating capability but I’ve never even looked into it since this has continued to work pretty smoothly. The basic idea is that it downloads the latest update (thankfully WordPress keeps the latest release at a constant URL) and then uncompresses it into the root of each site. It then calls the database-update function (available through a web request) to finalize the installation.

There are a number of things that could be improved on in this script. For example, the sites have to be hard-coded (we could just specify a base-path and auto-detect for a WordPress installation). In addition, the latest WordPress is redownloaded separately for each site instead of being shared. Minor things, but maybe someday I’ll update. If it’s useful, let me know.

sites=(theseitems
          wouldbe
          thenames
          ofthefolders
          thatyouwanttoupdate
          inabasepath
          suchas/var/www/
         )
 
base_path="/var/www/vhosts"
wordpress_download_url="http://wordpress.org/latest.tar.gz"
wordpress_download_file="latest.tar.gz"
wordpress_download_directory="wordpress"
wordpress_database_update_url="wp-admin/upgrade.php?step=1&backto=%2Fwp-admin%2F"
jailed_directory="httpdocs"
temp_directory="wp-temp"
 
number_of_sites=${#sites[@]}
 
 
echo "Updating $number_of_sites websites with the latest version of Wordpress."
 
for current_site in ${sites[@]}
do
  echo "Now processing $current_site..."
  echo "  Setting up directories..."
  if [ -e $base_path/$current_site/$jailed_directory ]
  then
    echo "  !!Detected a jail'ed website..."
    mkdir -p $base_path/$current_site/$jailed_directory/$temp_directory
    cd $base_path/$current_site/$jailed_directory/$temp_directory
  else
    mkdir -p $base_path/$current_site/$temp_directory
    cd $base_path/$current_site/$temp_directory
  fi
 
  echo "  Downloading latest version of Wordpress..."
  wget -q $wordpress_download_url
  echo "  Uncompressing..."
  tar zxfv $wordpress_download_file > /dev/null
  cd $wordpress_download_directory
  echo "  Copying into existing directory..."
  cp -r * ../..
  cd ../..
  echo "  Updating database..."
  wget -q "http://$current_site/$wordpress_database_update_url" -O /dev/null
  echo "  Cleaning up..."
  rm -rf $temp_directory
  echo "Done processing $current_site."
  echo ""
 
done
  1. No comments yet.
(will not be published)