#!/bin/bash
#
# Product setup script - Loki Entertainment Software
#
# Modifications by Borland/Inprise Corp.:
# 02/24/2000: added functions CheckKernel, CheckLibc, CheckX and enabling code in MAIN
# 01/24/2002: added FindLibrary function.  Changed CheckJpeg and CheckGtk detection logic.
#
# Modifications by MicroAPL Ltd.:
# 15 Nov 2002: re-branding and minor changes for APLX for Linux install
# 17 Feb 2007: removed check for libgtk [not used anyway]
#
#
# Version constants to check against
KERNEL_MAJOR=2
KERNEL_MINOR=2
KERNEL_BUILD=0
X_MAJOR=11
X_MINOR=0
LIBC_MAJOR=6
GLIBC_MAJOR=2
GLIBC_MINOR=1
GLIBC_BUILD=2
QT_MAJOR=2
JPEG_MAJOR=6
JPEG_MINOR=2
JPEG_BUILD=0
GTK_MAJOR=1
GTK_MINOR=2
GTK_BUILD=0
NCURSES_MAJOR=4

# Go to the proper setup directory (if not already there)
cd `dirname $0`

# BEGIN STRING TABLE
# These constants should be translated for international use
#
CHECK_DEP="Checking dependencies"
KERNEL_VER="Kernel version"
FAILED="FAILED"
OK="OK"
LIBC_VER="Glibc version"
X_VER="X11 Server"
QT_VER="Qt version"
LIBJPEG_VER="Libjpeg version"
LIBGTK_VER="Libgtk version"
CANNOT_FIND="Setup cannot locate"
X_SERVER="X Server"
X_FAILURE="Setup could not detect a suitable X11 server."
CONTINUE="Do you want to install APLX for Linux (default Y) ? "
EXIST_INSTALL="Setup has detected an existing installation at this location:"
NO_RELOCATE1="If you wish to reinstall, you will not be able to choose a"
NO_RELOCATE2="different installation location."
LIBNCURSES="Libncurses version"
LOADER_ERR1="Setup has determined that your system needs an updated version of glibc"
LOADER_ERR2="(C runtime library). The version of glibc that is required varies by"
LOADER_ERR3="distribution. Please read the document \"pre_install.txt\" on this disc."
FATAL_ERR1="Your system does not meet the minimum system requirements."
FATAL_ERR2="Setup cannot continue."
VERS_ERR1="Setup has detected another version of APLX is already installed on this system."
VERS_ERR2="You must remove the other version before installing this one."
CANNOT_LOAD_CHKLIBC="cannot load chklibc"
LESS_THAN="less than"
LOADER_TEST_NOT_FOUND="Test program not found"
COULD_NOT_FIND="could not find"
COULD_NOT_LOCATE="could not locate"
CANNOT_LOAD="cannot load"
FOUND_VIA_RPM="found via RPM query"
UNKNOWN="unknown"
NOT_ROOT_NO_CHECK="non-root install...check not performed"
DETECTED_RPM="Detected RPM"
FORCING_NON_RPM_INSTALL="forcing non-RPM install"
SETUP_FAILED="The setup program seems to have failed on"
CONTACT_TECH_SUPPORT="Please contact Technical Support."
UNSUPPORTED_LIBC_ARCH1="This installation does not support"
UNSUPPORTED_LIBC_ARCH2="on"
NOT_COREL_LINUX="Not Corel Linux"
INSTALL_LOG_HEAD="APLX for Linux install log"
KERNEL_VERSION="kernel version"
COREL_LINUX_CHECK="Corel Linux check"
LOADER_TEST_RESULT="loader test result code"
LIBC_VERSION="libc version"
LIBJPEG_VERSION="libjpeg version"
COULD_NOT_OBTAIN_LIBC_VER="Unable to obtain libc version."
COULD_NOT_COPY_CHKLIBC="Unable to copy chklibc."
EXISTS_NOT_DIR="exists but is not a directory"
WARNING="WARNING:"

# END STRING TABLE


#START OF FUNCTIONS

#Look in /etc/ld.so.conf and search each directory for a pattern in $1.
#Caller should capture the output from stdout.
function FindLibrary() {

  pattern="$1"

  #Try default paths first
  ls /usr/lib/${pattern} 2>/dev/null
  ls /lib/${pattern} 2>/dev/null

  #Look in /etc/ld.so.conf paths
  if [ -e /etc/ld.so.conf ]
  then
    for path in `cat /etc/ld.so.conf`
    do
      spath=$path/
      has_slash=`expr "$spath" : '\(.*//\)'`
      if [ -n "$has_slash" ]
      then
        spath=$path
      else
        spath=$path/
      fi
      ls ${spath}${pattern} 2>/dev/null
    done
  fi
}

function CheckKernel {
    major=`uname -r | awk -F. '{printf $1}'`
    minor=`uname -r | awk -F. '{printf $2}'`
    kernelOK=1
    if test $major -gt $KERNEL_MAJOR; then
	kernelOK=0
    elif test $major -eq $KERNEL_MAJOR; then
	if test $minor -ge $KERNEL_MINOR; then
	    kernelOK=0
	fi
    fi
    kernel_version="$major.$minor"
    return $kernelOK;
}

function CheckLibc {
    major=0
    minor=0
    build=0
    
    # copy the chklibc file to someplace where we know it can be executed
    chklibc="$HOME/.chklibc$$"
    if [ -e setup.data/chklibc ]; then
	cp "setup.data/chklibc" "$chklibc"
	if [ $? -ne 0 ]; then
	   echo "$COULD_NOT_COPY_CHKLIBC" 1>&2
	   libc_version="$CANNOT_LOAD_CHKLIBC"
	   return 1
	fi
	chmod 700 "$chklibc"
	libcver=`$chklibc`
    else
	libc_version="$CANNOT_LOAD_CHKLIBC"
	return 1
    fi

    if [ -e $chklibc ]; then
	rm -f $chklibc
    fi

    if [ -z "$libcver" ]; then
    	echo "$COULD_NOT_OBTAIN_LIBC_VER" 2>&1
	libc_version="$CANNOT_LOAD_CHKLIBC"
	return 1
    fi

    major=`echo $libcver |awk -F. '{printf $1}'`
    minor=`echo $libcver |awk -F. '{printf $2}'`
    build=`echo $libcver |awk -F. '{printf $3}'`
    libc_version="$major.$minor.$build"
    if [ $major -ge $GLIBC_MAJOR ]; then
	    if [ $minor -gt $GLIBC_MINOR ]; then
		return 0;
	    elif [ $minor -eq $GLIBC_MINOR ]; then
		if [ $build -ge $GLIBC_BUILD ]; then
		    return 0;
		else
		    return 1;
		fi
	    else
		return 1;
	    fi
    else
	libc_version="$LESS_THAN 2.0"
	return 1;
    fi
}

#function CheckLoader {
#    if [ -n "`expr "$args" : '\(.*-g\)'`" ]; then
#	ldresult=0
#	return 0;
#    else
#	ldresult=1
#	# copy the borpretest file to someplace where we know it can be executed
#	chkldpath="$HOME/.borchkld$$"
#	if [ -d pretest ]; then
#	    mkdir "$chkldpath"
#	    cp pretest/* "$chkldpath" &>/dev/null
#	    chmod 700 "$chkldpath/borpretest"
#	    if [ -n "$LD_LIBRARY_PATH" ]; then
#		oldldpath=`echo $LD_LIBRARY_PATH`
#		export LD_LIBRARY_PATH="$chkldpath":$LD_LIBRARY_PATH
#		`$chkldpath/borpretest -q`
#		ldresult=$?
#		export LD_LIBRARY_PATH=$oldldpath
#	    else
#		export LD_LIBRARY_PATH="$chkldpath"
#		`$chkldpath/borpretest -q`
#		ldresult=$?
#		unset LD_LIBRARY_PATH
#	    fi
#
#	    if [ -d "$chkldpath" ]; then
#		rm -rf "$chkldpath"
#	    fi
#	
#	    loader_result="$ldresult"
#	    return $ldresult
#	else
#	    loader_result="$LOADER_TEST_NOT_FOUND"
#	    return 1
#	fi
#    fi
#}

function CheckX {
    xOK=1
    major=0
    minor=0
    build=0
    # Since X may not be in their path, we have to find it
    #findx=`whereis xdpyinfo`
    findx=`whereis X | awk '{printf $2}'`
    if [ -n "$findx" ]; then
	xOK=0
	x_server="$findx"
    else
	x_server="$COULD_NOT_FIND"
    fi
    return $xOK;
}


function CheckJpeg {
    jpegOK=1
    major=0
    minor=0
    build=0
    jpeg_version=
    fname=

    if [ -e /usr/lib/libjpeg.so.62.0.0 ]; then
        jpegOK=0
        jpeg_version="6.2.0"
    else
       for fname in `FindLibrary "libjpeg.so.6.*"`
       do
	jpeg=`basename "$fname"`
	major=`echo $jpeg |awk -F. '{print $3}'`
	minor=`echo $jpeg |awk -F. '{print $4}'`
	if [ -z "$minor" ]; then
	   minor=0
	fi
	build=`echo $jpeg |awk -F. '{print $5}'`
	if [ -z "$build" ]; then
	   build=0
	fi
	if [ $major -gt $JPEG_MAJOR ]; then
	    jpegOK=0
	elif [ $major -eq $JPEG_MAJOR -a $minor -gt $JPEG_MINOR ]; then
	    jpegOK=0
	elif [ $major -eq $JPEG_MAJOR -a $minor -eq $JPEG_MINOR -a $build -ge $JPEG_BUILD ]; then
	    jpegOK=0
	fi
	jpeg_version="$major.$minor.$build"
	echo $jpeg_version
	if [ $jpegOK -eq 0 ]; then
	    return $jpegOK #return if found suitable version.  else keep looking.
	fi
       done
    fi

    return $jpegOK

#    if [ -e /usr/lib/libjpeg.so.62.0.0 ]; then
#        jpegOK=0
#	jpeg_version="6.2.0"
#    elif [ -L /usr/lib/libjpeg.so.6 ]; then
#	jpeg=`ls /usr/lib/libjpeg.so.6.* 2>/dev/null`
#	major=`echo $jpeg |awk -F. '{print $3}'`
#	minor=`echo $jpeg |awk -F. '{print $4}'`
#	build=`echo $jpeg |awk -F. '{print $5}'`
#	if [ $major -gt $JPEG_MAJOR ]; then
#	    jpegOK=0
#	elif [ $major -eq $JPEG_MAJOR -a $minor -gt $JPEG_MINOR ]; then
#	    jpegOK=0
#	elif [ $major -eq $JPEG_MAJOR -a $minor -eq $JPEG_MINOR -a $build -ge $JPEG_BUILD ]; then
#	    jpegOK=0
#	fi
#	jpeg_version="$major.$minor.$build"
#    fi
#
#    return $jpegOK
}

function GetRpmVersion {
   rpmver=`rpm --version 2>/dev/null`
   if [ -n "$rpmver" ]; then
      rpmver=`echo $rpmver | awk -F\  '{print $NF}'`
      major=`echo $rpmver | awk -F. '{print $1}'`
      minor=`echo $rpmver | awk -F. '{print $2}'`
      build=`echo $rpmver | awk -F. '{print $3}'`
      rpmver="$major.$minor.$build"
      return 0
   else
      return 1
   fi
}

function CheckGtk {
    gtkOK=1
    major=0
    minor=0
    build=0
    gtksolist=
    gtk_version="$CANNOT_FIND libgtk"
    gtkfiles=

    gtkfiles=`FindLibrary "libgtk-*.so.*"`

#    gtkfiles=`ls /usr/lib/libgtk-*.so.* 2>/dev/null`
#    if [ $? -ne 0 ]; then
#       gtkfiles=`ls /usr/X11R6/lib/libgtk-*.so.* 2>/dev/null`
#       if [ $? -ne 0 ]; then
#          gtkfiles=
#       fi
#    fi

    for gtkso in $gtkfiles; do
      gtkso=`basename $gtkso`
      gtksolist="$gtksolist `echo $gtkso | awk -F\  '{print $NF}' | sed s/-/./1`"
    done

    for gtkso in $gtksolist; do
       gtkOK=1
       major=`echo $gtkso | awk -F. '{print $2}'`
       minor=`echo $gtkso | awk -F. '{print $3}'`
       build=`echo $gtkso | awk -F. '{print $5}'`

      if [ $major -gt $GTK_MAJOR ]; then
         gtkOK=0
      elif [ $major -eq $GTK_MAJOR -a $minor -gt $GTK_MINOR ]; then
         gtkOK=0
      elif [ $major -eq $GTK_MAJOR -a $minor -eq $GTK_MINOR -a $build -ge $GTK_BUILD ]; then
         gtkOK=0
      fi

      if [ $gtkOK -eq 0 ]; then
         gtk_version="$major.$minor.$build"
         return $gtkOK
      fi
   done

   return $gtkOK
}


