Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1530 dpurdie 1
#!/bin/sh
2
#set -x
3
#========================================================
4
# **** Program Information ****
5
#
6
# Program Name      : reqlib.sh
7
#
8
# Program Type      : Bourne Shell Scripts(.sh)
9
#
10
# Original Author(s)  : Vasili Chatzimichail(vchatzim)
11
#
12
# Description / Purpose:
13
#     Called by the request script of a package providing a suite of
14
#     common functions to get user input.
15
#
16
# Exit Values:
17
#     NA. 
18
#
19
# References:
20
#     -None-
21
#
22
#========================================================
23
 
24
 
25
# Global Variables
26
#
27
REQLIB_ORA_TAB=/var/opt/oracle/oratab
28
 
29
 
30
# Function to get the module enable flag.
31
#
32
# Input is the module type and a string to describe the modlue.
33
#
34
reqlib_getOLSModuleEnable ()
35
{
36
    MODTYPE=$1
37
    MODSTR=$2
38
    MODDEF=$3
39
 
40
    MODDEF=`echo $MODDEF | tr '[A-Z]' '[a-z]'`
41
 
42
    printf "\n\n\n\n"
43
    printf "Will the $MODSTR module be enabled on this tier/node?\n"
44
 
45
    while [ 1 ]
46
    do
47
        case "$m_resp" in
48
 
49
        # Simple or Expert
50
        'y' | 'n')
51
            break
52
        ;;
53
        'q')
54
            exit 3;
55
        ;;
56
        *)
57
            m_resp=`ckstr -l 1 -d "$MODDEF" -p "(default: $MODDEF) [y,n,q=quit] :"`
58
            m_resp=`echo $m_resp | tr '[A-Z]' '[a-z]'`
59
        ;;
60
        esac
61
    done
62
 
63
    m_resp=`echo $m_resp | tr '[a-z]' '[A-Z]'`
64
    m_str="${MODTYPE}_ENABLED=$m_resp"
65
    eval $m_str
66
}
67
 
68
 
69
 
70
# Function to get the install type.
71
#
72
reqlib_getInstallType ()
73
{
74
    M_VAR=$1
75
    M_DEF=$2
76
 
77
    printf "\n\n\n\n"
78
    printf "Please enter the type of installation you would like,\n"
79
    printf "Note: s = SIMPLE install\n"
80
    printf "      e = EXPERT install\n"
81
    printf "      q = quit\n"
82
 
83
    while [ 1 ]
84
    do
85
        case "$m_resp" in
86
 
87
        # Simple or Expert
88
        's' | 'e')
89
            break
90
        ;;
91
        'q')
92
            exit 3;
93
        ;;
94
        *)
95
        m_resp=`ckstr -l 1 -d "$M_DEF" -p "(default: $M_DEF) [s,e,q=quit] :"`
96
        m_resp=`echo $m_resp | tr '[A-Z]' '[a-z]'`
97
        ;;
98
        esac
99
    done
100
 
101
    m_str="${M_VAR}=$m_resp"
102
    eval $m_str
103
 
104
    printf "\n\n\n\n"
105
    if [ "x$m_resp" = "xe" ]
106
    then
107
        printf "You have chosen an EXPERT installation.\n"
108
    else
109
        printf "You have chosen a SIMPLE installation.\n"
110
    fi
111
    printf "Please answer the following questions or accept the default paramaters.\n"
112
 
113
}
114
 
115
 
