Upgrade WordPress Manually

#!/bin/bash

# wordpress is installed on /home/web
WPDIR=/home/web
WPUSER=www-data
TODAY=$(date +%Y%m%d)

if [ ! -f $WPDIR/wp-config.php ]; then
    echo "ERROR: no file $WPDIR/wp-config.php"
    echo "Folder $WPDIR does not seem to contain WordPress"
    exit 1
fi

# backup
tar caf backup.$TODAY.tar.xz $WPDIR

# stop web server
service lighttpd stop

# download the new version
cd $WPDIR/..

rm -f wordpress.tar.gz
wget https://wordpress.org/latest.tar.gz -O wordpress-$TODAY.tar.gz

# unzip the new version
rm -rf wordpress
tar xaf wordpress-$TODAY.tar.gz

# start upgrading
rm -rf $WPDIR/wp-includes/ $WPDIR/wp-admin/
mv wordpress/wp-includes wordpress/wp-admin $WPDIR/
rsync -av wordpress/ $WPDIR/

# remove maintenance
rm -rf $WPDIR/.maintenance

# reset ownership
chown -R $WPUSER.$WPUSER $WPDIR

# restart web server
service lighttpd start