#!/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
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="`/bin/id`"
        if [ "`/bin/expr  \"$id\" : 'uid=\(.*\)(.*) gid=.*''`" != "0" ] ; then
            echo "$not_root_msg" > "$msgs"
            exit 1
        elif [ ! -d /usr/lib/rmmount -o ! -w /usr/lib/rmmount ]; then
            echo "$cannot_access_dir_msg    [ /usr/lib/rmmount ]" > "$msgs"
            exit 1
        elif [ ! -d /usr/lib/fs -o ! -w /usr/lib/fs ]; then
            echo "$cannot_access_dir_msg    [ /usr/lib/fs ]" > "$msgs"
            exit 1
        elif [ ! -w /etc/rmmount.conf ]; then
            echo "$cannot_write_file_msg    [ /etc/rmmount.conf ]" > "$msgs"
            exit 1
        else
            exit 0
        fi
        ;;
    ask_dest)    exit 1 ;;              # Do not ask user for 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
