You are here

build.sh in Drupal Commons 7.3

#!/bin/bash
set -e

#
# Build the distribution using the same process used on Drupal.org
#
# When building, we expect that you're building within a directory structure like
# the following:
#   commons/
#     /commons_profile
#     /docroot
#     /docroot2, etc, etc
#     /repos
#     /patches
#     /screenshots
#
#
# Usage: scripts/build.sh [-y] <destination> from the profile main directory.
#
# BUILD_ROOT = development path for commons
# DESTINATION = docroot for commons builds

confirm () {
  read -r -p "${1:-Are you sure? [Y/n]} " response
  case $response in
    [yY][eE][sS]|[yY])
      true
      ;;
    *)
      false
      ;;
  esac
}

# Figure out directory real path.
realpath () {
  TARGET_FILE=$1

  cd `dirname $TARGET_FILE`
  TARGET_FILE=`basename $TARGET_FILE`

  while [ -L "$TARGET_FILE" ]
  do
    TARGET_FILE=`readlink $TARGET_FILE`
    cd `dirname $TARGET_FILE`
    TARGET_FILE=`basename $TARGET_FILE`
  done

  PHYS_DIR=`pwd -P`
  RESULT=$PHYS_DIR/$TARGET_FILE
  echo $RESULT
}

usage() {
  echo "Usage: build.sh [-y] <DESTINATION_PATH>" >&2
  echo "Use -y to skip deletion confirmation" >&2
  echo "Use --gitusername to use authenticated git instead of http" >&2
  echo "Use --build_root to build the whole dir structure, not just the docroot" > &2
  exit 1
}

BUILD_ROOT=`pwd -P`
DESTINATION=$1
ASK=true

while getopts ":yhg:" opt; do
  case $opt in
    y)
      DESTINATION=$2
      ASK=false
      ;;
    h)
      usage
      ;;
    \?)
      echo "Invalid option: -$OPTARG" >&2
      usage
      ;;
  esac
done

if [ "x$DESTINATION" == "x" ]; then
  usage
fi

if [ ! -f drupal-org.make ]; then
  echo "[error] Run this script from the distribution base path, eg scripts/build.sh"
  exit 1
fi

DESTINATION=$(realpath $DESTINATION)

case $OSTYPE in
  darwin*)
    TEMP_BUILD=`mktemp -d -t tmpdir`
    ;;
  *)
    TEMP_BUILD=`mktemp -d`
    ;;
esac
# Drush make expects destination to be empty.
rmdir $TEMP_BUILD

if [ -d $DESTINATION ]; then
  echo "Removing existing destination: $DESTINATION"
  if $ASK; then
    confirm && chmod -R 777 $DESTINATION && rm -rf $DESTINATION
    if [ -d $DESTINATION ]; then
      echo "Aborted."
      exit 1
    fi
  else
    chmod -R 777 $DESTINATION && rm -rf $DESTINATION
  fi
  echo "done"
fi

# Build the profile.
echo "Building the profile..."
echo `pwd`

if [[ -d $BUILD_PATH ]]; then
    cd $BUILD_PATH
    rm -rf ./publish
    # do we have the profile?
    if [[ -d $BUILD_PATH/commons_profile ]]; then
      if [[ -d $BUILD_PATH/repos ]]; then
        drush make commons_profile/build-commons.make --no-cache --working-copy --prepare-install ./publish
      else
        mkdir $BUILD_PATH/repos
        mkdir $BUILD_PATH/repos/modules
        mkdir $BUILD_PATH/repos/themes
        build_distro $BUILD_PATH
      fi
      chmod -R 777 publish/sites/default
      # symlink the profile to our dev copy
      echo "untaring"
      tar -czvf modules.tar.gz publish/profiles/commons/modules/contrib
      tar -czvf themes.tar.gz publish/profiles/commons/themes/contrib
      rm -rf publish/profiles/commons
      ln -s $BUILD_PATH/commons_profile publish/profiles/commons
      tar -zxvf modules.tar.gz
      tar -zxvf themes.tar.gz
    else
      git clone --branch 7.x-3.x-merged ${USERNAME}@git.drupal.org:project/commons.git commons_profile
      build_distro $BUILD_PATH
    fi
else
  mkdir $BUILD_PATH
  build_distro $BUILD_PATH $USERNAME
fi



drush make --no-cache --no-core --contrib-destination drupal-org.make tmp

# Build a drupal-org-core.make file if it doesn't exist.
if [ ! -f drupal-org-core.make ]; then
  cat >> drupal-org-core.make <<EOF
api = 2
core = 7.x
projects[drupal] = 7
EOF
fi

# Build the distribution and copy the profile in place.
echo "Building the distribution..."
drush make drupal-org-core.make $TEMP_BUILD
echo -n "Moving to destination... "
cp -r tmp $TEMP_BUILD/profiles/commerce_kickstart
rm -rf tmp
cp -r . $TEMP_BUILD/profiles/commerce_kickstart
mv $TEMP_BUILD $DESTINATION
echo "done"

File

