|
| 1 | +#!/bin/sh -- |
| 2 | +# |
| 3 | +# This script staples a successfully notarized app ticket to an app package. |
| 4 | +# Must be run on macOS Catalina (or later) with XCode installed. |
| 5 | +# |
| 6 | +# Requirements for this script are: |
| 7 | +# |
| 8 | +# User must have successfully notarized the app first. |
| 9 | +# User must specify the application bundle name without extension: (example -a "MyApplication") |
| 10 | +# IMPORTANT: Packaged application bundle must exist in folder noted below |
| 11 | +# User must specify the package version: (example: -v 1.0.56) |
| 12 | +# |
| 13 | +# These files and folders must exist in the paths shown below (in relation to this script's folder): |
| 14 | +# ../dist/{APP_NAME}-{VERSION}-setup-MacOS.pkg |
| 15 | +# |
| 16 | + |
| 17 | +usage() |
| 18 | +{ |
| 19 | +cat << EOF |
| 20 | +Usage: $0 OPTIONS |
| 21 | +
|
| 22 | +This script staples a successfully notarized app ticket to a packaged macOS application. |
| 23 | +
|
| 24 | +OPTIONS: |
| 25 | + -h show usage |
| 26 | + -a (REQUIRED) application bundle name |
| 27 | + - example: -a "MyApplication" |
| 28 | + -v (REQUIRED) version |
| 29 | + - example: -v 0.5.1 |
| 30 | +
|
| 31 | + examples: $0 -a "MyApplication" -v 1.0.56 |
| 32 | +
|
| 33 | +EOF |
| 34 | +} |
| 35 | + |
| 36 | +# |
| 37 | +# Resource path |
| 38 | +# |
| 39 | +DISTRIBUTION="../dist/" |
| 40 | + |
| 41 | +# |
| 42 | +# initialize input options with default values |
| 43 | +# |
| 44 | +APP_NAME= |
| 45 | +VERSION= |
| 46 | + |
| 47 | +# |
| 48 | +# get parms as flags or as requiring arguments |
| 49 | +# |
| 50 | +while getopts "ha:v:" OPTION |
| 51 | +do |
| 52 | + case $OPTION in |
| 53 | + h) |
| 54 | + usage; exit 1 ;; |
| 55 | + a) |
| 56 | + APP_NAME=$OPTARG |
| 57 | + ;; |
| 58 | + v) |
| 59 | + VERSION=$OPTARG |
| 60 | + ;; |
| 61 | + ?) |
| 62 | + echo "[HALT] Misconfigured options - see usage notes" |
| 63 | + usage; exit ;; |
| 64 | + esac |
| 65 | +done |
| 66 | + |
| 67 | +# |
| 68 | +# Error if no application bundle name (-a bundle) was declared |
| 69 | +# |
| 70 | +if [[ -z $APP_NAME ]] |
| 71 | +then |
| 72 | + echo "[HALT] No application bundle was declared - see usage notes for -a." |
| 73 | + echo |
| 74 | + usage |
| 75 | + exit 1 |
| 76 | +fi |
| 77 | + |
| 78 | +# |
| 79 | +# Error if no version (-v) option declared |
| 80 | +# |
| 81 | +if [[ -z $VERSION ]] |
| 82 | +then |
| 83 | + echo "[HALT] No version option was declared - see usage notes for -v." |
| 84 | + echo |
| 85 | + usage |
| 86 | + exit 1 |
| 87 | +fi |
| 88 | + |
| 89 | +# |
| 90 | +# Error if no version string declared |
| 91 | +# |
| 92 | +if [ ${VERSION}X == X ] |
| 93 | +then |
| 94 | + echo "[HALT] No version string was declared - see usage notes for -v." |
| 95 | + echo |
| 96 | + usage |
| 97 | + exit 1 |
| 98 | +fi |
| 99 | + |
| 100 | +# |
| 101 | +# Show Info |
| 102 | +# |
| 103 | +echo |
| 104 | +echo "----- Stapling packaged app with notarization ticket -----" |
| 105 | +echo |
| 106 | +echo "Package: \"${DISTRIBUTION}${APP_NAME}-${VERSION}-setup-MacOS.pkg\"" |
| 107 | +echo |
| 108 | + |
| 109 | +# |
| 110 | +# Staple app package |
| 111 | +# |
| 112 | +xcrun stapler staple -v "${DISTRIBUTION}${APP_NAME}-${VERSION}-setup-MacOS.pkg" |
| 113 | + |
| 114 | +echo |
| 115 | +echo "Done!" |
| 116 | +exit 0 |
0 commit comments