File: install-jemboss-server.sh

package info (click to toggle)
emboss 6.6.0%2Bdfsg-12
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 571,584 kB
  • sloc: ansic: 460,579; java: 29,383; perl: 13,573; sh: 12,753; makefile: 3,294; csh: 706; asm: 351; xml: 239; pascal: 237; modula3: 8
file content (1600 lines) | stat: -rwxr-xr-x 43,109 bytes parent folder | download | duplicates (6)
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
#!/bin/sh
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
#  @author: Copyright (C) Tim Carver
#
#
# Installs EMBOSS & Jemboss server 
#
#

######################## Functions ########################


getJavaHomePath()
{
  JAVA_HOME_TMP=${JAVA_HOME_TMP-`which java 2>/dev/null`} 

  if [ ! -f "$JAVA_HOME_TMP" ]; then
     if [ -d /usr/java/j2sdk1.4.2 ]; then
       JAVA_HOME_TMP=/usr/java/j2sdk1.4.2
     elif [ -d /usr/local/java/j2sdk1.4.2 ]; then
       JAVA_HOME_TMP=/usr/local/java/j2sdk1.4.2
     else
       JAVA_HOME_TMP=0
     fi
  else
    JAVA_HOME_TMP=`dirname $JAVA_HOME_TMP`
    JAVA_HOME_TMP=`dirname $JAVA_HOME_TMP`
  fi
}


getClustalWPath()
{
  CLUSTALW=${CLUSTALW-`which clustalw 2>/dev/null`}

  echo
  echo "-------------------------- ClustalW --------------------------"
  echo
  echo "To use emma (EMBOSS interface to ClustalW) Jemboss needs to"
  echo "know the path to the clustalw binary."
  echo
  if (test "$CLUSTALW" != ""); then
    CLUSTALW=`dirname $CLUSTALW`
    echo "Enter the path to the clustalw or press return to use the"
    echo "default [$CLUSTALW]:"
    read CLUSTALW_TMP
    if (test "$CLUSTALW_TMP" != ""); then
      CLUSTALW="$CLUSTALW_TMP"
    fi
  else
    echo "Enter the path to clustalw or press return to set"
    echo "this later (in jemboss.properties)"
    read CLUSTALW
  fi
  
  if (test "$CLUSTALW" = ""); then
    CLUSTALW="/packages/clustal/"
  fi
  
}


getPrimerPath()
{
  PRIMER3=${PRIMER3-`which primer3_core 2>/dev/null`}
                                                                                
  echo
  echo "-------------------------- Primer3  --------------------------"
  echo
  echo "To use eprimer3 (EMBOSS interface to Primer3 from the Whitehead"
  echo "Institute) Jemboss needs to know the path to the primer3_core"
  echo "binary."
  echo
  if (test "$PRIMER3" != ""); then
    PRIMER3=`dirname $PRIMER3`
    echo "Enter the path to the primer3_core or press return to use the"
    echo "default [$PRIMER3]:"
    read PRIMER3_TMP
    if (test "$PRIMER3_TMP" != ""); then
      PRIMER3="$PRIMER3_TMP"
    fi
  else
    echo "Enter the path to primer3_core or press return to set"
    echo "this later in (jemboss.properties)"
    read PRIMER3
  fi

  if (test "$PRIMER3" = ""); then
    PRIMER3="/packages/primer3/bin"
  fi

}



embassy_install()
{
  
  EMBOSS_DOWNLOAD=$1
  RECORD=$2
  PLATFORM=$3
  EMBOSS_INSTALL=$4
  USER_CONFIG=$5

  echo
  echo "--------------------------------------------------------------"
  echo
  echo "EMBASSY packages can optionally be installed along with"
  echo "the EMBOSS applications, see:"
  echo "http://emboss.sourceforge.net/apps/release/version/embassy"
  echo "where 'version' corresponds to the EMBOSS version e.g. 6.0"
  echo
  echo "--------------------------------------------------------------"
  echo
  echo "Install EMBASSY packages (y,n) [y]?"
  read EMBASSY

  if [ "$EMBASSY" = "" ]; then
    EMBASSY="y"
  fi

  echo "$EMBASSY" >> $RECORD
  
  if [ $EMBASSY = "y" ]; then

    if [ ! -d $EMBOSS_DOWNLOAD/embassy ]; then
      mkdir $EMBOSS_DOWNLOAD/embassy
    fi
    echo
    echo "To install EMBASSY Packages:"
    echo "(1) Download these from ftp://emboss.open-bio.org/pub/EMBOSS/"
    echo "(2) And unpack (gunzip and untar) them in: "
    echo "$EMBOSS_DOWNLOAD/embassy"
    echo "(3) *before* pressing return to continue!"
    read BLANK

    cd $EMBOSS_DOWNLOAD/embassy

    echo
    echo "Install all packages that are downloaded in"
    echo "$EMBOSS_DOWNLOAD/embassy "
    echo "(if 'no' then prompts will be given for each package to "
    echo "install) (y,n) [y]?"
    
    read ALL
    if [ "$ALL" = "" ]; then
      ALL="y"
    fi

    for dir in *
    do
      if (test -d $dir ); then
      if [ $ALL = "y" ]; then
        INST="y"
      else
        echo "Install $dir (y,n) [y]?"
        read INST
        if [ "$INST" = "" ]; then
          INST="y"
        fi
      fi
      if [ $INST = "y" ]; then

        EMBASSY_INST="$EMBOSS_DOWNLOAD/embassy/$dir"
        if [ -f "$EMBASSY_INST/configure" ]; then
          echo
          echo "  ******** $dir will be configured and installed  ******** "
          echo
          cd $EMBASSY_INST
          ./configure --with-thread=$PLATFORM \
              --prefix=$EMBOSS_INSTALL $USER_CONFIG
          make
          make -j install
	  cd ..
        else
          echo
          echo "Did not install $dir cannot find"
          echo "$EMBASSY_INST/configure"
          echo
        fi
      fi
      fi
    done

  fi

}

ssl_print_notes()
{

 KEYSTOREFILE=$1
 TOMCAT_ROOT=$2
 PORT=$3
 NUM=2

 echo
 if [ -f $JAVA_HOME/jre/lib/security/java.security ]; then

   SECURITY=`sed -n  -e 's|^security.provider.\([0-9]\)=com.sun.net.ssl.internal.ssl.Provider|security|p' $JAVA_HOME/jre/lib/security/java.security`


   if [ $SECURITY = "security" ]; then 
     NUM=1 
   else
     echo "1) EDIT "$JAVA_HOME/jre/lib/security/java.security
     echo "   adding/changing the provider line (usually provider 2 or 3):"
     echo "   security.provider.2=com.sun.net.ssl.internal.ssl.Provider"
   fi
 else
   if [ "$MACOSX" != "y" ]; then
     echo "1) EDIT the java.security file "
     echo "   adding/changing the provider line (usually provider 2 or 3):"
     echo "   security.provider.2=com.sun.net.ssl.internal.ssl.Provider"
   fi
 fi

 echo "$NUM) COPY & PASTE THE FOLLOWING INTO "
 echo "   $TOMCAT_ROOT/conf/server.xml"
 echo 
 echo

 if [ -d "$TOMCAT_ROOT/shared/classes" ]; then

   TCVERSION=`sed -n -e 's|\(.*\)Running The Tomcat 4\(.*\)|4|p' $TOMCAT_ROOT/RUNNING.txt`

   if [ "$TCVERSION" != "4" ]; then 
#tomcat 5.x

     TCVERSION=`sed -n -e 's|\(.*\)Running The Tomcat 5.5\(.*\)|5|p' $TOMCAT_ROOT/RUNNING.txt`
    
     if [ "$TCVERSION" != "5" ]; then
       echo
       echo '    <!-- Define a SSL Coyote HTTP/1.1 Connector on port '$PORT' -->'
       echo '    <Connector className="org.apache.coyote.tomcat5.CoyoteConnector"'
       echo '               port="'$PORT'" minProcessors="5" maxProcessors="75"'
       echo '               enableLookups="false"'
       echo '               acceptCount="10" debug="0" scheme="https" secure="true"'
       echo '               useURIValidationHack="false">'
       echo '      <Factory className="org.apache.coyote.tomcat5.CoyoteServerSocketFactory"'
       echo '           keystoreFile="'$KEYSTOREFILE'" keystorePass="'$PASSWD'"'
       echo '           clientAuth="false" protocol="TLS"/>'
       echo '    </Connector>'
       echo
     else
#tomcat 5.5
       echo
       echo '    <!-- Define a SSL Coyote HTTP/1.1 Connector on port '$PORT' -->'
       echo '    <Connector port="'$PORT'" minProcessors="5" maxProcessors="75"'
       echo '               enableLookups="false"'
       echo '               acceptCount="10" debug="0" scheme="https" secure="true"'
       echo '               useURIValidationHack="false"'
       echo '               keystoreFile="'$KEYSTOREFILE'" keystorePass="'$PASSWD'"'
       echo '               clientAuth="false" sslProtocol="TLS"/>'
       echo
     fi
   else
#tomcat 4.1.x
     echo
     echo '    <!-- Define a SSL Coyote HTTP/1.1 Connector on port '$PORT' -->'
     echo '    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"'
     echo '               port="'$PORT'" minProcessors="5" maxProcessors="75"'
     echo '               enableLookups="false"'
     echo '               acceptCount="10" debug="0" scheme="https" secure="true"'
     echo '               useURIValidationHack="false">'
     echo '      <Factory className="org.apache.coyote.tomcat4.CoyoteServerSocketFactory"'
     echo '           keystoreFile="'$KEYSTOREFILE'" keystorePass="'$PASSWD'"'
     echo '           clientAuth="false" protocol="TLS"/>'
     echo '    </Connector>'
     echo
   fi
 else

   TCVERSION=`sed -n -e 's|\(.*\)Running The Apache Tomcat 6.0\(.*\)|6|p' $TOMCAT_ROOT/RUNNING.txt`

   if [ "$TCVERSION" = "6" ]; then 
   #tomcat 6.x
       echo
       echo '    <!-- Define an SSL HTTP/1.1 Connector on port '$PORT' -->'
       echo '    <Connector port="'$PORT'" protocol="HTTP/1.1" minSpareThreads="5" maxSpareThreads="75"'
       echo '           enableLookups="true" disableUploadTimeout="true"'
       echo '           acceptCount="100"  maxThreads="200"'
       echo '           scheme="https" secure="true" SSLEnabled="true"'
       echo '           keystoreFile="'$KEYSTOREFILE'" keystorePass="'$PASSWD'"'
       echo '           clientAuth="false" sslProtocol="TLS">'
       echo '    </Connector>'
       echo
   else

#tomcat 4.0.x
   echo '   <!-- Define an SSL HTTP/1.1 Connector on port '$PORT' -->'
   echo '   <Connector className="org.apache.catalina.connector.http.HttpConnector"'
   echo '           port="'$PORT'" minProcessors="5" maxProcessors="75"'
   echo '           enableLookups="true"'
   echo '           acceptCount="10" debug="0" scheme="https" secure="true">'
   echo '   <Factory className="org.apache.catalina.net.SSLServerSocketFactory"'
   echo '           keystoreFile="'$KEYSTOREFILE'" keystorePass="'$PASSWD'"'
   echo '           clientAuth="false" protocol="TLS"/>'
   echo '   </Connector>'  
   echo 
 fi
 fi
}

ssl_create_keystore()
{

  HOST=$1
  JEMBOSS_RES=$2
  KEYSTORE=$3
  ALIAS=$4
  PASSWD=$5
  VALID=$6

  keytool -genkey -alias $ALIAS -dname "CN=$HOST, \
      OU=Jemboss, O=HGMP-RC, L=CAMBRIDGE, S=CAMBRIDGE, C=UK" -keyalg RSA \
      -keypass $PASSWD -storepass $PASSWD -keystore $JEMBOSS_RES/$KEYSTORE.keystore -validity $VALID

  keytool -export -alias $ALIAS -storepass $PASSWD -file $JEMBOSS_RES/$KEYSTORE.cer \
      -keystore $JEMBOSS_RES/$KEYSTORE.keystore

}

ssl_import()
{
  FILE=$1
  KEYSTORE=$2
  PASSWD=$3

  keytool -import -v -trustcacerts -alias tomcat -file $FILE -keystore \
            $KEYSTORE -keypass $PASSWD -storepass $PASSWD -noprompt

}


make_jemboss_properties()
{

  EMBOSS_INSTALL=$1
  URL=$2
  AUTH=$3
  SSL=$4
  PORT=$5
  EMBOSS_URL=$6
  CLUSTALW=$7
  PRIMER3=$8
  RESULTSHOME=$9

  EMBOSSPATH=/usr/bin/:/bin
  export EMBOSSPATH

  EMBOSSPATH=${EMBOSSPATH}:$CLUSTALW
  EMBOSSPATH=${EMBOSSPATH}:$PRIMER3
 
  if [ $SSL = "y" ]; then
     URL=https://$URL:$PORT
  else
     URL=http://$URL:$PORT
  fi
  
  JEMBOSS_PROPERTIES=$EMBOSS_INSTALL/share/EMBOSS/jemboss/resources/jemboss.properties

  mv $JEMBOSS_PROPERTIES $JEMBOSS_PROPERTIES.orig
  touch $JEMBOSS_PROPERTIES

  if [ $AUTH = "y" ]; then
    echo "user.auth=true" > $JEMBOSS_PROPERTIES
  else
    echo "user.auth=false" > $JEMBOSS_PROPERTIES
  fi
  echo "jemboss.server=true" >> $JEMBOSS_PROPERTIES
  echo "server.public=$URL/axis/services" \
                                      >> $JEMBOSS_PROPERTIES

  echo "server.private=$URL/axis/services" \
                                       >> $JEMBOSS_PROPERTIES

  if [ $AUTH = "y" ]; then
   echo "service.public=JembossAuthServer" >> $JEMBOSS_PROPERTIES
   echo "service.private=JembossAuthServer" >> $JEMBOSS_PROPERTIES
  else
   echo "service.public=JembossServer" >> $JEMBOSS_PROPERTIES
   echo "service.private=JembossServer" >> $JEMBOSS_PROPERTIES
  fi

  echo "embossData=$EMBOSS_INSTALL/share/EMBOSS/data/" >> $JEMBOSS_PROPERTIES
  echo "embossBin=$EMBOSS_INSTALL/bin/" >> $JEMBOSS_PROPERTIES
  echo "embossPath=$EMBOSSPATH" >> $JEMBOSS_PROPERTIES

  echo "results.home=$RESULTSHOME" >> $JEMBOSS_PROPERTIES

# echo "embossPath=/usr/bin/:/bin:$CLUSTALW:$PRIMER3:/packages/clustal/:/packages/primer3/bin:" \
#                                                    >> $JEMBOSS_PROPERTIES
  echo "acdDirToParse=$EMBOSS_INSTALL/share/EMBOSS/acd/" >> $JEMBOSS_PROPERTIES
  echo "embossURL=$EMBOSS_URL" >> $JEMBOSS_PROPERTIES
  
  grep embossHavePDF $JEMBOSS_PROPERTIES.orig >> $JEMBOSS_PROPERTIES

  cp $JEMBOSS_PROPERTIES $JEMBOSS_PROPERTIES.bak

  echo
  echo "Changed $EMBOSS_INSTALL/share/EMBOSS/jemboss/resources/jemboss.properties"
  echo "to reflect this installation (original in jemboss.properties.orig)"
  echo

}


deploy_axis_services()
{

  JEMBOSS_LIB=$1
  AXIS=$1/axis
  CLASSPATH=$AXIS/axis.jar::$AXIS/jaxrpc.jar:$AXIS/saaj.jar:$AXIS/commons-logging.jar:
  CLASSPATH=${CLASSPATH}:$AXIS/commons-discovery.jar:$AXIS/wsdl4j.jar:$AXIS/servlet.jar
#  CLASSPATH=${CLASSPATH}:$JEMBOSS_LIB/jnet.jar:$JEMBOSS_LIB/jsse.jar:$JEMBOSS_LIB/jcert.jar

  PROXY_OFF="-DproxySet=false -DproxyHost= -DproxyPort= -Dhttp.proxyHost= -Dhttp.proxyPort= -Dhttps.proxyHost= -Dhttps.proxyPort= "
  SERVICE=$2
  URL=$3
  URL2=$4
  JAVAHOME=$5
  OPT_PROP1=$6
  OPT_PROP2=$7

  echo
# echo "$JAVAHOME/bin/java -classpath $CLASSPATH $OPT_PROP1 $OPT_PROP2 \\ "
# echo " org.apache.axis.client.AdminClient -l$URL/axis/services JembossServer.wsdd"
  echo

  $JAVAHOME/bin/java -classpath $CLASSPATH $OPT_PROP1 $OPT_PROP2 $PROXY_OFF \
        org.apache.axis.client.AdminClient \
        -l$URL/axis/services JembossServer.wsdd

  echo "#!/bin/csh " > deploy.csh
  echo "$JAVAHOME/bin/java -classpath $CLASSPATH $OPT_PROP1 $OPT_PROP2 $PROXY_OFF org.apache.axis.client.AdminClient -l$URL/axis/services JembossServer.wsdd" >> deploy.csh
  echo "" >> deploy.csh
  echo 'if ($status != 0) then' >> deploy.csh
  echo "  $JAVAHOME/bin/java -classpath $CLASSPATH $OPT_PROP1 $OPT_PROP2 $PROXY_OFF org.apache.axis.client.AdminClient -l$URL2/axis/services JembossServer.wsdd" >> deploy.csh
  echo "endif" >> deploy.csh
  chmod u+x deploy.csh
}

deploy_auth_services()
{

  JEMBOSS_LIB=$1
  CLASSPATH=$JEMBOSS_LIB/soap.jar:$JEMBOSS_LIB/activation.jar:$JEMBOSS_LIB/mail.jar
#  CLASSPATH=${CLASSPATH}:$JEMBOSS_LIB/jnet.jar:$JEMBOSS_LIB/jsse.jar:$JEMBOSS_LIB/jcert.jar

  SERVICE=$2
  URL=$3
  JAVAHOME=$4
  OPT_PROP1=$5
  OPT_PROP2=$6

  echo
  echo "Deploying $SERVICE "
  echo "$JAVAHOME/bin/java -classpath $CLASSPATH $OPT_PROP1 $OPT_PROP2 org.apache.soap.server.ServiceManagerClient  $URL/soap/servlet/rpcrouter deploy $SERVICE"
  echo

  $JAVAHOME/bin/java -classpath $CLASSPATH $OPT_PROP1 $OPT_PROP2 \
        org.apache.soap.server.ServiceManagerClient \
        $URL/soap/servlet/rpcrouter deploy $SERVICE

}


output_auth_xml()
{
  AUTH=$2
  if [ $AUTH = "y" ]; then
    JEM_CLASS="org.emboss.jemboss.server.JembossAuthServer"
    FIL_CLASS="org.emboss.jemboss.server.JembossFileAuthServer"
    ID="JembossAuthServer"
  else
    JEM_CLASS="org.emboss.jemboss.server.JembossServer"
    FIL_CLASS="org.emboss.jemboss.server.JembossFileServer"
    ID="JembossServer"
  fi

  XML_FILE=$1
  echo '<deployment xmlns="http://xml.apache.org/axis/wsdd/"' > $XML_FILE
  echo '            xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">' >> $XML_FILE
  echo "  <service name=\"$ID\" provider=\"java:RPC\">" >> $XML_FILE
  echo "    <parameter name=\"className\" value=\"$JEM_CLASS\"/>" >> $XML_FILE
  echo '    <parameter name="allowedMethods" value="*"/>' >> $XML_FILE
  echo '  </service>' >> $XML_FILE
  echo '  <service name="EmbreoFile" provider="java:RPC">' >> $XML_FILE
  echo "    <parameter name=\"className\" value=\"$FIL_CLASS\"/>" >> $XML_FILE
  echo '    <parameter name="allowedMethods" value="*"/>' >> $XML_FILE
  echo '  </service>' >> $XML_FILE
  echo '</deployment>' >> $XML_FILE

}

#
# Find the likely location for the png & gd libs
get_libs()
{
  USER_CONFIG=$1

  include_lib_dirs="
/usr/local
/opt/freeware
/usr/freeware"

  if (test -f /usr/include/png.h) && (test -f /usr/include/gd.h); then
     USER_CONFIG="default"
  else
    for lib_dir in `echo  "$include_lib_dirs"` ;
    do
      if (test -f $lib_dir/include/png.h) && (test -f $lib_dir/include/gd.h); then
        USER_CONFIG="--with-pngdriver=$lib_dir"
      fi  
    done
  fi
}

check_libs()
{
  USER_CONFIG=$1
  PLATFORM=$2

  if [ "$USER_CONFIG" = "" ]; then
    DIR="/usr"
  else
    DIR=`echo $USER_CONFIG | sed -n -e 's|\(.*\)--with-pngdriver=\([^ ]*\)\(.*\)|\2|p'`
  fi

  lib_dirs="
$DIR/lib
$DIR/lib32
$DIR/lib64
$DIR/lib/x86_64-linux-gnu
$DIR/lib/i386-linux-gnu"

  echo
  echo "Inspecting $DIR"
 
# test for libpng
  WARN="true"
  if (test ! -f $DIR/include/png.h ); then
    WARN="true"
  else
    for lib_dir in `echo  "$lib_dirs"` ; 
    do
      echo "checking $lib_dir"
      if (test -f $lib_dir/libpng.a) || (test -f $lib_dir/libpng.so); then
         WARN="false"
         echo "...found libpng in $lib_dir"
         break
      elif (test -f $lib_dir/libpng.dylib); then
         WARN="false"
         echo "...found libpng in $lib_dir"
         break
      fi                     
    done
  fi

  if (test $WARN = "true"); then
    echo
    echo "------------------------- WARNING ----------------------------"
    echo
    echo "The script has detected that $DIR/include/png.h"
    echo "does not exist!"
    echo
    echo "Download libpng from"
    echo "      http://www.libpng.org/pub/png/libpng.html"
    echo "      http://libpng.sourceforge.net/"
    echo
    echo "For details see the EMBOSS admin guide:"
    echo "http://emboss.sourceforge.net/admin/"
    echo
    echo "To exit use Control C or press return to continue."
    echo
    echo "--------------------------------------------------------------"
    read REPLY
  fi

# test for gd
  WARN="true"
  if (test ! -f $DIR/include/gd.h ); then
    WARN="true"
  else
    for lib_dir in `echo  "$lib_dirs"` ;
    do
      echo "checking $lib_dir"
      if (test -f $lib_dir/libgd.a) || (test -f $lib_dir/libgd.so); then
         WARN="false"
         echo "...found gd in $lib_dir"
         break
      elif (test -f $lib_dir/libgd.dylib); then
         WARN="false"
         echo "...found libpng in $lib_dir"
         break
      fi
    done
  fi

  if (test $WARN = "true"); then
    echo
    echo "------------------------- WARNING ----------------------------"
    echo
    echo "The script has detected that $DIR/include/gd.h"
    echo "does not exist"
    echo
    echo "Download gd from"
    echo "       http://www.boutell.com/gd/"
    echo
    echo "For details see the EMBOSS admin guide:"
    echo "http://emboss.sourceforge.net/admin/"
    echo
    echo "To exit use Control C or press return to continue."
    echo
    echo "--------------------------------------------------------------"
    read REPLY
  fi 

# test for zlib which can be either in /usr/lib or $DIR/lib

  lib_dirs="
$DIR/lib
$DIR/lib32
$DIR/lib64
/usr/lib
/usr/local/lib
/usr/lib64
$DIR/lib/x86_64-linux-gnu
$DIR/lib/i386-linux-gnu"

  WARN="true"
  for lib_dir in `echo  "$lib_dirs"` ;
  do
    echo "checking $lib_dir"
    if (test -f $lib_dir/libz.a) || (test -f $lib_dir/libz.so) || (test -f $lib_dir/libz.dylib); then
       WARN="false"
       echo "...found zlib in $lib_dir"
       break
    fi
  done

  if (test $WARN = "true"); then
    echo
    echo "------------------------- WARNING ----------------------------"
    echo
    echo "The script cannot find zlib installed under /usr"
    if( (test $PLATFORM = "macos") || (test $PLATFORM = "linux") ); then
      echo "or /usr/local"
    fi
    echo
    echo "Download zlib from"
    echo "       http://www.info-zip.org/pub/infozip/zlib/"
    echo
    echo "For details see the EMBOSS admin guide:"
    echo "http://emboss.sourceforge.net/admin/"
    echo
    echo "To exit use Control C or press return to continue."
    echo
    echo "--------------------------------------------------------------"
    read REPLY
  fi
}


clear
echo
echo "--------------------------------------------------------------"
echo "         EMBOSS and Jemboss Server installation script"
echo "--------------------------------------------------------------"
echo " "
echo "Note: any default values are given in square brackets []."
echo " "
echo "This script installs EMBOSS as well as Jemboss."
echo "Jemboss is deployed as a Java web application in your tomcat server."
echo "A script is prepared to run the Jemboss client that by default uses the"
echo "above Jemboss web application."
echo
echo "For detailed information on installing Jemboss see: "
echo "http://emboss.sourceforge.net/Jemboss/install/setup.html"
echo
echo
echo "*** This script needs to be run with permissions to be able"
echo "*** to install EMBOSS in the required directories. This may"
echo "*** be best done as root or as a tomcat user."
echo
echo "Before running this script you should download the latest:"
echo
echo "(1) EMBOSS release (contains Jemboss) ftp://emboss.open-bio.org/pub/EMBOSS/"
echo "(2) Tomcat 5.5 series (or above) release http://tomcat.apache.org/"
echo "(3) Apache AXIS (SOAP) release 1.4   http://ws.apache.org/axis/"
  
echo
echo "Have the above been downloaded (y/n)? "
read DOWNLOADED

if (test "$DOWNLOADED" != "y") && (test "$DOWNLOADED" != "Y"); then
  exit 1
fi


RECORD="install.record"
if [ -f "$RECORD" ]; then
  mv $RECORD $RECORD.old
fi

echo "$DOWNLOADED" > $RECORD
 
PLATTMP=`uname`

case $PLATTMP in
  Linux)
    PLATTMP="1"
    ;;
  AIX)
    PLATTMP="2"
    ;;
  IRIX)
    PLATTMP="3"
    ;;
  HP-UX)
    PLATTMP="4"
    ;;
  SunOS)
    PLATTMP="5"
    ;;
  Darwin)
    PLATTMP="6"
    ;;
  OSF1)
    PLATTMP="7"
    ;;
  FreeBSD)
    PLATTMP="8"
    ;;
  *)
    PLATTMP="1"
    ;;
esac


echo 
echo "Select the platform (1-8) that your Jemboss server will be"
echo "run on [$PLATTMP]:"
echo "(1)  linux"
echo "(2)  aix"
echo "(3)  irix"
echo "(4)  hp-ux"
echo "(5)  solaris"
echo "(6)  macosX"
echo "(7)  OSF"
echo "(8)  FreeBSD"
read PLAT

if [ "$PLAT" = "" ]; then
  PLAT=$PLATTMP
fi

echo "$PLAT" >> $RECORD

AUTH_TYPE_TMP=1
AIX="n"
MACOSX="n"
if [ "$PLAT" = "1" ]; then
  PLATFORM="linux"
  AUTH_TYPE_TMP=3
elif [ "$PLAT" = "2" ]; then
  PLATFORM="aix"
  AIX="y"
  AUTH_TYPE_TMP=4
elif [ "$PLAT" = "3" ]; then
  PLATFORM="irix"
  AUTH_TYPE_TMP=1
elif [ "$PLAT" = "4" ]; then
  PLATFORM="hpux"
  AUTH_TYPE_TMP=5
elif [ "$PLAT" = "5" ]; then
  PLATFORM="solaris"
  AUTH_TYPE_TMP=6
elif [ "$PLAT" = "6" ]; then
  PLATFORM="macos"
  MACOSX="y"
  AUTH_TYPE_TMP=3
elif [ "$PLAT" = "7" ]; then
  PLATFORM="osf"
  AUTH_TYPE_TMP=7
elif [ "$PLAT" = "8" ]; then
  PLATFORM="freebsd"
  AUTH_TYPE_TMP=7
else
  echo "Platform not selected from 1-8."
  exit 1
fi

SSL="y"

# keep the following variable for now so we have cvs compare for a while
INSTALL_TYPE="1";
if [ $INSTALL_TYPE = "1" ]; then
#
# localhost name
#
  echo
  echo "The IP address or fully qualified domain name (e.g. emboss.company.com)"
  echo "is needed by Jemboss to access the Tomcat web server."
  echo "Enter the IP address or the fully qualified domain name of the"
  echo "server machine [`hostname`]:"
  read LOCALHOST

  if [ "$LOCALHOST" = "" ]; then
    LOCALHOST=`hostname`
  fi

  echo "$LOCALHOST" >> $RECORD
#
# SSL
#
  echo
  echo "Enter if you want the Jemboss server to use data"
  echo "encryption (https/SSL) (y,n) [y]?"
  read SSL

  echo "$SSL" >> $RECORD

  JSSE_HOME=""

  if (test "$SSL" = "y") || (test "$SSL" = ""); then
    PORT=8443
    SSL="y"
  else
    PORT=8080
  fi

#
# PORT
#
  USER_PORT=""
  echo
  echo "Enter port number [$PORT]:"
  read USER_PORT

  if [ "$USER_PORT" = "" ]; then
    if [ $SSL = "y" ]; then
      PORT=8443
    else
      PORT=8080
    fi
  else
    PORT=$USER_PORT
  fi

  echo "$PORT" >> $RECORD

fi
echo

#
# JAVA_HOME
#
getJavaHomePath
JAVA_HOME=$JAVA_HOME_TMP
if [ "$JAVA_HOME" != "0" ]; then
  echo "Enter java (1.4 or above) location [$JAVA_HOME_TMP]: "
  read JAVA_HOME

  if [ "$JAVA_HOME" = "" ]; then 
    JAVA_HOME=$JAVA_HOME_TMP
  fi
fi

while [ ! -f "$JAVA_HOME/bin/javac" ]
do
  echo "Enter java (1.3 or above) location (/usr/java/jdk1.3.1/): "
  read JAVA_HOME
done
echo
echo "$JAVA_HOME" >> $RECORD

#
# add java bin to path
#
PATH=$JAVA_HOME/bin/:$PATH ; export PATH

#
#
# JNI location for linux/solaris/AIX/SGI/HP-UX
#
#  
#
JAVA_INCLUDE=$JAVA_HOME/include/
JAVA_INCLUDE_OS=$JAVA_INCLUDE
if [ -d $JAVA_INCLUDE/linux ]; then
  JAVA_INCLUDE_OS=${JAVA_INCLUDE}/linux
elif [ -d $JAVA_INCLUDE/solaris ]; then
  JAVA_INCLUDE_OS=${JAVA_INCLUDE}/solaris
elif [ -d $JAVA_INCLUDE/irix ]; then
  JAVA_INCLUDE_OS=${JAVA_INCLUDE}/irix
elif [ -d $JAVA_INCLUDE/hp-ux ]; then
  JAVA_INCLUDE_OS=${JAVA_INCLUDE}/hp-ux
elif [ -d $JAVA_INCLUDE/alpha ]; then
  JAVA_INCLUDE_OS=${JAVA_INCLUDE}/alpha
elif [ -d $JAVA_INCLUDE/freebsd ]; then
  JAVA_INCLUDE_OS=${JAVA_INCLUDE}/freebsd
elif [ -d $JAVA_INCLUDE ]; then
  JAVA_INCLUDE_OS=${JAVA_INCLUDE}
else
  echo "Enter java include/Header directory location (containing jni.h)? "
  read JAVA_INCLUDE
  JAVA_INCLUDE_OS=$JAVA_INCLUDE
  if [ -d $JAVA_INCLUDE/linux ]; then
    JAVA_INCLUDE_OS=${JAVA_INCLUDE}/linux
  elif [ -d $JAVA_INCLUDE/solaris ]; then
    JAVA_INCLUDE_OS=${JAVA_INCLUDE}/solaris
  elif [ -d $JAVA_INCLUDE/irix ]; then
    JAVA_INCLUDE_OS=${JAVA_INCLUDE}/irix
  elif [ -d $JAVA_INCLUDE ]; then
    JAVA_INCLUDE_OS=${JAVA_INCLUDE}
  else
    echo "Problems finding java include libraries!"
    exit 1
  fi

  echo "$JAVA_INCLUDE" >> $RECORD
fi

#
# EMBOSS_DOWNLOAD
#
EMBOSS_DOWNLOAD_TMP=`pwd`
EMBOSS_DOWNLOAD_TMP=`dirname $EMBOSS_DOWNLOAD_TMP`
EMBOSS_DOWNLOAD_TMP=`dirname $EMBOSS_DOWNLOAD_TMP`

echo "Enter EMBOSS download directory"
echo "[$EMBOSS_DOWNLOAD_TMP]: "
read EMBOSS_DOWNLOAD

if [ "$EMBOSS_DOWNLOAD" = "" ]; then
  EMBOSS_DOWNLOAD=$EMBOSS_DOWNLOAD_TMP
fi

while [ ! -d "$EMBOSS_DOWNLOAD/ajax" ]
do
  echo "Enter EMBOSS download directory (e.g. /usr/emboss/EMBOSS-2.x.x): "
  read EMBOSS_DOWNLOAD
done
echo
echo "$EMBOSS_DOWNLOAD" >> $RECORD

echo "Enter where EMBOSS should be installed [/usr/local/emboss]: "
read EMBOSS_INSTALL

if [ "$EMBOSS_INSTALL" = "" ]; then
  EMBOSS_INSTALL=/usr/local/emboss
fi

if [ -d "$EMBOSS_INSTALL/share/EMBOSS/jemboss" ]; then
  echo 
  echo "Jemboss has already be installed to: "
  echo "$EMBOSS_INSTALL/share/EMBOSS/jemboss "
  echo "It is recommended this is removed before continuing."
  echo "To continue press return."
  read BLANK
fi
echo
echo "$EMBOSS_INSTALL" >> $RECORD

if [ $INSTALL_TYPE = "1" ]; then
  echo "Enter URL for emboss documentation for application "
  echo "[http://emboss.sourceforge.net/]:"
  read EMBOSS_URL

  echo "$EMBOSS_URL" >> $RECORD
fi

if [ "$EMBOSS_URL" = "" ]; then
  EMBOSS_URL="http://emboss.sourceforge.net/"
fi
echo

#
# set JSSE_HOME to the EMBOSS install dir
#
JSSE_HOME=$EMBOSS_INSTALL/share/EMBOSS/jemboss
JEMBOSS_SERVER_AUTH=""
AUTH=y

if [ $INSTALL_TYPE = "1" ]; then
  echo "Do you want Jemboss to use unix authorisation (y/n) [y]? "
  read AUTH

  echo "$AUTH" >> $RECORD
else
  AUTH="n"
fi

if [ "$AUTH" = "" ]; then
  AUTH="y"
fi
echo

