-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
wp-git-update.sh
executable file
·71 lines (59 loc) · 1.89 KB
/
wp-git-update.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
69
70
71
#!/bin/bash
#
# Update WordPress core under git control with local git-dir.
#
# VERSION :0.2.0
# DATE :2015-12-12
# AUTHOR :Viktor Szépe <[email protected]>
# URL :https://github.com/szepeviktor/debian-server-tools
# LICENSE :The MIT License (MIT)
# BASH-VERSION :4.2+
# DEPENDS :apt-get install git
# LOCATION :/usr/local/bin/wp-git-update.sh
# Copy this to your wp-config.php
#
# define( 'WP_AUTO_UPDATE_CORE', false );
Error() {
echo "ERROR: #$*" 1>&2
exit "$1"
}
# Go to WP root directory
WP_WORKING_TREE="$(git rev-parse --show-toplevel)"
if [ $? == 0 ] && [ -n "$WP_WORKING_TREE" ] && [ -d "$WP_WORKING_TREE" ]; then
cd "$WP_WORKING_TREE"
else
Error 1 "This not a git working-tree ($(pwd))"
fi
# Is it WordPress from GitHub?
git config --get remote.origin.url | grep -qFx "https://github.com/WordPress/WordPress.git" \
|| Error 2 "This is not WordPress/WordPress"
# Detect changes (maybe auto update ran)
if [ -z "$(git status -s)" ]; then
echo "Working-tree is clean, resetting"
git reset --hard
else
git status
echo "Revert all: git reset --hard"
Error 3 "There are changes in the working-tree"
fi
# git log --decorate -1
echo "Here we were: $(git --no-pager log --pretty=format:"%d" -1)"
# Fetch new commits and tags
git fetch --prune --tags || Error 4 "Fetch failed"
LATEST_TAG="$(git tag | tail -n 1)"
echo "Upgrading to ${LATEST_TAG}"
if ! git checkout "$LATEST_TAG"; then
Error 5 "Checkout failed"
fi
# Upgrade database
cat << EOF | /usr/bin/php || Error 6 "Database upgrade failed"
<?php // wp --allow-root core update-db
define( 'WP_INSTALLING', true );
require 'wp-load.php';
// For wp_guess_url()
define( 'WP_SITEURL', get_option( 'siteurl' ) );
require_once 'wp-admin/includes/upgrade.php';
wp_upgrade();
delete_site_transient( 'update_core' );
print( "WordPress database upgraded successfully.\n" );
EOF