File: distinst

package info (click to toggle)
gridengine 6.2u5-7.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 57,216 kB
  • sloc: ansic: 438,030; java: 66,252; sh: 36,399; jsp: 7,757; xml: 5,850; makefile: 5,520; csh: 4,571; cpp: 2,848; perl: 2,401; tcl: 692; lisp: 669; yacc: 668; ruby: 642; lex: 344
file content (1641 lines) | stat: -rwxr-xr-x 55,342 bytes parent folder | download | duplicates (2)
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
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
#!/bin/sh
#
#  distinst
#___INFO__MARK_BEGIN__
##########################################################################
#
#  The Contents of this file are made available subject to the terms of
#  the Sun Industry Standards Source License Version 1.2
#
#  Sun Microsystems Inc., March, 2001
#
#
#  Sun Industry Standards Source License Version 1.2
#  =================================================
#  The contents of this file are subject to the Sun Industry Standards
#  Source License Version 1.2 (the "License"); You may not use this file
#  except in compliance with the License. You may obtain a copy of the
#  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
#
#  Software provided under this License is provided on an "AS IS" basis,
#  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
#  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
#  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
#  See the License for the specific provisions governing your rights and
#  obligations concerning the Software.
#
#  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
#
#  Copyright: 2001 by Sun Microsystems, Inc.
#
#  All Rights Reserved.
#
##########################################################################
#___INFO__MARK_END__

umask 022

TOPFILES="3rd_party bin catman ckpt doc examples include inst_sge \
          install_execd install_qmaster lib man mpi pvm hadoop qmon util utilbin"

HASARCHDIR="bin lib examples/jobsbin utilbin"

DEFAULTPROG="sge_qmaster sge_execd sge_shadowd \
             sge_shepherd sge_coshepherd qstat qsub qalter qconf qdel \
             qacct qmod qsh utilbin jobs qmon qhost qmake qtcsh qping \
             qloadsensor.exe sgepasswd qquota qrsub qrstat qrdel"

UTILITYBINARIES="uidgid gethostname gethostbyname gethostbyaddr \
                 getservbyname filestat checkprog loadcheck now checkuser \
                 adminrun qrsh_starter testsuidroot authuser read_raw echo_raw \
                 sge_share_mon infotext spooldefaults spooledit spoolinit \
                 fstype SGE_Helper_Service.exe SGE_Starter.exe valid_jvmlib"

BDBUTILITYBINARIES="berkeley_db_svc db_archive db_checkpoint db_deadlock db_dump db_load db_printlog db_recover db_stat db_upgrade db_verify"

SSLUTILITYBINARIES="openssl"

REMOTEBINARIES="rsh rshd rlogin"

JOBBINARIES="work showq"

SHARED_LIBRARIES="libcom libcull libgdi librmon libsched libsge libuti \
                  libspool libspoolb libspoold libspoolc libspoolf \
                  libsgeobj libsgeobjd \
                  libevc libevm libmir \
                  libjuti libjgdi"

QMON_SHARED_LIBRARIES="libXbae libXicon libXmt libXspin libXtab"
QMON_NEED_SHARED_LIBRARIES="libXltree"
OPENSSL_SHARED_LIBRARIES="libcrypto libssl"

BERKELEYDB_SHARED_LIBRARIES="libdb-4.4"

DRMAA_SHARED_LIBRARIES="libdrmaa"
# The last number listed here will be the verson linked from libdrmaa.so
DRMAA_SHARED_LIB_VERSIONS="1.0"
DRMAA_HEADER_FILES="libs/japi/drmaa.h"
DRMAAJ_FILES="CLASSES/jdrmaa/drmaa"

JNI_SHARED_LIBRARIES="libdrmaa libjuti libjgdi"

JUTIJ_FILES="CLASSES/juti/juti"
JGDIJ_FILES="libs/jgdi/build/jgdi"
JJSV_FILES="CLASSES/jjsv/JSV"
JAVA_LIBRARIES="${DRMAAJ_FILES} ${JUTIJ_FILES} ${JGDIJ_FILES} ${JJSV_FILES}"

PVMSOURCES="start_pvm.c stop_pvm.c slave.c master.c spmd.c Makefile"
PVMSRCSCRIPTS="install.sh aimk"
PVMSCRIPTS="startpvm.sh stoppvm.sh pvm.sh pvm_nogs.sh README pvm.template"

MPI_FILES="README README.atm mpi.template mpich.template"
MPI_SCRIPTS="hostname  mpi.sh mpi_cpi.sh rsh startmpi.sh stopmpi.sh"

HADOOP_FILES="logging.properties"
HADOOP_SCRIPTS="env.sh jsv.sh load_sensor.sh make_conf.sh pestart.sh pestop.sh setup.pl ssh wait.sh"

DTRACE_FILES="README-dtrace.txt monitor.d"
DTRACE_SCRIPTS="monitor.sh"

MYRINET_FILES="README README.x mpi.template mpich.template \
               mpich_multi.template"
MYRINET_SCRIPTS="gmps sge_mpirun sge_mpirun.x startmpi.sh startmpi.sh.x \
                 stopmpi.sh"

SUNHPCTIGHT_FILES="README pe_sunmpi_ci.template"
SUNHPCTIGHT_SCRIPTS="resume_sunmpi_ci.sh suspend_sunmpi_ci.sh"

SECFILES="security/gss/get_cred.c security/gss/put_cred.c \
          security/gss/delete_cred.c security/gss/sge_gsslib.c \
          security/gss/sge_gsslib.h security/gss/renew_cred.ksh \
          security/gss/starter_cred.ksh security/gss/msg_gss.h \
          security/gss/aimk security/gss/Makefile.security \
          security/gss/doc/gss_customer.html \
          common/basis_types.h security/gss/put_cred.sh \
          security/gss/get_cred.sh \
          security/gss/k5dcelogin.c security/gss/k5dce.h"

SECURITYBINARIES="get_cred put_cred delete_cred renew_cred \
                  starter_cred get_cred.sh put_cred.sh k5dcelogin"

GE_SOURCEDIR=`pwd`

#-------------------------------------------------------------------------
# help output, exits after printing help
#
ErrUsage()
{
   echo "Usage: distinst [-opts] [other archs] [-- other progs]"
   echo "       -all           = all binaries + common"
   echo "       -allall        = all binaries + common + doc + arco + sgeinspect"
   echo "       -basedir <dir> = define base directory for distribution"
   echo "       -bin           = all binaries and libraries"
   echo "       -help_arch     = show architectures table"
   echo "       -libs          = all libraries"
   echo "       -local         = install in \$SGE_ROOT"
   echo "       -shlibpath     = cause LD_LIBRARY_PATH be always set even if RUNPATH supported (Solaris/Linux)"
   echo "       -mansrc <dir>  = take man pages from MANSBUILD_<dir>"
   echo "       -nobdb         = do not install the Berkeley DB binaries and libs"
   echo "       -noexit        = do not exit on installation errors"
   echo "       -noinst        = no install, show target arch"
   echo "       -noopenssl     = do not install the OpenSSL binaries and libs"
   echo "       -nosource      = do not source \"distinst.private\""
   echo "       -onlybin       = all binaries, no libraries"
   echo "       -classic-targets = qmaster+spool* from <ARCHDIR>_classic"
   echo "       -resetarch     = set PROG="" (useful to override distinst.privat)"
   echo "       -resetprog     = set ARCH="" (useful to override distinst.privat)"
   echo "       -tcc           = create file .COMMON_CHANGED if common changed"
   echo "       -v             = more verbose"
   echo "       -vdir <dir>    = define version directory for distribution"
   echo "<other progs>:"
   echo "       \"arco\"       = ARCo files (dbwriter, reporting)"
   echo "       \"ckpt\"       = checkpointing support files"
   echo "       \"common\"     = arch. independent, no man/ and no doc/"
   echo "       \"distcommon\" = arch. independent stuff + man + doc/"
   echo "       \"doc\"        = doc/ directory tree"
   echo "       \"dtrace\"     = Dtrace scripts"
   echo "       \"examples\"   = examples/ directory tree without binaries"
   echo "       \"iscript\"    = install script"
   echo "       \"jobs\"       = examples/jobsbin/ example binaries"
   echo "       \"man\"        = manual pages"
   echo "       \"mpi\"        = MPI scripts"
   echo "       \"pvm\"        = PVM source files and scripts"
   echo "       \"hadoop\"        = Hadoop scripts and libraries"
   echo "       \"qmontree\"   = PIXMAPS, resource-, help-, copyright files"
   echo "       \"sec\"        = DCE/Kerberos security modules"
   echo "       \"secbin\"     = DCE/Kerberos security binaries"
   echo "       \"sgeinspect\" = SGE Inspect binaries"
   echo "       \"txtdoc\"     = doc/ directory tree without PS and PDF files"
   echo "       \"utilbin\"    = utilbin/\$ARCH/*"
   echo "       \"utiltree\"   = util/ directory tree"
   exit 0
}