if [ "$AUTH" = "y" ]; then

  echo "#include <stdio.h>" > dummy.c
  echo 'int main(){ printf("%d",getuid()); }' >> dummy.c
  if (cc dummy.c -o dummy >/dev/null 2>&1); then
    UUIDTMP=`./dummy`
    CC="cc"; 
  else
    gcc dummy.c -o dummy >/dev/null 2>&1
    UUIDTMP=`./dummy`
    CC="gcc";
  fi
  rm -f dummy.c dummy

  if (test "$UUIDTMP" = "") || (test "$UUIDTMP" = "0"); then
    UUIDTMP="506"
  fi

  echo "Provide the UID of the account (non-privileged) to run Tomcat,"
  echo "it has to be greater than 100 [$UUIDTMP]:"
  read UUID

  echo "$UUID" >> $RECORD

  if [ "$UUID" = "" ]; then
    UUID="$UUIDTMP"
  fi

  CC="$CC -DTOMCAT_UID=$UUID "; export CC

  echo
  echo "Unix Authentication Method, see:"
  echo "http://emboss.sourceforge.net/Jemboss/install/authentication.html"
  echo
  echo "(1) shadow      (3) PAM         (5) HP-UX shadow"
  echo "(2) no shadow   (4) AIX shadow  (6) Re-entrant shadow"
  echo "(7) Re-entrant no shadow"  
  echo 
  echo "Type of unix password method being used "
  echo "(select 1, 2, 3, 4, 5, 6 or 7 )[$AUTH_TYPE_TMP]"
  read AUTH_TYPE
  
  if [ "$AUTH_TYPE" = "" ]; then
     AUTH_TYPE="$AUTH_TYPE_TMP"
  fi

  echo "$AUTH_TYPE" >> $RECORD

  if [ "$AUTH_TYPE" = "1" ]; then
    JEMBOSS_SERVER_AUTH=" --with-auth=shadow"
  elif [ "$AUTH_TYPE" = "2" ]; then
    JEMBOSS_SERVER_AUTH=" --with-auth=noshadow"
  elif [ "$AUTH_TYPE" = "3" ]; then
    JEMBOSS_SERVER_AUTH=" --with-auth=pam"
  elif [ "$AUTH_TYPE" = "4" ]; then
    JEMBOSS_SERVER_AUTH=" --with-auth=aixshadow"
  elif [ "$AUTH_TYPE" = "5" ]; then
    JEMBOSS_SERVER_AUTH=" --with-auth=hpuxshadow"
  elif [ "$AUTH_TYPE" = "6" ]; then
    JEMBOSS_SERVER_AUTH=" --with-auth=rshadow"
  elif [ "$AUTH_TYPE" = "7" ]; then
    JEMBOSS_SERVER_AUTH=" --with-auth=rnoshadow"
  else
    JEMBOSS_SERVER_AUTH=" --with-auth=shadow"
  fi
fi
echo
 
if [ $INSTALL_TYPE = "1" ]; then
#
#
# Results directory for jobs
#

  echo "Define the directory you want to store the results in"
  echo "[/tmp/SOAP/emboss]"
  read JOBDIR

  if (test "$JOBDIR" = ""); then
    JOBDIR="/tmp/SOAP/emboss"
  fi

  echo "$JOBDIR" >> $RECORD

  echo

#
#
# Tomcat
#
  TOMCAT_ROOT=0

  while [ ! -d "$TOMCAT_ROOT/webapps" ]
  do
    echo "Enter Tomcat root directory (e.g. /usr/local/tomcat)"
    read TOMCAT_ROOT
  done
  echo "$TOMCAT_ROOT" >> $RECORD
  echo

  if [ -d "$TOMCAT_ROOT/webapps/axis/WEB-INF/classes/org" ]; then
    echo
    echo "It looks like an installation has already been carried out in: "
    echo "$TOMCAT_ROOT/webapps/axis/WEB-INF/classes/ "
    echo "It is recommended that tomcat is removed and a fresh copy of tomcat used."
    echo "This installation is likely to fail if you continue."
    read BLANK
  fi

  if [ -d "$TOMCAT_ROOT/webapps/axis/WEB-INF/classes/resources" ]; then
    echo
    echo "It looks like an installation has already been carried out in: "
    echo "$TOMCAT_ROOT/webapps/axis/WEB-INF/classes/ "
    echo "It is recommended that tomcat is removed and a fresh copy of tomcat used."
    echo "This installation is likely to fail if you continue."
    read BLANK
  fi

#
# Apache AXIS (SOAP)
#
  SOAP_ROOT=0

  while [ ! -d "$SOAP_ROOT/webapps/axis" ]
  do
    echo "Enter Apache AXIS (SOAP) root directory (e.g. /usr/local/axis-1.4)"
    read SOAP_ROOT
  done
  echo "$SOAP_ROOT" >> $RECORD
  echo
  cp -R $SOAP_ROOT/webapps/axis $TOMCAT_ROOT/webapps
  
  #already have commons-logging.jar in $TOMCAT_ROOT/server/lib/
  rm -f $TOMCAT_ROOT/webapps/axis/WEB-INF/lib/commons-logging.jar
fi

#
# Configuration options
#

USER_CONFIG=""
get_libs $USER_CONFIG

if [ "$USER_CONFIG" = "" ]; then
  echo
  echo "--------------------------------------------------------------"
  echo
  echo "The libraries for EMBOSS (libpng and gd) do not appear to"
  echo "be in /usr. It may be necessary to use the configuration"
  echo "flag --with-pngdriver to specify their location"
  echo
  echo "For details see the EMBOSS admin guide:"
  echo "http://emboss.sourceforge.net/admin/"
  echo
  echo "Enter any other EMBOSS configuration options (e.g. --with-pngdriver=pathname)"
  echo "or press return to leave blank:"
  read USER_CONFIG
elif [ "$USER_CONFIG" = "default" ]; then
  echo
  echo "--------------------------------------------------------------"
  echo
  echo "The libraries for EMBOSS (libpng and gd) appear to be in /usr,"
  echo "if these are the correct libraries then there should be no need"
  echo "to add any configuration options."
  echo
  echo "Enter any other EMBOSS configuration options (e.g. --with-pngdriver=pathname)"
  echo "or press return to leave blank:"
  read USER_CONFIG
else
  echo "Enter any other EMBOSS configuration options or press return to"
  echo "use default [$USER_CONFIG]:"
  read USER_CONFIG_TMP
  if [ "$USER_CONFIG_TMP" != "" ]; then
    USER_CONFIG="$USER_CONFIG_TMP"
  fi
fi

check_libs "$USER_CONFIG" $PLATFORM

echo "$USER_CONFIG" >> $RECORD
#
#
if [ "$AIX" = "y" ]; then
  if [ "$AUTH" = "y" ]; then
    CC="xlc_r -DTOMCAT_UID=$UUID "; export CC
  else
    CC=xlc_r; export CC
  fi
fi

echo
echo "  ******** EMBOSS will be configured with this information  ******** "
echo 
printf "%s\n" "./configure --with-java=$JAVA_INCLUDE \\"
printf "%s\n" "            --with-javaos=$JAVA_INCLUDE_OS \\"
printf "%s\n" "            --with-thread=$PLATFORM \\"
printf "%s\n" "            --prefix=$EMBOSS_INSTALL \\"
printf "%s\n" "           $JEMBOSS_SERVER_AUTH $USER_CONFIG"
echo

WORK_DIR=`pwd`
cd $EMBOSS_DOWNLOAD

./configure --with-java=$JAVA_INCLUDE \
            --with-javaos=$JAVA_INCLUDE_OS \
            --with-thread=$PLATFORM \
            --prefix=$EMBOSS_INSTALL $JEMBOSS_SERVER_AUTH $USER_CONFIG

CONFIGURE_EXIT_STAT=$?
if [ $CONFIGURE_EXIT_STAT -eq 0 ];then
   echo "EMBOSS configuration call has been completed."
else
   echo
   echo "EMBOSS configuration call returned with error."
   echo "Please check error messages and run the install script again."
   echo "Now terminating the install script."
   exit $CONFIGURE_EXIT_STAT
fi

make

MAKE_EXIT_STAT=$?
if [ $MAKE_EXIT_STAT -eq 0 ];then
   echo "EMBOSS build has been completed."
else
   echo
   echo "EMBOSS build returned with error."
   echo "Please check error messages and run the install script again."
   echo "Now terminating the install script."
   exit $MAKE_EXIT_STAT
fi


echo
echo "  ******* EMBOSS with Jemboss will be installed in $EMBOSS_INSTALL ******* "
echo
sleep 2

make -j install

#
#
# Config EMBASSY
#
embassy_install $EMBOSS_DOWNLOAD $RECORD $PLATFORM $EMBOSS_INSTALL $USER_CONFIG


#
#
# Get clustalw and primer3_core path
#
getClustalWPath
getPrimerPath

#
#
#


#cd $EMBOSS_INSTALL/share/EMBOSS/jemboss
JEMBOSS=$EMBOSS_INSTALL/share/EMBOSS/jemboss




#
# create resources.jar archive of the scoring matrix
#
cd $EMBOSS_INSTALL/share/EMBOSS/data
$JAVA_HOME/bin/jar cvf $JEMBOSS/resources/resources.jar EPAM* EBLOSUM* EDNA*


if [ "$MACOSX" = "y" ]; then
  cd $EMBOSS_INSTALL/lib/
  ln -s libajax.dylib libajax.jnilib
# ln -s $EMBOSS_INSTALL/lib/libajax.dylib $EMBOSS_INSTALL/lib/libajax.jnilib
# cp $EMBOSS_INSTALL/lib/libajax.[0-9].dylib /System/Library/Frameworks/JavaVM.framework/Libraries/libajax.jnilib
fi

cd $WORK_DIR

if [ "$PLATFORM" = "hpux" ]; then
  ln -s $EMBOSS_INSTALL/lib/libajax.sl $EMBOSS_INSTALL/lib/libajax.so
fi



make_jemboss_properties $EMBOSS_INSTALL $LOCALHOST $AUTH $SSL $PORT $EMBOSS_URL $CLUSTALW $PRIMER3 $JOBDIR

#
#
# Tomcat scripts
#
#

rm -f tomstart

echo
echo "#!/bin/csh " > tomstart
echo "setenv JAVA_HOME $JAVA_HOME" >> tomstart

if [ "$SSL" = "y" ]; then
  echo "setenv JSSE_HOME $JSSE_HOME" >> tomstart
fi
 
if [ "$AIX" = "y" ]; then
 echo "setenv LIBPATH /usr/lib/threads:/usr/lib:/lib:$EMBOSS_INSTALL/lib" >> tomstart
 cp $EMBOSS_DOWNLOAD/ajax/.libs/libajax.so.0 $EMBOSS_INSTALL/lib
 ln -s $EMBOSS_INSTALL/lib/libajax.so.0 $EMBOSS_INSTALL/lib/libajax.so
else
 echo "setenv JAVA_OPTS \"-Djava.library.path=$EMBOSS_INSTALL/lib\"" >> tomstart
 echo "setenv LD_LIBRARY_PATH $EMBOSS_INSTALL/lib" >> tomstart
fi

if [ "$MACOSX" = "y" ]; then
 echo "setenv DYLD_LIBRARY_PATH $EMBOSS_INSTALL/lib" >> tomstart
fi

if [ "$PLATFORM" = "hpux" ]; then
 echo "setenv SHLIB_PATH $EMBOSS_INSTALL/lib" >> tomstart
fi


if [ "$AUTH_TYPE" = "3" ]; then
  if [ -f "/lib64/libpam.so" ]; then
    echo "setenv LD_PRELOAD /lib64/libpam.so" >> tomstart
  elif [ -f "/usr/lib64/libpam.so" ]; then
    echo "setenv LD_PRELOAD /usr/lib64/libpam.so" >> tomstart
  elif [ -f "/lib/libpam.so" ]; then
    echo "setenv LD_PRELOAD /lib/libpam.so" >> tomstart
  elif [ -f "/usr/lib/libpam.so" ]; then
    echo "setenv LD_PRELOAD /usr/lib/libpam.so" >> tomstart
  elif [ -f "/usr/lib/libpam.dylib" ]; then
    echo "setenv LD_PRELOAD /usr/lib/libpam.dylib" >> tomstart
  else
    echo
    echo "WARNING: don't know what to set LD_PRELOAD to"
    echo "edit LD_PRELOAD in tomstart script!"
    echo "setenv LD_PRELOAD /usr/lib/libpam.so" >> tomstart
    echo
  fi
fi

echo 'set path=($path '"$JAVA_HOME/bin)"  >> tomstart
echo "rehash"  >> tomstart
echo "$TOMCAT_ROOT/bin/startup.sh"  >> tomstart


rm -f tomstop

echo
echo "#!/bin/csh " > tomstop
echo "setenv JAVA_HOME $JAVA_HOME" >> tomstop
echo "setenv LD_LIBRARY_PATH $EMBOSS_INSTALL/lib" >> tomstop
#if [ "$AUTH_TYPE" = "3" ]; then
#  echo "setenv LD_PRELOAD /lib/libpam.so" >> tomstop
#fi
echo 'set path=($path '"$JAVA_HOME/bin)"  >> tomstop
echo "rehash"  >> tomstop
echo "$TOMCAT_ROOT/bin/shutdown.sh"  >> tomstop


chmod u+x tomstart
chmod u+x tomstop


#
#
# Run Jemboss script
#
# The runJemboss.sh script is now generated from an Autoconf template
# runJemboss.sh.in with the location of the Java Application Launcher
# substituted.

# RUNFILE=$JEMBOSS/runJemboss.sh

#  sed "s|^java |$JAVA_HOME/bin/java |" $RUNFILE > $RUNFILE.new
#  rm -f $RUNFILE
#  mv $RUNFILE.new $RUNFILE
  

#
# Add classes to Tomcat path
#

  cp $JEMBOSS/lib/mail.jar $TOMCAT_ROOT/webapps/axis/WEB-INF/lib
  cp $JEMBOSS/lib/activation.jar $TOMCAT_ROOT/webapps/axis/WEB-INF/lib

  cp -R $JEMBOSS/resources $TOMCAT_ROOT/webapps/axis/WEB-INF/classes/  
  cp -R $EMBOSS_DOWNLOAD/jemboss/lib/axis $JEMBOSS/lib
  
