github.com/phobos182/packer@v0.2.3-0.20130819023704-c84d2aeffc68/scripts/dist.sh (about)

     1  #!/bin/bash
     2  set -e
     3  
     4  # Get the parent directory of where this script is.
     5  SOURCE="${BASH_SOURCE[0]}"
     6  while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
     7  DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
     8  
     9  # Change into that dir because we expect that
    10  cd $DIR
    11  
    12  # Determine the version that we're building based on the contents
    13  # of packer/version.go.
    14  VERSION=$(grep "const Version " packer/version.go | sed -E 's/.*"(.+)"$/\1/')
    15  VERSIONDIR="${VERSION}"
    16  PREVERSION=$(grep "const VersionPrerelease " packer/version.go | sed -E 's/.*"(.*)"$/\1/')
    17  if [ ! -z $PREVERSION ]; then
    18      PREVERSION="${PREVERSION}.$(date -u +%s)"
    19      VERSIONDIR="${VERSIONDIR}-${PREVERSION}"
    20  fi
    21  
    22  echo "Version: ${VERSION} ${PREVERSION}"
    23  
    24  # Determine the arch/os combos we're building for
    25  XC_ARCH=${XC_ARCH:-"386 amd64 arm"}
    26  XC_OS=${XC_OS:-linux darwin windows freebsd openbsd}
    27  
    28  echo "Arch: ${XC_ARCH}"
    29  echo "OS: ${XC_OS}"
    30  
    31  # This function builds whatever directory we're in...
    32  xc() {
    33      goxc \
    34          -arch="$XC_ARCH" \
    35          -os="$XC_OS" \
    36          -d="${DIR}/pkg" \
    37          -pv="${VERSION}" \
    38          -pr="${PREVERSION}" \
    39          $XC_OPTS \
    40          go-install \
    41          xc
    42  }
    43  
    44  # This function waits for all background tasks to complete
    45  waitAll() {
    46      RESULT=0
    47      for job in `jobs -p`; do
    48          wait $job
    49          if [ $? -ne 0 ]; then
    50              RESULT=1
    51          fi
    52      done
    53  
    54      if [ $RESULT -ne 0 ]; then
    55          exit $RESULT
    56      fi
    57  }
    58  
    59  # Make sure that if we're killed, we kill all our subprocseses
    60  trap "kill 0" SIGINT SIGTERM EXIT
    61  
    62  # Build our root project
    63  xc
    64  
    65  # Build all the plugins
    66  for PLUGIN in $(find ./plugin -mindepth 1 -maxdepth 1 -type d); do
    67      PLUGIN_NAME=$(basename ${PLUGIN})
    68      find ./pkg \
    69          -type f \
    70          -name ${PLUGIN_NAME} \
    71          -execdir mv ${PLUGIN_NAME} packer-${PLUGIN_NAME} ';'
    72      find ./pkg \
    73          -type f \
    74          -name ${PLUGIN_NAME}.exe \
    75          -execdir mv ${PLUGIN_NAME}.exe packer-${PLUGIN_NAME}.exe ';'
    76  done
    77  
    78  # Zip all the packages
    79  mkdir -p ./pkg/${VERSIONDIR}/dist
    80  for PLATFORM in $(find ./pkg/${VERSIONDIR} -mindepth 1 -maxdepth 1 -type d); do
    81      PLATFORM_NAME=$(basename ${PLATFORM})
    82      ARCHIVE_NAME="${VERSIONDIR}_${PLATFORM_NAME}"
    83  
    84      if [ $PLATFORM_NAME = "dist" ]; then
    85          continue
    86      fi
    87  
    88      (
    89      pushd ${PLATFORM}
    90      zip ${DIR}/pkg/${VERSIONDIR}/dist/${ARCHIVE_NAME}.zip ./*
    91      popd
    92      ) &
    93  done
    94  
    95  waitAll
    96  
    97  # Make the checksums
    98  pushd ./pkg/${VERSIONDIR}/dist
    99  shasum -a256 * > ./${VERSIONDIR}_SHA256SUMS
   100  popd
   101  
   102  exit 0