#-------------------------------------------------------------------------
#
SetArchBin()
{
   BUILDARCH=`$GE_SOURCEDIR/scripts/compilearch -b $1`
   if [ $? -ne 0 ]; then
      echo "No ARCHBIN name for \"$1\""
      if [ $exit_on_error = true ]; then
         exit 1
      else
         ARCHBIN="undefined"
      fi
   else
      ARCHBIN=`$GE_SOURCEDIR/scripts/compilearch -c $1`
      if [ "$ARCHBIN" = "" ]; then
         ARCHBIN=$BUILDARCH
      fi
   fi
}

#-------------------------------------------------------------------------
#
ArchTable()
{
   echo "Arch Name             Platform"
   echo "-------------------------------------------"
   echo "aix51                 AIX 5.1"
   echo "aix43                 AIX 4.3"
   echo "hp10                  HP-UX 10.x"
   echo "hp11                  HP-UX 11.x"
   echo "hp11-64               HP-UX 11.x 64bit"
   echo "irix65                Irix 6.5"
   echo "lx24-alpha            Alpha Linux v2.4 kernel"
   echo "lx26-alpha            Alpha Linux v2.6 kernel"
   echo "lx24-amd64            AMD Linux v2.4 kernel"
   echo "lx26-amd64            AMD Linux v2.6 kernel"
   echo "lx24-ia64             IA64 Linux v2.4 kernel"
   echo "lx26-ia64             IA64 Linux v2.6 kernel"
   echo "lx26-ppc              PPC Linux v2.6 kernel"
   echo "lx24-sparc            SPARC Linux v2.4 kernel"
   echo "lx26-sparc            SPARC Linux v2.6 kernel"
   echo "lx24-sparc64          SPARC 64bit Linux v2.4 kernel"
   echo "lx26-sparc64          SPARC 64bit Linux v2.6 kernel"
   echo "lx24-x86              x86 Linux v2.4 kernel"
   echo "lx26-x86              x86 Linux v2.6 kernel"
   echo "ulx24-x86             x86 Linux v2.4 kernel, libc < 2.3"
   echo "ulx24-amd64           AMD Linux v2.4 kernel, libc < 2.3"
   echo "osf4                  OSF 4.x"
   echo "tru64                 TRU64 UNIX"
   echo "sol-x86               Solaris x86"
   echo "sol-amd64             Solaris 10 AMD64"
   echo "sol-sparc             Solaris SPARC"
   echo "sol-sparc64           Solaris SPARC 64bit"
   echo "usol-x86              Solaris 8, x86"
   echo "usol-sparc            Solaris 7, SPARC"
   echo "usol-sparc64          Solaris 7, SPARC 64bit"
   echo "cray                  UNICOS"
   echo "crayts                UNICOS TS"
   echo "craytsieee            UNICOS TS IEEE"
   echo "necsx4                NECSX 4.x"
   echo "necsx5                NECSX 5.x"
   echo "sx                    NECSX 5.x"
   echo "necsx6                NECSX 6.x"
   echo "darwin-ppc            MacOS 10.x PowerPC"
   echo "darwin-x86            MacOS 10.x x86"
   echo "fbsd-alpha            Alpha FreeBSD"
   echo "fbsd-amd64            AMD64 FreeBSD"
   echo "fbsd-i386             x86 FreeBSD"
   echo "fbsd-ia64             IA64 FreeBSD"
   echo "fbsd-ppc              PowerPC FreeBSD"
   echo "fbsd-sparc64          SPARC FreeBSD 64bit"
   exit 0
}

#-------------------------------------------------------------------------
#
MakeArchDirs()
{
   echo Checking and creating binary directories 
   for d in $HASARCHDIR; do
      if [ ! -d $DEST_SGE_ROOT/$d ]; then
         Execute mkdir -p $DEST_SGE_ROOT/$d
      fi
      for a in $*; do
         if [ ! -d $DEST_SGE_ROOT/$d/$a ]; then
            Execute mkdir -p $DEST_SGE_ROOT/$d/$a
         fi
      done
   done
}

#-------------------------------------------------------------------------
# Call arguments, be verbose if $verbose is set and exit on error if
# $exit_on_error is set
#
Execute()
{
        if [ $verbose = true ]; then
                echo $*
        fi
        $*
        if [ $? -gt 0 ]; then
                echo
                echo This command failed: $* 
                echo
                if [ "$exit_on_error" = true ]; then
                   echo "Installation failed. Exiting."
                   echo
                   exit 1
                fi
        fi
}

#-------------------------------------------------------------------------
# Create directory if it doesn't exist
# and exit if $exit_on_error is set
#
MakeDir()
{
   if [ ! -d $DEST_SGE_ROOT/$1 ]; then
      Execute mkdir $DEST_SGE_ROOT/$1
   fi
   Execute chmod 755 $DEST_SGE_ROOT/$1
}

#-------------------------------------------------------------------------
# Delete CVS directories and backup files etc.
#
Cleanup()
{
   for i in $*; do
      find $DEST_SGE_ROOT/$i -name CVS -type d -exec rm -rf {} \; 2>/dev/null
      find $DEST_SGE_ROOT/$i \( -name "*~" -o -name "*.bak" -o \
                                -name ".#*" -o -name "*.swp" \) \
                              -type f -exec rm -f {} \;
      if [ $IAMROOT = true ]; then
         Execute chown -R 0:0 $DEST_SGE_ROOT/$i
      fi
   done
}

#-------------------------------------------------------------------------
# Install user.group permissions source destination
Install()
{
   Execute cp $3 $4
   if [ $IAMROOT = true ]; then
      target_uid=`echo $1 | cut -d. -f1`
      target_gid=`echo $1 | cut -d. -f2`
      Execute chown $target_uid $4
      Execute chgrp $target_gid $4
   fi
   if [ -d $4 ]; then
      Execute chmod $2 $4/`basename $3`
   else
      Execute chmod $2 $4
   fi
}

#-------------------------------------------------------------------------
#
InstallProg()
{
   echo Installing $1
   Install 0.0 755 $1 $DEST_SGE_ROOT/${UTILPREFIX}/$DSTARCH/`basename $1`
}

#-------------------------------------------------------------------------
#
InstallProgAs()
{
   echo Installing $1 as $2
   Install 0.0 755 $1 $DEST_SGE_ROOT/${UTILPREFIX}/$DSTARCH/$2
}

#-------------------------------------------------------------------------
#
InstallProgSUID()
{
   echo Installing $1
   Install 0.0 4755 $1 $DEST_SGE_ROOT/${UTILPREFIX}/$DSTARCH/`basename $1`
}

#-------------------------------------------------------------------------
# Only file permissions are different from InstallProg
InstallLib()
{
   echo Installing $1
   Install 0.0 644 $1 $DEST_SGE_ROOT/${UTILPREFIX}/$DSTARCH/$1
}

#-------------------------------------------------------------------------
# MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN

# How else I can find out that I'm user root?
# The code below worked everywhere
#
idout="`id`"
five=`expr "$idout" : "uid=0"`
if [ $five = 5 ]; then
  IAMROOT=true
else
  IAMROOT=false
fi

