pkgbuild-macosx.sh
11 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
#!/bin/bash
# ==========================================================================
# ctools Mac OS X package creation
#
# Copyright (C) 2017 Sylvie Brau-Nogué
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
#
# -------------------------------------------------------------------------
#
# This script installs the ctools and GammaLib packages in the location
# /usr/local/gamma and then builds a Mac OS X package which is finally put
# onto a disk image. Any existing content in /usr/local/gamma will be
# destroyed. The script needs the priviledges to create a folder in
# /usr/local.
#
# ==========================================================================
# ============================================= #
# Get ctools/GammaLib version from command line #
# ============================================= #
if [ $# -ne 1 ] ; then
echo "Please specify ctools/GammaLib version in the form x.y.z"
exit 1
fi
VERSION=$1
# =============================== #
# Set software component versions #
# =============================== #
CFITSIO=cfitsio3410
NCURSES=ncurses-5.9
READLINE=readline-6.3
GAMMALIB=gammalib-$VERSION
CTOOLS=ctools-$VERSION
# ============== #
# Set parameters #
# ============== #
INSTALLDIR=/usr/local/gamma
WRKDIR=$PWD/pkg_build
SRCDIR=$WRKDIR/src
PKGDIR=$WRKDIR/pkg
PRODDIR=$WRKDIR/prod
PLISTFILE=$PKGDIR/$CTOOLS-components.plist
DISTFILE=$PRODDIR/$CTOOLS.dist
DMGFILE=$WRKDIR/$CTOOLS-macosx10.7.dmg
LOGFILE=$PWD/pkg_build.log
# ============================= #
# Secure installation directory #
# ============================= #
if [ -d "$INSTALLDIR" ]; then
sudo mv $INSTALLDIR $INSTALLDIR.backup
fi
# ======================= #
# Clean package directory #
# ======================= #
sudo rm -rf $INSTALLDIR
rm -rf $PKGDIR
rm -rf $PRODDIR
rm -rf $DMGFILE
rm -rf $LOGFILE
# ============================= #
# Create package directory tree #
# ============================= #
mkdir -p $SRCDIR
mkdir -p $PKGDIR
mkdir -p $PRODDIR
# =============== #
# Install ncurses #
# =============== #
cd $SRCDIR
if [ ! -d "$NCURSES" ]; then
wget --no-check-certificate https://ftp.gnu.org/pub/gnu/ncurses/$NCURSES.tar.gz
if [ "$?" -ne "0" ]; then
echo "*** Unable to download $NCURSES.tar.gz"
exit 1
else
tar xvfz $NCURSES.tar.gz
rm -rf $NCURSES.tar.gz
fi
fi
cd $NCURSES
./configure --prefix=$INSTALLDIR --with-shared | tee -a $LOGFILE
make -j4 | tee -a $LOGFILE
sudo make install | tee -a $LOGFILE
make clean
# ================ #
# Install readline #
# ================ #
cd $SRCDIR
if [ ! -d "$READLINE" ]; then
wget --no-check-certificate https://ftp.gnu.org/pub/gnu/readline/$READLINE.tar.gz
if [ "$?" -ne "0" ]; then
echo "*** Unable to download $READLINE.tar.gz"
exit 1
else
tar xvfz $READLINE.tar.gz
rm -rf $READLINE.tar.gz
fi
fi
cd $READLINE
./configure --prefix=$INSTALLDIR | tee -a $LOGFILE
make -j4 | tee -a $LOGFILE
sudo make install | tee -a $LOGFILE
make clean
# =============== #
# Install cfitsio #
# =============== #
cd $SRCDIR
if [ ! -d "cfitsio" ]; then
wget http://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/$CFITSIO.tar.gz
if [ "$?" -ne "0" ]; then
echo "*** Unable to download $CFITSIO.tar.gz"
exit 1
else
tar xvfz $CFITSIO.tar.gz
rm -rf $CFITSIO.tar.gz
fi
fi
cd cfitsio
./configure --prefix=$INSTALLDIR | tee -a $LOGFILE
make -j4 shared | tee -a $LOGFILE
sudo make install | tee -a $LOGFILE
make clean
# ================ #
# Install GammaLib #
# ================ #
cd $SRCDIR
if [ ! -d "$GAMMALIB" ]; then
wget http://cta.irap.omp.eu/ctools/releases/gammalib/$GAMMALIB.tar.gz
if [ "$?" -ne "0" ]; then
if [ ! -d "gammalib" ]; then
echo "*** Unable to download $GAMMALIB.tar.gz, try cloning from GitLab"
export GIT_SSL_NO_VERIFY=true
git clone https://cta-gitlab.irap.omp.eu/gammalib/gammalib.git
if [ "$?" -ne "0" ]; then
echo "*** Unable to clone GammaLib from GitLab"
exit 1
fi
else
echo "*** Unable to download $GAMMALIB.tar.gz, use code in gammalib directory"
fi
cd gammalib
else
tar xvfz $GAMMALIB.tar.gz
rm -rf $GAMMALIB.tar.gz
cd $GAMMALIB
fi
fi
# If we got code from GitLab, then try using release branch, and if not
# available, use devel branch.
USE_BRANCH=
if [ -d ".git" ]; then
git fetch
git checkout release
if [ "$?" -ne "0" ]; then
echo "*** No release branch found on GitLab, try devel branch"
git checkout devel
if [ "$?" -ne "0" ]; then
echo "*** No devel branch found on GitLab"
exit 1
else
echo "*** Use devel branch of GammaLib"
USE_BRANCH=devel
fi
else
echo "*** Use release branch of GammaLib"
USE_BRANCH=release
fi
git pull
./autogen.sh
fi
# Build code
./configure --prefix=$INSTALLDIR | tee -a $LOGFILE
make -j4 | tee -a $LOGFILE
sudo make install | tee -a $LOGFILE
make clean
# ============== #
# Install ctools #
# ============== #
cd $SRCDIR
CTOOLS_DIR=$CTOOLS
if [ ! -d "$CTOOLS" ]; then
wget http://cta.irap.omp.eu/ctools/releases/ctools/$CTOOLS.tar.gz
if [ "$?" -ne "0" ]; then
if [ ! -d "ctools" ]; then
echo "*** Unable to download $CTOOLS.tar.gz, try cloning from GitLab"
export GIT_SSL_NO_VERIFY=true
git clone https://cta-gitlab.irap.omp.eu/ctools/ctools.git
if [ "$?" -ne "0" ]; then
echo "*** Unable to clone ctools from GitLab"
exit 1
fi
else
echo "*** Unable to download $CTOOLS.tar.gz, use code in ctools directory"
fi
cd ctools
CTOOLS_DIR=ctools
else
tar xvfz $CTOOLS.tar.gz
rm -rf $CTOOLS.tar.gz
cd $CTOOLS
fi
fi
# If we got code from GitLab, then use the same branch that was used for
# GammaLib
if [ -d ".git" ]; then
git fetch
git checkout $USE_BRANCH
if [ "$?" -ne "0" ]; then
echo "*** No $USE_BRANCH branch found on GitLab"
exit 1
fi
git pull
./autogen.sh
fi
# Build code
./configure --prefix=$INSTALLDIR | tee -a $LOGFILE
make -j4 | tee -a $LOGFILE
sudo make install | tee -a $LOGFILE
make clean
# ================= #
# Post-process code #
# ================= #
# Change links in libraries
for file in ${INSTALLDIR}/lib/*.dylib
do
echo $file | tee -a $LOGFILE
sudo install_name_tool -change "@rpath/libcfitsio.5.dylib" "$INSTALLDIR/lib/libcfitsio.5.dylib" $file
done
# Change links in binaries
for file in ${INSTALLDIR}/bin/ct*
do
echo $file | tee -a $LOGFILE
sudo install_name_tool -change "@rpath/libcfitsio.5.dylib" "$INSTALLDIR/lib/libcfitsio.5.dylib" $file
done
# Change links in Python modules
pythons="python2.7"
for python in $pythons
do
# Print Python version
echo $python | tee -a $LOGFILE
# Change links in gammalib modules
for file in ${INSTALLDIR}/lib/$python/site-packages/gammalib/_*.so
do
echo $file | tee -a $LOGFILE
sudo install_name_tool -change "@rpath/libcfitsio.5.dylib" "$INSTALLDIR/lib/libcfitsio.5.dylib" $file
done
# Change links in ctools modules
for file in ${INSTALLDIR}/lib/$python/site-packages/ctools/_*.so
do
echo $file | tee -a $LOGFILE
sudo install_name_tool -change "@rpath/libcfitsio.5.dylib" "$INSTALLDIR/lib/libcfitsio.5.dylib" $file
done
done
# ====================== #
# Build Mac OS X package #
# ====================== #
pkgbuild --analyze --root $INSTALLDIR $PLISTFILE
pkgbuild --identifier cta.irap.omp.eu.ctools.pkg \
--version $VERSION \
--root $INSTALLDIR \
--install-location /usr/local/gamma \
--component-plist $PLISTFILE \
$PKGDIR/$CTOOLS.pkg
# ======================= #
# Clean package directory #
# ======================= #
sudo rm -rf $INSTALLDIR
# ============================== #
# Recover installation directory #
# ============================== #
if [ -d "$INSTALLDIR.backup" ]; then
sudo mv $INSTALLDIR.backup $INSTALLDIR
fi
# ====================== #
# Build Mac OS X product #
# ====================== #
# Analyse existing package
productbuild --synthesize \
--package $PKGDIR/$CTOOLS.pkg \
$DISTFILE
# Add information to dist file
sed -i '' '$ i \
<license file="COPYING"/>\
<title>'$CTOOLS'</title>\
<organization>irap.omp.eu</organization>\
<description>CTA Science Analysis Tools</description>\
' "$PRODDIR/$CTOOLS.dist"
# Build product
productbuild --distribution $DISTFILE \
--version $VERSION \
--resources $SRCDIR/$CTOOLS \
--package-path $PKGDIR \
--sign 'ctools' \
$PRODDIR/$CTOOLS.pkg
# Add additional files to production folder
cp $SRCDIR/$CTOOLS_DIR/COPYING $PRODDIR/License.txt
# Add ReadMe
/bin/cat <<EOM >$PRODDIR/ReadMe.txt
This package will install
ctools-$VERSION and gammalib-$VERSION
for Mac OS X 10.7 or later.
Installation requires approximately 260 MB of disk space. The package
will be installed in the directory /usr/local/gamma, hence you need
administrator privileges to do the install.
Simply click on the installer package and follow the instructions.
The installation will take less than one minute.
After installing the package, you have to initialise the ctools
environment. This will be done by invoking an initialisation script
that can be found in the /usr/local/gamma/bin directory.
To invoke this script you need to add the following to your .bashrc
or $HOME/.profile script:
export CTOOLS=/usr/local/gamma
source \$CTOOLS/bin/gammalib-init.sh
If you use C shell or a variant then add the following to your
.cshrc or .tcshrc script:
setenv CTOOLS /usr/local/gamma
source \$CTOOLS/bin/gammalib-init.csh
More information on ctools can be found at
http://cta.irap.omp.eu/ctools/.
If you encounter problems in installing or using this package, please
send your error report to jurgen.knodlseder@irap.omp.eu. In your report,
please specify your Mac OS X version and Python version and the problem
you're facing.
EOM
# ==================== #
# Create Mac OS X disk #
# ==================== #
hdiutil create -volname $CTOOLS \
-srcfolder $PRODDIR/$CTOOLS.pkg \
-srcfolder $PRODDIR/License.txt \
-srcfolder $PRODDIR/ReadMe.txt \
$DMGFILE
# ======================= #
# Clean package directory #
# ======================= #
rm -rf $PKGDIR
rm -rf $PRODDIR