forked from pqrs-org/Karabiner-archived
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-package.sh
executable file
·140 lines (112 loc) · 4.19 KB
/
make-package.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/sh
# Package build into a signed .dmg file
# set $GEM_HOME/bin/ for CocoaPods.
# PATH="/bin:/sbin:/usr/bin:/usr/sbin:$GEM_HOME/bin"; export PATH
version=$(cat version)
make clean build || exit $?
# --------------------------------------------------
# https://developer.apple.com/library/mac/documentation/Darwin/Conceptual/KEXTConcept/KEXTConceptPackaging/packaging_tutorial.html
echo "Copy Files"
rm -rf pkgroot
mkdir -p pkgroot
mkdir -p "pkgroot/Applications"
cp -R "src/core/server/build/Release/Karabiner.app" "pkgroot/Applications"
basedir="pkgroot/Applications/Karabiner.app/Contents/Applications"
mkdir -p "$basedir"
for d in \
src/util/AXNotifier/build/Release/Karabiner_AXNotifier.app \
src/util/EventViewer/build/Release/EventViewer.app \
src/util/multitouchextension/build/Release/Karabiner_multitouchextension.app \
src/util/uninstaller/automator/KarabinerUninstaller.app \
;
do
cp -R "$d" "$basedir"
done
basedir="pkgroot/Applications/Karabiner.app/Contents/Applications/Utilities"
mkdir -p "$basedir"
cp -R files/Utilities/*.app "$basedir"
basedir="pkgroot/Applications/Karabiner.app/Contents/Library"
mkdir -p "$basedir"
cp -R src/core/kext/build/Release/Karabiner.kext "$basedir/Karabiner.signed.kext"
basedir="pkgroot/Applications/Karabiner.app/Contents/Library/bin"
mkdir -p "$basedir"
cp -R src/bin/kextload/build/Release/kextload "$basedir"
cp -R src/util/cli/build/Release/karabiner "$basedir"
basedir="pkgroot/Applications/Karabiner.app/Contents/Library/extra"
mkdir -p "$basedir"
cp -R pkginfo/Scripts/preinstall "$basedir/uninstall_core.sh"
for f in \
files/extra/launchUninstaller.sh \
files/extra/setpermissions.sh \
files/extra/uninstall.sh \
;
do
cp -R "$f" "$basedir"
done
basedir="pkgroot/Applications/Karabiner.app/Contents/Library/utilities/bin"
mkdir -p "$basedir"
cp -R src/util/warp-mouse-cursor-position/build/Release/warp-mouse-cursor-position "$basedir"
cp -R src/util/post-hid-event/build/Release/post-hid-event "$basedir"
basedir="pkgroot/Applications/Karabiner.app/Contents/Library/vendor/bin"
mkdir -p "$basedir"
cp -R src/vendor/blueutil/build/Release/blueutil "$basedir"
# Sign with Developer ID
bash files/extra/codesign.sh pkgroot
# Setting file permissions.
#
# Note:
# If target files are already exists in system disk,
# PackageMaker uses their permissions.
#
# For example:
# If /Applications/Karabiner.app permission is 0777 by accidental reasons,
# the directory permission will be 0777 in Archive.bom
# even if we set this directory permission to 0755 by setpermissions.sh.
#
# Then, we need to repair file permissions in postinstall script.
# Please also see postinstall.
#
chmod 4755 pkgroot/Applications/Karabiner.app/Contents/Library/bin/kextload
sh "files/extra/setpermissions.sh" pkgroot
sh "files/extra/setpermissions.sh" pkginfo
chmod 755 \
pkginfo/Scripts/postinstall \
pkginfo/Scripts/preinstall \
pkginfo/fixbom.rb
# --------------------------------------------------
echo "Create pkg"
pkgName="Karabiner.pkg"
pkgIdentifier="org.pqrs.driver.Karabiner"
archiveName="Karabiner-${version}"
rm -rf $archiveName
mkdir $archiveName
pkgbuild \
--root pkgroot \
--component-plist pkginfo/pkgbuild.plist \
--scripts pkginfo/Scripts \
--identifier $pkgIdentifier \
--version $version \
--install-location "/" \
$archiveName/Installer.pkg
echo "Fix Archive.bom"
pkgutil --expand $archiveName/Installer.pkg $archiveName/expanded
ruby pkginfo/fixbom.rb $archiveName/expanded/Bom pkgroot/
pkgutil --flatten $archiveName/expanded $archiveName/Installer.pkg
rm -r $archiveName/expanded
productbuild \
--distribution pkginfo/Distribution.xml \
--package-path $archiveName \
$archiveName/$pkgName
rm -f $archiveName/Installer.pkg
# --------------------------------------------------
echo "Sign with Developer ID"
bash files/extra/codesign-pkg.sh $archiveName/$pkgName
# --------------------------------------------------
echo "Make Archive"
# Note:
# Some third vendor archiver fails to extract zip archive.
# Therefore, we use dmg instead of zip.
rm -f $archiveName.dmg
hdiutil create -nospotlight $archiveName.dmg -srcfolder $archiveName
rm -rf $archiveName
chmod 644 $archiveName.dmg