vMA & PCNS 3.0 Update

Hallo Leute,

kleine Rückmeldung zu dem alten Beitrag:
vMA & PCNS 3.0

Dieses Update dreht des alten Beitrag dreht sich um ein angepasstes Skript welches dafür sorgt,
dass der PCNS mit der VIFP zusammenarbeitet.

Da bei Blogspot keine Dateien hochgeladen werden können mal wieder eine Plain-Copy des angepassten Installations-Skriptes.

PCNS 3.0.X Installation per „install_en.sh“

Bitte alles was jetzt folgt in eine „install_blafoobar.sh“ zu dem PCNS-Zip kopieren und die Installation dann bitte per oben genannter Datei starten.

Rot markiert ist der Eintrag für die entsprechende Version die installiert werden soll, mit Version 3.0.1 bereits getestet.

Also auf den Link klicken und dann: „Shift+Strg+Ende“ und per Putty in die vMA kopieren:

# PowerChute Installation for VIFP by troll-vmware
#!/bin/sh
######################################################################

# PowerChute Network Shutdown v.3.0.0
# Copyright (c) 1999-2011 Schneider Electric, All Rights Reserved. 
#
# History:
#   15Apr2009 Initial revision
#
######################################################################


######################################################################
# Global Constants
######################################################################
PCNS_TAR=“pcns300.tar“
PCNS_ZIP=“$PCNS_TAR.gz“
JRE_VERSION=“jre1.6.0_24″
JRE_REQUIRED_MAJOR=1
JRE_REQUIRED_MINOR=6
JRE_REQUIRED_MINI=0
JRE_REQUIRED_MICRO=0
LINUX=“Linux“
SOLARIS=“Solaris“
HPUX=“HP-UX“
AIX=“AIX“
VIMA=“VIMA“
UNKNOWN=“UNKNOWN“
XENSERVER=“XenServer“

GROUP1=“group1″
GROUP2=“group2″
GROUP3=“group3″

TRUE=0
FALSE=1
STR_YES=“YES“
YES=0
NO=1
QUIT=2
INVALID=99
# PCNS-1512: Make sure we have /sbin on the path
PATH=/sbin:$PATH

######################################################################
# Exit Codes
######################################################################
EXIT_SUCCESS=0
EXIT_USAGE=1
EXIT_NOT_ROOT_USER=4
EXIT_UNSUPPORTED_OS=5
EXIT_UPGRADE_NOT_SUPPORTED=6
EXIT_USER_ABORT=7
EXIT_CONFLICT_PCPLUS=8
EXIT_CONFLICT_PCBE=9
EXIT_CONFLICT_PCS=10
EXIT_CONFLICT_VMWARE=11
EXIT_INVALID_INSTALL_DIR=12
EXIT_INVALID_JAVA_VERSION=13
EXIT_INVALID_LOCALE=14
EXIT_ZIPFILE_MISSING=15
EXIT_SILENT_CONFIG_MISSING=16
EXIT_EULA_NOT_ACCEPTED=17
EXIT_SILENT_INSTALL_JAVA_DIR=20

######################################################################
# Global Variables
######################################################################
UPDATE_INSTALL=$FALSE
OS=$UNKNOWN
SILENT_MODE=$FALSE

SRC_DIR=““
INSTALL_DIR=““
APP_DIR=““
JAVA_DIR=““
ACCEPT_EULA=“NO“
REGISTER_NMC=“NO“
STARTUP=““
PCBE_STARTUP=““
PCS_STARTUP=““
OLD_INSTALL_DIR=““
JRE_FILE=““
SPARC=$FALSE
TR=“tr“

######################################################################
#  Functions
######################################################################

# trap keyboard interrupt on the following:
# 1 SIGHUP
# 2 SIGINT
# 3 SIGQUIT
# 6 SIGABRT
trap control_c 1 2 3 6

control_c()
# run if user hits control-c
{
  echo -en „n*** User Abort Detected! Exiting ***n“
  CancelAll $EXIT_USER_ABORT
}

# Waits for user key press.
Pause() {
    OLDCONFIG=`stty -g`
    stty -icanon -echo min 1 time 0
    dd count=1 2>/dev/null
    stty $OLDCONFIG
}

Echo() {
    string=“$1″
    echo „$string“
#    if [ $SILENT_MODE = $TRUE ]; then
#        echo „$string“ >> pcns_install.log
#    fi
}

PrintUsage() {
    Echo „Usage:“
    Echo “  $0 [-f <config file>] : Silent install with configuration file.“
    Echo “  $0 [-h|-H] : Print help.“
    exit $EXIT_USAGE
}

IsYN() {
    rval=$INVALID
    query_string=“$1″
    loop=$TRUE
    while [ $loop -eq $TRUE ]
    do
        Echo „“
        Echo „$query_string „
        read ynq
        case „$ynq“ in
        [Yy]*)
            rval=$YES
            loop=$FALSE
            ;;
        [Nn]*)
            rval=$NO
            loop=$FALSE
            ;;
        *)
            Echo „Invalid response.“
            ;;
        esac
    done
    return $rval
}

SetSilentConfig() {
    # Check parameter
    cnt=`grep ‚^INSTALL_DIR=‘ $SILENT_CONFIG | wc -l`
    if [ $cnt -gt 1 ]; then
        Echo „Error: Too many INSTALL_DIR in $SILENT_CONFIG“
        exit $EXIT_INVALID_INSTALL_DIR
    fi
    cnt=`grep ‚^JAVA_DIR=‘ $SILENT_CONFIG | wc -l`
    if [ $cnt -gt 1 ]; then
        Echo „Error: Too many JAVA_DIR in $SILENT_CONFIG“
        exit $EXIT_SILENT_INSTALL_JAVA_DIR
    fi

    # Get values from config file
    INSTALL_DIR=`grep ‚^INSTALL_DIR=‘ $SILENT_CONFIG | sed s/INSTALL_DIR=//`
    JAVA_DIR=`grep ‚^JAVA_DIR=‘ $SILENT_CONFIG | sed s/JAVA_DIR=//`
    ACCEPT_EULA=`grep ‚^ACCEPT_EULA=‘ $SILENT_CONFIG | sed s/ACCEPT_EULA=// | sed ’s/[^a-zA-Z]*//g‘ | $TR „[:lower:]“ „[:upper:]“ `
    REGISTER_NMC=`grep ‚^REGISTER_WITH_NMC=‘ $SILENT_CONFIG | sed s/REGISTER_WITH_NMC=// | $TR „[:lower:]“ „[:upper:]“ `

    # Verify INSTALL_DIR
    if [ -n „$INSTALL_DIR“ ]; then
        # Collapse multiple slashes on the path
        INSTALL_DIR=`echo $INSTALL_DIR | tr -s /`
    
        # Remove trailing slash (if any)
        buf=`echo $INSTALL_DIR | grep ‚/$‘ `
        if [ -n „$buf“ ]; then
            INSTALL_DIR=`echo $INSTALL_DIR | sed ’s//*$//’`
        fi
        
        # Ensure leading slash
        buf=`echo $INSTALL_DIR | grep ‚^/‘ ` 
        if [ -z „$buf“ ]; then
            Echo „Error: INSTALL_DIR must start with ‚/'“
            exit $EXIT_INVALID_INSTALL_DIR
        fi
        
        # Ensure no white space on path
        buf=`echo $INSTALL_DIR | grep ‚ ‚ ` 
        if [ -n „$buf“ ]; then
            Echo „Error: INSTALL_DIR must not contain white space.“
            exit $EXIT_INVALID_INSTALL_DIR
        fi
        
        # Ensure no backslashes on path
        buf=`echo $INSTALL_DIR | grep ‚\‘ ` 
        if [ -n „$buf“ ]; then
            Echo „Error: INSTALL_DIR must not contain back slash ‚\'“
            exit $EXIT_INVALID_INSTALL_DIR
        fi
        
        Echo „INSTALL_DIR=$INSTALL_DIR“
    else
        buf=`grep ‚^INSTALL_DIR=‘ $SILENT_CONFIG`
        buf2=`grep ‚^#INSTALL_DIR=‘ $SILENT_CONFIG`
        if [ -n „$buf“ -o -n „$buf2“ ]; then
            Echo „INSTALL_DIR is not specified.“
            Echo „PCNS is installed to the default directory „/opt/APC/PowerChute““
            Echo „“
        else
            Echo „Error: INSTALL_DIR is not configured“
            exit $EXIT_INVALID_INSTALL_DIR
        fi
    fi
    # Verify JAVA_DIR
    if [ -n „$JAVA_DIR“ ]; then

        #must have / at the end, so add it    
        buf=`echo $JAVA_DIR | grep ‚/$‘ ` 
        if [ -z „$buf“ ]; then
           JAVA_DIR=“$JAVA_DIR/bin/“
        fi

        # Add“/bin“ at the end of JAVA_DIR if needed.
        # This allows it to be backward compatible with previous versions, 
        # which did not have the bin
        
        buf=`echo $JAVA_DIR | grep ‚/bin/$‘ ` 
        if [ -z „$buf“ ]; then
               JAVA_DIR=“$JAVA_DIR/bin/“
        fi
        buf=`echo $JAVA_DIR | grep ‚^/‘ ` 
        if [ -z „$buf“ ]; then
            Echo „Error: JAVA_DIR must start with /“
            exit $EXIT_SILENT_INSTALL_JAVA_DIR
        fi
        
        buf=`echo $JAVA_DIR | grep ‚ ‚ ` 
        if [ -n „$buf“ ]; then
            Echo „Error: JAVA_DIR must not contain white space “ „“
            exit $EXIT_SILENT_INSTALL_JAVA_DIR
        fi
        
        buf=`echo $JAVA_DIR | grep ‚\‘ ` 
        if [ -n „$buf“ ]; then
            Echo „Error: JAVA_DIR must not contain back slash „\““
            exit $EXIT_SILENT_INSTALL_JAVA_DIR
        fi
        if [ ! -d „$JAVA_DIR“ ]; then
            Echo „Error: Invalid JAVA_DIR. $JAVA_DIR does not exist.“
            exit $EXIT_SILENT_INSTALL_JAVA_DIR
        fi
        Echo „JAVA_DIR=$JAVA_DIR“
    fi
}

IsSilentMode() {
    Echo „IsSilentMode“
}

IsRootUser() {
    ROOT=“root“
    case „$OS“ in    
    $SOLARIS)
        id | grep root > /dev/null 2>&1
        if [ $? -eq 0 ]; then
            USER=$ROOT
        fi
        ;;
    *)
        USER=`id -nu`
        ;;
    esac
    
    if [ $USER != $ROOT ]; then
        Echo „Error: $0 must be run with root privileges!“
        exit $EXIT_NOT_ROOT_USER
    fi
}

CheckOS() {
    OS=`uname | grep -i Linux`
    if [ ! -z „$OS“ ]; then
        # We’re a Linux derivative, decide which one.
        if [ -f /etc/vima-release ] || [ -f /etc/vma-release ]; then
            OS=$VIMA
        else 
            grep XenServer /etc/redhat-release > /dev/null 2>&1
            if [ $? -eq 0 ]; then
                OS=$XENSERVER
            else
                OS=$LINUX
            fi
        fi
    else
        OS=`uname | grep -i HP-UX`
        if [ ! -z „$OS“ ] 
        then
            OS=$HPUX
        else
            OS=`uname | grep -i AIX`
            if [ ! -z „$OS“ ] 
            then
                OS=$AIX
            else
                OS=`uname | grep -i SOLARIS`
                if [ ! -z „$OS“ ]
                then
                    OS=$SOLARIS
                    isSparc
                    SPARC=$?
                else 
                    OS=`uname | grep -i SUNOS`
                    if [ ! -z „$OS“ ]
                    then
                        OS=$SOLARIS
                        isSparc
                        SPARC=$?                        
                    else
                        Echo „Error: Unknown OS.“
                        exit $EXIT_UNSUPPORTED_OS
                    fi
                fi
            fi
        fi
    fi
    Echo „OS=$OS“
    Echo „“
}

isSparc() {
    rval=$FALSE
    tmp=`uname -a | grep -i SPARC`
    if [ ! -z „$tmp“ ] 
    then
        rval=$TRUE
    fi
    return $rval
}                        

Initialize() {
    Echo „Initializing …“
    case „$OS“ in
    $VIMA)
if [ -f /etc/SuSE-release ]; then
            STARTUP=/etc/init.d/PowerChute
        else
            STARTUP=/etc/rc.d/init.d/PowerChute
        fi
        PCBE_STARTUP=/etc/rc.d/init.d/PBEAgent
        PCS_STARTUP=/etc/rc.d/init.d/pcs
        ;;
    *)
        Echo „This version of PowerChute Network Shutdown only supports VMWare ESXi. Please consult www.apc.com for the required version of PowerChute Network Shutdown.“
        exit $EXIT_CONFLICT_VMWARE 
        ;;
    
    esac
}

IsPCNSInstalled() {
    upgrade=$FALSE    
    version=“Unknown“
    if [ -f „$STARTUP“ ]; then
        grep ‚PowerChute Network Shutdown, v2.2.4‘ $STARTUP 1>/dev/null 2>/dev/null
        if [ $? = 0 ]; then
            Echo „Found PowerChute Network Shutdown v2.2.4.“
            version=“2.2.4″
            upgrade=$TRUE
        fi
        
        grep ‚PowerChute Network Shutdown, v2.2.5‘ $STARTUP 1>/dev/null 2>/dev/null
        if [ $? = 0 ]; then
            Echo „Found PowerChute Network Shutdown v2.2.5.“
            version=“2.2.5″
            upgrade=$TRUE
        fi
        
        grep ‚PowerChute Network Shutdown, v2.2.6‘ $STARTUP 1>/dev/null 2>/dev/null
        if [ $? = 0 ]; then
            Echo „Found PowerChute Network Shutdown v2.2.6.“
            version=“2.2.6″
            upgrade=$TRUE
        fi
        
        grep ‚PowerChute Network Shutdown, v2.2.7‘ $STARTUP 1>/dev/null 2>/dev/null
        if [ $? = 0 ]; then
            Echo „Found PowerChute Network Shutdown v2.2.7.“
            version=“2.2.7″
            upgrade=$TRUE
        fi
        
        grep ‚PowerChute Network Shutdown, v3.0.0‘ $STARTUP 1>/dev/null 2>/dev/null
        if [ $? = 0 ]; then
            Echo „Found PowerChute Network Shutdown v3.0.0.“
            version=“3.0.0″
            upgrade=$TRUE
        fi
        
        if [ $upgrade = $FALSE ]; then
            Echo „PowerChute Network Shutdown is already installed. Upgrade is not supported for this version.“
            Echo „Please uninstall existing PCNS to continue with installation of PCNS v.3.0.“
            Echo „Installation cancelled.“
            Echo „“
            exit $EXIT_UPGRADE_NOT_SUPPORTED
        fi
        
        result=$FALSE
        while [ $result = $FALSE ]
        do
            prev_install_dir=`grep ‚^INSTALL_PATH=‘  $STARTUP | sed s/INSTALL_PATH=“// | sed s/“//`
            if [ -d „$prev_install_dir/$GROUP2“ ]; then
                Echo „Previous version of PowerChute Network Shutdown is installed.“
                Echo „Update install does not support multiple instances.“
                Echo „Please uninstall PCNS and run this install program again.“
                Echo „Installation cancelled.“
                Echo „“
                exit $EXIT_UPGRADE_NOT_SUPPORTED
            fi
            if [ $SILENT_MODE = $TRUE ]; then
                Echo „Previous version of PowerChute Network Shutdown is installed.“
                Echo „Start update installation.“
                val=$YES
            else
                Echo „Previous version of PowerChute Network Shutdown is installed.“
                IsYN „Do you want to update it [Yes|No]?“
                val=$?
            fi
            case $val in
            $YES)
                Echo „Update selected for existing version of PowerChute Network Shutdown.“
                UPDATE_INSTALL=$TRUE
                result=$TRUE
                ;;
            $NO)
                Echo „Installation cancelled.“
                Echo „“
                exit $EXIT_USER_ABORT
                ;;
            *)
                Echo „Invalid response.“
                ;;
            esac
        done
    fi
}

IsPCPlusInstalled() {
    if [ -d „/etc/apc_repository“ ]; then
        Echo „PowerChute Plus is installed. Please uninstall PowerChute Plus.“
        exit $EXIT_CONFLICT_PCPLUS
    fi
}

IsPCBEInstalled() {
    if [ -n „$PCBE_STARTUP“ -a -f „$PCBE_STARTUP“ ]
    then
        Echo „PowerChute Business Edition Agent is installed. Please uninstall PCBE Agent.“
        exit $EXIT_CONFLICT_PCBE
    fi
}

IsPCSInstalled() {
    if [ -n „$PCS_STARTUP“ -a -f „$PCS_STARTUP“ ]
    then
        Echo „PowerChute Server is installed. Please uninstall PowerChute Server.“
        exit $EXIT_CONFLICT_PCS
    fi
}

checkForVMWare() {
    lang=’ja_‘
    if env | grep ^LANG=$lang &>/dev/null;
    then
       if [ -e /usr/bin/vmware ]
       then
           # VMware detected!
           
           # Check for VMware Server
           if /usr/bin/vmware -v | grep Server &> /dev/null
           then
                Echo „VMware Server has been detected on your system. This version of PowerChute Network Shutdown does not support VMware. Please uninstall VMware Server, or consult www.apc.com for the required version of PowerChute Network Shutdown.“
                exit $EXIT_CONFLICT_VMWARE
           fi
           
           # Check for VMware Workstation
           if /usr/bin/vmware -v | grep Workstation &> /dev/null
           then
                Echo „VMware Workstation has been detected on your system. This version of PowerChute Network Shutdown does not support VMware. Please uninstall VMware Workstation, or consult www.apc.com for the required version of PowerChute Network Shutdown.“
                exit $EXIT_CONFLICT_VMWARE
           fi
       fi
       
       # Check for VMware-Player
       if [ -e /usr/bin/vmplayer ]
       then
           # VMware Player detected.
            Echo „VMware Player has been detected on your system. This version of PowerChute Network Shutdown does not support VMware. Please uninstall VMware Player, or consult www.apc.com for the required version of PowerChute Network Shutdown.“
            exit $EXIT_CONFLICT_VMWARE
       fi

     fi
}

checkForXenServer() {
    grep XenServer /etc/redhat-release > /dev/null 2>&1
    if [ $? -eq 0 ]; then
        Echo „Xen Server has been detected on your system.“
        Echo „This version of PowerChute Network Shutdown does not support Xen Server.“
        Echo „Please consult www.apc.com for the required version of PowerChute Network Shutdown.“
        exit $EXIT_CONFLICT_VMWARE
    fi
}

InitUpdate() {
    if [ $UPDATE_INSTALL = $TRUE ]; then
        # Get PCNS Path
        OLD_INSTALL_DIR=`grep ‚^INSTALL_PATH=‘  $STARTUP | sed s/INSTALL_PATH=“// | sed s/“//`
        Echo „PowerChute Network Shutdown previously installed at:$OLD_INSTALL_DIR“ 
        # Stop daemon
        case „$OS“ in
        $VIMA)
        if [ -f /etc/SuSE-release ]; then
            /etc/init.d/PowerChute stop
        else
            /etc/rc.d/init.d/PowerChute stop
        fi
            ;;
        $XENSERVER)
            /etc/rc.d/init.d/PowerChute stop
            ;;
        $LINUX)
            if [ -f /etc/SuSE-release ]; then
                /etc/init.d/PowerChute stop
            else
                /etc/rc.d/init.d/PowerChute stop
            fi
            ;;
        $SOLARIS)
            /etc/rc2.d/S99PowerChute stop
            ;;
        $HPUX)
            /sbin/init.d/pcns stop
            ;;
        $AIX)
            /etc/rc.APCpcns stop
            ;;
        esac
    fi
}

BackupOldPCNS() {
    if [ $UPDATE_INSTALL = $TRUE ]; then
        # Install dir is same as old PCNS
        if [ „$INSTALL_DIR/PowerChute“ = „$OLD_INSTALL_DIR“ ]; then
            backup_dir=“$INSTALL_DIR/PowerChute_update_backup“
            rm -rf $backup_dir
            mv $OLD_INSTALL_DIR $backup_dir
            mkdir -p $OLD_INSTALL_DIR
            OLD_INSTALL_DIR=$backup_dir
            Echo „Backup old PCNS directory to $OLD_INSTALL_DIR“
        fi
    fi
}

UninstallOldPCNS() {
    if [ $UPDATE_INSTALL = $TRUE ]; then
        # remove all files
        rm -rf $OLD_INSTALL_DIR
    fi
}

CopyUpdateFiles() {
    if [ $UPDATE_INSTALL = $TRUE ]; then
        Echo „Copying update files …“
        if [ -d „$OLD_INSTALL_DIR/$GROUP1“ ]; then
            # PCNS 222
            backup_dir=“$OLD_INSTALL_DIR/$GROUP1″
        else
            backup_dir=“$OLD_INSTALL_DIR“
        fi
        cp „$backup_dir/m11.cfg“ „$APP_DIR/$GROUP1/“ 1>/dev/null 2>/dev/null
        cp „$backup_dir/EventLog.txt“ „$APP_DIR/$GROUP1/“ 1>/dev/null 2>/dev/null
        
        # Convert m11.cfg to INI
        oldDir=$PWD
        cd $APP_DIR/$GROUP1
        m11Path=“$backup_dir/m11.cfg“
        #merge pcnsconfig.ini files.
        oldIniPath=“$backup_dir/pcnsconfig.ini“
        
        javaParams=“-cp .:comp/pcns.jar:lib/m11.jar:lib/commons-codec-1.4.jar:lib/commons-collections-3.2.1.jar:lib/commons-configuration-1.6.jar:lib/commons-lang-2.5.jar:lib/commons-logging-1.1.1.jar:lib/log4j-1.2.16.jar -Dm11Path=$m11Path -DoldIniPath=$oldIniPath -DapplicationDirectory=$APP_DIR -Dgroup=1 com.apcc.pcns.m11converter.M11Converter“
        #Echo ${JAVA_DIR}java  $javaParams
        ${JAVA_DIR}java  $javaParams 1>/dev/null 2>/dev/null
        cd $oldDir
    fi
}

SetInstallDir() {
    if [ $SILENT_MODE = $TRUE ]; then
        if [ -z „$INSTALL_DIR“ ]; then
            INSTALL_DIR=“/opt/APC“
        fi
    elif [ $UPDATE_INSTALL = $TRUE ]; then
        # Use the old location
        INSTALL_DIR=`dirname $OLD_INSTALL_DIR`
    else
        res=$FALSE
        while [ $res = $FALSE ]
        do
            Echo „“
            Echo „Please enter the installation directory or press enter to install to the default directory (/opt/APC/PowerChute):“
            read val
            if [ -z „$val“ ]; then
                INSTALL_DIR=“/opt/APC“    
            else
                INSTALL_DIR=$val    
                # Verify install path
                if [ -n „$INSTALL_DIR“ ]; then
                    buf=`echo $INSTALL_DIR | grep ‚^/‘ ` 
                    if [ -z „$buf“ ]; then
                        Echo „Installation directory must start with „/““
                        exit $EXIT_INVALID_INSTALL_DIR
                    fi
                    buf=`echo $INSTALL_DIR | grep ‚ ‚ ` 
                    if [ -n „$buf“ ]; then
                        Echo „Installation directory must not contain white space “ „“
                        exit $EXIT_INVALID_INSTALL_DIR
                    fi
                    buf=`echo $INSTALL_DIR | grep ‚\‘ ` 
                    if [ -n „$buf“ ]; then
                        Echo „Installation directory must not contain back slash „\““
                        exit $EXIT_INVALID_INSTALL_DIR
                    fi
                fi
            fi

            IsYN „Are you sure you want to install PCNS to $INSTALL_DIR/PowerChute [Yes|No]?“
            val=$?
            case $val in
            $YES)
                if [ -d „$INSTALL_DIR/PowerChute“ ]; then
                    IsYN „$INSTALL_DIR/PowerChute already exists. Do you want to use it [Yes|No]?“
                    val=$?
                    case $val in
                    $YES)
                        BackupOldPCNS
                        res=$TRUE
                        ;;
                    $NO)
#                        Echo „Please enter the installation directory:“
#                        read INSTALL_DIR
                        ;;
                    *)
                        Echo „Invalid response.“
                        ;;
                    esac
                else
                    res=$TRUE
                fi
                ;;
            $NO)
#                Echo „Please enter the installation directory (Example:/opt/APC):“
#                read INSTALL_DIR
                ;;
            *)
                Echo „Invalid response.“
                ;;
            esac
        done
    fi

    if [ ! -d „$INSTALL_DIR“ ]; then
        Echo „Creating $INSTALL_DIR directory …“
        mkdir -p „$INSTALL_DIR“
        if [ ! $? = 0 ]; then
            Echo „Failed to create directory $INSTALL_DIR.“
            exit $EXIT_INVALID_INSTALL_DIR
        fi
    fi
    Echo „PCNS will be installed to $INSTALL_DIR/PowerChute“
}

CheckBundledJava() {
    rval=$FALSE
    case „$OS“ in
    $VIMA)
        JRE_FILE=$JRE_VERSION“_linux64.tar.gz“
        ;;
    $LINUX)
        JRE_FILE=$JRE_VERSION“_linux32.tar.gz“
        ;;
    $SOLARIS)
        if [ $SPARC = $TRUE ]; then
            JRE_FILE=$JRE_VERSION“_solaris-sparc.tar.gz“            
        else
            JRE_FILE=$JRE_VERSION“_solaris-x86.tar.gz“
        fi
        ;;
    $XENSERVER)
        JRE_FILE=$JRE_VERSION“_linux32.tar.gz“
        ;;
    $HPUX)
        ;;
    $AIX)
        ;;
    esac
    if [ -f „$SRC_DIR/$JRE_FILE“ ]; then
        rval=$TRUE
    fi
    return $rval
}

AskJavaPath() {
    CheckBundledJava
    bundled=$?
    res=$FALSE
    while [ $res = $FALSE ]
    do
        Echo „“
        if [ $bundled = $TRUE ];then
            Echo „Please enter java directory if you want to use your system java (example:/usr/local/bin/jre/$JRE_VERSION) or press enter to install the bundled Java:“
        else
            Echo „JRE is not bundled. Please enter your java directory (example:/usr/local/bin/jre/$JRE_VERSION):“
        fi
        
        read str
                
        if [ $bundled = $TRUE -a -z „$str“ ]; then
            #the empty string is ok, means use the path JRE
            JAVA_DIR=““
            res=$TRUE
        else
            JAVA_DIR=$str
            res=$FALSE
        fi
        
        if [ $res = $FALSE -a -n „$JAVA_DIR“ ]; then
            #Fix it as needed
            
            #must have / at the end, so add it    
            buf=`echo $JAVA_DIR | grep ‚/$‘ ` 
            if [ -z „$buf“ ]; then
                  JAVA_DIR=“${JAVA_DIR}/“
            fi
        
            # Add/bin at the end of JAVA_DIR if needed
            # This allows it to be backward compatible
            # with previous versions, which did not have 
            # the bin
            buf=`echo $JAVA_DIR | grep ‚/bin/$‘ ` 
            if [ -z „$buf“ ]; then
                   JAVA_DIR=“$JAVA_DIR/bin/“
            fi
            
            buf=`echo $JAVA_DIR | grep ‚ ‚ ` 
            if [ -n „$buf“ ]; then
                Echo „Java directory must not contain white space “ „“
            else
                buf=`echo $JAVA_DIR | grep ‚^/‘ ` 
                if [ -z „$buf“ ]; then
                    Echo „Java directory must start with /“
                else
                    buf=`echo $JAVA_DIR | grep ‚\‘ ` 
                    if [ -n „$buf“ ]; then
                        Echo „Java directory must not contain back slash „\““
                    elif [ ! -d $JAVA_DIR ]; then
                        Echo „Invalid path: $JAVA_DIR“
                    else                                      
                        #Check the java version before confirming, no point in 
                        #asking them if they want it is we can’t accept it anyway.
                         CheckJavaVersion
                         res=$?                        
                    fi
                fi
            fi            
         fi 
    done
}

InstallBundledJava() {
    CheckBundledJava
    if [ $? = $FALSE ]; then
        Echo „No private JRE is bundled for this OS.  Please install and specify a JRE“
        CancelAll $EXIT_INVALID_JAVA_VERSION
    fi 
    
    # Copy jre file
    JAVA_DIR=“$APP_DIR/jre/bin/“

    Echo „Copying jre to $APP_DIR …“
    mkdir -p $APP_DIR
    cp $SRC_DIR/$JRE_FILE $APP_DIR/jre.tar.gz
    if [ ! $? -eq 0 ]; then
        Echo „Failed to copy jre file.“
        CancelAll
    fi
    cd $APP_DIR
    chmod 700 jre.tar.gz

    # Extract Java
    Echo „Extracting jre to $APP_DIR/jre …“
    gunzip jre.tar.gz
    tar -xf jre.tar
    if [ ! $? -eq 0 ]; then
        Echo „Failed to extract jre file.“
        CancelAll
    fi
    rm -rf jre.tar
    
    # Regenerating the Shared Archive
    if [ ! $OS = „$VIMA“ ]; then
        $JAVA_DIR/java -Xshare:dump 1>/dev/null 2>/dev/null
    fi
    cd $APP_DIR
}

CheckJavaVersion() {
    Echo „Checking version of Java …“
    rval=$FALSE

    # Show JRE Version
    ${JAVA_DIR}java -version >/dev/null 2>&1
    if [ ! $? -eq 0 ]; then 
        Echo 
        Echo „Java not found at ${JAVA_DIR}.“
    else
        VERSION=`${JAVA_DIR}java -version 2>&1 | head -n 1 | cut -d“ -f 2 | sed s/_/./g`
        Echo „Detected Java Version: $VERSION“

        MAJOR=`echo $VERSION | cut -d. -f 1`
        MINOR=`echo $VERSION | cut -d. -f 2`
        MINI=`echo $VERSION | cut -d. -f 3`
        MICRO=`echo $VERSION | cut -d. -f 4`

        if [ -z „$MICRO“ ]; then
            MICRO=0
        fi
        
        case „$OS“ in
        $HPUX)
            JRE_REQUIRED_MICRO=08
            ;;
        *) 
            JRE_REQUIRED_MICRO=0
            ;;
        esac
        
        if [ $VERSION ]; then
            if [ ( $MAJOR -gt $JRE_REQUIRED_MAJOR ) -o ( $MAJOR -eq $JRE_REQUIRED_MAJOR -a $MINOR -gt $JRE_REQUIRED_MINOR ) -o ( $MAJOR -eq $JRE_REQUIRED_MAJOR -a $MINOR -eq $JRE_REQUIRED_MINOR -a $MINI -gt $JRE_REQUIRED_MINI ) -o ( $MAJOR -eq $JRE_REQUIRED_MAJOR -a $MINOR -eq $JRE_REQUIRED_MINOR -a $MINI -eq $JRE_REQUIRED_MINI -a $MICRO -ge $JRE_REQUIRED_MICRO ) ]; then
                Echo „Acceptable version“
                rval=$TRUE
            else
                Echo „Wrong version of Java.  Minimum Java version required is $JRE_REQUIRED_MAJOR.$JRE_REQUIRED_MINOR.$JRE_REQUIRED_MINI.$JRE_REQUIRED_MICRO „
                Echo „Java can be downloaded from www.java.com“
            fi
        else
            Echo 
            Echo „Java not found at $JAVA_DIR“
        fi
    fi
    return $rval
}

SetupJava() {
    if [ $SILENT_MODE = $TRUE ]; then
        if [ -z „$JAVA_DIR“ ]; then
            InstallBundledJava
            res=$TRUE
        else
            CheckJavaVersion
            res=$?
            
            if [ $res -eq $FALSE ]; then
                # invalid java path
                CancelAll $EXIT_INVALID_JAVA_VERSION
            fi
        fi        
    else
        AskJavaPath
        if [ -z „$JAVA_DIR“ ]; then
            InstallBundledJava
        fi
    fi

    # Show JRE Version
    Echo „“
    $JAVA_DIR/java -version
    if [ ! $? -eq 0 ]; then 
        Echo „“ 
        Echo „Invalid jre path.“
        CancelAll
    fi
    Echo „“
    # Create java path config file
    Echo „JAVA_DIR=$JAVA_DIR“
    Echo „“
    cd $SRC_DIR
}

SetupM11Cfg() {
   Echo „Setup the m11.cfg file“
   filename=“$GROUP_DIR/m11.cfg“
   setting1=“host.ApplicationDirectory=$GROUP_DIR“
   setting2=“host.ComponentDirectory=$GROUP_DIR/comp“
   setting3=“Notifier.NotifierExe=$GROUP_DIR/bin/notifier“

    #echo „DEBUG: $setting1“
    #echo „DEBUG: $setting2“
    #echo „DEBUG: $setting3“
    
    PARAMS=“ -cp .:$GROUP_DIR/comp/pcns.jar:$GROUP_DIR/lib/m11.jar com.apcc.pcns.m11cfgInit.M11cfgInit $filename $setting1 $setting2 $setting3″
    #echo „DEBUG: ${JAVA_DIR}java $PARAMS“
   #Note:JAVA_DIR has the on the end
   ${JAVA_DIR}java $PARAMS 1>/dev/null 2>/dev/null
   
}

SetupCommandFiles() {
    case „$OS“ in
    $VIMA)
        cp VIMA/notifier.sh notifier
        cp VIMA/shutdown.sh shutdown
        cp VIMA/shutdownhost.pl shutdownhost.pl
        chmod 744 shutdownhost.pl
        ;;
    $XENSERVER)
        cp Linux/notifier.sh notifier
        cp Linux/shutdown.sh shutdown
        ;;        
    $LINUX)
        cp Linux/notifier.sh notifier
        cp Linux/shutdown.sh shutdown
        ;;
    $SOLARIS)
        cp Solaris/notifier.sh notifier
        cp Solaris/shutdown.sh shutdown
        ;;
    $HPUX)
        cp Hpux/notifier.sh notifier
        cp Hpux/shutdown.sh shutdown
        ;;
    $AIX)
        cp Aix/notifier.sh notifier
        cp Aix/shutdown.sh shutdown
        ;;
    esac    
    chmod 744 notifier
    chmod 744 shutdown
    rm -rf Linux Solaris Hpux Aix VIMA ESX XenServer
    cd „$APP_DIR“
}

SetupAllCommandFiles() {
    cd „$APP_DIR“
    if [ -d $GROUP1 ]; then
        cd ./$GROUP1/bin
        SetupCommandFiles
    else
        cd ./bin
        SetupCommandFiles
    fi
    cd „$APP_DIR“
}

ConfigureStartup() {
    APP_DIR_QUOTED=“$APP_DIR“
    group_dir_quoted=“$GROUP_DIR“

    # Update scripts
    if [ $OS = „$HPUX“ ]; then
        sed -e „s:nohup:/bin/nohup:g“ powerchute.sh > powerchute.sh.tmp$$
        mv -f powerchute.sh.tmp$$ powerchute.sh
    fi
    sed -e „s:GSUB_INSTALL_PATH:$APP_DIR_QUOTED:g“ startup.sh > startup.sh.tmp$$
    sed -e „s:GSUB_INSTALL_PATH:$group_dir_quoted:g“ powerchute.sh > powerchute.sh.tmp$$
    # Add LSB into startup script for insserv
        if [ -f /etc/SuSE-release ]; then
            sed -e „s:#!/bin/sh::“ startup.sh.tmp$$ > startup.sh
            echo „#!/bin/sh“ > startup.sh.tmp$$
            echo „### BEGIN INIT INFO “  >> startup.sh.tmp$$
            echo „# Provides: PowerChute “  >> startup.sh.tmp$$
            echo „# Required-Start: “  >> startup.sh.tmp$$
            echo „# Required-Stop: “  >> startup.sh.tmp$$
            echo „# Should-Start: “  >> startup.sh.tmp$$
            echo „# Should-Stop: “  >> startup.sh.tmp$$
            echo „# Default-Start: 3 5 “  >> startup.sh.tmp$$
            echo „# Default-Stop: “  >> startup.sh.tmp$$
            echo „# Short-Description: PowerChute “  >> startup.sh.tmp$$
            echo „# Description: PowerChute Network Shutdown Daemon “  >> startup.sh.tmp$$
            echo „### END INIT INFO “  >> startup.sh.tmp$$
            `cat startup.sh >> startup.sh.tmp$$`
    fi
    mv -f startup.sh.tmp$$ startup.sh
    cp powerchute.sh.tmp$$ $GROUP_DIR/powerchute.sh
    chmod 744 $GROUP_DIR/powerchute.sh
    rm -f *.tmp$$

    echo $JAVA_DIR > ${GROUP_DIR}/java.cfg
}

ConfigureAllStartup() {
    Echo „Configuring startup files …“
    cd „$APP_DIR“
    
    if [ -d $GROUP1 ]; then
        GROUP_DIR=“$APP_DIR/$GROUP1″
        ConfigureStartup
        rm -f powerchute.sh*
    else
        GROUP_DIR=$APP_DIR
        ConfigureStartup
    fi
    Echo „Startup script=$STARTUP“
    # Add symbolic link for SuSE OS
        if [ -f /etc/SuSE-release ]; then
            awk ‚/^VERSION/ { z = split($0,array,“=“); sub(“ „,““,array[z]); version=substr(array[z],1,index(array[z],“.“)-1); if(version >=8) exit 0 }‘ /etc/SuSE-release
            if [ $? -eq 0 ]; then
                ln -s /etc/init.d /etc/rc.d/init.d
            fi
    fi
    cp startup.sh $STARTUP
    chmod 0544 $STARTUP
    rm -f startup.sh
}

