-
Notifications
You must be signed in to change notification settings - Fork 172
/
build_dmg.sh
executable file
·168 lines (128 loc) · 3.24 KB
/
build_dmg.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
# Hydrogen
# Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
# Copyright(c) 2008-2024 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
#
# http://www.hydrogen-music.org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Default application bundle name
SRC_APP="hydrogen.app"
# Default dmg image name
DMG_PATH="Hydrogen.dmg"
# Option: enable verbosity
VERBOSE=0
# Option: open image after creating it
OPEN=0
# Option: Translation directory
TRANSLATIONS="data/i18n"
# Print message if verbose mode is enabled
function verbose {
if (( $VERBOSE )); then
echo $@
fi
}
# Show error message and exit (with cleanup)
function error {
echo $@ >&2
clean_up
exit 1
}
# Show usage info
function usage {
echo "Usage: build_dmg.sh [-vho] [hydrogen.app] [hydrogen.dmg]"
}
# Print help message
function show_help {
cat<<EOF
Build Hydrogen .dmg image
Usage: build_dmg.sh [-vho] [hydrogen.app] [hydrogen.dmg]
-v Be verbose
-h Show this help message
-o Open image afterwards
EOF
}
# Verify source app bundle
function verify_app {
APP="$1"
if [ ! -d "$APP" ]; then
error "Can't find $APP"
fi
if [ ! -x "$APP/Contents/MacOS/hydrogen" ]; then
error "Can't find executable in $APP"
fi
}
# Perform clean up; remove temporary directories
function clean_up {
rm -rf "$DMG_ROOT"
}
# Parse options
while getopts ":vhot:" opt; do
case $opt in
v)
VERBOSE=1
;;
h)
show_help
exit
;;
o)
OPEN=1
;;
t)
TRANSLATIONS="$OPTARG"
;;
\?)
echo "Unknown option: $OPTARG"
usage;
exit 1;
;;
esac
done
shift $((OPTIND - 1))
if (( $# > 0 )); then
SRC_APP="$1"
fi
if (( $# > 1 )); then
DMG_PATH="$2"
fi
if (( $# > 2 )); then
usage;
exit 1
fi
# Real work
if [ -f "$DMG_PATH" ]; then
error "Output file exists"
fi
verify_app "$SRC_APP"
DMG_ROOT=`mktemp -d`
verbose "Copying application bundle"
cp -r "$SRC_APP" "$DMG_ROOT/Hydrogen.app" || error "Can't copy $SRC_APP"
verbose "Deploying Qt libraries"
macdeployqt "$DMG_ROOT/Hydrogen.app" || error "macdeployqt failed"
verbose "Deploying translations"
I18N_DEST="$DMG_ROOT/Hydrogen.app/Contents/Resources/data/i18n"
mkdir -p "$I18N_DEST"
find "$TRANSLATIONS" -name '*.qm' -exec cp {} "$I18N_DEST" \;
verbose "Deploying additional assets"
ln -s /Applications "$DMG_ROOT/Applications"
cp "${BASH_SOURCE%/*}/DS_Store" "$DMG_ROOT/.DS_Store"
verbose "Creating dmg image"
hdiutil create -srcfolder "$DMG_ROOT" -volname "Hydrogen" -fs HFS+ -format UDZO "$DMG_PATH" || error "Creating dmg image failed"
verbose "Cleaning up"
clean_up
if (( $OPEN )); then
open "$DMG_PATH"
fi