-
Notifications
You must be signed in to change notification settings - Fork 2
/
update-wordpress
executable file
·81 lines (69 loc) · 1.92 KB
/
update-wordpress
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
#
# Download latest version of Wordpress and install to site directory
# Ensure running as root
if [ "$(id -u)" -ne 0 ]; then
echo 'This script is designed to run as root'
exit
fi
# Check arguments
if [ $# -ne 1 ]; then
echo 'Syntax: update-wordpress <site-name>'
exit
fi
# Determine site directory and user
SITENAME=$1
DESTDIR=/var/www/$SITENAME
SITE_USER=$SUDO_USER
SITE_GROUP='www-data'
ROOTDIR=$DESTDIR/wwwroot
TEMPDIR=tmp
if [ ! -d $DESTDIR ]; then
echo "Site $SITENAME is not found"
exit 1
fi
# Ensure destination directory exists
if [ ! -d $ROOTDIR ]; then
echo "Site root directory $ROOTDIR does not exist"
exit 1
fi
# Check prerequisites
if [ ! -d $TEMPDIR ]; then
mkdir $TEMPDIR
fi
echo 'Install required packages'
apt-get -qy install zip > tmp/logfile
# Download Wordpress
echo 'Download and unpack WordPress'
if [ -d tmp/wordpress ]; then
rm -rf tmp/wordpress
fi
wget --no-check-certificate -O tmp/wordpress.tar.gz https://wordpress.org/latest.tar.gz
cd tmp
tar xf wordpress.tar.gz > logfile
cd ..
# Create backup of current files in directory
echo 'Create backup of current files in site'
BACKUP_DIR='/var/www/backup'
if [ ! -d $BACKUP_DIR ]; then
mkdir $BACKUP_DIR
chown root:adm $BACKUP_DIR
chmod 770 $BACKUP_DIR
fi
TODAY=`date +%F`
zip -qr $BACKUP_DIR/$SITENAME-$TODAY.zip $DESTDIR/*
# Copy all files
echo 'Copy WordPress to site'
cp -r tmp/wordpress/* $ROOTDIR/
rm -rf tmp/wordpress
rm tmp/wordpress.tar.gz
# Set permissions (in case new files added/changed)
chown -R $SITE_USER:$SITE_GROUP $ROOTDIR
chmod -R 0750 $ROOTDIR
find $ROOTDIR -type d -exec chmod 2750 {} \;
chmod -R 0770 $ROOTDIR/wp-content
find $ROOTDIR/wp-content -type d -exec chmod 2770 {} \;
# Apply patches to Wordpress
# This one removes a replacement of -- when saving post content
sed -i 's/'\''--'\''/'\''-_'\''/' $ROOTDIR/wp-includes/formatting.php
echo "Updated Wordpress for site $1 successfully"