#!/bin/sh

##############################################################################
# Script : main.inc
# Author : Roy Westfall
# Copyright : 2000 Zeh Graphic Systems, Inc.  All rights reserved.
# Purpose: ZEHRaster Plus shell include file for UNIX
##############################################################################

# getString: get translated string from file $PROMPT_TXT
getString()
{
    key=$1
    shift
    data=`$GET_STRING $key $PROMPT_TXT $*`
    [ -z "$data" ] && data="(Untranslatable String $key)"
    echo $data
}

#fail() - print an error message and exit
fail()
{
    getString 1>&2 $*
    exit 1
}


#os: get os name
getOs()
{
    os=`uname`
    case $os in
        SunOS )
            os=solaris
            ;;
        IRIX* ) 
            os=irix
            ;;
        HP-UX )
            os=hpux
            ;;
        AIX )
            os=aix
            ;;
        Linux )
            os=linux
            ;;
        * )
            os=unknown-system-type
            ;;
    esac
    echo $os
    return 0
}

#checkFile validate existence of file, exit if not there
checkFile()
{
    file=$1
    [ -f "$file" ] && return 0
    
    [ -n "$PROMPT_TXT" ] && fail ERROR_FILE $file
    echo "File [$file] not found."
    exit 1
}

#getLanguage - prompt for the installation language
getLanguage()
{
    lang_dir_list=`ls international`
    language=`ls international | grep -i English`
    choice="-"

    echo 1>&2
    echo 1>&2
    echo 1>&2
    echo 1>&2 $LINE
    echo "Select the language for this installation from the choices below: [$language]" | $FMT 1>&2

    echo 1>&2
    
    index=0
    for i in $lang_dir_list
    do
        index=`expr $index + 1`
        echo 1>&2 "   $index.     $i "
    done
    echo 1>&2 $LINE


    while [ "$choice" = "-" ]
    do

        read choice
        echo 1>&2

        if [ -n "$choice" ]
        then
            x=`echo $choice | sed s/[0-9]//g`
            if [ -n "$x" ]
            then
                choice=-
            else
                if [ $choice -lt 1 -o $choice -gt $index ]
                then
                    choice=-
                fi
            fi
            if [ "$choice" = "-" ]
            then
                echo 1>&2 "The selection was not valid."
                echo 1>&2 "Please select one of the available choices."
            fi
        fi
    done

    if [ -n "$choice" ]
    then
        index=0
        for i in $lang_dir_list
        do
            index=`expr $index + 1`
            if [ $index -eq $choice ] 
            then
                language=$i
                break
            fi
        done
    fi

    echo $language

    return 0
}


# selectOption: Ask user to enter a number that is valid, or enter nothing
# for the default
selectOption()
{
    ERROR_SELECT=`getString ERROR_SELECT | $FMT`

    num="$1"
    have_default="$2"
    choice="-"

    while [ "$choice" = "-" ]
    do
        read choice
 
        [ -z "$choice" -a \( ! "$have_default" = "true" \) ] && choice="-"
        

        if [ "$choice" != "-" ]
        then
            x=`echo $choice | sed 's/[0-9]//g'`
            [ -n "$x" ] && choice="-"
        fi
			
        if [ -n "$choice" -a "$choice" != "-" ] 
        then
            if [ $choice -lt 1 -o $choice -gt $num ]
            then
                choice="-"
            fi
        fi

        if [ "$choice" = "-" ]
        then
            echo 1>&2 "$ERROR_SELECT"
        fi
    done
 
    [ -n "$choice" ] && echo $choice
    
    return 0
}

# getChoice: prompt the user with a list of choices, ask for the valid input
getChoice()
{
    default=$1
    shift
    prompt="$1"
    shift
    result=$default
    choice=""
 
    echo 1>&2
    echo 1>&2
    echo 1>&2
    echo 1>&2 $LINE
    echo "$prompt " | $FMT 1>&2
    [ -n "$default" ] && echo 1>&2 "[${default}]"

    echo 1>&2
 
    index=0
    for i
    do
        if [ -n "$i" ]
        then
            index=`expr $index + 1`
            echo 1>&2 "   $index.     $i "
        fi
    done
 
    echo 1>&2 $LINE
    
    have_default="false"
    [ -n "$default" ] && have_default="true"

    choice=`selectOption $index $have_default`
 
    if [ -n "$choice" ]
    then
        index=0
        for i
        do
            if [ -n "$i" ]
            then
                index=`expr $index + 1`
                if [ "$index" = "$choice" ]
                then
                    result=$i
                fi
            fi
 
        done
    fi
 
    echo "$result"
 
    return 0
 
}

# getQueueName - prompt for and validate the name of a queue
getQueueName()
{
    echo 1>&2
    echo 1>&2
    echo 1>&2
    echo 1>&2 $LINE
    getString PROMPT_QUEUE_NAME | $FMT 1>&2
    echo 1>&2 $LINE

    queue=
    while [ -z "$queue" ]
    do
        read queue
        echo 1>&2

        if [ -z "$queue" ]
        then
            getString ERROR_ENTER | $FMT 1>&2
        else
            # cant have spaces or _
            test=`echo $queue | sed 's/_/ /g' | sed 's/ //g'`
            if [ "$test" != "$queue" ]
            then
                getString ERROR_QUEUE_NAME | $FMT 1>&2
                queue=
            fi
        fi

        if [ -n "$queue" ]
        then
            for i 
            do
                if [ "$queue" = "$i" ]
                then
                    getString ERROR_EXIST_QUEUE | $FMT 1>&2
                    queue=
                fi
            done
        fi
    done

    echo $queue

    return 0

}


# updatePrinter - prompt for settings and add or modify printer
updatePrinter()
{
    update_type=$1
    
    regfile=$ZRPLUS_DIR/prg/zplus.reg
    zprts=$ZRPLUS_DIR/prg/bin/zprts.exe
    zreg=$ZRPLUS_DIR/prg/bin/zreg.exe

    printer_list=`$zprts $regfile`

    if [ "$update_type" = "add" ] 
    then
        lp_queue=`getQueueName $printer_list`
        default_rotation=
        default_quality=
        default_unit=
        default_model=
    else
        if [ -z "$printer_list" ]
        then
            getString ERROR_NO_PRINTER | $FMT 1>&2
            return 1
        fi
        prompt=`getString PROMPT_SELECT_QUEUE | $FMT`
        lp_queue=`getChoice "" "$prompt" $printer_list` 1>&2
        default_rotation=`$zreg get $regfile "Printers.$lp_queue" Rotation`
        default_quality=`$zreg get $regfile "Printers.$lp_queue" Quality`
        default_unit=`$zreg get $regfile "Printers.$lp_queue" Unit`
        default_model=`$zreg get $regfile "Printers.$lp_queue" Model`
    fi

    # get the printer model - can't call getChoice, model names have spaces
    
    if [ -z "$default_model" ]
    then
        default_index=`$zreg get $regfile PrinterModelsList default`
        default_model=`$zreg get $regfile PrinterModelsList $default_index`
    fi

    echo 1>&2
    echo 1>&2
    echo 1>&2
    echo 1>&2 $LINE
    getString PROMPT_PRINTER_MODEL | $FMT 1>&2
    echo 1>&2 "[$default_model]"

    index=1
    model_count=
    while model=`$zreg get $regfile PrinterModelsList $index`
    do
        model_count=$index
        echo 1>&2 "   $index.     $model "
        index=`expr $index + 1`
    done
    echo 1>&2 $LINE
    
    model=$default_model
    choice=`selectOption $model_count true`
    [ -n "$choice" ] && model=`$zreg get $regfile PrinterModelsList $choice`

    # get rotation
    prompt=`getString PROMPT_ROTATION | $FMT`
    [ -z "$default_rotation" ] && default_rotation=0
    rotation=`getChoice "$default_rotation" "$prompt" 0 90`


    # get print quality
    noq=`$zreg get $regfile "PrinterModel.$model" DisableQualitySelection`
    if [ "$noq" != "Yes" ]
    then
        q1=`getString PRINT_QUALITY_1`
        q2=`getString PRINT_QUALITY_2`
        q3=`getString PRINT_QUALITY_3`
        
        [ -z "$default_quality" ] && default_quality=$q1

        prompt=`getString PROMPT_PRINT_QUALITY | $FMT`

        quality=`getChoice "$default_quality" "$prompt" "$q1" "$q2" "$q3"`
    else
        quality=
    fi
    
    u1=`getString UNIT_1`
    u2=`getString UNIT_2`
    [ -z "$default_unit" ] && default_unit=$u1

    prompt=`getString PROMPT_UNITS`
    unit=`getChoice "$default_unit" "$prompt" "$u1" "$u2"`

    #add entries to registry file
    echo 1>&2
    echo 1>&2
    echo 1>&2
    echo 1>&2 $LINE
    getString PROMPT_UPDATE_FILE | $FMT 1>&2
    echo 1>&2 $LINE

    $zreg set "$regfile" "Printers.$lp_queue" Model "$model" || return 1
    $zreg set "$regfile" "Printers.$lp_queue" Rotation "$rotation" || return 1
    $zreg set "$regfile" "Printers.$lp_queue" Quality "$quality" || return 1
    $zreg set "$regfile" "Printers.$lp_queue" Unit "$unit" || return 1

    echo 1>&2
    echo 1>&2
    echo 1>&2
    echo 1>&2 $LINE
    if [ "$update_type" = add ]
    then
        getString PROMPT_PRINTER_ADDED $lp_queue 1>&2
    else
        getString PROMPT_PRINTER_MODIFIED $lp_queue 1>&2
    fi
    echo 1>&2 $LINE
    

    return 0

}


deletePrinter()
{
    regfile=$ZRPLUS_DIR/prg/zplus.reg
    zprts=$ZRPLUS_DIR/prg/bin/zprts.exe
    zreg=$ZRPLUS_DIR/prg/bin/zreg.exe

    # get list of printers
    printers=`$zprts $regfile`
    if [ -z "$printers" ]
    then
        getString ERROR_NO_PRINTER | $FMT 1>&2
        return 1
    fi

    prompt=`getString PROMPT_DELETE_CHOICE | $FMT`
    choice=`getChoice "" "$prompt" $printers`
    
    prompt=`getString PROMPT_CONFIRM_DELETE $choice | $FMT`
    
    confirm=`getChoice "$YES" "$prompt" "$YES" "$NO"`
    if [ "$confirm" = "$YES" ] 
    then
        $zreg delete $regfile "Printers.$choice"
        
        echo 1>&2
        echo 1>&2
        echo 1>&2 $LINE
        getString PROMPT_PRINTER_DELETED $choice | $FMT 1>&2
        echo 1>&2 $LINE
    fi
    return 0
}

managePrinterMain()
{
    add=`getString ADD_PRINTER`
    modify=`getString MODIFY_PRINTER`
    delete=`getString DELETE_PRINTER`

    printers=`$ZRPLUS_DIR/prg/bin/zprts.exe $ZRPLUS_DIR/prg/zplus.reg`
    if [ -z "$printers" ]
    then
        choice=$add
    else
        prompt=`getString PROMPT_MANAGE_PRINTER`
        choice=`getChoice "" "$prompt" "$add" "$modify" "$delete"`
    fi 

    case $choice in
        "$add")
            updatePrinter add || return 1
            ;;
        "$modify")
            updatePrinter change || return 1
            ;;
        "$delete")
            deletePrinter || return 1
            ;;
        *)
            return 1
            ;;
    esac

    return 0
}


checkLicense()
{
    checkFile $CHECK_LICENSE 

    prompt=`getString PROMPT_ENTER_LICENSE | $FMT`
    exit_prompt=`getString PROMPT_EXIT_INSTALL | $FMT`
    
    echo 1>&2
    echo 1>&2
    echo 1>&2

    echo $LINE 1>&2
    while true
    do
    {
        echo "$prompt" 1>&2
        echo 1>&2
        echo "$exit_prompt" 1>&2
        echo $LINE 1>&2

        read license
        echo 1>&2

        [ -z "$license" ] && return 1

        if $CHECK_LICENSE $license > /dev/null 2>&1
        then
            echo $license
            return 0
        fi

        getString ERROR_INVALID_LICENSE | $FMT 1>&2
        echo 1>&2
    } 
    done
}
 
 
#getDir - prompt for, create, and validate a directory
getDir()
{
    prompt=$1
    default=$2

    path_error=`getString ERROR_PATH | $FMT`

    echo 1>&2
    echo 1>&2
    echo 1>&2
    
    echo 1>&2 $LINE
    echo "$prompt" | $FMT 1>&2
    [ -n $default ] && echo 1>&2 "[$default]"
    echo 1>&2 $LINE

    done=
    while [ -z "$dir" ]
    do
        read dir
        echo 1>&2
        
        [ -z "$dir" ] && dir="$default"
        
        if [ -n "$dir" ]
        then
            mkdir -p $dir 2>/dev/null
            if [ -d $dir ] 
            then
                done=yes
            else
                getString ERROR_CREATE_DIR $dir | $FMT 1>&2
                dir=
            fi
        fi

        # make sure the directory is writeable
        
        if [ -n "$dir" ]
        then
            if [ ! -w $dir ]
            then
                getString ERROR_WRITE_PER "$dir" | $FMT 1>&2
                dir=
            fi
        fi
        
        [ -z "$dir" ] && echo 1>&2 $path_error

    done
        
    (cd $dir; pwd)

    return 0
}

#getTempDir - get temp dir and make sure it can be made writeable by all
getTempDir()
{
    permissions=
    while [ "$permissions" != "www" ]
    do
        temp_dir=`getDir "$1" "$2"`
        chmod 777 "$temp_dir" 2>/dev/null
        permissions=`/bin/ls -ld "$temp_dir" | \
            awk '{ print $1 }' | \
            sed 's/[^w]//g'`
        if [ "$permissions" != "www" ]
        then
            getString ERROR_WRITE_DIR "$temp_dir" | $FMT 1>&2
        fi
    done
    
    (cd $temp_dir; pwd)

    return 0
}

#createDir - create a target directory
createDir()
{
    echo "creating directory $1"
    mkdir -p $1
    chmod 755 $1
}

#installFile - install a single file/directory
installFile()
{
    source=$1
    target=$2
    mask=$3
    [ -z "$mask" ] && mask=0644
    echo "$INSTALL_IMAGE -m $mask -i $1 $2"
    $INSTALL_IMAGE -m $mask -i $1 $2
}

#copyFile - use copy/mkdir to install a single file/directory
copyFile()
{
    source=$1
    dest=$2
    type=$3
    [ -z "$type" ] && type=file

    case $type in
        exe)
            mask=0755
            text="executible file"
            ;;
        *)
            mask=0644
            text=$type
    esac
        
    inas=in
    [ -d "$dest" ] || inas=as

    echo "installing $text $source $inas $dest"

    cp -f "$source" "$dest"
            
    if [ -d "$dest" ]
    then
        source=`basename $source`
        chmod $mask "$dest/$source"
    else
        chmod $mask "$dest"
    fi
}

#installDir - install all the files in a given directory
installDir()
{
    source_dir=$1
    target_dir=$2

    (
        cd $source_dir
        for i in `ls`
        do
            if [ -d $i ] 
            then
                :
            else
                type=file
                [ -x $i ] && type=exe
                $INSTALL $i $target_dir $type
            fi
        done
    )
    
}

#installFiles - do the actual copying of files
installFiles()
{
    echo $LINE
    getString PROMPT_INSTALL_FILE | $FMT

    install_dir=$1
    install_type=$2

    createDir $install_dir/prg
    createDir $install_dir/prg/bin
    createDir $install_dir/prg/examples
    createDir $install_dir/doc
    createDir $install_dir/doc/images
    createDir $install_dir/locale
    createDir $install_dir/scripts
    
    echo

    installDir prg/$OSNAME/common $install_dir/prg
    installDir prg/$OSNAME/$install_type $install_dir/prg
    installDir prg/$OSNAME/bin/common $install_dir/prg/bin
    installDir prg/$OSNAME/bin/$install_type $install_dir/prg/bin
    installDir prg/shared/examples $install_dir/prg/examples
    installDir prg/shared $install_dir/prg
    [ $install_type = cgm ] && installDir cgmfonts $install_dir/prg
    
    installDir international/$LANGUAGE/doc $install_dir/doc
    installDir international/$LANGUAGE/doc/images $install_dir/doc/images

    $INSTALL scripts/manage_printer.sh $install_dir exe
    $INSTALL scripts/main.inc $install_dir/scripts file

    $INSTALL international/$LANGUAGE/locale/$LANGUAGE.txt \
        $install_dir/locale file
    $INSTALL international/$LANGUAGE/locale/prompt.txt \
        $install_dir/locale file
    $INSTALL international/$LANGUAGE/locale/zplus.qm.$install_type \
        $install_dir/locale/zplus.qm file

}

#getBrowser - find and verify an html browser
getBrowser()
{
    browser_list="netscape iexplorer"

    browser=
    dir_list=`echo $PATH | sed 's/:/ /g'`
    for dir in $dir_list
    do
        if [ -z "$browser" -a -d "$dir" ]
        then
            for b in $browser_list
            do
                if [ -z "$browser" -a -x "$dir/$b" ]
                then
                    browser="$dir/$b"
                fi
            done
        fi
    done
      
    response=$NO
    if [ -n "$browser" ] 
    then
        prompt=`getString PROMPT_FIND_DEFAULT_BROWSER "$browser" | $FMT`
        response=`getChoice "$YES" "$prompt" "$YES" "$NO"`
    fi

    if [ "$response" = "$NO" ] 
    then
        echo 1>&2
        echo 1>&2 $LINE
        getString PROMPT_ENTER_BROWSER | $FMT 1>&2
        echo 1>&2 $LINE
        read browser
        echo 1>&2
        while [ ! \( -z "$browser" -o -x "$browser" \) ]
        do
            getString PROMPT_REENTER_BROWSER | $FMT 1>&2
            read browser
            echo 1>&2
        done
    fi

    echo "$browser"
    return 0
}

restorePrinters()
{
    old_regfile=$TEMP_DIR/save.reg
    new_regfile=$ZRPLUS_DIR/prg/zplus.reg

    zreg="$ZRPLUS_DIR/prg/bin/zreg.exe"

    printers=`$zreg list $old_regfile -k Printers`
    
    [ -n "$printers" ] || return 1


    prompt=`getString PROMPT_GET_PRINTER_SETTINGS | $FMT`
    response=`getChoice "$YES" "$prompt" "$YES" "$NO"`
    [ "$response" = "$YES" ] || return 1

    for printer in $printers
    do
        keys=`$zreg list "$old_regfile" -k "Printers.$printer"`
        for i in $keys
        do
            value=`$zreg get "$old_regfile" "Printers.$printer" "$i"`
            $zreg set "$new_regfile" "Printers.$printer" "$i" "$value"
        done
    done

    prompt=`getString PROMPT_MODIFY_PRINTER_SETTINGS | $FMT`
    response=`getChoice "$NO" "$prompt" "$YES" "$NO"`
    

    [ "$response" = "$YES" ] && updatePrinter change

    return 0
}

#setPrinter - add/update the printer configuration
setupPrinter()
{
    if [ -f $TEMP_DIR/save.reg ] 
    then
        restorePrinters && return 0
    fi

    updatePrinter add || return 1
    return 0
}

#doInstall - perform the actual installation
doInstall()
{
    install_type=$1
    
    # check license code (for cgm installation only)
    # stash license_code for later insertion into the registry file
    license_code=
    if [ $install_type = cgm ]
    then
        license_code=`checkLicense`
        [ -z "$license_code" ] && return 1
    fi

    
    # prompt user to install printer first

    warning=`getString PROMPT_WARNING | $FMT`
    continue_option=`getString WARNING_CONTINUE`
    exit_option=`getString WARNING_EXIT`

    response=`getChoice "$continue_option" "$warning" \
                       "$continue_option" "$exit_option"`

    [ "$response" = "$exit_option" ] && exit 1

    # prompt for installation dir
    install_dir_prompt=`getString PROMPT_PROGRAM_DIR`
    install_dir=`getDir "$install_dir_prompt" /opt/zehrasterplus`


    # detect previous installation

    if [ -f $install_dir/prg/zplus.reg ]
    then
        prompt=`getString PROMPT_EXISTING_ZRPLUS | $FMT`
        response=`getChoice "$YES" "$prompt" "$YES" "$NO"`
        [ "$response" = "$NO" ] && exit 1
    fi

    temp_dir_prompt=`getString PROMPT_TEMP_DIR`
    temp_dir=`getTempDir "$temp_dir_prompt" "$install_dir/temp"`
    
    rm -f $temp_dir/save.reg 2>&1 >/dev/null

    if [ -f $install_dir/prg/zplus.reg ]
    then
        cp $install_dir/prg/zplus.reg $temp_dir/save.reg
    fi

    # export the install and temp directories
    ZRPLUS_DIR=$install_dir
    TEMP_DIR=$temp_dir
    export ZRPLUS_DIR TEMP_DIR

    # install the program files
    installFiles $install_dir $install_type || return 1

    # create and update registry files

    browser=`getBrowser`
    
    zreg="$install_dir/prg/bin/zreg.exe"
    zregcat="$install_dir/prg/bin/zregcat.exe"
    
    checkFile "$zreg"
    checkFile "$zregcat"

    regfile=$install_dir/prg/zplus.reg
    $zregcat -o $regfile regfiles/*.reg || return 1

    [ -n "$license_code" ] && $zreg set $regfile License Key "$license_code"
    [ -n "$browser" ] && $zreg set $regfile Contents Browser "$browser"
    $zreg set $regfile Contents Index $install_dir/doc/ZEHRasterplus.html
    $zreg set $regfile WorkingDir Name $temp_dir
    $zreg set $regfile Fonts Lang "$LANGUAGE"

    setupPrinter

    #done
    echo
    echo
    echo
    echo $LINE
    getString PROMPT_COMPLETE
    echo $LINE

    return 0
}

#managePrinter - called by installMain to execute manage printer option
managePrinter()
{
    echo 1>&2
    echo 1>&2
    echo 1>&2
    echo 1>&2 $LINE
    getString PROMPT_INSTALLED_DIR | $FMT 1>&2
    echo 1>&2 "[/opt/zehrasterplus]"
    echo 1>&2 $LINE

    done=
    while [ -z "$done" ]
    do
        read dir
        [ -z "$dir" ] && dir=/opt/zehrasterplus
        if [ -f "$dir/prg/zplus.reg" ]
        then
            mp="$dir/manage_printer.sh"
            [ -f "$mp" ] || fail ERROR_FILE "$mp"
            echo "roy: chaining $mp"
            exec /bin/sh "$mp"
        fi
        echo 1>&2
        getString ERROR_INSTALLED_DIR $dir | $FMT 1>&2
        echo 1>&2
    done

}

#installMain - main routine for install.sh
installMain()
{

    # prompt the user to accept the license agreement

    prompt_agreement=`getString PROMPT_AGREEMENT`
    prompt_accept=`getString PROMPT_ACCEPT`

    (
        echo "$prompt_agreement" | $FMT
        echo $NEWLINE
        echo $NEWLINE
        cat international/$LANGUAGE/locale/$LANGUAGE.txt
    ) | $FMT | more

    response=`getChoice "$YES" "$prompt_accept" "$YES" "$NO"`
    
    [ "$response" = "$NO" ] && exit 1
    
    prompt_install_choice=`getString PROMPT_INSTALL_CHOICE`
    
    install=
    install_cgm=
    [ -f prg/$OSNAME/nocgm/zplus.exe ] && install=`getString INSTALL`
    [ -f prg/$OSNAME/cgm/zplus.exe ] && install_cgm=`getString INSTALL_CGM`
    manage_printer=`getString MANAGE_PRINTER`

    response=`getChoice "" "$prompt_install_choice" "$install" "$install_cgm" "$manage_printer"`
    
    if [ "$response" = "$manage_printer" ] 
    then
        managePrinter || fail ERROR_MANAGE_PRINTER
    else
        installType=nocgm
        [ "$response" = "$install_cgm" ] && installType=cgm
        doInstall $installType || fail ERROR_INSTALL
    fi
}


# initializeSetup : find some files, set some variables
initializeSetup()
{
    mode=$1

    PATH=$PATH:/bin:/usr/bin
    
    PROMPT_TXT=

    OSNAME=`getOs`
    export OSNAME PROMPT_TXT PATH
    
    LINE="======================================================================"
    NEWLINE="
"
    
    export LINE NEWLINE

    [ -z "$PWD" ] && PWD=`pwd`
    
    export PWD

    FMT=fmt
    echo "" | ( $FMT ) 2>/dev/null >/dev/null || FMT=$PWD/prg/bin/fmt
    echo "" | ( $FMT ) 2>/dev/null >/dev/null || FMT=$PWD/prg/$OSNAME/bin/fmt
    echo "" | ( $FMT ) 2>/dev/null >/dev/null || FMT=cat

    export FMT

    # install specific stuff
    if [ "$mode" = install ]
    then
        LANGUAGE=`getLanguage` || exit 1
        export LANGUAGE
        
        GET_STRING="$PWD/prg/$OSNAME/bin/common/getstring.exe"
        checkFile "$GET_STRING"

        CHECK_LICENSE="$PWD/prg/$OSNAME/bin/cgm/checklicense.exe"

        PROMPT_TXT="$PWD/international/$LANGUAGE/locale/prompt.txt"
        checkFile "$PROMPT_TXT"

        export GET_STRING PROMPT_TXT CHECK_LICENSE
        
        # find install
#        INSTALL=installFile
#        INSTALL_IMAGE=`which install 2>/dev/null`
#        [ -x "$INSTALL_IMAGE" ] || INSTALL=copyFile
        INSTALL=copyFile
        export INSTALL INSTALL_IMAGE

    else # manage_printers specific stuff
        GET_STRING="$PWD/prg/bin/getstring.exe"
        checkFile "$GET_STRING"

        PROMPT_TXT="$PWD/locale/prompt.txt"
        checkFile "$PROMPT_TXT"

        export GET_STRING PROMPT_TXT

        ZRPLUS_DIR=$PWD
        export ZRPLUS_DIR
    fi
 
    YES=`getString YES`
    NO=`getString NO`
    
    export YES NO
}

