|
| 1 | +#!/bin/bash |
| 2 | +die () { |
| 3 | + echo "$*" >&2 |
| 4 | + exit 1 |
| 5 | +} |
| 6 | + |
| 7 | +# Directories |
| 8 | +THISDIR="$( cd "$(dirname "$0")" ; pwd -P )" |
| 9 | + |
| 10 | +# Product information |
| 11 | +IDENTIFIER="com.github.gitbundleserver" |
| 12 | +INSTALL_LOCATION="/usr/local/git-bundle-server" |
| 13 | + |
| 14 | +# Parse script arguments |
| 15 | +for i in "$@" |
| 16 | +do |
| 17 | +case "$i" in |
| 18 | + --version=*) |
| 19 | + VERSION="${i#*=}" |
| 20 | + shift # past argument=value |
| 21 | + ;; |
| 22 | + --payload=*) |
| 23 | + PAYLOAD="${i#*=}" |
| 24 | + shift # past argument=value |
| 25 | + ;; |
| 26 | + --output=*) |
| 27 | + PKGOUT="${i#*=}" |
| 28 | + shift # past argument=value |
| 29 | + ;; |
| 30 | + *) |
| 31 | + die "unknown option '$i'" |
| 32 | + ;; |
| 33 | +esac |
| 34 | +done |
| 35 | + |
| 36 | +# Perform pre-execution checks |
| 37 | +if [ -z "$VERSION" ]; then |
| 38 | + die "--version was not set" |
| 39 | +fi |
| 40 | +if [ -z "$PAYLOAD" ]; then |
| 41 | + die "--payload was not set" |
| 42 | +elif [ ! -d "$PAYLOAD" ]; then |
| 43 | + die "Could not find '$PAYLOAD'. Did you run layout-unix.sh first?" |
| 44 | +fi |
| 45 | +if [ -z "$PKGOUT" ]; then |
| 46 | + die "--output was not set" |
| 47 | +fi |
| 48 | + |
| 49 | +# Exit as soon as any line fails |
| 50 | +set -e |
| 51 | + |
| 52 | +# Cleanup any old component |
| 53 | +if [ -e "$PKGOUT" ]; then |
| 54 | + echo "Deleting old component '$PKGOUT'..." |
| 55 | + rm -f "$PKGOUT" |
| 56 | +fi |
| 57 | + |
| 58 | +# Ensure the parent directory for the component exists |
| 59 | +mkdir -p "$(dirname "$PKGOUT")" |
| 60 | + |
| 61 | +# Build the component package |
| 62 | +PKGTMP="$PKGOUT.tmp" |
| 63 | + |
| 64 | +# Remove any unwanted .DS_Store files |
| 65 | +echo "Removing unnecessary files..." |
| 66 | +find "$PAYLOAD" -name '*.DS_Store' -type f -delete |
| 67 | + |
| 68 | +# Set full read, write, execute permissions for owner and just read and execute permissions for group and other |
| 69 | +echo "Setting file permissions..." |
| 70 | +/bin/chmod -R 755 "$PAYLOAD" |
| 71 | + |
| 72 | +# Remove any extended attributes (ACEs) |
| 73 | +echo "Removing extended attributes..." |
| 74 | +/usr/bin/xattr -rc "$PAYLOAD" |
| 75 | + |
| 76 | +# Build component package |
| 77 | +echo "Building core component package..." |
| 78 | +/usr/bin/pkgbuild \ |
| 79 | + --root "$PAYLOAD/" \ |
| 80 | + --install-location "/" \ |
| 81 | + --scripts "$THISDIR/scripts" \ |
| 82 | + --identifier "$IDENTIFIER" \ |
| 83 | + --version "$VERSION" \ |
| 84 | + "$PKGTMP" |
| 85 | + |
| 86 | +echo "Component pack complete." |
| 87 | + |
| 88 | +# Build product installer |
| 89 | +echo "Building product package..." |
| 90 | +/usr/bin/productbuild \ |
| 91 | + --package "$PKGTMP" \ |
| 92 | + --identifier "$IDENTIFIER" \ |
| 93 | + --version "$VERSION" \ |
| 94 | + "$PKGOUT" |
| 95 | + |
| 96 | +echo "Product build complete." |
0 commit comments