UninstallOldStartupLink() {
    if [ $UPDATE_INSTALL = $TRUE ]; then
        if [ $OS = „$LINUX“ -o $OS = „$VIMA“ -o $OS = „$XENSERVER“ ]; then
            Echo „Deleting Linux symbolic link …“
            rm -f /etc/rc.d/rc0.d/*99PowerChute
            rm -f /etc/rc.d/rc1.d/*99PowerChute
            rm -f /etc/rc.d/rc2.d/*99PowerChute
            rm -f /etc/rc.d/rc3.d/*99PowerChute
            rm -f /etc/rc.d/rc4.d/*99PowerChute
            rm -f /etc/rc.d/rc5.d/*99PowerChute
            rm -f /etc/rc.d/rc6.d/*99PowerChute
        fi
    fi
}

ConfigureStartupLink() {
     if [ $OS = „$LINUX“ -o $OS = „$VIMA“ -o $OS = „$XENSERVER“ ]; then
        Echo „Updating Linux symbolic link …“
        if [ -f /etc/SuSE-release ]; then
   insserv PowerChute 1>/dev/null 2>/dev/null
        elif [ -f /sbin/chkconfig ]; then
            chkconfig –add PowerChute
            chkconfig PowerChute on
        else
            ln -s /etc/rc.d/init.d/PowerChute /etc/rc.d/rc0.d/K99PowerChute
            ln -s /etc/rc.d/init.d/PowerChute /etc/rc.d/rc1.d/K99PowerChute
            ln -s /etc/rc.d/init.d/PowerChute /etc/rc.d/rc2.d/S99PowerChute
            ln -s /etc/rc.d/init.d/PowerChute /etc/rc.d/rc3.d/S99PowerChute
            ln -s /etc/rc.d/init.d/PowerChute /etc/rc.d/rc4.d/S99PowerChute
            ln -s /etc/rc.d/init.d/PowerChute /etc/rc.d/rc5.d/S99PowerChute
            ln -s /etc/rc.d/init.d/PowerChute /etc/rc.d/rc6.d/K99PowerChute
        fi
    else
        case „$OS“ in
        $SOLARIS)
            cp $STARTUP /etc/rc0.d/K99PowerChute
            ;;
        $HPUX)
            Echo „Updating HP-UX symbolic link …“
            ln -s $STARTUP /sbin/rc1.d/K990pcns
            ln -s $STARTUP /sbin/rc2.d/S990pcns
            ;;
        $AIX)
            Echo „Updating AIX inittab …“
            mkitab „PCNS:2:wait:$STARTUP start #PowerChute Network Shutdown“ >/dev/null 2>&1
            ;;
        esac
    fi
}

ConfigureUninstall() {
    Echo „Configuring uninstall script …“
    cd „$APP_DIR“
    APP_DIR_QUOTED=“$APP_DIR“
    sed -e „s:GSUB_INSTALL_PATH:$APP_DIR_QUOTED:g“ uninstall > uninstall.tmp$$
    mv -f uninstall.tmp$$ uninstall
    chmod 0544 uninstall 
}

CopyUninstallPatch() {
Echo „Copying Uninstall patch file to App_Dir …“
cd „$SRC_DIR“
cp -f uninstall $APP_DIR
Echo „Copying Done …“
}

ConfigureOwner() {
    chown -R root „$APP_DIR“
    if [ $OS = „$AIX“ ]; then
        chgrp -R system $APP_DIR
    else
        chgrp -R root $APP_DIR
    fi
}

RemoveStartup() {
  if [ $OS = „$LINUX“ -o $OS = „$VIMA“ -o $OS = „$XENSERVER“ ]; then
    if [ -f $STARTUP ]; then
        if [ -f /sbin/chkconfig ]; then
            chkconfig PowerChute off
            chkconfig –del PowerChute
        else
            rm -f /etc/rc.d/rc1.d/K99PowerChute
            rm -f /etc/rc.d/rc2.d/S99PowerChute
            rm -f /etc/rc.d/rc3.d/S99PowerChute
            rm -f /etc/rc.d/rc4.d/S99PowerChute
            rm -f /etc/rc.d/rc5.d/S99PowerChute
            rm -f /etc/rc.d/rc6.d/K99PowerChute
        fi
        rm -f $STARTUP
    fi
  else
    case „$OS“ in
    $SOLARIS)
        rm -f /etc/rc2.d/S99PowerChute
        rm -f /etc/rc0.d/K99PowerChute
        ;;
    $HPUX)
        if [ -f /sbin/init.d/pcns ]; then
            rm -f /sbin/rc1.d/K990pcns
            rm -f /sbin/rc2.d/S990pcns
            rm -f /sbin/init.d/pcns
        fi
        ;;
    $AIX)
        if [ -f /etc/rc.APCpcns ]; then
            rmitab PCNS
            rm -f /etc/rc.APCpcns
        fi
        ;;
    esac
  fi
}

CancelAll() {
    cd „$SRC_DIR“
    if [ -n „$INSTALL_DIR“ ]; then
        if [ -d „$INSTALL_DIR/PowerChute“ ]; then
            rm -rf „$INSTALL_DIR/PowerChute“
            RemoveStartup
        else
            rm -f „$INSTALL_DIR/$PCNS_TAR*“
        fi
    fi
    Echo „“
    Echo „Installation cancelled.“
    Echo „“
    exit $1
}

ConfigureFirewall(){
    if [ -f /usr/sbin/esxcfg-firewall ]; then
        esxcfg-firewall -o 80,tcp,out,“APC PowerChute Port 80″
        esxcfg-firewall -o 3052,tcp,out,“APC PowerChute Port 3052″
        esxcfg-firewall -o 3052,tcp,in,“APC PowerChute Port 3052″
        esxcfg-firewall -o 3052,udp,out,“APC PowerChute Port 3052″
        esxcfg-firewall -o 3052,udp,in,“APC PowerChute Port 3052″
        esxcfg-firewall -o 6547,tcp,in,“APC PowerChute Port 6547″
    else
        if [ -f /sbin/iptables ]; then
            iptables -I OUTPUT -p tcp –sport 80 -j ACCEPT
            iptables -I OUTPUT -p tcp –sport 3052 -j ACCEPT
            iptables -I INPUT -p tcp –dport 3052 -j ACCEPT
            iptables -I OUTPUT -p udp –sport 3052 -j ACCEPT
            iptables -I INPUT -p udp –dport 3052 -j ACCEPT
            iptables -I INPUT -p tcp –dport 6547 -j ACCEPT
            
            service iptables save
        fi        
   fi
}

DisplayEULA(){
    
    # Default to english license
    EULA=“apclicense.txt“

    Echo „$LANG“ | grep -i ‚ja_JP.utf-*8‘
    if [ $? -eq 0 ]; then
       EULA=“apclicense.txt.ja_UTF8″
    fi

    Echo „$LANG“ | grep -i ‚ja_JP.IBM-*943‘
    if [ $? -eq 0 ]; then
       EULA=“apclicense.txt.ja_ANSI“
    fi

    Echo „$LANG“ | grep -i ‚eucJP‘
    if [ $? -eq 0 ]; then
        EULA=“apclicense.txt.ja_EUC“
    fi 
    
    # Extract EULA
    cp $PCNS_ZIP backup.tar.gz
    gunzip $PCNS_ZIP
    tar -xof $PCNS_TAR > /dev/null 2>&1
        
    # Display EULA
    printf „nPress any key to display End User License Agreementn“
    Pause
    more „PowerChute/group1/$EULA“
    
    # Remove file, now that we’ve read it.
    rm -rf PowerChute > /dev/null 2>&1
    rm -rf $PCNS_TAR > /dev/null 2>&1
    mv backup.tar.gz $PCNS_ZIP > /dev/null 2>&1
    
    agreed=
    while [ -z „$agreed“ ]
    do
        printf „nDo you agree to the above license terms? [yes or no]n“
        read reply leftover
        case $reply in
            [yY] | [yY][eE][sS])
                agreed=1
                ;;
            [nN] | [nN][oO])
                printf „If you don’t agree to the license you can’t install this softwaren“
                exit $EXIT_USER_ABORT
                ;;
            *)
                printf „Please enter „yes“ or „no“.“
                ;;
        esac
     done
}

AddESXiTargetServer() {

    if [ -f /etc/vima-release ] || [ -f /etc/vma-release ]; then
        echo “ „
        echo „In order for PCNS to shutdown the ESXi host, it must be added as a target server.“
        
        # validIP:
        # 0 – IP is valid
        # 1 – IP is invalid
        # 2 – User is skipping this
        
        validIP=1
                
        while [ $validIP -eq 1 ]
        do
            echo „Please enter ESXi host IP (XXX.XXX.XXX.XXX) or (q) to skip:“
            read esxihostip
        
            case $esxihostip in
                [qQ])
                    validIP=2
                    printf „nSkipping configuration of ESXi Host Shutdown.n“
                    ;;
            esac
            
            
            if [ $validIP -ne 2 ]; then
                #
                # Validate IP
                #
                valid_ip $esxihostip
                if [ $? -ne 0 ]; then
                    # invalid ip
                    printf „nInvalid IP entered.n“
                    validIP=1
                else
                    validIP=0
                fi                
            fi            
        done
        
        if [ $validIP -eq 0 ]; then
            echo „Please enter ESXi host username:“
            read esxihostuser
        
            echo „Please enter ESXi host password:“
            OLDCONFIG=`stty -g`
            stty -icanon -echo min 1 time 0
            read esxihostpwd
            stty $OLDCONFIG
        
            echo „Adding target server…“
            
            vifp addserver $esxihostip –username $esxihostuser –password $esxihostpwd
            vifp listservers | grep $esxihostip
            if [ $? -eq 0 ]; then
                    echo „Successfully added ESXi host to target server list.“                    
                    echo „“
            else
                    echo „Failed to add ESXi host.“
                    echo „To add the host manually please run – sudo vifp addserver <ipaddress>“
                    echo „“
            fi        
        fi        
    fi
}

valid_ip()
{
    ERROR=0
    oldIFS=$IFS
    IFS=.
    set -f
    set — $1
    if [ $# -eq 4 ]; then
        for seg
        do
            case $seg in
                „“|*[!0-9]*) ERROR=1;break ;; ## Segment empty or non-numeric char
                *) [ $seg -gt 255 ] && ERROR=2 ;;
            esac
        done
    else
        ERROR=3 ## Not 4 segments
    fi
    IFS=$oldIFS
    set +f
    return $ERROR
}

CheckLocale(){
    Echo „$LANG“ | grep -i ‚ja*‘
    if [ $? -eq 0 ]; then   
        # Abort, can’t install english on Japanese OS.
        printf „nThis version of PowerChute Network Shutdown does not support the Japanese language. Please consult www.apc.com for the required version of PowerChute Network Shutdown.n“
        exit $EXIT_INVALID_LOCALE
    fi    
}

ApplySilentConfig(){
    if [ „$SILENT_MODE“ = „$TRUE“ ]; then
        Echo „Applying Configuration …“
        
        # Register with NMC
        oldDir=$PWD
        cd $APP_DIR/$GROUP1

        upgrade=“false“
        if [ „$UPDATE_INSTALL“ = „$TRUE“ ]; then
            upgrade=“true“
        fi                
        
        javaParams=“-cp .:comp/pcns.jar:lib/m11.jar:lib/commons-codec-1.4.jar:lib/commons-collections-3.2.1.jar:lib/commons-configuration-1.6.jar:lib/commons-lang-2.5.jar:lib/commons-logging-1.1.1.jar:lib/log4j-1.2.16.jar -DsilentConfig=$SILENT_CONFIG -DsourceDir=$SRC_DIR -DapplicationDirectory=$APP_DIR -Dgroup=1 -Dupgrade=$upgrade com.apcc.pcns.silentconfig.SilentConfig“
        ${JAVA_DIR}java  $javaParams 2>/dev/null
        
        code=$?
        if [ $code -ne 0 ]; then
            Echo „Error applying configuration.  Error code is: $code“
            CancelAll $code
        fi
        
        Echo „Configuration complete.“
        cd $oldDir    
    fi
}

InstallComplete(){
    NODE_NAME=`uname -n`
    Echo „“
    Echo „Installation has completed.“
    Echo „PowerChute Network Shutdown can be accessed through your browser at https://<your_server_ip_address>:6547“

    if [ $UPDATE_INSTALL = $FALSE ]; then    
        Echo „Please complete the configuration wizard so that PowerChute Network Shutdown can protect your server.“
    fi
    
    Echo „“
}

######################################################################
# Main routine
######################################################################
SRC_DIR=`pwd`

# Check zipped install file
if [ ! -f $PCNS_ZIP ]; then
    Echo „Can’t find $PCNS_ZIP“
    exit $EXIT_ZIPFILE_MISSING
fi

# Print Banner
Echo „——————————————————————„
Echo “     PowerChute Network Shutdown 3.0.0 for VMware ESXi“
Echo “     Copyright (c) 1999-2011 Schneider Electric.“
Echo “     All Rights Reserved.“
Echo „——————————————————————„
Echo „“

# Check OS type
CheckOS

# Check root account
IsRootUser

# Check Locale Compatibility
CheckLocale

# Initialize
Initialize

# Check silent install
if [ -z „$1“ ]; then
    SILENT_MODE=$FALSE
elif [ „$1“ = „-f“ ]; then 
    if [ -r „$2“ ]; then
        SILENT_MODE=$TRUE
        SILENT_CONFIG=$2
        Echo „Silent mode input from $SILENT_CONFIG“
        Echo „“
        SetSilentConfig
    else
        Echo „Error: Invalid file $2“
        exit $EXIT_SILENT_CONFIG_MISSING
    fi
else
    PrintUsage
fi

# Show EULA
if [ $SILENT_MODE = $TRUE ]; then
   if [ „$ACCEPT_EULA“ = „$STR_YES“ ];  then
        Echo „EULA has been accepted“
   else
        Echo „Error: EULA must be accepted by setting ACCEPT_EULA=$STR_YES in config file“
        exit $EXIT_EULA_NOT_ACCEPTED
   fi
else
   DisplayEULA
fi

# Check installed applications
IsPCPlusInstalled
IsPCBEInstalled
IsPCSInstalled
IsPCNSInstalled

InitUpdate

# Set Install dir
SetInstallDir
BackupOldPCNS

APP_DIR=“$INSTALL_DIR/PowerChute“

# Setup java
SetupJava

# Copy tar file to install dir
Echo „Copying the installation files …“
cp „$PCNS_ZIP“ „$INSTALL_DIR“
cd „$INSTALL_DIR“

# Extract PCNS files
Echo „Extracting PCNS files …“
gunzip $PCNS_ZIP
tar -xf $PCNS_TAR > /dev/null 2>&1
if [ ! $? = 0 ]
then
    Echo „Failed to extract files“
fi
rm -rf $PCNS_TAR


cd „$APP_DIR“
Echo „PCNS is extracted to $APP_DIR“

# Setup script files
SetupAllCommandFiles

# Configure startup script
ConfigureAllStartup 
UninstallOldStartupLink
ConfigureStartupLink
if [ ! -f /etc/SuSE-release ]; then
ConfigureFirewall
fi

if [ $SILENT_MODE -ne $TRUE ]; then
    AddESXiTargetServer
fi

#Patch for vMA5.0
CopyUninstallPatch

# Configure uninstall script
ConfigureUninstall
ConfigureOwner

# For Update install
CopyUpdateFiles
UninstallOldPCNS

# Start the Service
SetupM11Cfg
ApplySilentConfig
$STARTUP start

InstallComplete

cd „$SRC_DIR“
exit $EXIT_SUCCESS