Last active
April 13, 2023 14:01
-
-
Save wabson/de8206d018925144fa525c2e48ac871f to your computer and use it in GitHub Desktop.
Upgrade wordpress to latest version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NOW=`date +%Y%m%d%H%M%S` | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <source-zip>|<source-dir> <target-dir>" | |
exit 1 | |
fi | |
if [ -z "$2" ]; then | |
wget "http://wordpress.org/latest.zip" -O "wordpress-$NOW.zip" | |
src="wordpress-$NOW.zip" | |
target=$1 | |
elif [[ $1 =~ https?://.* ]]; then | |
wget "$1" | |
src=`basename $1` | |
target=$2 | |
else | |
if [ ! -f "$1" -a "$1" == "wordpress-*.zip" ]; then | |
wget "https://downloads.wordpress.org/release/$1" | |
src=`basename $1` | |
target=$2 | |
else | |
src=$1 | |
target=$2 | |
fi | |
fi | |
if [ -f "$src" ]; then | |
mkdir "wp-temp-$NOW" | |
if [ $? != 0 ]; then | |
echo echo "Unable to extract from zipfile '$src'" | |
exit 1 | |
fi | |
unzip -q "$src" -d "wp-temp-$NOW" | |
if [ $? != 0 ]; then | |
rm -r "wp-temp-$NOW" | |
echo "Unable to extract from zipfile '$src'" | |
exit 1 | |
fi | |
SOURCE="wp-temp-$NOW/wordpress" | |
else | |
SOURCE="$src" | |
fi | |
if [ ! -d "$SOURCE" ]; then | |
echo "Source '$src' does not exist or is not a file or directory" | |
exit 1 | |
fi | |
TARGET="$target" | |
if [ ! -d "$TARGET" ]; then | |
echo "Target '$TARGET' does not exist or is not a directory" | |
exit 1 | |
fi | |
if [ -d "$TARGET/wp-includes" ]; then | |
echo "Copying new wp-includes - old contents will be moved to $TARGET/wp-includes-$NOW" | |
mv "$TARGET/wp-includes" "$TARGET/wp-includes-$NOW" && cp -pr "$SOURCE/wp-includes" "$TARGET" | |
else | |
cp -pr "$SOURCE/wp-includes" "$TARGET" | |
fi | |
if [ -d "$TARGET/wp-admin" ]; then | |
echo "Copying new wp-admin - old contents will be moved to $TARGET/wp-admin-$NOW" | |
mv "$TARGET/wp-admin" "$TARGET/wp-admin-$NOW" && cp -pr "$SOURCE/wp-admin" "$TARGET" | |
else | |
cp -pr "$SOURCE/wp-admin" "$TARGET" | |
fi | |
for f in `ls "$SOURCE"`; do | |
if [ -f "$SOURCE/$f" ]; then | |
echo "Copying $f" | |
cp "$SOURCE/$f" "$TARGET" | |
fi | |
done | |
echo "Cleaning up" | |
if [ -d "wp-temp-$NOW" ]; then | |
rm -r "wp-temp-$NOW" | |
fi | |
if [ -f "wordpress-$NOW.zip" ]; then | |
rm "wordpress-$NOW.zip" | |
fi | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment