Skip to content

Instantly share code, notes, and snippets.

@matglas
Last active July 12, 2017 14:47
Show Gist options
  • Save matglas/9547542 to your computer and use it in GitHub Desktop.
Save matglas/9547542 to your computer and use it in GitHub Desktop.
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Git ref to checkout in the ./src directory
NO_FETCH=$2
REF=$1
# Don't use - or . in the project name!
PROJECT=`basename $DIR`
SEPERATOR="_"
DRUSH=drush
if [ "$REF" != "" ]
then
cd $DIR
cd src
if [ "$NO_FETCH" != "no" ]
then
# Fetch all new commits
git fetch
fi
# Checkout correct ref.
echo "Checkout $REF"
git checkout $REF
if [ "$?" -eq 0 ]
then
# Attach a tag label when the tag is annotated.
TAG=`git describe --tags`
TAG_ANNOTATED=`git describe`
TAG_LABEL=""
if [ "$TAG" == "$TAG_ANNOTATED" ]
then
# We have to remove the . in the label.
TAG_LABEL=$SEPERATOR$TAG_ANNOTATED
TAG_LABEL=${TAG_LABEL//./_}
TAG_LABEL=${TAG_LABEL//-/_}
fi
# Go to main dir and create a new build.
cd $DIR
# Run kraftwagen build.
$DRUSH kw-build --verbose
if [ "$?" -eq 0 ]
then
# Our new platform is.
# Name based on path
PLATFORM_DIR=`ls builds --indicator-style=none | sort | tail -1`
# We need to replace - with _ because Aegir aliases can't work with spaces or - on platform names.
# With sites this is no problem.
PLATFORM_NAME=${PLATFORM_DIR//-/_}
NEW_PLATFORM="$DIR/builds/$PLATFORM_DIR"
NEW_ALIAS="@platform_$PROJECT$SEPERATOR$PLATFORM_NAME$TAG_LABEL"
echo ""
echo "The new platform location is $NEW_PLATFORM"
echo ""
echo "drush provision-save $NEW_ALIAS --context_type=platform --root=$NEW_PLATFORM --web_server=@server_master"
echo "drush provision-verify $NEW_ALIAS"
echo "drush @hostmaster hosting-import $NEW_ALIAS"
echo
$DRUSH provision-save $NEW_ALIAS --context_type=platform --root=$NEW_PLATFORM --web_server=@server_master
$DRUSH provision-verify $NEW_ALIAS
$DRUSH @hostmaster hosting-import $NEW_ALIAS
$DRUSH provision-verify $NEW_ALIAS
else
echo "! Build could not be created"
fi
else
echo "! Could no checkout $REF"
fi
else
echo "No ref provided (v1.0, a313h, origin/development)"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment