File: configure.gtc

package info (click to toggle)
fis-gtm 6.3-000A-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 34,688 kB
  • ctags: 36,764
  • sloc: ansic: 314,889; asm: 5,173; csh: 4,915; sh: 2,192; awk: 95; makefile: 87; sed: 13
file content (820 lines) | stat: -rwxr-xr-x 25,227 bytes parent folder | download
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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
#!/bin/sh
#################################################################
#								#
# Copyright (c) 2009-2016 Fidelity National Information		#
# Services, Inc. and/or its subsidiaries. All rights reserved.	#
#								#
#	This source code contains the intellectual property	#
#	of its copyright holder(s), and is made available	#
#	under a license.  If you do not know the terms of	#
#	the license, please stop and do not read further.	#
#								#
#################################################################

. ./arch.gtc

# Path to the correct echo program
# depending on the list of locales configured, locale -a might be considered a binary output.
# grep needs -a option to process the output as text but -a is not supported on the non-linux servers we have.
if [ $arch = "sun"  -o  $arch = "solaris" ]; then
	echo=/usr/5bin/echo
	# Solaris 11 does not have /usr/5bin/echo
	if [ ! -f $echo ]; then
		echo=/usr/bin/echo
	fi
	binaryopt=""
elif [ $arch = "linux" ]; then
	echo="/bin/echo -e"
	binaryopt="-a"
else
	echo=/bin/echo
	binaryopt=""
fi

# add path to strip for solaris
if [ $arch = "sun"  -o  $arch = "solaris" ]; then
	PATH="$PATH:/usr/ccs/bin"
	export PATH
fi

# Options to ps
psopts="-ea"

# GTCM definitions
if [ -f gtcm_server ]; then
	deliver_gtcm="yes"
else
	deliver_gtcm="no"
fi

if [ -f gtcm_gnp_server ]; then
	deliver_gtcm_gnp="yes"
else
	deliver_gtcm_gnp="no"
fi

# create symbolic links if utf8 directory exists.  Ignore the "file exists" errors for the .o files
# which exist in both directories.

if [ -d utf8 ]; then
	(cd utf8; ln -s ../* . 2> /dev/null)
fi

# Native shared library extension.
if [ $arch = "hp" -a `uname -m` != "ia64" ]; then
	ext=".sl"
else
	ext=".so"
fi

# Flags to build shared libraries of M routines
if [ "hp" = $arch ] ; then ldflags="-b" ; ldcmd="ld" # HP-UX - all platforms
elif [ "ibm" = $arch ] ; then ldflags="-brtl -G -bexpfull -bnoentry -b64" ; ldcmd="ld" # AIX
elif [ "linux" = $arch ] ; then ldflags="-shared" ; ldcmd="ld" # Linux - all platforms
elif [ "solaris" = $arch ] ; then ldflags="-G -64" ; ldcmd="ld" # Solaris SPARC
else echo "Shared libary ldflags not set for this platform"; exit 1
fi

# Binaries
binaries="mupip mumps libgtmshr$ext lke dse  geteuid ftok semstat2"

# Normal scripts - executed by anyone
nscripts="gtmbase lowerc_cp"

# Root scripts - only executed by root
rscripts="gtmstart gtmstop"
if [ $deliver_gtcm = "yes" ]; then
	rscripts="$rscripts gtcm_run gtcm_slist"
	binaries="$binaries gtcm_server gtcm_pkdisp gtcm_play gtcm_shmclean"
fi

if [ $deliver_gtcm_gnp = "yes" ]; then
	binaries="$binaries gtcm_gnp_server"
fi

# Help files
hlpfiles="*help.dat *help.gld *.h"
# Other files (left here for future use)
ofiles="$hlpfiles"

# Files that need to have $gtm_dist, $echo, etc. set in them.
pathmods="gtmbase.gtc gtmstart.gtc gtmstop.gtc gtmcshrc.gtc gtmprofile.gtc gtm.gtc gtmprofile_preV54000.gtc gdedefaults.gtc"

if [ $deliver_gtcm = "yes" ]; then
	pathmods="$pathmods gtcm_run.gtc gtcm_slist.gtc"
fi

# geteuid is no longer executable in distribution so change it
chmod 755 ./geteuid

if [ "`./geteuid`" != "root" ] ; then
	$echo "You must run Configure as root."
	exit
fi

$echo "                     GT.M Configuration Script"
$echo "Copyright 2009, 2014 Fidelity Information Services, Inc. Use of this"
$echo "software is restricted by the provisions of your license agreement."
$echo ""

# Native super user and group
rootuser=root
bingroup=bin
defowner=bin

# create temporary file to test for valid user and group names
touch tmp_owngrp
$echo "What user account should own the files? ($defowner) \c"
read resp
if [ "$resp" = "" ] ; then
	owner=$defowner
else
	owner=$resp
fi

chown $owner tmp_owngrp 2> /dev/null
if [ 0 != "$?" ] ; then
	$echo $owner is not a valid user name - exiting!
	rm tmp_owngrp
	exit
fi

$echo "What group should own the files? ($bingroup) \c"
read resp
if [ "$resp" != "" ] ; then
	bingroup=$resp
fi

chgrp $bingroup tmp_owngrp 2> /dev/null
if [ 0 != "$?" ] ; then
	$echo $bingroup is not a valid group name - exiting!
	rm tmp_owngrp
	exit 1
fi

$echo "Should execution of GT.M be restricted to this group? (y or n) \c"
read resp
if [ "$resp" = "Y" -o "$resp" = "y" ] ; then
	# root and bin are invalid groups to be restricted
	if [ 0 = $bingroup -o "bin" = $bingroup -o "root" = $bingroup ] ; then
		$echo GTM-E-GROUPNOTVALID - $bingroup not allowed to be a restricted group - exiting!
		exit 1
	fi
	# for all owners other than root or bin do an owner in group membership check
	if [ 0 != $owner -a "bin" != $owner -a "root" != $owner -a  `groups $owner | grep -w -c $bingroup` -eq 0 ] ; then
		$echo GTM-E-NOTINGROUP - $owner is not a member of $bingroup - exiting!
		exit 1
	fi
	group=$bingroup
fi

rm tmp_owngrp

$echo "In what directory should GT.M be installed? \c"
read gtmdist

# if gtmdist is relative then need to make it absolute

if [ `$echo $gtmdist | grep -c '^/'` -eq 0 ] ; then
    gtmdist=`pwd`/$gtmdist
fi

# ensure that canonical paths do not exceed PATH_MAX
getconf PATH_MAX $gtmdist | \
	awk '{max=$0-max;if(max<0)max+=1024;if(length(dist)>max){print dist" exceeds the maximum path length: "max;exit 1}}' \
		dist=$gtmdist max=50 || exit
$echo ""

if [ -d $gtmdist ]; then
	$echo "Directory $gtmdist exists. If you proceed with this installation then"
	$echo "some files will be over-written. Is it ok to proceed? (y or n) \c"
	read resp
	if [ "$resp" = "Y" -o "$resp" = "y" ] ; then
		chmod 0755 $gtmdist
		chown $owner $gtmdist
		chgrp $bingroup $gtmdist
	else
		exit
	fi

else
	$echo "Directory $gtmdist does not exist. Do you wish to create it as part of"
	$echo "this installation? (y or n) \c"

	read resp
	if [ "$resp" = "Y" -o "$resp" = "y" ] ; then
		mkdir -p        $gtmdist/plugin/r $gtmdist/plugin/o
		chmod 0755      $gtmdist/plugin/r $gtmdist/plugin/o $gtmdist
		chown $owner    $gtmdist/plugin/r $gtmdist/plugin/o $gtmdist
		chgrp $bingroup $gtmdist/plugin/r $gtmdist/plugin/o $gtmdist
	else
		exit
	fi
fi

if [ ! -w $gtmdist ]; then
	$echo "Directory $gtmdist is not writeable, so exiting"
	exit
fi

server_id=42

$echo ""
$echo "Installing GT.M...."
$echo ""


# Create $gtmdist/utf8 if this platform can support "UTF-8" mode.

# keep the utf8 libicu search code in gtm_test_install.csh in sync with the following!

if [ -d "utf8" ]; then
	unset gtm_icu_version
	# If package has utf8 directory, see if system has libicu and locale
	# Setup library path (in prep for looking for libicu and crypto libs)
	if [ "$arch" = "hp" ] ; then
		is64bit_gtm=`file mumps | grep "IA64" | wc -l`
	else
		is64bit_gtm=`file mumps | grep "64-bit" | wc -l`
	fi
# please keep in sync with sr_unix/set_library_path.csh
	if [ $is64bit_gtm -eq 1 ] ; then
		library_path="/usr/local/lib64 /usr/local/lib /usr/lib64 /usr/lib /usr/lib/x86_64-linux-gnu /lib64 /lib /usr/local/ssl/lib"  #BYPASSOK line length
	else
		library_path="/usr/local/lib32 /usr/local/lib /usr/lib32 /usr/lib /usr/lib/i386-linux-gnu /lib32 /lib"
	fi
	$echo "Should UTF-8 support be installed? (y or n) \c"
	read resp
	if [ "$resp" = "Y" -o "$resp" = "y" ] ; then
		would_like_utf8=1
		$echo "Should an ICU version other than the default be used? (y or n) \c"
		read resp
		if [ "$resp" = "Y" -o "$resp" = "y" ] ; then
			$echo "Enter ICU version (at least ICU version 3.6 is required. Enter as <major-ver>.<minor-ver>): \c"
			read gtm_icu_version
			icu_ver=`$echo $gtm_icu_version | sed 's/\.//'`
			majmin=`$echo $icu_ver | cut -f 1 -d "."`
			if [ "$majmin" -lt "36" ] ; then
				$echo "WARNING: ICU version $gtm_icu_version is less than 3.6. \c"
				$echo "UTF-8 support will not be installed"
				would_like_utf8=0
				doutf8=0
			fi
		fi
	else
		would_like_utf8=0
		doutf8=0
	fi
	# Look for libicu libraries
	found_icu=0
	icu_ext=".so"
	if [ $arch = "ibm" ] ; then
		icu_ext=".a"
	elif [ $arch = "hp" ] ; then
		icu_ext=".sl"
	fi
	if [ "$would_like_utf8" -eq 1 ] ; then
		for libpath in $library_path
		do
			icu_lib_found=0
			if [ "$gtm_icu_version" = "" -a -f "$libpath/libicuio$icu_ext" ] ; then
				icu_lib_found=1
				# Find the actual version'ed library to which libicuio.{so,sl,a} points to
				icu_versioned_lib=`ls -l $libpath/libicuio$icu_ext | awk '{print $NF}'`
				# Find out vital parameters
				if [ $arch = "ibm" ]; then
					# From the version'ed library(eg. libicuio36.0.a) extract out
					# 36.0.a
					full_icu_ver_string=`$echo $icu_versioned_lib | sed 's/libicuio//g'`
					# Extract 36 from 36.0.a
					majmin=`$echo $full_icu_ver_string | cut -f 1 -d '.'`
				else
					full_icu_ver_string=`$echo $icu_versioned_lib | sed 's/libicuio\.//g'`
					majmin=`$echo $full_icu_ver_string | cut -f 2 -d '.'`
				fi
			elif [ "$gtm_icu_version" != "" ] ; then
				# If the user specified a desired version number, then check if the ICU
				# library with that version number exists.
				# AIX and z/OS reference ICU as libicuioVERSION.{so,a}
				# The other platforms reference the libraries as libicuio.{sl,so}.VERSION
				if [ -f "$libpath/libicuio$majmin$icu_ext" -o -f "$libpath/libicuio$icu_ext.$majmin" ] ; then
					icu_lib_found=1
				else
					icu_lib_found=0
				fi
			fi
			if [ $icu_lib_found -eq 1 ] ; then
				# Figure out the object mode(64 bit or 32 bit)  of ICU libraries on the target machine
				if [ $arch = "linux" -o $arch = "sun"  -o  $arch = "solaris" ] ; then
					icu_full_ver_lib=`ls -l $libpath/libicuio$icu_ext.$majmin 2>/dev/null | awk '{print $NF}'`
					is64bit_icu=`file $libpath/$icu_full_ver_lib 2>/dev/null | grep "64-bit" | wc -l`
				elif [ $arch = "hp" ] ; then
					icu_full_ver_lib=`ls -l $libpath/libicuio$icu_ext.$majmin 2>/dev/null | awk '{print $NF}'`
					is64bit_icu=`file $libpath/$icu_full_ver_lib 2>/dev/null | grep "IA64" | wc -l`
				elif [ $arch = "ibm" ] ; then
					icu_full_ver_lib=`ls -l $libpath/libicuio$majmin$icu_ext 2>/dev/null | awk '{print $NF}'`
					is64bit_icu=`nm -X64 $libpath/$icu_full_ver_lib 2>/dev/null | head -n 1 | wc -l`
				fi
				# Make sure both GTM and ICU are in sync with object mode compatibility (eg both are 32 bit/64 bit )
				if [ "$is64bit_gtm" -eq 1 -a "$is64bit_icu" -ne 0 ] ; then
					found_icu=1
				elif [ "$is64bit_gtm" -ne 1 -a "$is64bit_icu" -eq 0 ] ; then
					found_icu=1
				else
					found_icu=0
				fi
				# If we have everything we want, then save the libpath that contains the proper ICU library and
				# set the gtm_icu_version
				if [ "$found_icu" -eq 1 -a "$majmin" -ge 36 ] ; then
					save_icu_libpath="$libpath"
					minorver=`expr $majmin % 10`
					majorver=`expr $majmin / 10`
					gtm_icu_version="$majorver.$minorver"
					export gtm_icu_version
					break
				fi
			fi
		done
		if [ "$found_icu" -eq 0 ] ; then
			if [ "$majmin" != "" ] ; then
				$echo "WARNING: ICU version $gtm_icu_version not found. Not installing UTF-8 support."
			else
				$echo "WARNING: Default ICU version not found. Not installing UTF-8 support."
			fi
		fi
		# Look for locale
		utflocale=`locale -a | grep $binaryopt -iE '\.utf.?8$' | head -n1`
		if [ "$utflocale" = "" ] ; then
			$echo "WARNING: UTF8 locale not found. Not installing UTF-8 support."
		fi
		# If both libicu and locale are on system then install UTF-8 support
		if [ "$found_icu" -ne 0  -a "$utflocale" != "" ] ; then
			doutf8=1
		else
			doutf8=0
		fi
	fi
else
	# If utf8 dir does not exist in package, can't install UTF-8 support
	doutf8=0
fi

# Solaris 10 bourne shell does not support ${var#word} syntax
install_dest=$gtmdist
if [ X"$gtm_destdir" != X"" ] ; then
	install_dest=`echo $install_dest | sed "s;${gtm_destdir};;"`
fi

# Modify the scripts as necessary for target configuration
cat << SEDSCRIPT > sedin$$
s|ARCH|$arch|g
s|ECHO|"$echo"|g
s|GTMDIST|${install_dest}|g
s|SERVERID|$server_id|g
SEDSCRIPT
for i in $pathmods
do
	dest=`basename $i .gtc`
	sed -f sedin$$ $i > $dest
	if [ "$doutf8" -ne 0 ]; then
		cd utf8
		if ( test -f "$dest" ) then rm $dest; fi
		ln -s ../$dest $dest
		cd ..
	fi
done
rm sedin$$
if [ "$doutf8" -ne 0 ]; then
	if [ ! -d $gtmdist/utf8 ]; then
		mkdir -p $gtmdist/utf8 $gtmdist/plugin/o/utf8
	fi
fi

# Install COPYING if it is applicable
file=COPYING
if [ -f $file ]; then
	cp -p $file $gtmdist
	if [ "$doutf8" -ne 0 ]; then
		ln -s ../$file $gtmdist/utf8/$file
	fi
fi

# Install README.txt if it is applicable
file=README.txt
if [ -f $file ]; then
	cp -p $file $gtmdist
	if [ "$doutf8" -ne 0 ]; then
		ln -s ../$file $gtmdist/utf8/$file
	fi
fi

# Install custom_errors_sample.txt if it is applicable
file=custom_errors_sample.txt
if [ -f $file ]; then
	cp -p $file $gtmdist
	if [ "$doutf8" -ne 0 ]; then
		ln -s ../$file $gtmdist/utf8/$file
	fi
fi
# Install the .cshrc and .profile files
cp -p gdedefaults gtmprofile gtmprofile_preV54000 gtm gtmcshrc $gtmdist
chmod 0444 $gtmdist/gdedefaults
chown $owner $gtmdist/gdedefaults
chmod 0755 $gtmdist/gtmprofile
chown $owner $gtmdist/gtmprofile
chmod 0755 $gtmdist/gtmprofile_preV54000
chown $owner $gtmdist/gtmprofile_preV54000
chmod 0755 $gtmdist/gtm
chown $owner $gtmdist/gtm
chmod 0755 $gtmdist/gtmcshrc
chown $owner $gtmdist/gtmcshrc

# Install the normal scripts
for i in $nscripts
do
	cp -p $i $gtmdist
	chmod 0755 $gtmdist/$i
	chown $owner $gtmdist/$i
done

# Install the root scripts
for i in $rscripts
do
	cp -p $i $gtmdist
	chmod 0744 $gtmdist/$i
	chown $rootuser $gtmdist/$i
done

# Install the normal binaries
for i in $binaries
do
	if [ $arch = "sun" -o $arch = "linux" ]; then
		install -g $bingroup -o $owner -m 644 $i $gtmdist
	elif [ $arch = "ibm" ]; then
		/usr/bin/install -f $gtmdist -M 644 -O $owner -G $bingroup $i
	elif [ -x /usr/sbin/install ]; then
		/usr/sbin/install -f $gtmdist -m 644 -u $owner -g $bingroup $i $gtmdist
	else
		install -f $gtmdist -m 644 -u $owner -g $bingroup $i $gtmdist
	fi
#		strip $gtmdist/$i >/dev/null 2>&1
done

# Install other individual files
for i in  $ofiles
do
	cp -p $i $gtmdist
	chown $owner $gtmdist/$i
done

# For linux systems, attempt to execute the chcon command to allow use of the libgtmshr shared library. This
# command is required on many modern SELinux based systems but depends on the filesystem in use (requires context
# support). For that reason, we attempt the command and if it works, great. If it doesn't, oh well we tried.
if [ -f /usr/bin/chcon ]; then
	chcon -t texrel_shlib_t $gtmdist/libgtmshr$ext > /dev/null 2>&1
fi

# Create $gtmdist/plugin/gtmcrypt directory if this platform supports encryption

# Define variables to denote plugin and gtmcrypt directory names
plugin="plugin"
plugin_gtmcrypt="$plugin/gtmcrypt"

# Gtmcrypt scripts
gtmcryptscripts="gen_sym_key.sh encrypt_sign_db_key.sh gen_keypair.sh pinentry-gtm.sh"
gtmcryptscripts="$gtmcryptscripts import_and_sign_key.sh gen_sym_hash.sh show_install_config.sh"

# Gtmcrypt related M file
gtmcryptmfile="pinentry.m"

# Gtmcrypt source files
gtmcryptsrcfiles="Makefile README gtmcrypt_ref.c gtmcrypt_ref.h gtmcrypt_interface.h maskpass.c"
gtmcryptsrcfiles="$gtmcryptsrcfiles gtmcrypt_dbk_ref.c gtmcrypt_dbk_ref.h gtmcrypt_pk_ref.c gtmcrypt_pk_ref.h"
gtmcryptsrcfiles="$gtmcryptsrcfiles gtmcrypt_sym_ref.h gtmcrypt_sym_ref.c gtm_tls_interface.h gtm_tls_impl.h"
gtmcryptsrcfiles="$gtmcryptsrcfiles gtm_tls_impl.c gtmcrypt_util.c gtmcrypt_util.h $gtmcryptmfile"

dogtmcrypt=0
if [ -d "$plugin_gtmcrypt" ]; then
	dogtmcrypt=1
	# Create plugin directory and gtmcrypt directory
	mkdir -p $gtmdist/plugin/gtmcrypt
	chmod 0755 $gtmdist/plugin
	chown $owner $gtmdist/plugin
	chgrp $bingroup $gtmdist/plugin
	chmod 0755 $gtmdist/plugin/gtmcrypt
	chown $owner $gtmdist/plugin/gtmcrypt/
	chgrp $bingroup $gtmdist/plugin/gtmcrypt

	# Tar the source files
	cat > $plugin_gtmcrypt/README << EOF
#
# WARNING: This file was generated by the GT.M install script at install time.
#
# Dependency information:
#  Please install a compiler toolchain and libgcrypt, libgpgme, libconfig, and
#  libssl development libraries. On Debian you can do:
#    sudo apt-get install libgcrypt11-dev libgpgme11-dev libconfig-dev libssl-dev
#
# Installation instructions:
#  You may need to edit the Makefile to add include (IFLAGS) and library paths
#  (LIBFLAGS) for your system.
#
#  The commands below to compile, install and set the file permissions on the
#  encryption plugin libraries make the following assumptions:
#    - The shell is bourne shell compatible
#    - The user is root
#    - The permissions defined for the gtm installation are appropriate for the
#      plug-in
#
#  You should be able to cut and paste the following commands
#
gtm_dist="$gtmdist"
export gtm_dist
make && make install && make clean
find \$gtm_dist/plugin -type f -exec chown ${owner}:${bingroup} {} +
EOF
	if [ "$group" != "" ] ; then
		echo "chmod -R o-rwx \$gtm_dist/plugin" >> $plugin_gtmcrypt/README
	fi
	(cd $plugin_gtmcrypt			&& \
	 chmod 0644 $gtmcryptsrcfiles		&& \
	 chmod 0755 $gtmcryptscripts 		&& \
	 chown ${owner}:${bingroup} *		&& \
	 tar -cvf $gtmdist/$plugin_gtmcrypt/source.tar $gtmcryptsrcfiles $gtmcryptscripts >/dev/null 2>&1)
	chmod 0644 $gtmdist/$plugin_gtmcrypt/source.tar
	chown ${owner}:${bingroup} $gtmdist/$plugin_gtmcrypt/source.tar
	rm $plugin_gtmcrypt/README
	(cd $gtmdist/$plugin_gtmcrypt && tar -xvf source.tar)
fi

# Install GDE, GTMHELP, and all the percent routines
cp -p *.o *.m $gtmdist

# Install a mirror image (using soft links) of $gtmdist under $gtmdist/utf8 if this platform can support "UTF-8" mode.
if [ "$doutf8" -ne 0 ]; then
	cd utf8
	for file in *
	do
		# Skip directories
		if [ -d "$file" ]; then
			continue
		fi
		# Skip gtmsecshr/dir
		if [ "$file" = "gtmsecshr" -o "$file" = "gtmsecshrdir" ]; then
			continue
		fi
		# Install .o files
		base="`basename $file .o`"
		if [ "$base" != "$file" ]; then
			cp -p "$file" $gtmdist/utf8
		else
			# Soft link everything else
			if [ -f $gtmdist/utf8/"$file" ]; then
				rm -f $gtmdist/utf8/"$file"
			fi
			if [ -f $gtmdist/"$file" ]; then
				ln -s ../"$file" $gtmdist/utf8/"$file"
			fi
		fi
	done
	if [ "$dogtmcrypt" -ne 0 ]; then
		ln -s ../plugin $gtmdist/utf8/plugin
	fi
	cd ..
fi

$echo ""
$echo "All of the GT.M MUMPS routines are distributed with uppercase names."
$echo "You can create lowercase copies of these routines if you wish, but"
$echo "to avoid problems with compatibility in the future, consider keeping"
$echo "only the uppercase versions of the files."
$echo ""
$echo "Do you want uppercase and lowercase versions of the MUMPS routines? (y or n)\c"
read resp
if [ "$resp" = "Y" -o "$resp" = "y" ] ; then
	$echo ""
	$echo "Creating lowercase versions of the MUMPS routines."
	(cd $gtmdist; ./lowerc_cp *.m)
	if [ "$doutf8" -ne 0 ]; then
		(cd $gtmdist/utf8; ./lowerc_cp *.m)
	fi
fi

# Change mode to executable for mumps and libgtmshr to do the compiles
chmod 755 $gtmdist/mumps $gtmdist/libgtmshr$ext

gtmroutines=$gtmdist
gtmgbldir=$gtmdist/mumps.gld
gtm_dist=$gtmdist
export gtm_dist
export gtmroutines
export gtmgbldir

$echo ""
$echo "Compiling all of the MUMPS routines. This may take a moment."
$echo ""

# Ensure we are NOT in UTF-8 mode
gtm_chset="M"
export gtm_chset
(cd $gtmdist; ./mumps -noignore *.m; $echo $?>compstat ; \
 if [ "$is64bit_gtm" -eq 1 -o "linux" != $arch ] ; then $ldcmd $ldflags -o libgtmutil$ext *.o ; fi )

# Now work on UTF-8 mode
if [ "$doutf8" -ne 0 ]; then
	# Enclose UTF-8 operations inside a subshell. This avoids changing the current M mode execution
	(
		# Ensure we ARE in UTF-8 mode
		utflocale=`locale -a | grep $binaryopt -iE 'en_us\.utf.?8$' | head -n1`
		if [ "$utflocale" = "" ]; then
			# If no locale defined, try C.UTF-8
			utflocale="C.UTF-8"
		fi
		LC_CTYPE=$utflocale
		export LC_CTYPE
		unset LC_ALL
		gtm_chset="UTF-8"
		export gtm_chset
		if [ $arch = "ibm" ]; then
			export LIBPATH=$save_icu_libpath
		else
			LD_LIBRARY_PATH=$save_icu_libpath
			export LD_LIBRARY_PATH
		fi
		(gtm_dist=$gtmdist/utf8; export gtm_dist; cd $gtm_dist; ./mumps -noignore *.m; $echo $?>>$gtmdist/compstat; \
		if [ $is64bit_gtm -eq 1 -o "linux" != $arch ] ; then $ldcmd $ldflags -o libgtmutil$ext *.o ; fi )
	)
fi

# Change mode to executable for the normal binaries
for i in $binaries
do
	chmod 755 $gtmdist/$i
done

chmod 0644 $gtmdist/*.m
chmod 0644 $gtmdist/*.o
chown $owner $gtmdist/*.m
chown $owner $gtmdist/*.o
chown $owner $gtmdist/*.txt
chgrp $bingroup $gtmdist/*.m
chgrp $bingroup $gtmdist/*.o
chgrp $bingroup $gtmdist/*.txt

if [ "$doutf8" -ne 0 ]; then
	chmod 0644 $gtmdist/utf8/*.m
	chmod 0644 $gtmdist/utf8/*.o
	chown $owner $gtmdist/utf8
	chown $owner $gtmdist/utf8/*.m
	chown $owner $gtmdist/utf8/*.o
	chown $owner $gtmdist/utf8/*.txt
	chgrp $bingroup $gtmdist/utf8/*.m
	chgrp $bingroup $gtmdist/utf8/*.o
	chgrp $bingroup $gtmdist/utf8/*.txt
fi

if [ -f $gtm_dist/libgtmutil$ext ] ; then
    gtmroutines="$gtm_dist/libgtmutil$ext $gtmdist"
else
    gtmroutines="$gtmdist"
fi
export gtmroutines

other_object_files=""
csh_script_files=""

# make database files read only
chmod 0444 $gtmdist/*.dat
chmod 0444 $gtmdist/*.gld

# $other_object_files, $csh_script_files should be removed unconditionally
savedir=`pwd`
# temporarily change to $gtmdist
cd $gtmdist
\rm -rf $other_object_files $csh_script_files lowerc_cp

if [ -d utf8 ]; then
	cd utf8
	\rm -rf $other_object_files $csh_script_files lowerc_cp
fi
# change back to original directory
cd $savedir

# Optionally remove .o files if they are in a shared library
if [ -f $gtm_dist/libgtmutil$ext ] ; then
	chown ${owner}:${bingroup} $gtm_dist/libgtmutil$ext
	$echo ""
	$echo "Object files of M routines placed in shared library $gtm_dist/libgtmutil$ext"
	$echo "Keep original .o object files (y or n)? \c"
	read resp
	if [ "n" = "$resp" -o "N" = "$resp" ] ; then rm -f $gtm_dist/*.o $gtm_dist/utf8/*.o ; fi
	$echo ""
	if [ -f $gtm_dist/utf8/libgtmutil$ext ] ; then
		chown ${owner}:${bingroup} $gtm_dist/utf8/libgtmutil$ext
	fi
fi

# change group ownership of all files if group restricted
# otherwise change to the default as some files were created with root group
if [ "$group" != "" ] ; then
	chgrp -R $group $gtmdist
	chmod -R o-rwx $gtmdist
else
	chgrp -R $bingroup $gtmdist
fi

# Install real gtmsecshr with special permissions in $gtmdist/gtmsecshrdir
tgtmsecshrdir=$gtmdist/gtmsecshrdir
mkdir $tgtmsecshrdir
chmod 700 $tgtmsecshrdir
chgrp $bingroup $tgtmsecshrdir

# Install gtmsecshr and the wrapper with special permissions
if [ $arch = "sun" -o $arch = "linux" ]; then
	install -m 4555 -o root -g $bingroup gtmsecshr $gtmdist
	install -m 4500 -o root -g $bingroup gtmsecshrdir/gtmsecshr $tgtmsecshrdir/gtmsecshr
elif [ $arch = "ibm" ]; then
	/usr/bin/install -f $gtmdist -M 4555 -O root -G $bingroup gtmsecshr
	/usr/bin/install -f $tgtmsecshrdir -M 4500 -O root -G $bingroup gtmsecshrdir/gtmsecshr
elif [ -x /usr/sbin/install ]; then
	/usr/sbin/install -f $gtmdist -m 4555 -u root -g $bingroup gtmsecshr $gtmdist
	/usr/sbin/install -f $tgtmsecshrdir -m 4500 -u root -g $bingroup gtmsecshrdir/gtmsecshr $tgtmsecshrdir
else
	install -f $gtmdist -m 4555 -u root -g $bingroup gtmsecshr $gtmdist
	install -f $tgtmsecshrdir -m 4500 -u root -g $bingroup gtmsecshrdir/gtmsecshr $tgtmsecshrdir
fi

strip $gtmdist/gtmsecshr > /dev/null 2>&1
strip $tgtmsecshrdir/gtmsecshr > /dev/null 2>&1

if [ -d $gtmdist/utf8 ]; then

	# Delete the gtmsecshr symlink
	if [ -f $gtmdist/utf8/gtmsecshr -o -h $gtmdist/utf8/gtmsecshr ]; then
		rm -f $gtmdist/utf8/gtmsecshr
	fi
	ln $gtmdist/gtmsecshr $gtmdist/utf8/gtmsecshr || \
		echo ln $gtmdist/gtmsecshr $gtmdist/utf8/gtmsecshr

	# Delete the gtmsecshrdir symlink
	if [ -f $gtmdist/utf8/gtmsecshrdir -o -h $gtmdist/utf8/gtmsecshrdir ]; then
		rm -f $gtmdist/utf8/gtmsecshrdir
	fi
	mkdir -p $gtmdist/utf8/gtmsecshrdir
	chmod 0500 $gtmdist/utf8/gtmsecshrdir
	ln $gtmdist/gtmsecshrdir/gtmsecshr $gtmdist/utf8/gtmsecshrdir/gtmsecshr || \
		echo ln $gtmdist/gtmsecshrdir/gtmsecshr $gtmdist/utf8/gtmsecshrdir/gtmsecshr

fi

# change group ownership of wrapper if group restricted
# also remove user privileges for wrapper if group changed
if [ "$group" != "" ] ; then
	chgrp $group $gtmdist/gtmsecshr
	$echo ""
	$echo "Removing world permissions from gtmsecshr wrapper since group restricted to \"$group\""
	chmod 4550 $gtmdist/gtmsecshr
fi

# leave nothing writeable
chmod a-w $gtmdist
chmod a-w $gtmdist/*

if [ -d $gtmdist/utf8 ]; then
	chmod a-w $gtmdist/utf8/*
fi

if [ -d $gtmdist/plugin ]; then
	chmod a-w $gtmdist/plugin/*
fi

if [ -d $gtmdist/plugin/gtmcrypt ]; then
	chmod a-w $gtmdist/plugin/gtmcrypt/*
fi

# if we had a mumps error then remove executable bit recursively and exit
# this could include compile and/or library load errors
if [ 0 != `grep -c '[1-9]' $gtm_dist/compstat` ]; then
	$echo ""
	$echo "GT.M installation FAILED – please review error messages"
	$echo ""
	chmod -R a-x $gtmdist
	exit 1
fi

rm -f $gtmdist/compstat

$echo ""
$echo "Installation completed. Would you like all the temporary files"
$echo "removed from this directory? (y or n) \c"
read resp

if [ "$resp" = "Y" -o "$resp" = "y" ] ; then
	\rm -rf $binaries $pathmods $rscripts $nscripts $dirs configure \
		*.gtc gtm* gde* GDE*.o _*.m _*.o mumps.dat mumps.gld geteuid $other_object_files $csh_script_files lowerc_cp\
		*.hlp core *.h *.m *help.dat *help.gld COPYING README.txt
	\rm -rf GETPASS.o plugin GTMHELP.o custom_errors_sample.txt
	if [ -d utf8 ]; then
		\rm -rf utf8
	fi
fi