scripts/build.sh
View source
  1. #!/bin/bash
  2. set -e
  3. #
  4. # Build the distribution using the same process used on Drupal.org
  5. #
  6. # When building, we expect that you're building within a directory structure like
  7. # the following:
  8. # commons/
  9. # /commons_profile
  10. # /docroot
  11. # /docroot2, etc, etc
  12. # /repos
  13. # /patches
  14. # /screenshots
  15. #
  16. #
  17. # Usage: scripts/build.sh [-y] from the profile main directory.
  18. #
  19. # BUILD_ROOT = development path for commons
  20. # DESTINATION = docroot for commons builds
  21. confirm () {
  22. read -r -p "${1:-Are you sure? [Y/n]} " response
  23. case $response in
  24. [yY][eE][sS]|[yY])
  25. true
  26. ;;
  27. *)
  28. false
  29. ;;
  30. esac
  31. }
  32. # Figure out directory real path.
  33. realpath () {
  34. TARGET_FILE=$1
  35. cd `dirname $TARGET_FILE`
  36. TARGET_FILE=`basename $TARGET_FILE`
  37. while [ -L "$TARGET_FILE" ]
  38. do
  39. TARGET_FILE=`readlink $TARGET_FILE`
  40. cd `dirname $TARGET_FILE`
  41. TARGET_FILE=`basename $TARGET_FILE`
  42. done
  43. PHYS_DIR=`pwd -P`
  44. RESULT=$PHYS_DIR/$TARGET_FILE
  45. echo $RESULT
  46. }
  47. usage() {
  48. echo "Usage: build.sh [-y] " >&2
  49. echo "Use -y to skip deletion confirmation" >&2
  50. echo "Use --gitusername to use authenticated git instead of http" >&2
  51. echo "Use --build_root to build the whole dir structure, not just the docroot" > &2
  52. exit 1
  53. }
  54. BUILD_ROOT=`pwd -P`
  55. DESTINATION=$1
  56. ASK=true
  57. while getopts ":yhg:" opt; do
  58. case $opt in
  59. y)
  60. DESTINATION=$2
  61. ASK=false
  62. ;;
  63. h)
  64. usage
  65. ;;
  66. \?)
  67. echo "Invalid option: -$OPTARG" >&2
  68. usage
  69. ;;
  70. esac
  71. done
  72. if [ "x$DESTINATION" == "x" ]; then
  73. usage
  74. fi
  75. if [ ! -f drupal-org.make ]; then
  76. echo "[error] Run this script from the distribution base path, eg scripts/build.sh"
  77. exit 1
  78. fi
  79. DESTINATION=$(realpath $DESTINATION)
  80. case $OSTYPE in
  81. darwin*)
  82. TEMP_BUILD=`mktemp -d -t tmpdir`
  83. ;;
  84. *)
  85. TEMP_BUILD=`mktemp -d`
  86. ;;
  87. esac
  88. # Drush make expects destination to be empty.
  89. rmdir $TEMP_BUILD
  90. if [ -d $DESTINATION ]; then
  91. echo "Removing existing destination: $DESTINATION"
  92. if $ASK; then
  93. confirm && chmod -R 777 $DESTINATION && rm -rf $DESTINATION
  94. if [ -d $DESTINATION ]; then
  95. echo "Aborted."
  96. exit 1
  97. fi
  98. else
  99. chmod -R 777 $DESTINATION && rm -rf $DESTINATION
  100. fi
  101. echo "done"
  102. fi
  103. # Build the profile.
  104. echo "Building the profile..."
  105. echo `pwd`
  106. if [[ -d $BUILD_PATH ]]; then
  107. cd $BUILD_PATH
  108. rm -rf ./publish
  109. # do we have the profile?
  110. if [[ -d $BUILD_PATH/commons_profile ]]; then
  111. if [[ -d $BUILD_PATH/repos ]]; then
  112. drush make commons_profile/build-commons.make --no-cache --working-copy --prepare-install ./publish
  113. else
  114. mkdir $BUILD_PATH/repos
  115. mkdir $BUILD_PATH/repos/modules
  116. mkdir $BUILD_PATH/repos/themes
  117. build_distro $BUILD_PATH
  118. fi
  119. chmod -R 777 publish/sites/default
  120. # symlink the profile to our dev copy
  121. echo "untaring"
  122. tar -czvf modules.tar.gz publish/profiles/commons/modules/contrib
  123. tar -czvf themes.tar.gz publish/profiles/commons/themes/contrib
  124. rm -rf publish/profiles/commons
  125. ln -s $BUILD_PATH/commons_profile publish/profiles/commons
  126. tar -zxvf modules.tar.gz
  127. tar -zxvf themes.tar.gz
  128. else
  129. git clone --branch 7.x-3.x-merged ${USERNAME}@git.drupal.org:project/commons.git commons_profile
  130. build_distro $BUILD_PATH
  131. fi
  132. else
  133. mkdir $BUILD_PATH
  134. build_distro $BUILD_PATH $USERNAME
  135. fi
  136. drush make --no-cache --no-core --contrib-destination drupal-org.make tmp
  137. # Build a drupal-org-core.make file if it doesn't exist.
  138. if [ ! -f drupal-org-core.make ]; then
  139. cat >> drupal-org-core.make <
  140. api = 2
  141. core = 7.x
  142. projects[drupal] = 7
  143. EOF
  144. fi
  145. # Build the distribution and copy the profile in place.
  146. echo "Building the distribution..."
  147. drush make drupal-org-core.make $TEMP_BUILD
  148. echo -n "Moving to destination... "
  149. cp -r tmp $TEMP_BUILD/profiles/commerce_kickstart
  150. rm -rf tmp
  151. cp -r . $TEMP_BUILD/profiles/commerce_kickstart
  152. mv $TEMP_BUILD $DESTINATION
  153. echo "done"