function CheckCurses {
    
    result=1

    # first copy chkcurses to someplace that is executable.
    chkcurses="$HOME/.chkcurses$$"
    if [ -e setup.data/chkcurses ]; then
	cp "setup.data/chkcurses" "$chkcurses"
	chmod 700 "$chkcurses"
	ncurses=`$chkcurses 2>/dev/null`
    else
	found_ncurses="$CANNOT_LOAD chkcurses"
	return 1
    fi

    if [ $? -eq 0 ]; then
	found_ncurses="$FOUND_VIA_RPM"
	result=0
    elif [ $? -eq 1 ]; then
    	for fname in `FindLibrary "libncurses.so.4"`
    	do
    	    found_ncurses="$fname"
    	    result=0
    	    break
    	done
    	
#	if [ -e /usr/lib/libncurses.so.4 ]; then
#	    found_ncurses="/usr/lib/libncurses.so.4"
#	    result=0
#	elif [ -e /usr/local/lib/libncurses.so.4 ]; then
#	    found_ncurses="/usr/local/lib/libncurses.so.4"
#	    result=0
#	elif [ -e /lib/libncurses.so.4 ]; then
#	    found_ncurses="/lib/libncurses.so.4"
#	    result=0
#	fi
    fi

    if [ -e "$chkcurses" ]; then
	rm -f "$chkcurses"
    fi
    return $result
}


# Return the appropriate architecture string
function DetectARCH {
	status=1
	case `uname -m` in
		i?86)  echo "x86"
			status=0;;
		*)     echo "`uname -m`"
			status=0;;
	esac
	return $status
}

# Return the appropriate version string
function DetectLIBC {
      status=1
      if [ -f `echo /lib/libc.so.6* | tail -1` ]; then
	      if fgrep GLIBC_2.1 /lib/libc.so.6* 2>&1 >/dev/null; then
	              echo "glibc-2.1"
	              status=0
	      else    
	              echo "glibc-2.0"
	              status=0
	      fi        
      elif [ -f /lib/libc.so.5 ]; then
	      echo "libc5"
	      status=0
      else
	      echo "$UNKNOWN"
      fi
      return $status
}


# Find the installation program
function try_run
{
    setup=$1
    shift
    fatal=$1
    if [ "$1" != "" ]; then
        shift
    fi

    # First find the binary we want to run
    failed=0
    setup_bin="setup.data/bin/$arch/$libc/$setup"
    if [ ! -f "$setup_bin" ]; then
        setup_bin="setup.data/bin/$arch/$setup"
        if [ ! -f "$setup_bin" ]; then
            failed=1
        fi
    fi
    if [ $failed -eq 1 ]; then
        if [ "$fatal" != "" ]; then
            cat <<__EOF__
$UNSUPPORTED_LIBC_ARCH1 $libc $UNSUPPORTED_LIBC_ARCH2 $arch

$CONTACT_TECH_SUPPORT
__EOF__
            exit 1
        fi
        return $failed
    fi

    # Try to run the binary
    # The executable is here but we can't execute it from CD
    setup="$HOME/.setup$$"
    cp "$setup_bin" "$setup"
    chmod 700 "$setup"
    if [ "$fatal" != "" ]; then
# User has already been prompted if there is an existing install.
#	if [ -n "$pathargs" ]; then
#	    cat <<EOF
#
#$EXIST_INSTALL
#
#$pathargs
#
#$NO_RELOCATE1
#$NO_RELOCATE2
#
#EOF
#	    echo -n "$CONTINUE "
#	    read response
#	    case $response in
#		n|N|no|No|NO )
#		    fatal_error=1
#		    ;;
#		* )
#		    "$setup" $installargs -i$pathargs $*
#		    ;;
#	    esac
#	else
	    "$setup" $installargs $*
#	fi
        failed=$?
    else
	if [ -n "$pathargs" ]; then
	    cat <<EOF

$EXIST_INSTALL

$pathargs

$NO_RELOCATE1
$NO_RELOCATE2

EOF
	    echo -n "$CONTINUE "
	    read response
	    case $response in
		n|N|no|No|NO )
		    fatal_error=1
		    ;;
		* )
		    "$setup" $installargs -i$pathargs $* 2>/dev/null
		    ;;
	    esac
	else
	    "$setup" $installargs $* 2>/dev/null
	fi
        failed=$?
    fi
    rm -f "$setup"
    return $failed
}

function DirInPath() {
  apath="$1"

  if [ -n "$apath" -a -n "$PATH" ]; then
  	for dpath in `echo $PATH | sed s/:/\ /g`; do
 		if [ "$apath" = "$dpath" ]; then
			return 0
		fi
  	done
  fi
  return 1
}

function ShowWarnings {
#   # check for stdint.h
#   if [ ! -e /usr/include/stdint.h ]
#   then
#   	echo "$WARNING $COULD_NOT_FIND stdint.h"
#   fi

   # check for libX11.so
   libx11files=`FindLibrary "libX11.so"`
   if [ -z "$libx11files" ]
   then
   	echo "$WARNING $COULD_NOT_LOCATE libX11.so"
   fi
}

function CheckSystem {

    fatal_error=0
    error=""

    ShowWarnings

#    if [ -e ~/.borland -a ! -d ~/.borland ]; then
#    	fatal_error=1
#    	echo "$HOME/.borland $EXISTS_NOT_DIR....$FAILED"
#    fi

#    if DirInPath "$HOME/bin"; then
#    	if [ ! -d "$HOME/bin" ]; then
#    		mkdir "$HOME/bin" 2>/dev/null
#    	fi
#    fi

    if ! CheckKernel; then
	echo "$KERNEL_VER >= $KERNEL_MAJOR.$KERNEL_MINOR.$KERNEL_BUILD....$FAILED"
        if [ -z $FORCE_APLX_INSTALL ]; then
            fatal_error=1
        fi
    else
	echo "$KERNEL_VER >= $KERNEL_MAJOR.$KERNEL_MINOR.$KERNEL_BUILD....$OK"
    fi

#    if ! CheckLoader; then
#	fatal_error=1
#	echo "$LIBC_VER....$FAILED"
#	cat <<EOF
#
#$LOADER_ERR1
#$LOADER_ERR2
#$LOADER_ERR3
#
#EOF
#    elif ! CheckLibc; then
    if ! CheckLibc; then
	echo "$LIBC_VER >= $GLIBC_MAJOR.$GLIBC_MINOR.$GLIBC_BUILD....$FAILED"
        if [ -z $FORCE_APLX_INSTALL ]; then
            fatal_error=1
        fi
    else
	echo "$LIBC_VER >= $GLIBC_MAJOR.$GLIBC_MINOR.$GLIBC_BUILD....$OK"
    fi

    if ! CheckX; then
	echo "$X_VER....$FAILED"
        cat <<EOF

$X_FAILURE

EOF
	echo -n "$CONTINUE "
	read response
	case $response in
        n|N|no|No|NO )
	  fatal_error=1
	  ;;
	* )
	  ;;
        esac
    else
	echo "$X_VER....$OK"
    fi

    if ! CheckJpeg; then
	echo "$LIBJPEG_VER >= $JPEG_MAJOR.$JPEG_MINOR.$JPEG_BUILD....$FAILED"
        if [ -z $FORCE_APLX_INSTALL ]; then
            fatal_error=1
        fi
    else
	echo "$LIBJPEG_VER >= $JPEG_MAJOR.$JPEG_MINOR.$JPEG_BUILD....$OK"
    fi

# Removed 17 Feb 07:Not used anyway
#    if ! CheckGtk; then
#	fatal_error=1
#	echo "$LIBGTK_VER >= $GTK_MAJOR.$GTK_MINOR.$GTK_BUILD....$FAILED"
#    else
#	echo "$LIBGTK_VER >= $GTK_MAJOR.$GTK_MINOR.$GTK_BUILD....$OK"
#    fi


#    if ! CheckCurses; then
#	fatal_error=1
#	echo "$LIBNCURSES = $NCURSES_MAJOR....$FAILED"
    #    else
#	echo "$LIBNCURSES = $NCURSES_MAJOR....$OK"
#    fi

    if test $fatal_error -eq 1; then
	cat <<EOF

$FATAL_ERR1
$FATAL_ERR2

EOF
	return 1
    fi
    echo 
    echo
    return 0
}

function CheckPreviousInstall {
    uid=`id -u`
    if [ "$uid" = "0" ]; then
	sh setup.data/chkprevvers.sh
	if [ $? -ne 0 ]; then
	    cat <<EOF

$VERS_ERR1
$VERS_ERR2

$FATAL_ERR2
EOF
	    exit 1
	fi
    fi
    return 0
}

function GetAPLXSerialCode {
    # Run the regaplx application to request and save the APLX serial code
    # Return 0 if successful, 1 otherwise

    echo "To install and use APLX for Linux, you must enter the \"serial code\" supplied "
    echo "with the product. The serial code consists of 8 letters and digits. "
    echo " "
    echo "If you have misplaced your serial code, please contact MicroAPL for a "
    echo "replacement. "
    echo " "
	
    # copy the "regaplx" file somewhere we know it can be executed
    regaplx="$HOME/.regaplx$$"
    status=1
    if [ -e setup.data/regaplx ]; then
	cp "setup.data/regaplx" "$regaplx"
	if [ $? -ne 0 ]; then
	   echo "Installation error: Unable to copy setup.data/regaplx" 1>&2
	   return 1
	fi
	chmod 700 "$regaplx"
	$regaplx -quiet
	status=$?
    else
        echo "Installation error: setup.data/regaplx missing" 1>&2
	return 1
    fi

    if [ -e $regaplx ]; then
	rm -f $regaplx
    fi
    echo " "
    return $status;
}

function CheckForCorel {
    uid=`id -u`
    if [ "$uid" = "0" ]; then
	dist=`grep -i "corel" /etc/issue`
	if [ -n "$dist" ]; then
	    found_corel="Corel Linux: $dist"
	    installargs="-m $installargs"
	else
	    found_corel="$NOT_COREL_LINUX"
	fi
    else
	found_corel="$NOT_ROOT_NO_CHECK"
    fi
}

function WriteLog {
    findx=`whereis xdpyinfo | awk '{printf $2}'`
    if [ -n "$findx" ]; then
    cat <<EOF > ~/aplx_install_log
$INSTALL_LOG_HEAD -- `date`
OS: Linux
$KERNEL_VERSION: $kernel_version
$COREL_LINUX_CHECK: $found_corel
$LOADER_TEST_RESULT: $loader_result
$LIBC_VERSION: $libc_version
$LIBJPEG_VERSION: $jpeg_version
xdpyinfo:
`$findx 2>&1`
EOF
    else
	cat <<EOF > ~/aplx_install_log
$INSTALL_LOG_HEAD -- `date`
OS: Linux
$KERNEL_VERSION: $kernel_version
$COREL_LINUX_CHECK: $found_corel
$LIBC_VERSION: $libc_version
$LIBJPEG_VERSION: $jpeg_version
#found libncurses: $found_ncurses
xdpyinfo: $COULD_NOT_LOCATE xdpyinfo
EOF

    fi

}

#END OF FUNCTIONS

fatal_error=0
# Detect the Linux environment
arch=`DetectARCH`
libc=`DetectLIBC`

# Initial display
echo
echo
echo
echo "                                   APLX for Linux"
echo 
echo "$CHECK_DEP..."

kernel_version=""
libc_version=""
x_server=""
jpeg_version=""
found_corel=""
found_ncurses=""
loader_result=""
args=$*

# 5 Jul 16: Remove these checks as they cause too many spurious errors.
#if ! CheckSystem; then
#    exit 1
#fi

if ! GetAPLXSerialCode; then
    exit 1
fi

pathargs=""

#if [ -n "`expr "$args" : '\(.*-m\)'`" ]; then
#   #non-rpm install forced
#    installargs="-m"
#else
#    installargs=""
#    #check rpm version and force -m if relocation bug
#    if [ $UID -eq 0 ]; then
#       if GetRpmVersion; then
#          if [ "$rpmver" = "4.0.2" ]; then
#             echo "$DETECTED_RPM 4.0.2; $FORCING_NON_RPM_INSTALL."
#             installargs="-m"
#          fi
#       fi
#    fi
#fi

# APLX install never uses RPM
installargs="-m"

CheckForCorel
WriteLog

if CheckPreviousInstall; then
    # Try to run the setup program
    status=0
    rm -f "$setup"
    if ! try_run setup.gtk; then
	if [ $fatal_error -eq 0 ]; then
	    if ! try_run setup -fatal; then
		echo "$SETUP_FAILED $arch/$libc"
		echo
		echo "$CONTACT_TECH_SUPPORT"
		status=1
	    fi
	fi
    fi
fi
exit $status

