-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWordpressUpgrade.sh
68 lines (54 loc) · 1.66 KB
/
WordpressUpgrade.sh
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
#!/bin/bash
LIVE_SITE="$1"
BACKUP_DIR="old-site"
##
# Error checking
##
if [ "$LIVE_SITE" == "" ]; then
echo "error! requires one argument"
exit
fi
if [ ! -d "$LIVE_SITE" ]; then
echo "$LIVE_SITE is not a directory!"
exit
fi
if [ ! -f "$LIVE_SITE/wp-config.php" ]; then
echo "$LIVE_SITE is not a wordpress installation!"
exit
fi
if [ ! -d "wordpress" ]; then
echo "wordpress directory does not exist!"
exit
fi
if [ -d "$BACKUP_DIR" ]; then
echo "refusing to upgrade since './$BACKUP_DIR' still exists"
exit
fi
##
# Real work begins...
##
echo "beginning wordpress upgrade..."
mkdir $BACKUP_DIR
files=`cat diff -Nqr "$LIVE_SITE" wordpress | grep -v wp-content | grep -v favicon | grep -v htaccess | grep -v wp-config.php | grep -v wp-admin | grep -v wp-includes | awk '{ print $4 }' | sed "s/^wordpress\///"`
echo "copying over wp-includes..."
mv "$LIVE_SITE/wp-includes" $BACKUP_DIR/wp-includes && mv wordpress/wp-includes "$LIVE_SITE/wp-includes"
echo "copying over wp-admin..."
mv "$LIVE_SITE/wp-admin" $BACKUP_DIR/wp-admin && mv wordpress/wp-admin "$LIVE_SITE/wp-admin"
for f in $files; do
subdir=`dirname $f` # also ${f%/*}
if [ -f "wordpress/$f" ]; then
if [ -f "$LIVE_SITE/$f" ]; then
echo "Upgrading: $f"
mkdir -p "$BACKUP_DIR/$subdir"
mv "$LIVE_SITE/$f" "$BACKUP_DIR/$f" && mv "wordpress/$f" "$LIVE_SITE/$f"
else
echo "Installing: $f"
mkdir -p "$LIVE_SITE/$subdir"
cp "wordpress/$f" "$LIVE_SITE/$f"
fi
else
echo "Removing: $f"
mkdir -p "$BACKUP_DIR/$subdir"
mv "$LIVE_SITE/$f" "$BACKUP_DIR/$f"
fi
done