Last active
November 20, 2016 13:57
-
-
Save idimopoulos/ef801b7bc38fa97064b9de6873830fde to your computer and use it in GitHub Desktop.
Update Drupal 7 core files without drush
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 | |
# Update Drupal core for an existing Drupal 7 installation. | |
# Change directory to the web root and run this through there. | |
# No root rights needed. | |
# | |
# From the update, 'sites' folder and '.htaccess' file are excluded. | |
# | |
# WARNING: There might be security updates to the .htacess file. Make sure that | |
# the security updates are merged in. | |
root_dir=`pwd` | |
tmp_dir=`mktemp -d` | |
if [ ! -d "$tmp_dir" ]; then | |
echo "There was a problem creating a temporary directory. Exiting." | |
exit 1; | |
fi | |
echo "Drupal directory: $root_dir" | |
echo "Temporary directory: $tmp_dir" | |
# Download the latest drupal version. | |
read -p "You are about to dowload the latest Drupal and update core. Proceed? " -n 1 -r | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
cd $tmp_dir | |
echo "Downloading the latest version of drupal 7" | |
wget $(wget -O- -q https://updates.drupal.org/release-history/drupal/7.x | grep -oPm1 "(?<=<download_link>)[^<]+") -O latest_drupal.tar.gz | |
mkdir latest_drupal | |
echo "Extracting..." | |
tar -xzf latest_drupal.tar.gz --strip 1 -C latest_drupal | |
else | |
echo "Abording..." | |
rm -rf $tmp_dir | |
exit -1 | |
fi | |
# Perform the update. | |
read -p "WARNING: You are about to update Drupal core. All files except sites folder and .htaccess will be overriden. Proceed? " -n 1 -r | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
echo "Updating core..." | |
rsync -cazr --exclude="sites" --exclude=".htaccess" latest_drupal/ $root_dir | |
else | |
echo "Abording..." | |
rm -rf $tmp_dir | |
exit -1 | |
fi | |
# When the rsync completes, the permission of the web root directory changes to 0775. | |
# This impacts some hosting services which raise a fatal error when the directory is | |
# writable by group (e.g. cPanel). Fix permissions. | |
echo "Changing web root directory permissions to 0755." | |
chmod 0755 $root_dir | |
# Clean up. | |
echo "Update complete. Please update the database. Removing $tmp_dir" | |
rm -rf $tmp_dir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment