Created
September 25, 2017 13:42
-
-
Save tassilogroeper/f3f2af84adcd983e93fb71bae508362b to your computer and use it in GitHub Desktop.
Drupal update script to update configuration
This file contains hidden or 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
#!/usr/bin/env bash | |
CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)" | |
CURRENT_FOLDER="$(basename $(pwd))" | |
TARGET_FOLDER="web" | |
LOCAL_ALIAS="local" | |
DRUSH_ALIAS_GROUP="your-website-name" | |
DRUSH_PATH="../vendor/bin/drush" | |
SERVER_ABSOLUTE_PATH="/app/web/" | |
UPLOAD_FILES_DIRECTORY="sites/default/files/uploads" | |
TARGET_BRANCH="master" | |
WITH_DB=0 | |
WITH_FILES=0 | |
ARG_BRANCH=""; | |
ARG_FILES=""; | |
ARG_DB=""; | |
RSYNC_FLAGS="rvuc"; | |
CONFIG_FOLDERS[0]="default"; | |
CONFIG_FOLDERS[1]="prod"; | |
for arg; do | |
case $arg in | |
'branch='*) ARG_BRANCH=${arg#*=} ;; | |
'db='*) ARG_DB=${arg#*=} ;; | |
'files='*) ARG_FILES=${arg#*=} ;; | |
esac | |
done | |
echo $ARG_BRANCH | |
if ! [[ `git branch --list "$ARG_BRANCH"` ]]; then | |
if [[ $ARG_BRANCH != "" ]]; then | |
echo "The target branch does not exist" | |
exit 1 | |
fi | |
fi | |
if [[ "$ARG_BRANCH" != "" ]]; then | |
TARGET_BRANCH=$ARG_BRANCH | |
echo "target branch is $TARGET_BRANCH" | |
else | |
TARGET_BRANCH="master" | |
fi | |
if [ "$ARG_DB" == "1" ]; then | |
WITH_DB=1 | |
fi | |
if [ "$ARG_FILES" == "1" ]; then | |
WITH_FILES=1 | |
fi | |
if [ "$CURRENT_BRANCH" != "$TARGET_BRANCH" ]; then | |
git checkout $TARGET_BRANCH | |
echo "checkout out the $TARGET_BRANCH branch" | |
fi | |
if [[ `git status --porcelain` ]]; then | |
echo "you can't have a unclean git repository in the $TARGET_BRANCH branch" | |
if [ "$CURRENT_BRANCH" != "$TARGET_BRANCH" ]; then | |
git checkout $CURRENT_BRANCH | |
fi | |
exit 1 | |
fi | |
if [[ "$TARGET_FOLDER" != "$CURRENT_FOLDER" && -d "$TARGET_FOLDER" ]]; then | |
cd $TARGET_FOLDER | |
echo "changed folder to $TARGET_FOLDER" | |
fi | |
echo "with DB : $WITH_DB" | |
echo "with FILES : $WITH_FILES" | |
# Run actual config and database update | |
eval $DRUSH_PATH -y @$DRUSH_ALIAS_GROUP.$TARGET_BRANCH cex | |
for i in "${CONFIG_FOLDERS[@]}" | |
do | |
eval $DRUSH_PATH -y rsync --mode=$RSYNC_FLAGS @$DRUSH_ALIAS_GROUP.$TARGET_BRANCH:/app/remote-config/$i/ ../config/drupal/$i --exclude=.htaccess --delete | |
done | |
if [ "$WITH_DB" == 1 ]; then | |
echo "pulling database" | |
eval $DRUSH_PATH -y sql-sync @$DRUSH_ALIAS_GROUP.$TARGET_BRANCH @$DRUSH_ALIAS_GROUP.$LOCAL_ALIAS | |
fi | |
eval $DRUSH_PATH -y @$DRUSH_ALIAS_GROUP.$LOCAL_ALIAS cr | |
eval $DRUSH_PATH -y @$DRUSH_ALIAS_GROUP.$LOCAL_ALIAS cim | |
if [ "$WITH_FILES" == 1 ]; then | |
echo "pulling files" | |
eval $DRUSH_PATH -y rsync @$DRUSH_ALIAS_GROUP.$TARGET_BRANCH:$SERVER_ABSOLUTE_PATH$UPLOAD_FILES_DIRECTORY/ $UPLOAD_FILES_DIRECTORY | |
fi | |
if [ -d "$TARGET_FOLDER" ]; then | |
cd .. | |
echo "changed folder back" | |
fi | |
if [ "$CURRENT_BRANCH" != "$TARGET_BRANCH" ]; then | |
git checkout $CURRENT_BRANCH | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment