#!/bin/sh

#------------------------------------------------------------------------------
# Make sure that we were called with the correct args
#------------------------------------------------------------------------------
if [ $# -ne 3 ]; then
    echo > /dev/tty
    echo "    ASSERT ERROR:" > /dev/tty
    echo "    Incorrect number of args passed to `basename \"$0\"`" > /dev/tty
    echo >/dev/tty
    exit 1
fi

#------------------------------------------------------------------------------
# Initialize globals
#------------------------------------------------------------------------------
prog="$0"                               # Name of this program
dest="$1"                               # Target dir for software package (IGNORE)
msgs="$2"                               # Name of message passing file
verb="$3"                               # Verb (preflight, destination)
launch_dir="`dirname \"$prog\"`"        # Directory where installer program lives
name="`expr \"$prog\" : '\(.*\)\.VAL'`" # Name of package (including path)
pkg_name="`basename \"$name\"`"         # Name of package (no path)

#------------------------------------------------------------------------------
# Find the correct strings file
#------------------------------------------------------------------------------
catalog_dir="${LC_ALL:-${LC_MESSAGES:-${LANG:-C}}}"
eval catalog_dir=\"`echo $catalog_dir | tr "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"`\"

if [ ! -r "${launch_dir}/LOCALE/${catalog_dir}/${pkg_name}.STR" ]; then
    echo "Cannot read strings in  '${launch_dir}/LOCALE/${catalog_dir}'" > "$msgs"
    catalog_dir="C"                     # Try finding English strings
    if [ ! -r "${launch_dir}/LOCALE/${catalog_dir}/${pkg_name}.STR" ]; then
        echo "Cannot read strings in  '${launch_dir}/LOCALE/${catalog_dir}'" >> "$msgs"
        exit 1
    fi
fi

. "${launch_dir}/LOCALE/${catalog_dir}/${pkg_name}.STR"  # Load localized strings

case $verb in
    preflight)
        id="`/usr/bin/id`"
        if [ "`/bin/expr  \"$id\" : 'uid=\(.*\)(.*) gid=.*''`" != "0" ] ; then
            echo "$not_root_msg" > "$msgs"
            exit 1
        fi

        # See if the ATALK.EXE command is available
        if [ ! -x "${launch_dir}/ATALK.EXE" ]; then
            echo "$cannot_run_atalk_msg" > "$msgs"
            exit 1
        fi

        # See if AppleTalk is running (up)
        "${launch_dir}/ATALK.EXE" -s > /dev/null 2>&1
        if [ $? -eq 0 ]; then
            echo "$atalk_active_msg" > "$msgs"
            exit 1
        fi

        if [ ! -f /etc/devlink.tab -o ! -w /etc/devlink.tab ]; then
            echo "$cannot_write_file_msg    [ /etc/devlink.tab ]" > "$msgs"
            exit 1
        elif [ -d /usr/kernel/drv -a ! -w /usr/kernel/drv ]; then
            echo "$cannot_access_dir_msg    [ /usr/kernel/drv ]" > "$msgs"
            exit 1
        elif [ -d /kernel/strmod -a ! -w /kernel/strmod ]; then
            echo "$cannot_access_dir_msg    [ /kernel/strmod ]" > "$msgs"
            exit 1
        else
            exit 0
        fi
        ;;
    ask_dest)     exit 1 ;;     # Do not ask for a destination
    ask_rem)      exit 0 ;;     # Ask if they want to remove pkg
    mk_alias)     exit 1 ;;     # Do not create alias in home directory
    destination)  exit 0 ;;     # Everything is checked in 'preflight'
esac
