#! /usr/bin/sh
#
# ident	"@(#)ap_reboot_host.sh	1.7	99/02/22 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# This command is used by edd to attempt a reboot
# through an alternate path if the initial boot fails.

PATH=$PATH:/usr/ucb
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/SUNWssp/lib 
set -- `getopt d: $*`
if [ $? != 0 ]
then
        exit 2
fi
for i in $*
do
        case $i in
        -d)     domain=$2; shift 2;;
        --)     shift; break;;
        esac
done
 
SUNW_HOSTNAME=$domain;
export SUNW_HOSTNAME

logger -p local0.info -t "ap_reboot_host-(${SUNW_HOSTNAME}) " "INFO : Attempting
reboot..."
 
if [ -f /var/tmp/boot_path.txt.${SUNW_HOSTNAME} ]
then
    old_path=`cat /var/tmp/boot_path.txt.${SUNW_HOSTNAME}`
    # convert SUNW,ssd to ssd and strip trailing colon and letter if
    # present
    # Is host runing > AP2.0?
    canon_old_path=`echo $old_path | sed -e 's/\/SUNW,ssd/\/ssd/g' \
                -e 's/:.$//g'`
    new_path=`apssp -p $canon_old_path -d $SUNW_HOSTNAME`
    # Is host runing AP2.0?
    if [ "$new_path" = "" ]
    then
        canon_old_path=`echo $old_path | sed -e 's/\/ssd/\/SUNW,ssd/g' \
                    -e 's/:.$//g'`
        new_path=`apssp -p $canon_old_path -d $SUNW_HOSTNAME`
    fi
    if [ -n "$new_path" ]
    then
        last=${SSPLOGGER}/${SUNW_HOSTNAME}/last_ap_reboot_host_bringup.out
        bringup -L -F -Q -A on $new_path 1>${last} 2>&1
        exit 0
    else
        logger -p local0.info -t "ap_reboot_host-(${SUNW_HOSTNAME}) " "WARNING : Reboot failed.  No alternate path."
        exit 9
    fi
else
    logger -p local0.info -t "ap_reboot_host-(${SUNW_HOSTNAME}) " "WARNING : Reboot failed.  No boot_path file."
    exit 9
fi