# Ensure that the native library is not loaded more than once.
# To avoid place classes that load native libraries outside of the
# web app, and ensure that the loadLibrary() call is executed only once
# during the lifetime of a particular JVM.
  cd $JEMBOSS;
  echo "moving Ajax class from jemboss.jar into ajax.jar"
  mkdir tmp;
  cd tmp;
  jar -xf ../lib/jemboss.jar org/emboss/jemboss/server/Ajax.class
  jar -cf ../lib/ajax.jar org
  jar -xf ../lib/jemboss.jar
  rm org/emboss/jemboss/server/Ajax.class
  echo "copying Java class files to axis web-application classes folder"
  cp -R org $TOMCAT_ROOT/webapps/axis/WEB-INF/classes/
  cd ..;
  rm -rf tmp;

  echo "copying ajax.jar to Tomcat shared libraries folder"
  if [ -d "$TOMCAT_ROOT/shared/lib" ]; then
  #tomcat 4.1.x and 5.5.x
    cp lib/ajax.jar $TOMCAT_ROOT/shared/lib/
  elif [ -d "$TOMCAT_ROOT/lib" ]; then
  #tomcat 4.1.x and 5.5.x
    cp lib/ajax.jar $TOMCAT_ROOT/lib/
  else
    echo "WARNING: no $TOMCAT_ROOT/lib or $TOMCAT_ROOT/shared/lib found"
    echo "ajax.jar not added to Tomcat shared libraries folder"
  fi

  cd $WORK_DIR


#
#
# Create XML deployment descriptor files
#

output_auth_xml JembossServer.wsdd $AUTH

if [ "$SSL" != "y" ]; then

  echo
  echo "Tomcat XML deployment descriptors have been created for"
  echo "the Jemboss Server. Would you like an automatic deployment"
  echo "of the Jemboss web services to be tried (y/n) [y]?"
  echo "(Please make sure your Tomcat server not running currently,"
  echo " install script will start it.)"
  read DEPLOYSERVICE

  if (test "$DEPLOYSERVICE" = "y") || (test "$DEPLOYSERVICE" = ""); then
    echo
    echo "Please wait, starting tomcat......."
    ./tomstart

    sleep 2
    deploy_axis_services $JEMBOSS/lib JembossServer.wsdd http://localhost:$PORT/ http://$LOCALHOST:$PORT/ $JAVA_HOME "" ""
  fi

else

  echo
  echo "--------------------------------------------------------------"
  echo
  echo "Client and server certificates need to be generated for the"
  echo "secure (https) connection. These are then imported into"
  echo "keystores. The keystores act as databases for the security"
  echo "certificates."
  echo  
  echo "For details see:"
  echo "http://emboss.sourceforge.net/Jemboss/install/ssl.html"
  echo
  echo "--------------------------------------------------------------"
  echo 
  PASSWD=""
  while [ "$PASSWD" = "" ]
  do
    echo "Provide a password (must be at least 6 characters): "
    read PASSWD
  done

  echo
  echo "Provide the validity period for these certificates, i.e. the"
  echo "number of days before they expire and new ones need to be made [90]:"
  read VALID
  echo

  if [ "$VALID" = "" ]; then
    VALID=90
  fi

  echo "Please wait, creating certificates......."
  ssl_create_keystore $LOCALHOST $JEMBOSS/resources "server" "tomcat-sv" $PASSWD $VALID
  ssl_create_keystore "Client" $JEMBOSS/resources "client" "tomcat-cl" $PASSWD $VALID

  ssl_import $JEMBOSS/resources/server.cer $JEMBOSS/resources/client.keystore $PASSWD
  ssl_import $JEMBOSS/resources/client.cer $JEMBOSS/resources/server.keystore $PASSWD

  cd $JEMBOSS/resources
  $JAVA_HOME/bin/jar cvf client.jar client.keystore
  cd $WORK_DIR

  echo
  echo "Tomcat XML deployment descriptors have been created for the Jemboss Server."
  echo "Would you like an automatic deployment of these to be tried (y/n) [y]?"
  echo "(Please make sure your Tomcat server is not currently running as"
  echo "the install script will start it.)"
  
  read DEPLOYSERVICE

  if (test "$DEPLOYSERVICE" = "y") || (test "$DEPLOYSERVICE" = ""); then
    ssl_print_notes $JEMBOSS/resources/server.keystore $TOMCAT_ROOT $PORT
    echo

    VAL=0
    while [ $VAL != "y" ] 
    do
      echo "To continue you must have changed the above file(s)!"
      echo "Have the above files been edited (y/n)?"
      read VAL
    done

    echo
    echo "Please wait, starting tomcat......."
    ./tomstart

    sleep 2
    OPT_PROP1="-Djava.protocol.handler.pkgs=com.sun.net.ssl.internal.www.protocol"
    OPT_PROP2="-Djavax.net.ssl.trustStore=$JEMBOSS/resources/client.keystore"

    deploy_axis_services $JEMBOSS/lib JembossServer.wsdd https://localhost:$PORT/ https://$LOCALHOST:$PORT $JAVA_HOME $OPT_PROP1 $OPT_PROP2
  fi
fi

#
# Change jemboss.properties to reflect server location
# $EMBOSS_INSTALL/share/EMBOSS/jemboss/resources/jemboss.properties
#
#

echo
echo "--------------------------------------------------------------"
echo "--------------------------------------------------------------"

if [ "$AUTH" = "y" ]; then

  if [ $SSL = "y" ]; then
     URL=https://$LOCALHOST:$PORT
  else
     URL=http://$LOCALHOST:$PORT
  fi

  echo 
  echo "Tomcat should be running and the Jemboss web services deployed!"
  echo "(see $URL/axis/)"
  echo
  echo "It is *very* important to now:"
  echo "1. As root:"
  echo "   chown root $EMBOSS_INSTALL/bin/jembossctl"
  echo "   chmod u+s $EMBOSS_INSTALL/bin/jembossctl"
  echo "2. Ensure that tomcat is running as the non-privileged user,"
  echo "   with the same UID (i.e. $UUID) that was given to this script"
  echo "   (and NOT as root!)."
  echo "3. Use the tomstop & tomstart scripts in this directory"
  echo "   to stop & start tomcat."
  echo 
else
  echo
  echo "Note: Tomcat may still be running!"
  echo "Use the tomstop & tomstart scripts to stop & start tomcat."
  echo
fi

if [ ! -d "$JOBDIR" ]; then
  echo "Create the user results directory (and ensure this is world read/write-able): "
  echo "   mkdir $JOBDIR"
  echo
fi
echo "Try running Jemboss with the script:"
# The runJemboss.sh script is now automatically installed by Automake as
# bin_SCRIPT in the bin directory.
# echo "   $JEMBOSS/runJemboss.sh"
echo "   runJemboss.sh"
echo
echo "To create a web launch page see:"
echo "http://emboss.sourceforge.net/Jemboss/install/deploy.html"
echo

# The runJemboss.sh script is now automatically installed by Automake as
# bin_SCRIPT in the bin directory.
# chmod a+x $JEMBOSS/runJemboss.sh
chmod u+x $JEMBOSS/utils/*sh

exit 0;