forked from bdrister/dterm
-
Notifications
You must be signed in to change notification settings - Fork 15
/
build.sh
executable file
·147 lines (131 loc) · 3.2 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
set -e -o pipefail
help() {
cat <<HELP
Usage: $(basename $0) [--help] [--clean] [--no-code-sign] [--code-sign-identity NAME] [--with-dmg]
HELP
}
main() {
CLEAN=""
BUILD=""
WITH_DMG="no"
WITH_CODESIGN="yes"
CODESIGN_IDENTITY=""
until [ -z "$1" ]; do
case "$1" in
-h|--help)
help;
exit 0;
;;
--clean)
CLEAN="yes";
shift;
;;
--build)
BUILD="yes";
shift;
;;
--no-code-sign)
BUILD="yes";
WITH_CODESIGN="no";
shift;
;;
--code-sign-identity)
BUILD="yes";
shift;
if [ -z "$1" ]; then
error "missing code-sign-identity NAME"
exit 1
fi
CODESIGN_IDENTITY="$1"
shift;
;;
--with-dmg)
BUILD="yes";
WITH_DMG="yes";
shift;
;;
*)
error "unknown option $1";
exit 1;
;;
esac
done
if [[ -z "$CLEAN" ]]; then
CLEAN="$WITH_DMG"
fi
if [[ "$WITH_DMG" == "yes" ]]; then
ensure_create_dmg
fi
if [[ "$CLEAN" == "yes" ]]; then
xcodebuild \
-project "./DTerm.xcodeproj" \
-target "DTerm" \
-configuration "Release" \
clean
EX=$?
if [[ -z "$BUILD" ]]; then
exit $EX
fi
fi
xcodebuild \
-project "./DTerm.xcodeproj" \
-target "DTerm" \
-configuration "Release"
TARGET_APP="./build/Release/DTerm.app"
TARGET_VERSION="$(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "$TARGET_APP/Contents/Info.plist")"
if [[ ! -d "$TARGET_APP" ]]; then
error "missing $TARGET_APP"
exit 1;
fi
if [[ "$WITH_CODESIGN" == "yes" ]]; then
if [ -z "$CODESIGN_IDENTITY" ]; then
CODESIGN_IDENTITY="$(git config --get user.name)"
fi
set -x
codesign --deep -s "$CODESIGN_IDENTITY" -f "$TARGET_APP" -v
set +x
fi
if [[ "$WITH_DMG" == "yes" ]]; then
TARGET_DMG="./build/Release/DTerm.dmg"
TARGET_DMG_RW="./build/Release/rw.DTerm.dmg"
SOURCE_DIR="./build/Release.dmg-tmp"
[ -e "$TARGET_DMG" ] && rm -f "$TARGET_DMG"
[ -e "$TARGET_DMG_RW" ] && rm -f "$TARGET_DMG_RW"
[ -e "$SOURCE_DIR" ] && rm -rf "$SOURCE_DIR"
mkdir -p "$SOURCE_DIR"
cp -r "$TARGET_APP" "$SOURCE_DIR"
create-dmg \
--window-size 500 300 \
--background "./Images/[email protected]" \
--icon-size 96 \
--volname "DTerm" \
--app-drop-link 380 116 \
--icon "DTerm" 110 116 \
"$TARGET_DMG" \
"$SOURCE_DIR"
fi
echo "---------------------------------------------------"
echo ">> Build Complete: $(dirname $TARGET_APP)"
echo ">> Version: $TARGET_VERSION"
echo ">> APP: $TARGET_APP"
if [[ "$WITH_DMG" == "yes" ]]; then
echo ">> DMG: $TARGET_DMG"
fi
if [[ "$WITH_CODESIGN" == "yes" ]]; then
echo ">> Codesigning Details:"
codesign -dvvv "$TARGET_APP" 2>&1 | awk '{ printf ">> %s\n", $0}'
fi
echo ">> done."
}
ensure_create_dmg() {
if [[ ! $(type -P "create-dmg") ]]; then
echo >&2 "Ouch: missing 'create-dmg' toolkit."
echo >&2 "Hint: You can install it via: brew install create-dmg"
exit 1;
fi
}
error() {
echo >&2 "Error: " "$@"
}
main "$@"