# Main targets and target directories
#
# BASEDIR      -> base dir for distribution
# VERSIONDIR   -> directory below $BASEDIR where distribution is installed
# MANSRCDIR    -> directory from which proprocessed man pages are taken
# ARCH         -> list of binary architectures
# PROG         -> list of programs and special install targets
# localinst    -> Use $SGE_ROOT for target directory
BASEDIR=undefined
VERSIONDIR=undefined
localinst=false
MANSRCDIR=ge
ARCH=""
PROG=""

# General variables which influence script behavior
#
# verbose               -> echo commands called via Execute() function
# exit_on_error         -> exit if command called via Execute() exits != 0
# touchcommonchanged    -> create file .COMMON_CHANGED in target dir if 
#                          "common" install target has changed
verbose=false
exit_on_error=true
touchcommonchanged=false

# Install targets
#
instjobs=false
instsharedlibs=false
instckpt=false
instdrmaa=false
instiscript=false
instutiltree=false
instexamples=false
instman=false
instdoc=false
instdtrace=false
insttxtdoc=false
instjava=false
instjavadoc=false
instpvm=false
instmpi=false
insthadoop=false
instqmon=false
instcommon=false
instutilbin=false
instsec=false
instsecbin=false
inst3rdparty=false
instclassictargets=false
instopenssl=true
instbdb=true
instarco=false
instguiinst=true
instsgeinspect=false
enforce_shlibpath=false

cmdname=`basename $0`

if [ $cmdname = myinst ]; then
   echo "\"myinst\" is no longer supported. Use \"% scripts/distinst -local\""
   echo "instead. See \"scripts/distinst -help\" for further command line options."
   exit 1
elif [ $cmdname = sgeinst -o $cmdname = sgeeeinst ]; then
   echo \"sge[ee]inst\" is no longer supported. Use \"% scripts/distinst -mansrc sge\"
   echo instead.
   exit 1
fi

#-------------------------------------------------------------------------
# source sitewide and private files after setting defaults
# this allows a convenient override of all default settings
#
if [ -f scripts/distinst.site ]; then
   . ./scripts/distinst.site
fi

if [ -f scripts/distinst.private ]; then
   echo Sourcing of \"scripts/distinst.private\" is no longer supported.
   echo Copy this script to \"./distinst.private\" instead.
   exit 1
fi

if [ "$1" != -nosource ]; then
   if [ -f distinst.private ]; then
      . ./distinst.private
   fi
else
   shift
fi

#-------------------------------------------------------------------------
# command line parsing
#
if  [ $# -eq 0 ]; then
   ErrUsage
fi

while [ $# -ge 1 ]; do
   case "$1" in
   -allall)
      PROG="$DEFAULTPROG distcommon arco sgeinspect"
      instsharedlibs=true
      ;;
   -all)
      PROG="$DEFAULTPROG common"
      instsharedlibs=true
      ;;
   -basedir)
      shift
      if [ "$1" != "" ]; then
         BASEDIR=$1
      else
         echo
         echo need argument for \"-basedir\". Installation failed.
         echo
         exit 1
      fi
      ;;
   -bin)
      PROG="$DEFAULTPROG $PROG"
      instsharedlibs=true
      ;;
   -onlybin)
      PROG="$DEFAULTPROG $PROG"
      ;;
   -h|-help)
      ErrUsage
      ;;
   -help_arch)
      ArchTable
      ;;
   -resetprog)
      PROG=""
      ;;
   -resetarch)
      ARCH=""
      ;;
   -classic-targets)
      instclassictargets=true
      ;;
   -tcc)
      touchcommonchanged=true
      ;;
   -libs)
      instsharedlibs=true
      ;;
   -local)
      if [ "$SGE_ROOT" = "" ]; then
         echo Please set variable SGE_ROOT. Installation failed.
         exit 1
      fi
      if [ ! -d $SGE_ROOT ]; then
         echo Please create directory \"$SGE_ROOT\" first. Installation failed.
         exit 1
      fi
      DEST_SGE_ROOT=$SGE_ROOT
      localinst=true
      ;;
   -mansrc)
      shift
      if [ "$1" != "" ]; then
         MANSRCDIR=$1
      else
         echo
         echo need argument for \"-mansrc\". Installation failed.
         echo
         exit 1
      fi
      ;;
   -nobdb)
      instbdb=false
      ;;
   -noexit)
      exit_on_error=false
      ;;
   -noinst)
      PROG="$DEFAULTPROG"
      INSTOPT="noinst"
      ;;
   -noopenssl)
      instopenssl=false
      ;;
   -shlibpath)
      enforce_shlibpath=true
      ;;
   -v)
      verbose=true
      ;;
   -vdir)
      shift
      if [ "$1" != "" ]; then
         VERSIONDIR=$1
      else
         echo
         echo need argument for \"-vdir\". Installation failed.
         echo
         exit 1
      fi
      ;;
   --)
      break
      ;;
   -*)
      echo option \"$1\" is not supported. Installation failed.
      exit 1
      ;;
   *)
      break
      ;;
   esac
   shift
done

if [ $instbdb = true ]; then
   UTILITYBINARIES="$UTILITYBINARIES $BDBUTILITYBINARIES"
fi

if [ $instopenssl = true ]; then
   UTILITYBINARIES="$UTILITYBINARIES $SSLUTILITYBINARIES"
fi


if [ $localinst = false ]; then
   if [ $BASEDIR = undefined ]; then
      echo "Set \$BASEDIR with -basedir switch."
      exit 1
   fi

   if [ $VERSIONDIR = undefined ]; then
      echo "Set \$VERSIONDIR with -vdir switch."
      exit 1
   fi   

   if [ ! -d $BASEDIR ]; then
      echo "Directory \"$BASEDIR\" does not exist. Please create it first."
      exit 1
   fi

   DEST_SGE_ROOT=$BASEDIR/$VERSIONDIR

   if [ ! -d $DEST_SGE_ROOT ]; then
      Execute mkdir $DEST_SGE_ROOT
   fi

   Execute chmod 755 $DEST_SGE_ROOT
   
   if [ -f $DEST_SGE_ROOT/LOCKED ]; then
      echo "File \"$DEST_SGE_ROOT/LOCKED\" exits"
      exit 1
   fi
else
   if [ "$BASEDIR" != undefined -o "$VERSIONDIR" != undefined ]; then
      echo
      echo Switch \""-local\" cannot be combined with \"-vdir\" and/or \"-basedir\" switch."
      echo
      echo "Check \"scripts/distinst.site\" and/or \"./distinst.private\" if these"
      echo "scripts set the variables \"BASEDIR\" or \"VERSIONDIR\"".
      echo
      exit 1
   fi
fi

whoseargs="archs"
while [ "$1" != "" ]; do
   case "$1" in
      --)             
         whoseargs="progs" 
         ;;
      *)              
         if [ "$whoseargs" = "archs" ]; then
            ARCH="$ARCH $1"
         else
            PROG="$PROG $1"
         fi 
         ;;
   esac
   shift
done

if [ "$INSTOPT" = "noinst" ]; then
   if [ ! -z "$ARCH" ]; then
      echo
      echo Target directory for distribution: $DEST_SGE_ROOT
      SetArchBin $ARCH
      echo Binary subdirectory for $ARCH: $ARCHBIN
      echo
      exit 0
   else
      ARCH=`dist/util/arch`
      echo
      echo no architecture specified.  Assuming architecture is $ARCH
      echo
   fi
fi

if [ -z "$ARCH" ]; then
   ARCH=`dist/util/arch`
   echo
   echo No architecture specified.  Assuming architecture is $ARCH
   echo
fi

echo
echo   "    Installing:" $PROG
echo   " Architectures:" $ARCH
echo   "Base directory:" $DEST_SGE_ROOT
printf "   OK [Y/N][Y]: "

read ans
if [ "$ans" = y -o "$ans" = Y -o "$ans" = "" ]; then
   :
else
   echo
   echo Ciao
   echo
   exit 1
fi

echo

