# no_x.tcl
# Copyright (c) 2003-2004 Digi International Inc., All Rights Reserved
# 
# This software contains proprietary and confidential information of Digi
# International Inc.  By accepting transfer of this copy, Recipient agrees
# to retain this software in confidence, to prevent disclosure to others,
# and to make no use of this software other than that for which it was
# delivered.  This is an unpublished copyrighted work of Digi International
# Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
# prohibited.
# 
# Restricted Rights Legend
#
# Use, duplication, or disclosure by the Government is subject to
# restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
# Technical Data and Computer Software clause at DFARS 252.227-7031 or
# subparagraphs (c)(1) and (2) of the Commercial Computer Software -
# Restricted Rights at 48 CFR 52.227-19, as applicable.
#
# Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
#
# ***************************************************************************

set PKG_FILE specific/packages
set lstOSES [list AIX4X \
AIX5X \
HPUX \
LINUX \
OPENSERVER \
UNIXWARE \
SOLARISINTEL \
SOLARISSPARC ]

set lstHWS [list apcx \
apepcx \
apras \
apxe \
apxem \
apxp \
apxr \
classic \
neo \
sync570 \
ether \
psii \
scsi ]

set apcx "AccelePort C/X"
set apepcx "AccelePort EPC/X"
set apras "AccelePort RAS"
set apxe "AccelePort Xe"
set apxem "AccelePort Xem"
set apxp "AccelePort Xp"
set apxr "AccelePort Xr"
set classic "ClassicBoard"
set neo "Digi Neo"
set sync570 "DataFire SYNC/570"
set sync2000 "DataFiree SYNC 2000"
set ether "EtherLite"
set psii "PortServer II"
set scsi "SCSI Terminal Server"

set RP "RealPort Driver"

set AIX "AIX"
set AIX4X "AIX 4.x"
set AIX5X "AIX 5.x"
set HPUX "HP-UX"
set LINUX "Linux"
set OPENSERVER "SCO OpenServer"
set UNIXWARE "SCO UnixWare"
set SOLARISINTEL "Solaris - Intel"
set SOLARISSPARC "Solaris - SPARC"
set SOLARIS "Solaris - Intel/SPARC"

set AIX_I frontend/specific/sh_scripts/aix_installer
set AIX4X_I frontend/specific/sh_scripts/aix_installer
set AIX5X_I frontend/specific/sh_scripts/aix_installer
set HPUX_I frontend/specific/sh_scripts/hpux_installer
set LINUX_I frontend/specific/sh_scripts/linux_installer   
set OPENSERVER_I frontend/specific/sh_scripts/openserver_installer
set SOLARISINTEL_I frontend/specific/sh_scripts/unix_installer 
set SOLARISSPARC_I frontend/specific/sh_scripts/unix_installer 
set SOLARIS_I frontend/specific/sh_scripts/unix_installer
set UNIXWARE_I frontend/specific/sh_scripts/unixware_installer 

proc dginstall {OS HW DRIVER_FILE} {
    set SELECTED_OS $OS
    set OS ""
    set REALOS [exec uname -s]
        
        switch -exact -- $REALOS {
            HP-UX {
                set OS HPUX             
            }
            SCO_SV {
                set OS OPENSERVER
            }
            SunOS {
                if {[string equal $SELECTED_OS SOLARIS]} {
                    set OS SOLARIS
                } else {
                    set PLAT [exec uname -p]
                    switch -glob -- $PLAT {
                        sparc {
                            set OS SOLARISSPARC
                        }
                        i?86 {
                            set OS SOLARISINTEL
                        }
                        default {
                            set OS UNKNOWN
                        }
                    }
                }
            }
            UNIX_SV -
            UnixWare {
                set OS UNIXWARE
            }
            AIX {
                set VER [exec uname -v]
                set OS AIX${VER}X
            }
            Linux {
                set OS LINUX
            }
            default {
                set OS UNKNOWN
            }
        }
        
    if { $SELECTED_OS !=  $OS } {
        return
    } else {
        puts -nonewline "Would you like to run the install script? (y/n):"
        flush stdout
        gets stdin ans
        if {[regexp {[yY]} $ans]} {
                set SOFT rp
            set strInstaller [set ::${OS}_I]
            flush stdout
            catch {exec $strInstaller $DRIVER_FILE $HW $SOFT NOGUI >&@stdout}
        }
    }
}


proc getos {} {
    set ret ""
    set i 1
    foreach arg $::lstOSES {
        puts "${i}\) [set ::$arg]"
        incr i
    }
    incr i -1
    puts -nonewline "Select your operating system from the list above (1-$i):"
    flush stdout
    gets stdin SELECT
    if {[regexp {[qQ]} $SELECT ]} {
      exit 0
    }
    set i 1
    foreach arg $::lstOSES {
        if {[string equal $i $SELECT ]} {
            set ret $arg
        }
        incr i
    }
    return $ret
}


puts "This is a text based file locator for the Digi Software CD-ROM."
puts "You are seeing this because your DISPLAY shell variable was not"
puts "set properly.  It runs as an alternative to the graphical front"
puts "end that is designed to run in X Windows."
puts "Press <Enter> to continue, Ctrl-C to quit."
flush stdout
gets stdin not


set OS [getos]
while {[ string equal $OS "" ]} {
    set OS [getos]
}

set HW RP
set DRIVER RP
if {[string first SOLARIS $OS] == 0 } {
    set OS SOLARIS
}

puts "Files for [set $HW] on [set $OS]:"
set ch [open $PKG_FILE r]
set lstPackages [read $ch]
close $ch
set lstPackages [split $lstPackages \n]
set strSearch ${OS}_${DRIVER}

## This part depends on the .ini file used by tracker
## The main driver file MUST be listed first in the Extract or Copy sections
foreach strPart $lstPackages {
    if {[regexp $strSearch $strPart]} {
        set lstPart [split $strPart \=]
        set TEMP [lindex $lstPart 1]
        if {![info exists DRIVER_FILE]} {
            set DRIVER_FILE $TEMP
        }
        puts $TEMP
    }
}

if {[info exists DRIVER_FILE]} {
    dginstall $OS $HW $DRIVER_FILE
} else {
   puts "There are no related files for your selection."
   puts "Visit support.digi.com for an up to date list of"
   puts "supported drivers and software."
}

