-
-
Notifications
You must be signed in to change notification settings - Fork 307
/
binaryInstall.src
executable file
·348 lines (287 loc) · 9.7 KB
/
binaryInstall.src
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
#!/bin/sh
##########################################################################
#
# IMPORTANT: The binaryInstall.src file is a source file, NOT an
# executable shell script!! Used to generate grass-MAJ.MIN.VER-ARCH-DD_MM_YYYY-install.sh by
# make bindist
#
# GRASS binary package installation tool
# platform independent
#
# 1999-2000, 2010 by Markus Neteler, and the GRASS development team
#
##########################################################################
# Set a zero size variable for testing if this file is a source file. Note
# that the make bindist command will change this line to TEST_STR = executable
# without the spaces surrounding the equal sign
TEST_STR=
# Use a text string for sed to recognize to insert the proper version
NAME_VER=BIN_DIST_VERSION
TAR_FILE_SIZE=SIZE_TAR_FILE
ARCH=ARCHITECTURE
GRASSPRG=GRASSPRG_NAME
# Set the default BINDIR and DESTDIR directories
BINDIR=/usr/local/bin
DESTDIR=/usr/local/grass$NAME_VER
UNINSTALL=grass${NAME_VER}uninstall.sh
# Check if this is a source file or not
if [ -z "$TEST_STR" ] ; then
echo "This is a source script, not an executable script which can be run."
exit
fi
# Check for first parameter:
if [ $# -lt 1 -o "$1" = "-h" -o "$1" = "-help" -o "$1" = "--help" ] ; then
echo "
GRASS GIS $NAME_VER binary package installation tool
Usage: grass-$NAME_VER-install.sh grass-$NAME_VER.tar.gz [dest_dir] [bin_dir]
with:
[dest_dir] - optional: FULL path name to the installation directory
(default: /usr/local/grass$NAME_VER/)
[bin_dir] - optional: FULL path name to the grass binary directory
(default: /usr/local/bin/)
Notes: 1) Only the grass executable file is stored here
2) If you want to change the binary directory only
then you need to specify the destination
directory as well
You may need login as root for installation.
"
exit
fi
# Check for second parameter:
if [ "$2" ] ; then
DESTDIR=$2
fi
# Check for third parameter:
if [ "$3" ] ; then
BINDIR=$3
fi
# Print out script identification message
echo ""
echo "GRASS GIS $NAME_VER binary package installation tool"
echo ""
# Check for correct package name:
if [ ! -f $1 ] ; then
echo "ERROR: Wrong package name $1. File does not exists."
echo ""
exit
fi
# Obtain the package name and path
CURR_DIR=`pwd`
PACKAGE_NAME=`basename $1`
PACKAGE_DIR=`dirname $1`
# the dirname command uses . and .. if found so we need the absolute path
cd $PACKAGE_DIR
PACKAGE_DIR=`pwd`
# Check if package is first parameter and in gz or bz2 compression:
# is package in .tar.gz format?
echo $PACKAGE_NAME | grep "\.tar\.gz" > /dev/null
if [ $? -eq 0 ] ; then
UNPACK=gunzip
# Is gunzip there?
IFSSAVE="$IFS"
IFS=":"
GUNZIP=""
for TEST in $PATH ; do
if [ -x $TEST/gunzip ] ; then
GUNZIP="$TEST/gunzip"
fi
done
# which gunzip | grep -v no > /dev/null
IFS="$IFSSAVE"
if [ ! "$GUNZIP" ] ; then
echo "No gunzip installed. Please get from:"
echo " https://www.gnu.org/software/gzip/gzip.html"
exit
fi
else
# not in .tar.gz format, perhaps in .tar.bz2 format?
echo $PACKAGE_NAME | grep "\.tar\.bz2" > /dev/null
if [ $? -eq 0 ] ; then
UNPACK=bunzip2
# Is bunzip2 there?
IFSSAVE="$IFS"
IFS=":"
BUNZIP2=""
for TEST in $PATH ; do
if [ -x $TEST/bunzip2 ] ; then
BUNZIP2="$TEST/bunzip2"
fi
done
IFS="$IFSSAVE"
# which bunzip2 | grep -v no > /dev/null
if [ ! "$BUNZIP2" ] ; then
echo "No bunzip2 installed. Please get from:"
echo " http://sources.redhat.com/bzip2/index.html"
exit
fi
else
# not in .tar.gz or .tar.bz2 format, completely wrong!
echo "ERROR: You need the GRASS binary package in .tar.gz compression "
echo "or .tar.bz2."
echo ""
exit
fi
fi
# Check if the size of the tar gzip file is the same as what was on the server
SIZE=`ls -l $PACKAGE_NAME | tr -s " " | cut -d" " -f5`
if [ $? -ne 0 ] ; then
echo "ERROR while installing binaries!"
echo "Exiting."
exit
fi
if [ $SIZE -ne $TAR_FILE_SIZE ] ; then
echo "ERROR: The size of the binary package is not correct."
echo " Perhaps there was a transmission error. Please download"
echo " the package again"
echo ""
exit
fi
echo "Using $UNPACK decompressor..."
echo "The package $PACKAGE_NAME seems to be OK"
echo "Proceeding..."
echo ""
# Check if the paths for the binary and the destination are the same
BIN_PATH1=$BINDIR/grass-$NAME_VER
BIN_PATH2=$BIN_PATH1/
if [ $BIN_PATH1 = $DESTDIR -o $BIN_PATH2 = $DESTDIR ] ; then
echo "ERROR:"
echo "It appears that the destination directory path is the same as the"
echo "path for the grass binary executable. This results in a name"
echo "conflict between the destination directory and the executable."
echo "Please run this script again with a different path name for the"
echo "destination directory."
exit
fi
# Check if BINDIR is a directory
if [ ! -d "$BINDIR" ] ; then
# Check if BINDIR is a file
if [ -f "$BINDIR" ] ; then
echo ""
echo "ERROR: $BINDIR is a file not a directory."
echo "Please specify a directory for the binary executable directory."
exit
fi
mkdir -p $BINDIR
if [ $? -ne 0 ] ; then
echo "An error occurred trying to create $BINDIR ! Exiting."
exit
fi
fi
# Check if DESTDIR is appropriate
echo "Checking and creating installation directory..."
if [ ! -d "$DESTDIR" ] ; then
# Check if a word "grass" is in string $DESTDIR
echo $DESTDIR | grep "grass" > /dev/null
if [ $? -eq 1 ] ; then
echo "WARNING: Your destination path $DESTDIR does not contain the word 'grass'"
echo "Continue (y/n)?"
read ans
if [ "$ans" = "n" -o "$ans" = "N" ] ; then
exit
fi
fi
# Check if DESTDIR is a file
if [ -f "$DESTDIR" ] ; then
echo ""
echo "ERROR: $DESTDIR is a file not a directory."
echo "Please specify a directory for the destination directory"
exit
fi
mkdir -p $DESTDIR
if [ $? -ne 0 ] ; then
echo "An error occurred trying to create $DESTDIR! Exiting."
exit
fi
else
if [ -d $DESTDIR/bin ] ; then
echo ""
echo "ERROR: Old GRASS distribution existing in $DESTDIR!"
echo "Remove first!"
exit
else
# Check if a word "grass" is in string $DESTDIR
echo $DESTDIR | grep "grass" > /dev/null
if [ $? -eq 1 ] ; then
echo "WARNING: Your destination path $DESTDIR does not contain the word 'grass'"
echo "Continue (y/n)?"
read ans
if [ "$ans" = "n" -o "$ans" = "N" ] ; then
exit
fi
fi
# Check if DESTDIR is writable
touch $DESTDIR/test$$ > /dev/null
if [ $? -ne 0 ] ; then
echo "ERROR: Destination directory $DESTDIR is not"
echo "writable, try installing as root!"
echo "Exiting."
exit 1
fi
rm -f $DESTDIR/test$$ > /dev/null
fi
fi
# Start the installation job...
echo "Installing GRASS binaries into $DESTDIR"
echo ""
echo "Uncompressing the package and extracting to target directory..."
PACK_FILE=`echo $PACKAGE_DIR/$PACKAGE_NAME | sed 's+^//+/+g'`
cd $DESTDIR; $UNPACK -c $PACK_FILE | tar -xf -
if [ $? -eq 1 ] ; then
echo "An error occurred or user break while installing binaries! Exiting."
exit
fi
# Get rid of any CVS directories
find . -name CVS -exec rm -rf {} \; 2>/dev/null ; true
cd $CURR_DIR
# Creating start script
echo "Creating start script:"
echo "$BINDIR/$GRASSPRG -> $BINDIR/grass-$NAME_VER"
sed -e "s#@GISBASE@#$DESTDIR#g" \
$DESTDIR/$GRASSPRG.tmp > $BINDIR/grass-$NAME_VER
if [ $? -eq 1 ] ; then
echo "An error occurred trying to create the grass start script! Exiting."
echo "You probably do not have permission to install into $BINDIR."
echo "You may need to be the root user to install in that directory."
exit
fi
ln -sf $BINDIR/grass-$NAME_VER $BINDIR/$GRASSPRG
chmod ugo+x $BINDIR/grass-$NAME_VER
if [ $? -eq 1 ] ; then
echo "An error occurred trying to create the grass start script! Exiting."
echo "You probably do not have permission to install into $BINDIR."
echo "You may need to be the root user to install in that directory."
exit
fi
echo "Creating the locks directory for monitors..."
SERVERNAME=`uname -n | sed -e "s/\..*//"`
if [ ! -d $DESTDIR/locks ] ; then
mkdir $DESTDIR/locks
fi
rm -rf $DESTDIR/locks/*
mkdir $DESTDIR/locks/$SERVERNAME
chmod -R 1777 $DESTDIR/locks
echo""
echo "Generating display font configuration file..."
GISBASE="$DESTDIR" GISRC=junk LD_LIBRARY_PATH_VAR="${DESTDIR}/lib:$LD_LIBRARY_PATH_VAR" "${DESTDIR}/bin/g.mkfontcap" --overwrite
echo""
# fix include/Make/Platform.make file for g.extension
mv ${DESTDIR}/include/Make/Platform.make ${DESTDIR}/include/Make/Platform.make.orig
cat ${DESTDIR}/include/Make/Platform.make.orig | \
sed "s+prefix = /usr/local+prefix = $DESTDIR+g" | \
sed "s+INST_DIR = $prefix/grass-$NAME_VER+INST_DIR = $prefix+g" | \
sed "s+^.*GRASS_HOME.*$+GRASS_HOME = $DESTDIR+" | \
sed "s+^.*RUN_GISBASE.*$+RUN_GISBASE = $DESTDIR+" | \
sed "s+^.*RUN_GISRC.*$+RUN_GISRC = +" > ${DESTDIR}/include/Make/Platform.make
# rm -f ${DESTDIR}/include/Make/Platform.make.orig
# Print out some messages
echo "Installation finished. Start GRASS $NAME_VER with"
echo " $BINDIR/grass-$NAME_VER"
echo ""
#echo "The graphical user interface can be started within GRASS GIS."
#echo ""
#echo "You can uninstall grass by typing"
#echo " sh $UNINSTALL"
#echo "in the directory $BINDIR"
echo ""
echo "Welcome to GRASS GIS. Enjoy this open source GRASS GIS!"
echo ""