for prog in $PROG; do
   case $prog in
      arco)
         instarco=true
         ;;
      sgeinspect)
         instsgeinspect=true
         ;;
      common|distcommon) 
         instdrmaa=true
         instcommon=true
         inst3rdparty=true
         instckpt=true
         instdtrace=true
         instexamples=true
         instiscript=true
         instjava=true
         instmpi=true
         instpvm=true
         insthadoop=true
         instqmon=true
         instutiltree=true
         case $prog in
         distcommon)
            instman=true
            instdoc=true
            insttxtdoc=true
            instjavadoc=true
            ;;
         esac    
         ;;
      ckpt)
         instckpt=true
         instcommon=true
         ;;
      doc)
         instdoc=true
         insttxtdoc=true
         instcommon=true
         instjavadoc=true
         ;;
      dtrace)    
         instdtrace=true
         instcommon=true
         ;;
      examples)
         instexamples=true
         instcommon=true
         ;;
      iscript)
         instiscript=true
         instcommon=true
         ;;
      java)
         instjava=true
         ;;
      jobs)   
         instjobs=true
         ;;
      man)
         instman=true
         instcommon=true
         ;;
      pvm)    
         instpvm=true
         instcommon=true
         ;;
      mpi)    
         instmpi=true
         instcommon=true
         ;;
      hadoop)
         insthadoop=true
         ;;
      qmontree)
         instqmon=true
         instcommon=true
         ;;
      sec)
         instsec=true
         instcommon=true
         ;;
      secbin)
         instsecbin=true
         ;;
      txtdoc)
         insttxtdoc=true
         instcommon=true
         ;;
      utilbin) 
         instutilbin=true 
         ;;
      utiltree)
         instutiltree=true
         instcommon=true
         ;;
   esac
done


# ------------------ Install common files ------------------
#