116
# ---------------------------------------------------------------------------------------
117
reqlib_testDBConnection ()
118
#
119
# this function tests the database connection based on the
120
# data entered by the user. Variables used are
121
# sid, user, passowrd and description.
122
#
123
# ---------------------------------------------------------------------------------------
124
{
125
    M_SID=$1
126
    M_USER=$2
127
    M_PASSWORD=$3
128
    M_DESC=$4
129
 
130
    printf "\n\n\n\n"
131
 
132
    # lets verify we can connect to the database
133
    #
134
    printf "$M_DESC\n"
135
 
136
    # do we even have access to sqlplus?
137
    #
138
    su - oracle -c ". .profile; sqlplus -? > /dev/null 2>&1"
139
    if [ "$?" -ne "0" ]
140
    then
141
        printf "Cannot connect to database $M_SID - check database before continuing.\n"
142
        exit 1;
143
    fi
144
 
145
    # we have access to sqlplus, lets try the database entered
146
    #
147
    rm -f /tmp/xx_lastsql.txt
148
    su - oracle -c ". .profile; sqlplus ${M_USER}/${M_PASSWORD}@${M_SID} <<EOF 1>/tmp/xx_lastsql.txt 2>&1
149
      select 1 from dual;
150
      exit
151
    EOF"
152
 
153
    if [ -f /tmp/xx_lastsql.txt ]
154
    then
155
        OK=`cat /tmp/xx_lastsql.txt | grep ORA- | wc -l`
156
        if [ "$OK" -ne "0" ]
157
        then
158
            printf "Cannot connect to database $M_SID - check database before continuing.\n"
159
            exit 1;
160
        else
161
            printf "Database connection OK.\n"
162
        fi
163
    else
164
        printf "Cannot connect to database $M_SID - check database before continuing.\n"
165
        exit 1;
166
    fi
167
}
168
 
169
 
170
# ---------------------------------------------------------------------------------------
171
reqlib_setVariableNoCheck ()
172
#
173
# ---------------------------------------------------------------------------------------
174
{
175
    M_VAR=$1
176
    M_DEF=$2
177
    M_DESC=$3
178
 
179
    printf "\n\n\n\n"
180
    printf "$M_DESC" 
181
    m_resp=`ckstr -d "$M_DEF" -p "(default: $M_DEF) [q=quit] :"`
182
    if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]
183
    then
184
        exit 3;
185
    fi
186
    m_str="${M_VAR}=$m_resp"
187
    eval $m_str
188
}
189
 
190
 
191
# ---------------------------------------------------------------------------------------
192
reqlib_setVariableNoCheck_lc ()
193
#
194
# ---------------------------------------------------------------------------------------
195
{
196
    M_VAR=$1
197
    M_DEF=$2
198
    M_DESC=$3
199
 
200
    printf "\n\n\n\n"
201
    printf "$M_DESC" 
202
    m_resp=`ckstr -d "$M_DEF" -p "(default: $M_DEF) [q=quit] :"`
203
    if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]
204
    then
205
        exit 3;
206
    fi
207
    m_resp=`echo $m_resp | tr '[A-Z]' '[a-z]'`
208
    m_str="${M_VAR}=$m_resp"
209
    eval $m_str
210
}
211
 
212
 
213
reqlib_setVariableNoCheck_uc ()
214
{
215
    M_VAR=$1
216
    M_DEF=$2
217
    M_DESC=$3
218
 
219
    printf "\n\n\n\n"
220
    printf "$M_DESC" 
221
    m_resp=`ckstr -d "$M_DEF" -p "(default: $M_DEF) [q=quit] :"`
222
    if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]
223
    then
224
        exit 3;
225
    fi
226
    m_resp=`echo $m_resp | tr '[a-z]' '[A-Z]'`
227
    m_str="${M_VAR}=$m_resp"
228
    eval $m_str
229
}
230
 
231
 
232
reqlib_getIntegerResponse ()
233
{
234
    M_VAR=$1
235
    M_DESC=$2
236
    M_DEF=$3
237
 
238
    printf "\n\n\n\n"
239
    printf "$M_DESC" 
240
    m_resp=`ckint -d "$M_DEF" -p "(default: $M_DEF) [q=quit] :"`
241
    if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]
242
    then
243
        exit 3;
244
    fi
245
    m_str="${M_VAR}=$m_resp"
246
    eval $m_str
247
}
248
 
249
 
250
# lets just test if the oracle config exists.
251
#
252
reqlib_testOratabConfig ()
253
{
254
    if [ ! -f "$REQLIB_ORA_TAB" ]
255
    then
256
        printf "ERROR: Failed to find file [$REQLIB_ORA_TAB].\n"
257
        printf "Check oracle installation before proceeding.\n"
258
        exit 1
259
    fi
260
}
261
 
262
 
263
reqlib_getRsOracleSidNoCheck ()
264
{
265
     reqlib_getRsOracleSid "$1" "$2" "YES"
266
}
267
 
268
 
269
# Function to get the report server Oracle SID.
270
#
271
reqlib_getRsOracleSid ()
272
{
273
    M_VAR=$1
274
    M_DEF=$2
275
    M_NOCHK=$3    # if empty then a check is done as per normal
276
 
277
    printf "\n\n\n\n"
278
    printf "Please enter the report server Oracle SID.\n"
279
 
280
    if [ -z "$M_NOCHK" ]; then
281
        m_SIDs=`egrep -v "#|\*" $REQLIB_ORA_TAB | cut -d: -f 1 | tr '[:space:]' | tr '[a-z] [A-Z]'`
282
        printf "The current list of active database SIDs on this machine include:\n"
283
        printf "$m_SIDs\n"
284
    fi
285
 
286
    m_resp=`ckstr -d "$M_DEF" -p "(default: $M_DEF) [q=quit] :"`
287
    if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]
288
    then
289
        exit 3;
290
    fi
291
 
292
    if [ -z "$M_NOCHK" ]; then
293
        foundIt=0
294
        if [ -n "$m_SIDs" ]
295
        then
296
            for i in $m_SIDs
297
            do
298
                m_Match=`echo $i | egrep "^$m_resp$" | wc -l`
299
                if [ "$m_Match" -eq "1" ]
300
                then
301
                    foundIt=1
302
                fi
303
            done
304
        fi
305
 
306
        if [ "$foundIt" -eq "0" ]
307
        then
308
            printf "\n\n\n<<<WARNING: [$m_resp] SID entered does not match any in current active list.>>>\n"
309
        fi
310
    else
311
        printf "\n\n\n<<<NOTE:  Make sure the SID [$m_resp] entered is defined in the tnsnames.ora file>>>\n"
312
    fi
313
 
314
    m_str="${M_VAR}=$m_resp"
315
    eval $m_str
316
}
317
 
318
 
319
# Function to get a generic Oracle SID.
320
#
321
reqlib_getOracleSid ()
322
{
323
    M_VAR=$1
324
    M_DEF=$2
325
    M_TYPE=$3
326
 
327
 
328
    # first we need to get a list of the current SIDs on this machine.
329
    #
330
    m_SIDs=`egrep -v "#|\*" $REQLIB_ORA_TAB | cut -d: -f 1 | tr '[:space:]' | tr '[a-z] [A-Z]'`
331
 
332
    printf "\n\n\n\n"
333
    printf "Please enter the $M_TYPE server Oracle SID,\n"
334
    printf "the current list of active database SIDs on this machine include:\n"
335
    printf "$m_SIDs\n"
336
 
337
    m_resp=`ckstr -d "$M_DEF" -p "(default: $M_DEF) [q=quit] :"`
338
    if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]
339
    then
340
        exit 3;
341
    fi
342
 
343
    # so the user has entered something..
344
 
345
    # convert what was entered to upper case
346
    m_resp=`echo $m_resp | tr '[:lower:]' '[:upper:]'`
347
 
348
    foundIt=0
349
    if [ -n "$m_SIDs" ]
350
    then
351
        for i in $m_SIDs
352
        do
353
            m_Match=`echo $i | egrep "^$m_resp$" | wc -l`
354
            if [ "$m_Match" -eq "1" ]
355
            then
356
                foundIt=1
357
            fi
358
        done
359
    fi
360
 
361
    if [ "$foundIt" -eq "0" ]
362
    then
363
        printf "\n\n\n<<<WARNING: [$m_resp] SID entered does not match any in current active list.>>>\n"
364
    fi
365
 
366
    m_str="${M_VAR}=$m_resp"
367
    eval $m_str
368
}
369
 
370
 
371
 
372
# ---------------------------------------------------------------------------------------
373
reqlib_getYesNoQuitResponse ()
374
#
375
# a simple function that determines yes/no respones
376
# we pass to the function:
377
#   1) the variable name as a string
378
#   2) the description displayed to the user
379
#   3) the default value
380
#
381
# ---------------------------------------------------------------------------------------
382
{
383
    m_VAR=$1
384
    m_DESC=$2
385
    m_DEFAULT=$3
386
 
387
    m_DEFAULT=`echo $m_DEFAULT | tr '[A-Z]' '[a-z]'`
388
 
389
    printf "\n\n\n\n"
390
    printf "$m_DESC\n"
391
 
392
    while [ 1 ]
393
    do
394
        case "$m_resp" in
395
 
396
        'y' | 'n')
397
            break
398
        ;;
399
        'q')
400
            exit 3;
401
        ;;
402
        *)
403
            m_resp=`ckstr -l 1 -d "${m_DEFAULT}" -p "(default: ${m_DEFAULT}) [y,n,q=quit] :"`
404
            m_resp=`echo $m_resp | tr '[A-Z]' '[a-z]'`
405
        ;;
406
        esac
407
    done
408
 
409
    m_resp=`echo $m_resp | tr '[a-z]' '[A-Z]'`
410
    m_str="${m_VAR}=$m_resp"
411
    eval $m_str
412
}
413
 
414
 
415
# Function to get proxy peer hostname.
416
#
417
reqlib_getHostname ()
418
{
419
    m_VAR=$1
420
    m_DESC=$2
421
    m_DEFAULT=$3
422
 
423
    printf "\n\n\n\n"
424
    printf "$m_DESC\n"
425
 
426
    m_resp=`ckstr -d "${m_DEFAULT}" -p "(default: ${m_DEFAULT}) [q=quit] :"`
427
    if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]
428
    then
429
        exit 3;
430
    fi
431
 
432
    # lets test to see if the host is contactable
433
    #
434
    printf "\n"
435
    # lets ping the host with 5 sec timeout.
436
    /usr/sbin/ping $m_resp 5
437
    retVal=$?
438
 
439
    if [ $retVal != 0 ]
440
    then
441
        printf "WARNING: Host [$m_resp] not contactable, ENSURE you check the network config.\n"
442
    fi
443
 
444
    m_str="${m_VAR}=$m_resp"
445
    eval $m_str
446
}
447
 
448
 
449
# ---------------------------------------------------------------------------------------
450
reqlib_setProxyClientConnectionType ()
451
#
452
#    This function asks the user to select the proxy client connection type.
453
#
454
#    It assumes the input parameters of:
455
#
456
#    1.  connection type variable name
457
#    2.  conection type descriptive string variable name
458
#    3.  description presented to the user
459
#    4.  the currently set default value.
460
#
461
#    Currently the user can only select from two types of connections these include:
462
#    1. IPMS
463
#    2. RPC
464
#   
465
# ---------------------------------------------------------------------------------------
466
{
467
    m_CONN_TYPE=$1
468
    m_CONN_TYPE_STR=$2
469
    m_DESC=$3
470
    m_DEFAULT=$4
471
 
472
    m_DEFAULT=`echo $m_DEFAULT | tr '[A-Z]' '[a-z]'`
473
 
474
    printf "\n\n\n\n"
475
    printf "$m_DESC\n"
476
    printf "Note: i = IPMS proxy client connection type\n"
477
    printf "      r = RPC proxy client connection type\n"
478
    printf "      q = quit\n"
479
 
480
    while [ 1 ]
481
    do
482
        case "$m_resp" in
483
 
484
        # ipms or rpc
485
        'i' | 'r')
486
            break
487
        ;;
488
        'q')
489
            exit 3;
490
        ;;
491
        *)
492
        m_resp=`ckstr -l 1 -d "$m_DEFAULT" -p "(default: $m_DEFAULT) [i,r,q=quit] :"`
493
        m_resp=`echo $m_resp | tr '[A-Z]' '[a-z]'`
494
        ;;
495
        esac
496
    done
497
 
498
    m_str="${m_CONN_TYPE}=$m_resp"
499
    eval $m_str
500
 
501
    if [ "x$m_resp" = "xi" ]
502
    then
503
        m_str="${m_CONN_TYPE_STR}=IPMS"
504
    else
505
        m_str="${m_CONN_TYPE_STR}=RPC"
506
    fi
507
    eval $m_str
508
 
509
}
510
 
511
 
512
# ---------------------------------------------------------------------------------------
513
reqlib_updateFileTag ()
514
#
515
#    This function is used to update a tag in a file with a new string, globally.
516
#
517
#    It assumes the input parameters of:
518
#
519
#    1.  the location of the file to be updated
520
#    2.  the tag to replaced
521
#    3.  the value to be substitued
522
#
523
# ---------------------------------------------------------------------------------------
524
{
525
    m_file=$1
526
    m_tag=$2
527
    m_nStr=$3
528
 
529
    if [ "x$m_nStr" = "x" ]
530
    then
531
        m_tStr=""
532
    else
533
        m_tStr=`echo $m_nStr | sed 's/\//\\\\\//g'`
534
    fi
535
 
536
 
537
    echo "Updating file [$m_file] tag [$m_tag] with string [$m_nStr] ..."
538
 
539
 
540
    # in here we need to inform the pkg database that we have
541
    # updated the file from the original
542
    #
543
    installf -c none $PKGINST $m_file f
544
 
545
 
546
    sed "s/<$m_tag>/$m_tStr/g" $m_file > /tmp/xx.tmp
547
    if [ $? -eq 0 ]
548
    then
549
 
550
        cp /tmp/xx.tmp $m_file
551
        rm /tmp/xx.tmp
552
 
553
        echo "Updating file [$m_file] tag [$m_tag] completed."
554
 
555
    else
556
 
557
        echo "sed command failed, file [$m_file] not updated."
558
 
559
    fi
560
 
561
 
562
    # lets inform the pkg database that files have been updated.
563
    #
564
    installf -f $PKGINST
565
 
566
}
567
 
568
 
569
# ---------------------------------------------------------------------------------------
570
reqlib_updateFileTag2 ()
571
#
572
#    This function is used to update a tag in a file with a new string, globally.
573
#
574
#    It assumes the input parameters of:
575
#
576
#    1.  the location of the file to be updated
577
#    2.  the tag to replaced
578
#    3.  the value to be substitued
579
#
580
# ---------------------------------------------------------------------------------------
581
{
582
    m_file=$1
583
    m_tag=$2
584
    m_nStr=$3
585
 
586
    if [ "x$m_nStr" = "x" ]
587
    then
588
        m_tStr=""
589
    else
590
        m_tStr=`echo $m_nStr | sed 's/\//\\\\\//g'`
591
    fi
592
 
593
    sed "s/$m_tag/$m_tStr/g" $m_file > /tmp/xx.tmp
594
    if [ $? -eq 0 ]
595
    then
596
        cp /tmp/xx.tmp $m_file
597
        rm /tmp/xx.tmp
598
    else
599
        echo "sed command failed, file [$m_file] not updated."
600
    fi
601
}
602
 
603
 
604
 
605
# ---------------------------------------------------------------------------------------
606
reqlib_updateAllFileTags ()
607
#
608
#    This function is used to update tags in a file with a new string, globally.
609
#
610
#    It assumes the input parameters of:
611
#
612
#    1.    the location of the file to be updated
613
#    2 ... A number of args of type A=B where string A in File will be replaced by B
614
#
615
# ---------------------------------------------------------------------------------------
616
{
617
    m_file=$1
618
    shift
619
 
620
    sedScript="/tmp/updateAllFileTags.sed.$$"
621
 
622
    echo "Updating Tags in file [$m_file] as follows"
623
    while [ -n "$1" ] 
624
    do
625
        m_tag=`echo $1 | sed -e 's|^ *\(.*\)=.*$|\1|' -e 's| *$||'`
626
        m_rep=`echo $1 | sed -e 's|^.*= *\(.*\)$|\1|' -e 's| *$||'`
627
        echo "        [$m_tag] = [$m_rep]"
628
        echo "s|<$m_tag>|$m_rep|g" >> $sedScript
629
        shift
630
    done
631
 
632
    # in here we need to inform the pkg database that we have
633
    # updated the file from the original
634
    #
635
    installf -c none $PKGINST $m_file f
636
 
637
 
638
    eval sed -f $sedScript $m_file > /tmp/xx.tmp
639
    if [ $? -eq 0 ]
640
    then
641
 
642
        cp /tmp/xx.tmp $m_file
643
        rm /tmp/xx.tmp
644
 
645
        echo "Updating Tags for file [$m_file] completed."
646
 
647
    else
648
 
649
        echo "sed command failed, file [$m_file] not updated."
650
 
651
    fi
652
    rm $sedScript
653
 
654
    # lets inform the pkg database that files have been updated.
655
    #
656
    installf -f $PKGINST
657
 
658
}
659
 
660
 
661
# ---------------------------------------------------------------------------------------
662
reqlib_cleanLocalFiles ()
663
#
664
#   this function is used to clean any new local.profile, local.login
665
#   and local.cshrc files that are created by the system when you create
666
#   a new user. we never use these files.
667
#
668
#    It assumes the input parameters of:
669
#
670
#    1.  the location of the user's home directory
671
#
672
# ---------------------------------------------------------------------------------------
673
{
674
    m_HOMEDIR=$1
675
 
676
    if [ "x$m_HOMEDIR" = "x" ]
677
    then
678
        echo "ERROR: incorrect number of parameters supplied to reqlib_cleanLocalFiles () function."
679
        exit 1;
680
    fi
681
 
682
    rm -f $m_HOMEDIR/local.profile
683
    rm -f $m_HOMEDIR/local.login
684
    rm -f $m_HOMEDIR/local.cshrc
685
}
686
 
687
 
688
 
689
# ---------------------------------------------------------------------------------------
690
reqlib_getStrWithSpacesResponse ()
691
#
692
# ---------------------------------------------------------------------------------------
693
{
694
    M_VAR=$1
695
    M_DESC=$2
696
    M_DEF=$3
697
 
698
    printf "\n\n\n\n"
699
    printf "$M_DESC" 
700
    m_resp=`ckstr -d "$M_DEF" -r ".*" -p "(default: $M_DEF) [q=quit] :"`
701
    if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]
702
    then
703
        exit 3;
704
    fi
705
    m_str="${M_VAR}=\"$m_resp\""
706
    eval $m_str
707
}
708
 
709
 
710
# ---------------------------------------------------------------------------------------
711
reqlib_getRsIDatasrc ()
712
#
713
# Function to get the report server data source interface type.
714
#
715
# ---------------------------------------------------------------------------------------
716
{
717
    M_VAR=$1
718
    M_DESC=$2
719
 
720
    printf "\n\n\n\n"
721
    printf "$M_DESC\n"
722
 
723
    m_resp=`ckitem -o -l "Data Source Type List" "oracle9i - Oracle 9i" "mssqlserver2000 - MS SQLServer 2000"`
724
    if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]
725
    then
726
        exit 3;
727
    fi
728
 
729
    m_str="${M_VAR}=$m_resp"
730
    eval $m_str
731
 
732
    if [ "x$m_resp" = "xoracle9i" ]
733
    then
734
 
735
        # lets just be sure oracle exists on this machine
736
        #
737
        reqlib_testOratabConfig
738
 
739
    fi
740
}
741
 
742
 
743
# ---------------------------------------------------------------------------------------
744
reqlib_getListEntry ()
745
#
746
# Function to get a list item selected by the user.
747
# The list is provided in a simple text file
748
# with the format:
749
#
750
# item - description
751
# 
752
# if the user enters a 'q' or 'Q' the funtion exits.
753
#
754
# ---------------------------------------------------------------------------------------
755
{
756
 
757
    M_VAR=$1
758
    M_DESC=$2
759
    M_IFILE=$3
760
    M_SORT=$4
761
 
762
    printf "\n\n\n\n"
763
    printf "$M_DESC\n"
764
 
765
    if [ -f "./$M_IFILE" ]
766
    then
767
        _file="./$M_IFILE"
768
    else
769
        _file="$INFODIR/$M_IFILE"
770
    fi
771
 
772
 
773
    if [ "x$M_SORT" = "xNO_SORT" ]
774
    then
775
        _sortOption="-n"
776
    else
777
        _sortOption=""
778
    fi
779
 
780
 
781
    m_resp=`ckitem -o -f $_file $_sortOption`
782
    if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]
