Skip to content

Instantly share code, notes, and snippets.

@christianhanne
Created August 10, 2017 15:44
Show Gist options
  • Save christianhanne/eab02899f413c927104ce94e11510e53 to your computer and use it in GitHub Desktop.
Save christianhanne/eab02899f413c927104ce94e11510e53 to your computer and use it in GitHub Desktop.
Automated drupal update with Git integration.
#!/bin/bash
ROOT_DIR=$(pwd)
PUBLIC_DIR="$ROOT_DIR/web"
PATCHES_DIR="$ROOT_DIR/patches"
DRUPGNORE_PATH="$ROOT_DIR/.drupgnore"
issue="$1"
if [[ $issue == "" ]]; then
echo "Usage: drupdate [Issue number]"
exit 1
fi
ignore=""
if [ -f "$DRUPGNORE_PATH" ]; then
ignore=$(cat $DRUPGNORE_PATH)
fi
echo "Starting update..."
if [ -d "$PUBLIC_DIR" ]; then
cd $PUBLIC_DIR
fi
modules=$(drush ups -p)
while read module; do
if [[ $ignore == *"$module"* ]]; then
echo "Ignoring $module..."
else
echo "Updating $module..."
description=$(drush up $module -y)
if [ "$module" == "drupal" ]; then
git checkout HEAD -- .htaccess
git checkout HEAD -- .gitignore
fi
git add --all
git commit -m "Updated $module. #$issue" -m "$description"
fi
done <<< "$(echo "$modules")"
echo "Updates finished."
cd $ROOT_DIR
if [ -d "$PATCHES_DIR" ]; then
echo "Applying patches.."
for file in $PATCHES_DIR/*; do
echo "Applying $(basename $file)..."
git apply $file
done
git add --all
git commit -m "Applied patches. #$issue"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment