#!/bin/sh
echo "fsserver Shell de ativacao do servidor FileShare"
echo " "
echo "COBOLware 7.0"
echo "Copyright (C) 1984-2025 COBOLware Services Ltda."
echo " "
if test -z "$COBDIR"
   then if test -f /opt/lib/cobol/ADISCTRL
           then CWD=/opt/lib/cobol
           else if test -f /opt/cobol/ADISCTRL
                   then CWD=/opt/cobol
                   else if test -f /cobol/ADISCTRL
                           then CWD=/cobol
                           else if test -f /opt/cobol/cobdir/ADISCTRL
                                   then CWD=/opt/cobol/cobdir
                                   else if test -f /home/cob41/ADISCTRL
                                           then CWD=/home/cob41
                                        fi
                                fi
                        fi
                fi
        fi
        COBDIR=$CWD
        LD_LIBRARY_PATH=/lib:$COBDIR/coblib
        PATH=$COBDIR:$LD_LIBRARY_PATH:$PATH
        export COBDIR LD_LIBRARY_PATH PATH
fi
if test -z "$1"
   then echo Formato: fsserver IP [Diretorio de dados] [Porta]
   else CCITCP2=$1
        export CCITCP2
        if test -z "$3"
           then FSPORT=86
           else FSPORT=$3
        fi
        grep -i 'mfcobol' /etc/services>/dev/null
        if test "$?" = "1"
           then echo 'mfcobol         '$FSPORT'/udp                          # Micro Focus FileShare'>> /etc/services
        fi
        if test -z "$FSSERVER"
           then FSSERVER=cobshare
                export FSSERVER
        fi
        if test -z "$FSCOMMS"
           then FSCOMMS=ccitcp
                export FSCOMMS
        fi
        if test "$FSCOMMS" = "ccitcp"
           then ccitcp2 -n $CCITCP2 & echo CCITCP2 ativado em background.
        fi
        if test -z "$FSTO"
           then FSTO="99999"
                export FSTO
        fi
        if test -z "$PWDIR"
           then if ! test -z "$COBOLWARE"
                then PWDIR=$COBOLWARE
                else PWDIR=`pwd`
                     if test -f /opt/lib/COBOLware/COBOLware.lbr
                        then PWDIR=/opt/lib/COBOLware
                        else if test -f /opt/COBOLware/COBOLware.lbr
                                then PWDIR=/opt/COBOLware
                                else if test -f /COBOLware/COBOLware.lbr
                                        then PWDIR=/COBOLware
                                     fi
                             fi
                     fi
                fi
        fi
        if ! test -z "$2"
             then cd $2
        fi
        FSDIR=`pwd`
        COBSHARE=$FSDIR/$FSSERVER.dat
        export COBSHARE
        if test -f $FSDIR/fsscreen.lst
           then rm $FSDIR/fsscreen.lst
        fi
        if ! test -f $COBSHARE
           then mkdir $FSDIR/$FSSERVER
                fs -d $COBSHARE -l $FSDIR/$FSSERVER/journal
           else if test -f $FSDIR/$FSSERVER/journal.L99
                   then mv $FSDIR/$FSSERVER/journal.L99 /journal.L01
                        rm -rf $FSDIR/$FSSERVER/journal.*
                        mv /journal.L01 $FSDIR/$FSSERVER 
                fi
        fi
        if ! test -f $PWDIR/password
           then if test -f $PWDIR/password.fs
                   then mv $PWDIR/password.fs $PWDIR/password
                fi
        fi
        if ! test -f $PWDIR/password
           then fs -d:$COBSHARE -s $FSSERVER -t $FSTO
           else fs -d:$COBSHARE -s $FSSERVER -pf $PWDIR/password -t $FSTO -b &
        fi
fi
