forked from pqrs-org/Karabiner-Elements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-package.sh
executable file
·130 lines (99 loc) · 3.95 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
#!/bin/bash
set -u
# Check Xcode version
sdkversion=$(xcrun --show-sdk-version)
if [ ${sdkversion%.*} -lt 12 ]; then
echo
echo 'ERROR:'
echo ' Xcode is too old.'
echo ' You have to use Xcode 13.1 or later.'
echo
exit 1
fi
# Package build into a signed .dmg file
version=$(cat version)
echo "make build"
ruby scripts/reduce-logs.rb 'make build' || exit 99
# --------------------------------------------------
echo "Copy Files"
set -e
rm -rf pkgroot
mkdir -p pkgroot
basedir="pkgroot/Library/Application Support/org.pqrs/Karabiner-Elements"
mkdir -p "$basedir"
cp version "$basedir/package-version"
cp src/scripts/uninstall.sh "$basedir"
cp src/scripts/uninstall_core.sh "$basedir"
cp files/complex_modifications_rules_example.json "$basedir"
cp -R "src/apps/AppIconSwitcher/build/Release/Karabiner-AppIconSwitcher.app" "$basedir"
cp -R "src/apps/Menu/build/Release/Karabiner-Menu.app" "$basedir"
cp -R "src/apps/MultitouchExtension/build/Release/Karabiner-MultitouchExtension.app" "$basedir"
cp -R "src/apps/NotificationWindow/build/Release/Karabiner-NotificationWindow.app" "$basedir"
# Save a copy of Karabiner-Elements.app so that we can restore it if /Applications/Karabiner-Elements.app is manually deleted.
cp -R "src/apps/SettingsWindow/build/Release/Karabiner-Elements.app" "$basedir"
basedir="pkgroot/Library/Application Support/org.pqrs/Karabiner-Elements/scripts"
mkdir -p "$basedir"
cp src/scripts/copy_current_profile_to_system_default_profile.applescript "$basedir"
cp src/scripts/remove_system_default_profile.applescript "$basedir"
cp src/scripts/uninstaller.applescript "$basedir"
basedir="pkgroot/Library/Application Support/org.pqrs/Karabiner-Elements/bin"
mkdir -p "$basedir"
cp src/bin/cli/build/Release/karabiner_cli "$basedir"
cp src/core/console_user_server/build/Release/karabiner_console_user_server "$basedir"
cp src/core/grabber/build/Release/karabiner_grabber "$basedir"
cp src/core/session_monitor/build/Release/karabiner_session_monitor "$basedir"
mkdir -p "pkgroot/Library"
cp -R files/LaunchDaemons "pkgroot/Library"
cp -R files/LaunchAgents "pkgroot/Library"
basedir="pkgroot/Applications"
mkdir -p "$basedir"
cp -R "src/apps/EventViewer/build/Release/Karabiner-EventViewer.app" "$basedir"
cp -R "src/apps/SettingsWindow/build/Release/Karabiner-Elements.app" "$basedir"
set +e
# Sign with Developer ID
bash scripts/codesign.sh "pkgroot"
sh "scripts/setpermissions.sh" pkginfo
sh "scripts/setpermissions.sh" pkgroot
chmod 755 pkginfo/Scripts/postinstall
chmod 755 pkginfo/Scripts/preinstall
# --------------------------------------------------
echo "Create pkg"
pkgName="Karabiner-Elements.pkg"
pkgIdentifier="org.pqrs.Karabiner-Elements"
archiveName="Karabiner-Elements-${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
#
# Copy Karabiner-DriverKit-VirtualHIDDevice.pkg.
#
virtualHIDDeviceDmg=$(ls src/vendor/Karabiner-DriverKit-VirtualHIDDevice/dist/Karabiner-DriverKit-VirtualHIDDevice-*.pkg | sort --version-sort | tail -n 1)
cp $virtualHIDDeviceDmg $archiveName/Karabiner-DriverKit-VirtualHIDDevice.pkg
#
# productbuild
#
productbuild \
--distribution pkginfo/Distribution.xml \
--package-path $archiveName \
$archiveName/$pkgName
rm -f $archiveName/Installer.pkg
rm -f $archiveName/Karabiner-DriverKit-VirtualHIDDevice.pkg
# --------------------------------------------------
echo "Sign with Developer ID"
bash scripts/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 -fs 'Journaled HFS+' -format ULMO
rm -rf $archiveName
chmod 644 $archiveName.dmg