783
    then
784
        exit 3;
785
    fi
786
 
787
    m_str="${M_VAR}=$m_resp"
788
    eval $m_str
789
}
790
 
791
 
792
# ---------------------------------------------------------------------------------------
793
reqlib_testDBConnection2 ()
794
#
795
# this function tests the database connection based on the
796
# data entered by the user. 
797
# 
798
# The input Variables used are:
799
#
800
#     datasrc,
801
#     sid, 
802
#     user, 
803
#     passowrd
804
#     description.
805
#
806
# ---------------------------------------------------------------------------------------
807
{
808
    M_DATASRC=$1
809
    M_SID=$2
810
    M_USER=$3
811
    M_PASSWORD=$4
812
    M_DESC=$5
813
 
814
 
815
 
816
    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/easysoft/lib
817
    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/easysoft/oob/client
818
    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/easysoft/unixODBC/lib
819
    export LD_LIBRARY_PATH
820
 
821
 
822
 
823
    printf "\n\n\n\n"
824
 
825
    # lets verify we can connect to the database
826
    #
827
    printf "$M_DESC\n"
828
 
829
    # we know what to do with various datasrc types
830
    #
831
    if [ "x$M_DATASRC" = "xoracle9i" ]
832
    then
833
 
834
        # do we even have access to sqlplus?
835
        #
836
        su - oracle -c ". .profile; sqlplus -? > /dev/null 2>&1"
837
        if [ "$?" -ne "0" ]
838
        then
839
            printf "Cannot connect to database $M_SID - check database before continuing.\n"
840
            exit 1;
841
        fi
842
 
843
        # we have access to sqlplus, lets try the database entered
844
        #
845
        rm -f /tmp/xx_lastsql.txt
846
        su - oracle -c ". .profile; sqlplus ${M_USER}/${M_PASSWORD}@${M_SID} <<EOF 1>/tmp/xx_lastsql.txt 2>&1
847
          select 1 from dual;
848
          exit
849
        EOF"
850
 
851
        if [ -f /tmp/xx_lastsql.txt ]
852
        then
853
            OK=`cat /tmp/xx_lastsql.txt | grep ORA- | wc -l`
854
            if [ "$OK" -ne "0" ]
855
            then
856
                printf "Cannot connect to database $M_SID - check database before continuing.\n"
857
                exit 1;
858
            else
859
                printf "Database connection OK.\n"
860
            fi
861
        else
862
            printf "Cannot connect to database $M_SID - check database before continuing.\n"
863
            exit 1;
864
        fi
865
 
866
    elif [ "x$M_DATASRC" = "xmssqlserver2000" ]
867
    then
868
 
869
        # here we test the SQL connection
870
 
871
        myEasySoftLoc="/usr/local/easysoft"
872
        myPinger="$myEasySoftLoc/bin/oobpingd"
873
        if [ -d "$myEasySoftLoc" ]
874
        then
875
 
876
            if [ -x "$myPinger" ]
877
            then
878
 
879
                $myPinger -d "DSN=$M_SID;UID=$M_USER;PWD=$M_PASSWORD" > /dev/null 2>&1
880
                if [ $? -ne 0 ]
881
                then
882
 
883
                    printf "Cannot connect to database $M_SID - check database before continuing.\n"
884
                    exit 1;
885
 
886
                else
887
 
888
                    printf "Database connection OK.\n"
889
 
890
                fi
891
 
892
            else
893
 
894
                printf "ERROR cannot locate easysoft tool [$myPinger].\n"
895
                exit 1;
896
 
897
            fi
898
 
899
        else
900
 
901
            printf "ERROR cannot locate easysoft default installation location [$myEasySoftLoc].\n"
902
            exit 1;
903
 
904
        fi
905
 
906
 
907
    else
908
 
909
        echo "\n\n*** Database connection test for datasource [$M_DATASRC] - NOT SUPPORTED (yet!). ***"
910
 
911
    fi
912
 
913
}
914
 
915
 
916
# EOF, done.
917