You are here

build.sh in Commerce Kickstart 7.2

#!/bin/bash
set -e

#
# Build the distribution using the same process used on Drupal.org
#
# Usage: scripts/build.sh [-y] <destination> from the profile main directory.
#

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
  exit 1
}

DESTINATION=$1
ASK=true

while getopts ":y" opt; do
  case $opt in
    y)
      DESTINATION=$2
      ASK=false
      ;;
    \?)
      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."
  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..."
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
rsync -r --exclude '.git' . $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. # Usage: scripts/build.sh [-y] from the profile main directory.
  7. #
  8. confirm () {
  9. read -r -p "${1:-Are you sure? [Y/n]} " response
  10. case $response in
  11. [yY][eE][sS]|[yY])
  12. true
  13. ;;
  14. *)
  15. false
  16. ;;
  17. esac
  18. }
  19. # Figure out directory real path.
  20. realpath () {
  21. TARGET_FILE=$1
  22. cd `dirname $TARGET_FILE`
  23. TARGET_FILE=`basename $TARGET_FILE`
  24. while [ -L "$TARGET_FILE" ]
  25. do
  26. TARGET_FILE=`readlink $TARGET_FILE`
  27. cd `dirname $TARGET_FILE`
  28. TARGET_FILE=`basename $TARGET_FILE`
  29. done
  30. PHYS_DIR=`pwd -P`
  31. RESULT=$PHYS_DIR/$TARGET_FILE
  32. echo $RESULT
  33. }
  34. usage() {
  35. echo "Usage: build.sh [-y] " >&2
  36. echo "Use -y to skip deletion confirmation" >&2
  37. exit 1
  38. }
  39. DESTINATION=$1
  40. ASK=true
  41. while getopts ":y" opt; do
  42. case $opt in
  43. y)
  44. DESTINATION=$2
  45. ASK=false
  46. ;;
  47. \?)
  48. echo "Invalid option: -$OPTARG" >&2
  49. usage
  50. ;;
  51. esac
  52. done
  53. if [ "x$DESTINATION" == "x" ]; then
  54. usage
  55. fi
  56. if [ ! -f drupal-org.make ]; then
  57. echo "[error] Run this script from the distribution base path."
  58. exit 1
  59. fi
  60. DESTINATION=$(realpath $DESTINATION)
  61. case $OSTYPE in
  62. darwin*)
  63. TEMP_BUILD=`mktemp -d -t tmpdir`
  64. ;;
  65. *)
  66. TEMP_BUILD=`mktemp -d`
  67. ;;
  68. esac
  69. # Drush make expects destination to be empty.
  70. rmdir $TEMP_BUILD
  71. if [ -d $DESTINATION ]; then
  72. echo "Removing existing destination: $DESTINATION"
  73. if $ASK; then
  74. confirm && chmod -R 777 $DESTINATION && rm -rf $DESTINATION
  75. if [ -d $DESTINATION ]; then
  76. echo "Aborted."
  77. exit 1
  78. fi
  79. else
  80. chmod -R 777 $DESTINATION && rm -rf $DESTINATION
  81. fi
  82. echo "done"
  83. fi
  84. # Build the profile.
  85. echo "Building the profile..."
  86. drush make --no-cache --no-core --contrib-destination="." drupal-org.make tmp
  87. # Build a drupal-org-core.make file if it doesn't exist.
  88. if [ ! -f drupal-org-core.make ]; then
  89. cat >> drupal-org-core.make <
  90. api = 2
  91. core = 7.x
  92. projects[drupal] = 7
  93. EOF
  94. fi
  95. # Build the distribution and copy the profile in place.
  96. echo "Building the distribution..."
  97. drush make drupal-org-core.make $TEMP_BUILD
  98. echo -n "Moving to destination... "
  99. cp -r tmp $TEMP_BUILD/profiles/commerce_kickstart
  100. rm -rf tmp
  101. rsync -r --exclude '.git' . $TEMP_BUILD/profiles/commerce_kickstart
  102. mv $TEMP_BUILD $DESTINATION
  103. echo "done"