if [ $instcommon = true ]; then

   if [ $inst3rdparty = true ]; then
      echo Installing \"3rd_party/\" directory tree
      Execute rm -rf $DEST_SGE_ROOT/3rd_party
      MakeDir 3rd_party
      Execute cp -r dist/3rd_party $DEST_SGE_ROOT
      Cleanup 3rd_party
   fi

   if [ $instiscript = true ]; then
      rm -f $DEST_SGE_ROOT/inst_sge $DEST_SGE_ROOT/install_qmaster $DEST_SGE_ROOT/install_execd
      echo "Installing \"inst_sge\", \"install_qmaster\" and \"install_execd\""
      Execute cp dist/inst_sge dist/install_qmaster dist/install_execd $DEST_SGE_ROOT 
      Execute chmod 755 $DEST_SGE_ROOT/inst_sge $DEST_SGE_ROOT/install_execd $DEST_SGE_ROOT/install_qmaster
      Cleanup inst_sge install_execd install_qmaster         
   fi
    
   if [ $instutiltree = true ]; then
      echo Installing \"util/\" directory tree
      Execute rm -rf $DEST_SGE_ROOT/util
      MakeDir util
      Execute cp -r dist/util $DEST_SGE_ROOT
      Execute cp libs/jgdi/util/java.policy.template $DEST_SGE_ROOT/util
      Execute cp libs/jgdi/util/rmiconsole.policy $DEST_SGE_ROOT/util
      Execute cp libs/jgdi/util/jmxremote.access $DEST_SGE_ROOT/util
      Execute cp libs/jgdi/util/jmxremote.password.template $DEST_SGE_ROOT/util/jmxremote.password
      Execute cp libs/jgdi/util/management.properties.template $DEST_SGE_ROOT/util
      Execute cp libs/jgdi/util/jaas.config.template $DEST_SGE_ROOT/util
      Execute cp libs/jgdi/util/logging.properties.template $DEST_SGE_ROOT/util
      if [ $enforce_shlibpath = true ]; then
         Execute grep -v "#ENFORCE_SHLIBPATH#" dist/util/create_settings.sh > $DEST_SGE_ROOT/util/create_settings.sh
         Execute grep -v "#ENFORCE_SHLIBPATH#" dist/util/rctemplates/sgemaster_template > $DEST_SGE_ROOT/util/rctemplates/sgemaster_template
         Execute grep -v "#ENFORCE_SHLIBPATH#" dist/util/rctemplates/sgeexecd_template > $DEST_SGE_ROOT/util/rctemplates/sgeexecd_template
         Execute grep -v "#ENFORCE_SHLIBPATH#" dist/util/rctemplates/sgebdb_template > $DEST_SGE_ROOT/util/rctemplates/sgebdb_template
         Execute grep -v "#ENFORCE_SHLIBPATH#" dist/util/install_modules/inst_common.sh > $DEST_SGE_ROOT/util/install_modules/inst_common.sh
      else
         Execute sed -e "s/#ENFORCE_SHLIBPATH#//" dist/util/create_settings.sh > $DEST_SGE_ROOT/util/create_settings.sh
         Execute sed -e "s/#ENFORCE_SHLIBPATH#//" dist/util/rctemplates/sgemaster_template > $DEST_SGE_ROOT/util/rctemplates/sgemaster_template
         Execute sed -e "s/#ENFORCE_SHLIBPATH#//" dist/util/rctemplates/sgeexecd_template > $DEST_SGE_ROOT/util/rctemplates/sgeexecd_template
         Execute sed -e "s/#ENFORCE_SHLIBPATH#//" dist/util/rctemplates/sgebdb_template > $DEST_SGE_ROOT/util/rctemplates/sgebdb_template
         Execute sed -e "s/#ENFORCE_SHLIBPATH#//" dist/util/install_modules/inst_common.sh > $DEST_SGE_ROOT/util/install_modules/inst_common.sh
      fi

      # DetectJvmLibrary
      if [ -f dist/DetectJvmLibrary/build/jar/DetectJvmLibrary.jar ]; then
         Execute cp dist/DetectJvmLibrary/build/jar/DetectJvmLibrary.jar $DEST_SGE_ROOT/util
      fi

      # JSV Java language binding
      if [ -f libs/jjsv/java/com/sun/grid/jsv/examples/SimpleJsv.java ]; then
         Execute cp libs/jjsv/java/com/sun/grid/jsv/examples/SimpleJsv.java $DEST_SGE_ROOT/util/resources/jsv
      elif [ $exit_on_error = true ]; then
         echo "\"libs/jjsv/java/com/sun/grid/jsv/examples/SimpleJsv.java\" not found. Installation failed."
         exit 1
      fi

      Cleanup util

      # Not available in Beta
      Execute rm -rf $DEST_SGE_ROOT/util/update_commands
      Execute rm -f $DEST_SGE_ROOT/util/sge_update.sh

      # Install arch.dist as arch for installation process
      Execute rm -f $DEST_SGE_ROOT/util/arch
      Execute mv $DEST_SGE_ROOT/util/arch.dist $DEST_SGE_ROOT/util/arch

      Execute chmod 755 $DEST_SGE_ROOT/util/install_modules \
			$DEST_SGE_ROOT/util/upgrade_modules \
                        $DEST_SGE_ROOT/util/rctemplates \
                        $DEST_SGE_ROOT/util/resources \
                        $DEST_SGE_ROOT/util/sgeCA \
                        $DEST_SGE_ROOT/util/resources/calendars \
                        $DEST_SGE_ROOT/util/resources/centry \
                        $DEST_SGE_ROOT/util/resources/loadsensors \
                        $DEST_SGE_ROOT/util/resources/pe \
                        $DEST_SGE_ROOT/util/resources/schemas \
                        $DEST_SGE_ROOT/util/resources/schemas/qhost \
                        $DEST_SGE_ROOT/util/resources/schemas/qquota \
                        $DEST_SGE_ROOT/util/resources/schemas/qrstat \
                        $DEST_SGE_ROOT/util/resources/schemas/qstat \
                        $DEST_SGE_ROOT/util/resources/starter_methods \
                        $DEST_SGE_ROOT/util/resources/usersets
      
      Execute chmod 755 $DEST_SGE_ROOT/util/arch \
                        $DEST_SGE_ROOT/util/*.sh \
                        $DEST_SGE_ROOT/util/sgeremoterun \
                        $DEST_SGE_ROOT/util/sgeCA/sge_ca \
                        $DEST_SGE_ROOT/util/sgeST/sge_st \
                        $DEST_SGE_ROOT/util/sgeSMF/sge_smf.sh \
                        $DEST_SGE_ROOT/util/resources/loadsensors/* \
                        $DEST_SGE_ROOT/util/resources/starter_methods/*

      Execute chmod 644 $DEST_SGE_ROOT/util/install_modules/* \
                        $DEST_SGE_ROOT/util/rctemplates/* \
                        $DEST_SGE_ROOT/util/sgeCA/*.cnf \
                        $DEST_SGE_ROOT/util/sgeSMF/*.xml \
                        $DEST_SGE_ROOT/util/sgeSMF/sge_smf_support.sh \
                        $DEST_SGE_ROOT/util/DetectJvmLibrary.jar \
                        $DEST_SGE_ROOT/util/resources/calendars/* \
                        $DEST_SGE_ROOT/util/resources/centry/* \
                        $DEST_SGE_ROOT/util/resources/pe/* \
                        $DEST_SGE_ROOT/util/resources/schemas/*/* \
                        $DEST_SGE_ROOT/util/resources/usersets/*

      Execute chmod 755 $DEST_SGE_ROOT/util/resources/jsv/jsv.sh \
                        $DEST_SGE_ROOT/util/resources/jsv/jjsv.sh \
                        $DEST_SGE_ROOT/util/resources/jsv/jsv.pl \
                        $DEST_SGE_ROOT/util/resources/jsv/jsv.tcl
   fi
   
   if [ $instexamples = true ]; then
      echo Installing \"examples/jobs\"
      Execute rm -rf $DEST_SGE_ROOT/examples/jobs
      MakeDir examples
      MakeDir examples/jobs      
      Execute cp dist/examples/jobs/*.sh $DEST_SGE_ROOT/examples/jobs
      Execute chmod 755 $DEST_SGE_ROOT/examples/jobs/*.sh
      MakeDir examples/drmaa
      Execute cp libs/japi/example.c $DEST_SGE_ROOT/examples/drmaa
      Execute cp libs/japi/howto/*.c $DEST_SGE_ROOT/examples/drmaa
      Cleanup examples
   fi

   if [ $instqmon = true ]; then
      echo Copying Pixmaps and Qmon resource file
      Execute rm -rf $DEST_SGE_ROOT/qmon
      MakeDir qmon
      MakeDir qmon/PIXMAPS
      MakeDir qmon/PIXMAPS/big

      Execute cp dist/qmon/PIXMAPS/small/*.xpm $DEST_SGE_ROOT/qmon/PIXMAPS
      Execute cp dist/qmon/PIXMAPS/big/toolbar*.xpm $DEST_SGE_ROOT/qmon/PIXMAPS/big

      Execute chmod 644 $DEST_SGE_ROOT/qmon/PIXMAPS/*.xpm
      Execute chmod 644 $DEST_SGE_ROOT/qmon/PIXMAPS/big/*.xpm

      Execute cp dist/qmon/Qmon $DEST_SGE_ROOT/qmon
      Execute chmod 644 $DEST_SGE_ROOT/qmon/Qmon
   
      Execute cp dist/qmon/qmon_help.ad $DEST_SGE_ROOT/qmon
      Execute chmod 644 $DEST_SGE_ROOT/qmon/qmon_help.ad

      ( echo changing to $DEST_SGE_ROOT/qmon/PIXMAPS ; \
        cd $DEST_SGE_ROOT/qmon/PIXMAPS; \
        echo ln -s intro-sge.xpm intro.xpm; \
        ln -s intro-sge.xpm intro.xpm; \
        echo ln -s logo-sge.xpm logo.xpm; \
        ln -s logo-sge.xpm logo.xpm \
      )
      Cleanup qmon
   fi 

   if [ $instpvm = true ]; then
      echo Installing \"pvm\"
      Execute rm -rf $DEST_SGE_ROOT/pvm
      MakeDir pvm
      MakeDir pvm/src
           
      for f in $PVMSCRIPTS; do
         Execute cp dist/pvm/$f $DEST_SGE_ROOT/pvm
      done
      chmod 755 $DEST_SGE_ROOT/pvm/*.sh

      for f in $PVMSOURCES; do
         Execute cp dist/pvm/src/$f $DEST_SGE_ROOT/pvm/src
      done

      for f in $PVMSRCSCRIPTS; do
         Execute cp dist/pvm/src/$f $DEST_SGE_ROOT/pvm/src
         chmod 755 $DEST_SGE_ROOT/pvm/src/$f
      done
      Cleanup pvm
   fi

   if [ $instdrmaa = true ]; then
      echo Installing DRMAA include files
      Execute rm -rf $DEST_SGE_ROOT/include
      MakeDir include

      for f in $DRMAA_HEADER_FILES; do
         Execute cp $f $DEST_SGE_ROOT/include
      done

      Cleanup include
   fi

   if [ $instjava = true -o $instdrmaa = true ]; then
      if [ $instjava = true ]; then
         JAVA_FILES=$JAVA_LIBRARIES
      else
         JAVA_FILES=$DRMAAJ_FILES
      fi

      for filename in $JAVA_FILES; do
         filename="${filename}.jar"
         if [ -f $filename ]; then
            echo Installing `basename $filename`
            Execute rm -f $DEST_SGE_ROOT/lib/`basename $filename`
            MakeDir lib
            Install 0.0 644 $filename $DEST_SGE_ROOT/lib/`basename $filename`
         elif [ $exit_on_error = true ]; then
            echo "\"$filename\" not found. Installation failed."
            exit 1
         fi
      done
   fi

   if [ $instdtrace = true ]; then
      echo Installing \"Dtrace scripts\"
      rm -rf $DEST_SGE_ROOT/dtrace
      MakeDir dtrace

      for f in $DTRACE_FILES; do
         Execute cp scripts/dtrace/$f $DEST_SGE_ROOT/dtrace
         Execute chmod 644 $DEST_SGE_ROOT/dtrace/$f
      done

      for f in $DTRACE_SCRIPTS; do
         Execute cp scripts/dtrace/$f $DEST_SGE_ROOT/dtrace
         Execute chmod 755 $DEST_SGE_ROOT/dtrace/$f
      done

      Cleanup dtrace
   fi

   if [ $instmpi = true ]; then
      echo Installing \"mpi/\"
      rm -rf $DEST_SGE_ROOT/mpi
      MakeDir mpi

      for f in $MPI_FILES; do
         Execute cp dist/mpi/$f $DEST_SGE_ROOT/mpi
         Execute chmod 644 $DEST_SGE_ROOT/mpi/$f
      done

      for f in $MPI_SCRIPTS; do
         Execute cp dist/mpi/$f $DEST_SGE_ROOT/mpi
         Execute chmod 755 $DEST_SGE_ROOT/mpi/$f
      done

      MYRINETBASE=mpi/myrinet
      Execute mkdir -p $DEST_SGE_ROOT/$MYRINETBASE
      for f in $MYRINET_FILES; do
         Execute cp dist/$MYRINETBASE/$f $DEST_SGE_ROOT/$MYRINETBASE
         Execute chmod 644 $DEST_SGE_ROOT/$MYRINETBASE/$f
      done

      for f in $MYRINET_SCRIPTS; do
         Execute cp dist/$MYRINETBASE/$f $DEST_SGE_ROOT/$MYRINETBASE
         Execute chmod 755 $DEST_SGE_ROOT/$MYRINETBASE/$f
      done

      HPCBASE=mpi/SunHPCT5
      Execute mkdir -p $DEST_SGE_ROOT/$HPCBASE
      
      for f in $SUNHPCTIGHT_FILES; do
         Execute cp dist/$HPCBASE/$f $DEST_SGE_ROOT/$HPCBASE
         Execute chmod 644 $DEST_SGE_ROOT/$HPCBASE/$f
      done
   
      for f in $SUNHPCTIGHT_SCRIPTS; do
         Execute cp dist/$HPCBASE/$f $DEST_SGE_ROOT/$HPCBASE
         Execute chmod 755 $DEST_SGE_ROOT/$HPCBASE/$f
      done

      Cleanup mpi
   fi

   if [ $insthadoop = true ]; then
      echo Installing \"hadoop/\"
      rm -rf $DEST_SGE_ROOT/hadoop
      MakeDir hadoop

      for f in $HADOOP_FILES; do
         Execute cp dist/hadoop/$f $DEST_SGE_ROOT/hadoop/$f
         Execute chmod 644 $DEST_SGE_ROOT/hadoop/$f
      done

      for f in $HADOOP_SCRIPTS; do
         Execute cp dist/hadoop/$f $DEST_SGE_ROOT/hadoop/$f
         Execute chmod 755 $DEST_SGE_ROOT/hadoop/$f
      done

      if [ -f CLASSES/herd/herd.jar ]; then
         Execute cp CLASSES/herd/herd.jar $DEST_SGE_ROOT/lib/herd.jar
      elif [ $exit_on_error = true ]; then
         echo "\"CLASSES/herd/herd.jar\" not found. Installation failed."
         exit 1
      fi
   fi

   if [ $instman = true ]; then
      echo Installing \"man/\" and \"catman/\"
      Execute rm -rf $DEST_SGE_ROOT/man $DEST_SGE_ROOT/catman
      Execute cp -r MANSBUILD_$MANSRCDIR/SEDMAN/man $DEST_SGE_ROOT

      if [ -d MANSBUILD_$MANSRCDIR/ASCMAN/catman ]; then
         Execute mkdir -p $DEST_SGE_ROOT/catman
         Execute cp -r MANSBUILD_$MANSRCDIR/ASCMAN/catman/?_man $DEST_SGE_ROOT/catman
      fi

      if [ -d MANSBUILD_$MANSRCDIR/ASCMAN/man ]; then
         SOURCEDIR=MANSBUILD_$MANSRCDIR/ASCMAN/man
         DESTDIR=$DEST_SGE_ROOT/catman/cat
         for dir in `ls $SOURCEDIR`; do
            dir_num=`basename $dir | cut -d"n" -f2`
            for file in `ls $SOURCEDIR/$dir`; do
               if [ ! -d "$DESTDIR/cat$dir_num" ]; then
                  Execute mkdir -p $DESTDIR/cat$dir_num
               fi
               Execute cp $SOURCEDIR/$dir/$file $DESTDIR/cat$dir_num/$file.$dir_num
            done
         done
      fi

      Execute find $DEST_SGE_ROOT/man -type d | xargs chmod 755
      Execute find $DEST_SGE_ROOT/man -type f | xargs chmod 644

      Execute find $DEST_SGE_ROOT/catman -type d | xargs chmod 755
      Execute find $DEST_SGE_ROOT/catman -type f | xargs chmod 644
      
      Cleanup man catman
   fi

   if [ $instdoc = true ]; then
      # currently no docs in CVS repository
      echo Installing \"doc/\"
      Execute rm -rf $DEST_SGE_ROOT/doc
      MakeDir doc
   fi

   # this rule must come *after* the "instdoc" rule
   #
   if [ $insttxtdoc = true ]; then
      echo "Installing README, ... files"
      Execute cp ../doc/*.asc   $DEST_SGE_ROOT/doc
      #Execute cp ../doc/README-Autoinstall.txt $DEST_SGE_ROOT/doc
      #Execute cp ../doc/README-Upgrade.txt $DEST_SGE_ROOT/doc
      Execute cp ../doc/README-DRMAA.txt $DEST_SGE_ROOT/doc
      Execute chmod 644 $DEST_SGE_ROOT/doc/*
      Cleanup doc      
   fi

   if [ $instjavadoc = true ]; then
      if [ -d JAVADOCS ]; then
         echo "Installing doc/javadocs"
         Execute rm -rf $DEST_SGE_ROOT/doc/javadocs
         MakeDir doc/javadocs

         Execute cp -R JAVADOCS/* $DEST_SGE_ROOT/doc/javadocs

         Execute find $DEST_SGE_ROOT/doc/javadocs -type d | xargs chmod 755
         Execute find $DEST_SGE_ROOT/doc/javadocs -type f | xargs chmod 644

         Cleanup doc/javadocs
      fi
   fi

   if [ $instckpt = true ]; then
      echo Installing \"ckpt/\"
      Execute rm -rf $DEST_SGE_ROOT/ckpt
      MakeDir ckpt
      Execute cp dist/ckpt/*_command $DEST_SGE_ROOT/ckpt
      Execute chmod 755 $DEST_SGE_ROOT/ckpt/*_command
      Execute cp dist/ckpt/README* $DEST_SGE_ROOT/ckpt
      Execute chmod 644 $DEST_SGE_ROOT/ckpt/README*
      Cleanup ckpt
   fi

   if [ $instsec = true ]; then
      echo Installing \"security\" modules
      MakeDir security
      for f in $SECFILES; do
         Execute cp $f $DEST_SGE_ROOT/security
         fb=`basename $f`
         if [ -x $DEST_SGE_ROOT/security/$fb ]; then
            chmod 755 $DEST_SGE_ROOT/security/$fb
         else
            chmod 644 $DEST_SGE_ROOT/security/$fb
         fi
      done
      ( echo changing to $DEST_SGE_ROOT/security; \
        ln -s gss_customer.html README.html )
      Cleanup security
   fi      

   if [ $touchcommonchanged = true ]; then
      touch $DEST_SGE_ROOT/.COMMON_CHANGED
   fi

   echo common part done
   echo
fi

if [ $instarco = true ]; then
   ARCO_SOURCE_DIR=`pwd`/../arco/source
   if [ -d "$ARCO_SOURCE_DIR" ]; then 
      echo Installing \"ARCo\" directory tree
      Execute rm -rf $DEST_SGE_ROOT/reporting
      Execute rm -rf $DEST_SGE_ROOT/dbwriter
      (cd $DEST_SGE_ROOT; \
       Execute $TAR xvpzf $ARCO_SOURCE_DIR/dbwriter/dbwriter.tar.gz; \
       Execute $TAR xvpzf $ARCO_SOURCE_DIR/reporting/reporting.tar.gz; \
       chown -R root:root $DEST_SGE_ROOT/reporting $DEST_SGE_ROOT/dbwriter )
      Cleanup reporting dbwriter 
      echo ARCo part done
      echo
   else
      echo "ARCo dir \"$ARCO_SOURCE_DIR\" does not exist"
   fi
fi

if [ $instguiinst = true ]; then
   GUI_DIR=`pwd`/clients/gui-installer
   if [ -d "$GUI_DIR" ]; then 
      rm -rf $DEST_SGE_ROOT/start_gui_installer $DEST_SGE_ROOT/util/gui-installer 
      echo "Installing \"start_gui_installer\" and \"/util/gui-installer\""
      Execute mkdir -p $DEST_SGE_ROOT/util/gui-installer/html/en/help
      Execute mkdir -p $DEST_SGE_ROOT/util/gui-installer/templates
      Execute cp $GUI_DIR/dist/installer.jar $DEST_SGE_ROOT/util/gui-installer
      Execute cp $GUI_DIR/templates/start_gui_installer.sh $DEST_SGE_ROOT/start_gui_installer
      Execute cp -r $GUI_DIR/html $DEST_SGE_ROOT/util/gui-installer
      Execute cp $GUI_DIR/templates/install_component $GUI_DIR/templates/gui_inst_template.conf $GUI_DIR/templates/readme_template.html $GUI_DIR/templates/check_host $DEST_SGE_ROOT/util/gui-installer/templates
      Execute chmod 755 $DEST_SGE_ROOT/start_gui_installer
      Cleanup util/gui-installer
      echo GUI installer part done
      echo
   else
      echo "GUI Installer dir \"$GUI_DIR\" does not exist"
   fi
fi

if [ $instsgeinspect = true ]; then
   if [ -d "$SGE_INSPECT_SRC_DIR" ]; then
      if [ `echo $SGE_INSPECT_SRC_DIR | cut -c 1` = "/" ]; then
         ABSOLUTE_SGE_INSPECT_SRC_DIR=$SGE_INSPECT_SRC_DIR
      else
         ABSOLUTE_SGE_INSPECT_SRC_DIR=`pwd`/$SGE_INSPECT_SRC_DIR
      fi
      echo Installing \"sgeinspect\" directory tree
      Execute rm -rf $DEST_SGE_ROOT/sgeinspect
      ( cd $DEST_SGE_ROOT; \
        Execute unzip $ABSOLUTE_SGE_INSPECT_SRC_DIR/EventMonitor/dist/sgeinspect.zip; \
      )
      Execute mkdir -p $DEST_SGE_ROOT/bin
      Execute cp $ABSOLUTE_SGE_INSPECT_SRC_DIR/scripts/sgeinspect.sh $DEST_SGE_ROOT/bin/
      chown root:root $DEST_SGE_ROOT/bin/sgeinspect.sh
      Execute chmod 755 $DEST_SGE_ROOT/bin/sgeinspect.sh
      
      if [ -f $ABSOLUTE_SGE_INSPECT_SRC_DIR/scripts/logging.properties ]; then
         Execute cp $ABSOLUTE_SGE_INSPECT_SRC_DIR/scripts/logging.properties $DEST_SGE_ROOT/sgeinspect/etc
         chown root:root $DEST_SGE_ROOT/sgeinspect/etc/logging.properties
         Execute chmod 644 $DEST_SGE_ROOT/sgeinspect/etc/logging.properties
      fi

      Cleanup sgeinspect
      echo sgeinspect part done
      echo
   else
      echo "sgeinspect dir \"$SGE_INSPECT_SRC_DIR\" does not exist"
   fi
fi

# ------------------  Copy architecure dependent stuff ----------------------
#

if [ "$ARCH" != "" ]; then
   MakeArchDirs $ARCH
fi

for i in $ARCH; do
   DSTARCH=$i
   SetArchBin $i

   if [ $ARCHBIN != undefined ]; then

      UTILPREFIX=bin

      cd $ARCHBIN
      
      echo "Installing binaries for $i from `pwd` -->"
      echo "                          --> $DEST_SGE_ROOT/bin/$i"
      echo ------------------------------------------------------------------------

      for prog in $PROG; do
         case $prog in
            jobs|ckpt|doc|inst_sge|utiltree|examples|man|mpi|pvm|hadoop|qmontree|common|distcommon|utilbin|arco)
               : 
               ;;
            qmake)
               echo Installing qmake
               Install 0.0 755 ../3rdparty/qmake/$ARCHBIN/make $DEST_SGE_ROOT/${UTILPREFIX}/$DSTARCH/qmake
               ;;
            qtcsh)
               echo Installing qtcsh
               Install 0.0 755 ../3rdparty/qtcsh/$ARCHBIN/tcsh $DEST_SGE_ROOT/${UTILPREFIX}/$DSTARCH/qtcsh
               ;;
            sgepasswd)
               if [ "$DSTARCH" != "win32-x86" ]; then
                  InstallProg $prog
               fi
               ;;
            sge_qmaster|spoolinit|spooldefaults)
               if [ "$DSTARCH" != "win32-x86" ]; then
                  if [ $instclassictargets = false ]; then
                     InstallProg $prog
                  else
                     if [ -f ../${ARCHBIN}_classic/$prog ]; then
                        InstallProgAs ../${ARCHBIN}_classic/$prog ${prog}.spool_classic
                        InstallProgAs $prog ${prog}.spool_bdb
                        ( echo changing to $DEST_SGE_ROOT/bin/$DSTARCH ; \
                          cd $DEST_SGE_ROOT/bin/$DSTARCH ; \
                          echo ln -s ${prog}.spool_bdb $prog ; \
                          ln -s ${prog}.spool_bdb $prog
                        )
                     else
                        InstallProg $prog
                     fi
                  fi
               fi
               ;;
            sge_shadowd|qmon|spooledit)
               if [ "$DSTARCH" != "win32-x86" ]; then
                  InstallProg $prog
               fi
               ;;
            qloadsensor.exe)
               if [ "$DSTARCH" = "win32-x86" ]; then
                  # Currently qloadsensor.exe is needed only for win32-x86
                  InstallProg $prog
               fi
               ;;
            sgeinspect)
               if [ -f "$DEST_SGE_ROOT/bin/sgeinspect.sh" ]; then
                  ( echo changing to $DEST_SGE_ROOT/bin/$DSTARCH ; \
                    cd $DEST_SGE_ROOT/bin/$DSTARCH ; \
                    rm sgeinspect 2>&1 > /dev/null ; \
                    echo ln -s ../sgeinspect.sh sgeinspect; \
                    ln -s ../sgeinspect.sh sgeinspect; \
                  )
               fi
               ;;
            *)
               InstallProg $prog
               if [ $prog = qstat ]; then
                  ( echo changing to $DEST_SGE_ROOT/bin/$DSTARCH ; \
                    cd $DEST_SGE_ROOT/bin/$DSTARCH ; \
                    echo ln -s qstat qselect ; \
                    ln -s qstat qselect \
                  )
               elif [ $prog = qalter ]; then
                  ( echo changing to $DEST_SGE_ROOT/bin/$DSTARCH ; \
                    cd $DEST_SGE_ROOT/bin/$DSTARCH ; \
                    echo ln -s qalter qresub ; \
                    ln -s qalter qresub ; \
                    echo ln -s qalter qhold ; \
                    ln -s qalter qhold ; \
                    echo ln -s qalter qrls ; \
                    ln -s qalter qrls \
                  )
               elif [ $prog = qsh ]; then
                  ( echo changing to $DEST_SGE_ROOT/bin/$DSTARCH ; \
                    cd $DEST_SGE_ROOT/bin/$DSTARCH ; \
                    echo ln -s qsh qlogin ; \
                    ln -s qsh qlogin ; \
                    echo ln -s qsh qrsh ; \
                    ln -s qsh qrsh  ; \
                  )
               fi
               ;;
         esac
      done

      if [ $instutilbin = true ]; then
         UTILPREFIX="utilbin"    
         echo "Installing utility binaries"
         echo "---------------------------"
         for prog in $UTILITYBINARIES; do
            if [ $prog = openssl ]; then
               if [ -f $OPENSSLBASE/$DSTARCH/bin/openssl ]; then
                  InstallProg $OPENSSLBASE/$DSTARCH/bin/openssl
               elif [ -f $OPENSSLBASE/bin/openssl ]; then
                  InstallProg $OPENSSLBASE/bin/openssl
               else
                  echo \"openssl\" binary not found
               fi
            elif [ $prog = testsuidroot ]; then
                  InstallProgSUID $prog
            elif [ $prog = authuser ]; then
               if [ "$DSTARCH" != "win32-x86" ]; then
                  InstallProgSUID $prog
               else
                  InstallProg $prog.exe
               fi
            elif [ $prog = loadcheck ]; then
               if [ "$DSTARCH" != "win32-x86" ]; then
                  InstallProg $prog
               else
                  InstallProg $prog.exe
               fi
            elif [ $prog = berkeley_db_svc -o $prog = db_archive \
                   -o $prog = db_checkpoint -o $prog = db_deadlock \
                   -o $prog = db_dump -o $prog = db_load \
                   -o $prog = db_printlog -o $prog = db_recover \
                   -o $prog = db_stat -o $prog = db_upgrade \
                   -o $prog = db_verify ]; then
               if [ "$DSTARCH" != "win32-x86" ]; then
                  if [ -f $BERKELEYDBBASE/$DSTARCH/bin/$prog ]; then
                     InstallProg $BERKELEYDBBASE/$DSTARCH/bin/$prog
                  elif [ -f $BERKELEYDBBASE/bin/$prog ]; then
                     InstallProg $BERKELEYDBBASE/bin/$prog
                  fi
               fi
            elif [ $prog = spoolinit -o $prog = spooldefaults ]; then
               if [ "$DSTARCH" != "win32-x86" ]; then
                  if [ $instclassictargets = false ]; then
                     InstallProg $prog
                  elif [ -f ../${ARCHBIN}_classic/$prog ]; then
                     InstallProgAs ../${ARCHBIN}_classic/$prog ${prog}.spool_classic
                     InstallProgAs $prog ${prog}.spool_bdb
                     ( echo changing to $DEST_SGE_ROOT/utilbin/$DSTARCH ; \
                       cd $DEST_SGE_ROOT/utilbin/$DSTARCH ; \
                       echo ln -s ${prog}.spool_bdb $prog ; \
                       ln -s ${prog}.spool_bdb $prog
                     )
                  else
                     InstallProg $prog
                  fi
               fi
            elif [ "$prog" = "SGE_Helper_Service.exe" -o "$prog" = "SGE_Starter.exe" ]; then
               if [ "$DSTARCH" = "win32-x86" ]; then
                  InstallProg $prog
               fi
            elif [ "$DSTARCH" = "win32-x86" -a \( "$prog" = "spooledit" -o "$prog" = "valid_jvmlib" \) ]; then
               # Don't install spooledit, valid_jvmlib for win32-x86
               :
            else
               InstallProg $prog
            fi
         done
         for prog in $REMOTEBINARIES; do
            if [ $prog = "rsh" ] || [ $prog = "rlogin" ]; then
               InstallProgSUID ../3rdparty/remote/$ARCHBIN/$prog
            else   
               InstallProg ../3rdparty/remote/$ARCHBIN/$prog
            fi
         done
      fi 

      if [ $instsecbin = true ]; then
         UTILPREFIX="utilbin"
         echo "Installing security binaries"
         echo "----------------------------"
         for prog in $SECURITYBINARIES; do
            InstallProg $prog
         done
      fi

      if [ $instjobs = true ]; then
         UTILPREFIX="examples/jobsbin"   
         echo "Installing job binaries"
         echo "-----------------------"
         for prog in $JOBBINARIES; do
            InstallProg $prog
         done
      fi 

      if [ $instsharedlibs = true ]; then
         # Install libraries - we need to evaluate shlib extension
         case $i in 
         hp10|hp11|hp11-64)
            shlibext="sl"
            jnilibext="sl"
            ;;
         darwin-*)
            shlibext="dylib"
            jnilibext="jnilib"
            ;;
         *)
            shlibext="so"
            jnilibext="so"
            ;;
         esac

         UTILPREFIX="lib"
         echo "Installing shared libraries"
         echo "---------------------------"

         Execute rm -f $DEST_SGE_ROOT/$UTILPREFIX/$i/*
         for lib in $SHARED_LIBRARIES; do
            if [ "$DSTARCH" != "win32-x86" \
                 -o \( "$lib" != "libspool" -a "$lib" != "libspoolb" \
                    -a "$lib" != "libspoold" -a "$lib" != "libspoolc" \
                    -a "$lib" != "libspoolf" \) ]; then
               if [ -f $lib.$shlibext ]; then
                  InstallProg $lib.$shlibext
                  if [ "$DSTARCH" = "sol-sparc64" ]; then
                     if [ "$lib" = "libjuti" -o "$lib" = "libjgdi" ]; then
                        # Install the 32bit libraries
                        DSTARCH="sol-sparc"
                        SetArchBin $DSTARCH

                        Execute mkdir -p $DEST_SGE_ROOT/lib/sol-sparc
                        InstallProg ../$ARCHBIN/$lib.$shlibext

                        DSTARCH="sol-sparc64"
                        SetArchBin $DSTARCH
                     fi
                  fi
               fi
            fi
         done

         for lib in $QMON_SHARED_LIBRARIES; do
            if [ "$DSTARCH" != "win32-x86" ]; then
               libname="../3rdparty/qmon/$ARCHBIN/$lib.$shlibext"
               if [ -f $libname ]; then
                  InstallProg $libname
               fi
            fi
         done

         for lib in $QMON_NEED_SHARED_LIBRARIES; do
            if [ "$DSTARCH" != "win32-x86" ]; then
               libname="../3rdparty/qmon/$ARCHBIN/$lib.$shlibext"
               if [ -f $libname ]; then
                  InstallProg $libname
               elif [ $exit_on_error = true ]; then
                  echo "\"$libname\" not found. Installation failed."
                  exit 1
               fi
            fi
         done

         if [ $instopenssl = true ]; then
            for lib in $OPENSSL_SHARED_LIBRARIES; do

               if [ $DSTARCH = tru64 ]; then
                  libname="$lib.$shlibext"
               elif [ $DSTARCH = darwin-ppc -o $DSTARCH = darwin-x86 ];  then
                  libname="$lib.$OPENSSLSOVERSION.$shlibext"
               else
                  libname="$lib.$shlibext.$OPENSSLSOVERSION"
               fi

               if [ -f $OPENSSLBASE/$DSTARCH/lib/$libname ]; then
                  libname=$OPENSSLBASE/$DSTARCH/lib/$libname
               elif [ -f $OPENSSLBASE/lib/$libname ]; then
                  libname=$OPENSSLBASE/lib/$libname
               fi

               if [ -f $libname ]; then
                  InstallProg $libname
                  if [ $DSTARCH = tru64 ]; then
                     :
                  elif [ $DSTARCH = darwin-ppc -o $DSTARCH = darwin-x86 ]; then
                     (cd $DEST_SGE_ROOT/${UTILPREFIX}/$DSTARCH; \
                      ln -s $lib.$OPENSSLSOVERSION.$shlibext $lib.$shlibext)
                  else
                     (cd $DEST_SGE_ROOT/${UTILPREFIX}/$DSTARCH; ln -s $lib.${shlibext}.$OPENSSLSOVERSION $lib.$shlibext)
                  fi
               elif [ $exit_on_error = true ]; then
                  echo "\"$libname\" not found. Installation failed."
                  exit 1
               fi
            done
         fi

         if [ $DSTARCH != win32-x86 ]; then
            if [ $instbdb = true ]; then
               for lib in $BERKELEYDB_SHARED_LIBRARIES; do
                  libname="$lib.$shlibext"

                  if [ -f $BERKELEYDBBASE/$DSTARCH/lib/$libname ]; then
                     libname=$BERKELEYDBBASE/$DSTARCH/lib/$libname
                  elif [ -f $BERKELEYDBBASE/lib/$libname ]; then
                     libname=$BERKELEYDBBASE/lib/$libname
                  fi

                  if [ -f $libname ]; then
                     InstallProg $libname
                  else
                     echo "\"$libname\" not found. Assuming binaries are statically linked."
                  fi
               done
            fi

            for lib in $DRMAA_SHARED_LIBRARIES; do
               for version in $DRMAA_SHARED_LIB_VERSIONS; do
                  libname=$lib.$shlibext.$version
                  if [ -f $libname ]; then
                     InstallProg $libname
                     if [ "$DSTARCH" = "sol-sparc64" ]; then
                        # Install the 32bit libraries
                        DSTARCH="sol-sparc"
                        SetArchBin $DSTARCH

                        Execute mkdir -p $DEST_SGE_ROOT/lib/sol-sparc
                        InstallProg ../$ARCHBIN/$libname

                        DSTARCH="sol-sparc64"
                        SetArchBin $DSTARCH
                     fi
                  elif [ $exit_on_error = true ]; then
                     echo "\"$libname\" not found. Installation failed."
                     exit 1
                  fi
               done
            done

            ( cd $DEST_SGE_ROOT/lib/$DSTARCH
            ln -s $libname $lib.$shlibext )

            if [ "$DSTARCH" = "sol-sparc64" ]; then
               ( cd $DEST_SGE_ROOT/lib/sol-sparc
               ln -s $libname $lib.$shlibext )
            fi

            for lib in $JNI_SHARED_LIBRARIES; do
               # On MacOS X, the JVM expects a special JNI extension for shared libraries
               if [ "$shlibext" != "$jnilibext" -a -f "$lib.$shlibext" ]; then
                  ( echo Linking $lib.$jnilibext to $lib.$shlibext
                  cd $DEST_SGE_ROOT/lib/$DSTARCH
                  if [ -f $lib.$jnilibext ]; then
                     rm $lib.$jnilibext
                  fi
                  ln -s $lib.$shlibext $lib.$jnilibext )
               fi
            done

            if [ -f $CORE_HOME/$DSTARCH/libcore.$shlibext ]; then
               InstallProg $CORE_HOME/$DSTARCH/libcore.$shlibext
            fi
         fi
      fi
      cd ..
   fi
done