我的Wordpress自动更新脚本

我是老古板,虽然WP已经早就自带了自动更新的功能,但是我还是信不过它,所以自建了一个。

#!/bin/sh
if [ -d blog ] && [ -d wordpress ]
then
  # Do the dirty work.
  echo "Updating..."
  echo ""
  # Copy the configuration file
  cp ./blog/wp-config.php ./wordpress/
  chmod a+x ./wordpress/wp-config.php
  # Copy themes and plugins
  cp -R ./blog/wp-content/themes/* ./wordpress/wp-content/themes/
  cp -R ./blog/wp-content/plugins/* ./wordpress/wp-content/plugins/
  # Copy files need for WP Super Cache
  cp ./blog/wp-content/*.php ./wordpress/wp-content/
  cp -R ./blog/wp-content/cache/ ./wordpress/wp-content/
  chmod a+w ./wordpress/wp-content/cache/
  # Copy .htaccess
  cp ./blog/.htaccess ./wordpress/
  # Copy sitemap
  cp ./blog/sitemap.xml ./wordpress/
  cp ./blog/sitemap.xml.gz ./wordpress/
  chmod a+w ./wordpress/sitemap.xml
  chmod a+w ./wordpress/sitemap.xml.gz
  # Copy Google indentification file
  cp ./blog/google*.html ./wordpress/
  # Delete old backup folder if exist.
  if [ -e blog-old ]
  then
    chmod 777 blog-old
    rm -rf blog-old
    sleep 2 # Wait for slow disk IO to finish
  fi
  # Do move job.
  mv blog blog-old
  mv wordpress blog
  chmod 600 blog-old
  echo "Done!"
  echo ""
  echo "You may now visit http://your.blog/wp-admin/upgrade.php "
  echo "  to update database structure."
  echo "Enjoy!"
else
  # If some preparation not done
  echo "Cannot find blog and wordpress folder."
  echo "  - Are you in the correct directory?"
  echo "  - Have you unpacked the wordpress tarball?"
  exit 1
fi

使用的方法是:
ssh到你的主机,wget最新的WP安装包,解压缩,然后将上面的脚本保存为一个文件,名字随便,如autoupdate,执行chmox +x autoupdate,然后./autoupdate。稍等片刻后,脚本完成。
登录后台就会提示升级数据库(如果需要升级数据库的话)。基本上就这些。

你可以经过简单的修改之后用在自己的Blog中。留在这里仅仅是为了作为备忘。

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License