-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·129 lines (112 loc) · 4.41 KB
/
build.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
#!/bin/sh
set -e -x
LAYOUT="Programmer Dvorak"
LANGUAGE=en
VERSION=1.2
COPYRIGHT="Copyright 1997--2019 (c) Roland Kaufmann"
# copy files from where this script is located
pushd $(dirname $0)
SRC_DIR="$(pwd)"
popd
# create a fakeroot directory and path therein
ROOT_DIR="$LAYOUT.tmp"
rm -rf "$ROOT_DIR"
mkdir -p "$ROOT_DIR/Library/Keyboard Layouts"
pushd "$ROOT_DIR/Library/Keyboard Layouts"
# Recipe by jagboy
# <http://hints.macworld.com/comment.php?mode=view&cid=60218>
mkdir "$LAYOUT.bundle"
mkdir "$LAYOUT.bundle/Contents"
# Text Input Source Services keys by Jordan Rose
# <http://belkadan.com/blog/2012/04/Keyboard-Adventures/>
# see bottom of HIToolbox.framework/.../TextInputSources.h
cat >> "$LAYOUT.bundle/Contents/Info.plist" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key><string>com.apple.keyboardlayout.$LAYOUT</string>
<key>CFBundleName</key><string>$LAYOUT</string>
<key>CFBundleVersion</key><string>$VERSION</string>
<key>KLInfo_$LAYOUT</key>
<dict>
<key>TISInputSourceID</key><string>com.apple.keyboardlayout.$LAYOUT</string>
<key>TISIntendedLanguage</key><string>$LANGUAGE-Latn</string>
</dict>
</dict>
</plist>
EOF
cat >> "$LAYOUT.bundle/Contents/version.plist" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildVersion</key><string>$VERSION</string>
<key>CFBundleVersion</key><string>$VERSION</string>
<key>ProjectName</key><string>$LAYOUT</string>
<key>SourceVersion</key><string>$VERSION</string>
</dict>
</plist>
EOF
mkdir "$LAYOUT.bundle/Contents/Resources"
cp "$SRC_DIR/$LAYOUT.keylayout" "$LAYOUT.bundle/Contents/Resources/"
# Install Keyboard Tools (needs Rosetta from Optional Installs) from:
# http://developer.apple.com/fonts/fonttools/AppleFontToolSuite3.1.0.dmg.zip
KLCOMPILER="$(which klcompiler)"
[ -x "${KLCOMPILER}" ] && "${KLCOMPILER}" "$SRC_DIR/$LAYOUT.keylayout" > /dev/null
if [ -e "$SRC_DIR/$LAYOUT.png" ]; then
sips -s format icns "$SRC_DIR/$LAYOUT.png" --out "$LAYOUT.bundle/Contents/Resources/$LAYOUT.icns"
elif [ -e "$SRC_DIR/$LAYOUT.icns" ]; then
cp "$SRC_DIR/$LAYOUT.icns" "$LAYOUT.bundle/Contents/Resources/";
fi
mkdir "$LAYOUT.bundle/Contents/Resources/English.lproj"
cat >> "$LAYOUT.bundle/Contents/Resources/English.lproj/InfoPlist.strings" <<EOF
NSHumanReadableCopyright = "$COPYRIGHT";
"$LAYOUT" = "$LAYOUT";
EOF
# try to figure out where PackageMaker from the Auxiliary Tools is
if [ -d /Applications/Xcode.app/Contents/Applications/PackageMaker.app ]; then
APPROOT=/Applications/Xcode.app/Contents/Applications
elif [ -d /Developer/Applications/Utilities/PackageMaker.app ]; then
APPROOT=/Developer/Application/Utilities
else
APPROOT=/Applications
fi
# bundle bit must be set on the directory for it to be recognized as a bundle
/usr/bin/SetFile -a B "$LAYOUT.bundle"
# leave fakeroot
popd
# create a package
# <http://www.manpagez.com/man/1/packagemaker/>
$APPROOT/PackageMaker.app/Contents/MacOS/PackageMaker \
-v \
-k \
-r "$ROOT_DIR" \
-f "$ROOT_DIR/Library/Keyboard Layouts/$LAYOUT.bundle/Contents/Info.plist" \
-o "$LAYOUT v$VERSION.pkg" \
-n "$VERSION" \
-t "$LAYOUT" \
-x \\.DS_Store \
-g 10.3 \
-h system \
# final files that are uploaded should be without spaces
TRANSLATED=$(echo "$LAYOUT" | sed 's/\ //g')-$(echo "$VERSION" | sed 's/\./_/g')
rm -rf "$TRANSLATED.pkg.zip"
rm -rf "$TRANSLATED.src.zip"
# create a packed file from the directory (use -k for .zip)
ditto -c -k --noacl --sequesterRsrc --keepParent "$LAYOUT v$VERSION.pkg" "$TRANSLATED.pkg.zip"
#hdiutil create --srcfolder "$LAYOUT v$VERSION.pkg" -format UDZO -volname "$LAYOUT v$VERSION" -o "$TRANSLATED.dmg"
# create source distribution
rm -rf "$LAYOUT.src"
mkdir "$LAYOUT.src"
cp "$SRC_DIR/$LAYOUT.keylayout" "$LAYOUT.src"
cp "$SRC_DIR/build.sh" "$LAYOUT.src"
ditto -c -k --noacl --sequesterRsrc "$LAYOUT.src" "$TRANSLATED.src.zip"
# sudo installer -pkg "$LAYOUT v$VERSION.pkg" -target /
# lsbom -fls "/var/db/receipts/com.apple.keyboardlayout.$LAYOUT.bom"
# uninstall:
# sudo rm -rf "/Library/Keyboard Layouts/$LAYOUT.bundle/"
# sudo pkgutil --forget com.apple.keyboardlayout.$LAYOUT
# sudo rm /System/Library/Caches/com.apple.IntlDataCache.le*
# rm /private/var/folders/*/*/-Caches-/com.apple.IntlDataCache.le*
# sudo shutdown -r now