1 | #!/bin/bash |
---|
2 | # Create macOS installation packages. |
---|
3 | # Based on bomutils tutorial: http://bomutils.dyndns.org/tutorial.html |
---|
4 | |
---|
5 | cd $(dirname $0) |
---|
6 | [ -r ../src/VERSION ] && VERSION="$(cat ../src/VERSION)" || (echo "Can't get version from ../src/VERSION" 1>&2; exit 1) |
---|
7 | AUTHOR="OpenGnsys Project" |
---|
8 | |
---|
9 | # Create empty directories. |
---|
10 | rm -fr build |
---|
11 | mkdir -p build && cd build |
---|
12 | mkdir -p flat/base.pkg flat/Resources/en.lproj |
---|
13 | mkdir -p root/Applications |
---|
14 | |
---|
15 | # Copy application and script files. Exclude 'test_modules' |
---|
16 | cp -a ../../src root/Applications/OGAgent.app; rm -rf root/Applications/OGAgent.app/test_modules |
---|
17 | cp -a ../scripts . |
---|
18 | |
---|
19 | # Create plist file. |
---|
20 | cat << EOT > root/Applications/OGAgent.app/OGAgent.plist |
---|
21 | <?xml version="1.0" encoding="UTF-8"?> |
---|
22 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
---|
23 | <plist version="1.0"> |
---|
24 | <dict> |
---|
25 | <key>BuildAliasOf</key> |
---|
26 | <string>OGAgent</string> |
---|
27 | <key>BuildVersion</key> |
---|
28 | <value>$VERSION</value> |
---|
29 | <author>$AUTHOR</author> |
---|
30 | </dict> |
---|
31 | </plist> |
---|
32 | EOT |
---|
33 | |
---|
34 | # Add files in the base package. |
---|
35 | ( cd root && find . | cpio -o --format odc --owner 0:80 | gzip -c ) > flat/base.pkg/Payload |
---|
36 | |
---|
37 | # Create PackageInfo file. |
---|
38 | cat << EOT > flat/base.pkg/PackageInfo |
---|
39 | <pkg-info format-version="2" identifier="es.opengnsys.ogagent.base.pkg" version="$VERSION" install-location="/" auth="root"> |
---|
40 | <payload installKBytes="$(du -k -s root)" numberOfFiles="$(find root | wc -l)"/> |
---|
41 | <scripts> |
---|
42 | <postinstall file="./postinstall"/> |
---|
43 | </scripts> |
---|
44 | <bundle-version> |
---|
45 | <bundle id="es.opengnsys.ogagent" CFBundleIdentifier="es.opengnsys.ogagent" path="./Applications/OGAgent.app" CFBundleVersion="$VERSION"/> |
---|
46 | </bundle-version> |
---|
47 | </pkg-info> |
---|
48 | EOT |
---|
49 | |
---|
50 | # Compress the scripts folder. |
---|
51 | ( cd scripts && find . | cpio -o --format odc --owner 0:80 | gzip -c ) > flat/base.pkg/Scripts |
---|
52 | |
---|
53 | # Create BOM file. |
---|
54 | mkbom -u 0 -g 80 root flat/base.pkg/Bom |
---|
55 | |
---|
56 | # Create Distribution file. |
---|
57 | cat << EOT > flat/Distribution |
---|
58 | <?xml version="1.0" encoding="utf-8"?> |
---|
59 | <installer-script minSpecVersion="1.000000" authoringTool="com.apple.PackageMaker" authoringToolVersion="3.0.3" authoringToolBuild="174"> |
---|
60 | <title>OGAgent $VERSION</title> |
---|
61 | <options customize="never" allow-external-scripts="no"/> |
---|
62 | <domains enable_anywhere="true"/> |
---|
63 | <installation-check script="pm_install_check();"/> |
---|
64 | <script>function pm_install_check() { |
---|
65 | if(!(system.compareVersions(system.version.ProductVersion,'10.5') >= 0)) { |
---|
66 | my.result.title = 'Failure'; |
---|
67 | my.result.message = 'You need at least Mac OS X 10.5 to install OGAgent.'; |
---|
68 | my.result.type = 'Fatal'; |
---|
69 | return false; |
---|
70 | } |
---|
71 | return true; |
---|
72 | } |
---|
73 | </script> |
---|
74 | <choices-outline> |
---|
75 | <line choice="choice1"/> |
---|
76 | </choices-outline> |
---|
77 | <choice id="choice1" title="base"> |
---|
78 | <pkg-ref id="es.opengnsys.ogagent.base.pkg"/> |
---|
79 | </choice> |
---|
80 | <pkg-ref id="es.opengnsys.ogagent.base.pkg" installKBytes="$(du -k -s root)" version="$VERSION" auth="Root">#base.pkg</pkg-ref> |
---|
81 | </installer-script> |
---|
82 | EOT |
---|
83 | |
---|
84 | # Create new Xar application archive. |
---|
85 | rm -f ../../../OGAgentInstaller-$VERSION.pkg |
---|
86 | ( cd flat && xar --compression none -cf "../../../OGAgentInstaller-$VERSION.pkg" * ) |
---|