Last active
February 6, 2019 04:40
-
-
Save peacefixation/316bf1ab9f9dcb57258de2014d787325 to your computer and use it in GitHub Desktop.
Create OS X package with preinstall and postinstall scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ## | |
| # Create the directory skeleton for a new package and a Makefile to build it | |
| ## | |
| if [ "$#" -ne 1 ]; then | |
| echo "Usage: $0 \"package name\"" | |
| exit 1 | |
| fi | |
| ROOT_DIR=/tmp | |
| PACKAGE_DIR="$ROOT_DIR/$1" | |
| # create the directory skeleton | |
| /bin/mkdir -p "$PACKAGE_DIR/files" "$PACKAGE_DIR/scripts" | |
| # convert the package name in the Makefile to lower case and replace spaces with hyphens | |
| PACKAGE_NAME=`echo "$1" | tr '[:upper:]' '[:lower:]' | tr ' ' '-'` | |
| # create the Makefile | |
| /bin/cat > "$PACKAGE_DIR/Makefile" << EOF | |
| NAME="${PACKAGE_NAME}" | |
| IDENTIFIER="au.com.company.\$(NAME)" | |
| VERSION="1.0" | |
| INSTALL_LOCATION="/Applications/" | |
| all: | |
| @/bin/mkdir target | |
| @/usr/bin/pkgbuild \\ | |
| --root files/ \\ | |
| --install-location \$(INSTALL_LOCATION) \\ | |
| --scripts scripts/ \\ | |
| --identifier \$(IDENTIFIER) \\ | |
| --version \$(VERSION) \\ | |
| "target/\$(NAME).pkg" | |
| clean: | |
| @/bin/rm -rf target | |
| EOF | |
| # create a README file | |
| /bin/cat > "$PACKAGE_DIR/README.md" << EOF | |
| # $1 | |
| TODO: tell us about this package | |
| EOF | |
| # place the files to package in the $PACKAGE_DIR/files directory | |
| # place scripts named 'preinstall'/'postinstall' in the $PACKAGE_DIR/scripts directory along with any resources | |
| # make sure to chmod +x the scripts | |
| # if there is no payload (i.e. just scripts) add the '--nopayload' parameter to the 'pkgbuild' command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment