On 06/17/2015 09:35 AM, Rich Sudlow wrote:
On 06/17/2015 09:20 AM, Jarrod Johnson wrote:

Hi Jarrod
Interesting, what distro and profile?  Do you have a custom profile or custom
partitioning?

Using RHELS 6.6 - No just a single / partition

The need for /boot/efi should be autodetected and put into the automatic
partition plan by one of the following snippets of code (depending on
distro/profile):
# grep '/boot/efi' /opt/xcat/share/xcat/install/scripts/pre.*
/opt/xcat/share/xcat/install/scripts/pre.rh:    echo 'part /boot/efi --size 50
--ondisk '$instdisk' --fstype $EFIFSTYPE' >> /tmp/partitioning
/opt/xcat/share/xcat/install/scripts/pre.rh.rhel7:      echo 'part /boot/efi
--size 50 --ondisk '$instdisk' --fstype '$EFIFSTYPE >> /tmp/partitioning
/opt/xcat/share/xcat/install/scripts/pre.sles:  sed -e
's!<device>XCATPARTITIONHOOK</device>!<device>'$instdisk'</device><partitions
config:type="list"><partition><filesystem
config:type="symbol">vfat</filesystem><mount>/boot/efi</mount><size>128mb</size></partition><partition><mount>swap</mount><size>auto</size></partition><partition><mount>/</mount><size>auto</size></partition></partitions>!'
/tmp/profile/autoinst.xml > /tmp/profile/modified.xml
[root@odin scripts]#

I see

[root@opt-mgmt scripts]# grep '/boot/efi' pre.rh
    echo 'part /boot/efi --size 50 --ondisk '$instdisk' --fstype vfat' >>
/tmp/partitioning

The only partition in my template file (compute.rhels6.x86_64.tmpl)
is

part / --size 1 --grow --fstype ext4 --ondisk sda

where does $instdisk come from?

Rich

P.S. I'll create another template with /boot/efi in it and see if that works
while waiting for your response - unfortunately this machine has 3 TB of RAM so
it takes a while to reboot.

Surprisingly - This seemed to fail too

The following errors occurred with your partitioning:

/boot must be less than 2TB. Shrink / or create a separate /boot partition.

This can happen if there is not enough space on your hard drive(s) for the installation.

I'm also attaching my /install/autoinst/daccssfe file


Rich







-----Original Message-----
From: Rich Sudlow [mailto:[email protected]]
Sent: Wednesday, June 17, 2015 9:03 AM
To: xCAT Users Mailing list
Subject: [xcat-user] Installing a machine using xnba

I'm new to using uefi so this is a naive question.

I'm using xcat version 2.8.3 trying to install a Dell R920 using uefi as I'd
like to install using a singe > 5 TB RAID virtual disk -

I'm using xnba which seems to work fine until I hit

You have not created a /boot/efi partition -

Is this something I should be doing manually prior to install?
Any help would be appreciated.

Rich



Here are more details.
*****************************
waiting for hardware to initialize...
Retrieving http://10.32.64.2:80/install/autoinst/daccssfe...
Waiting for NetworkManager to configure p9p1.
Retrieving http://10.32.64.2/install/rhels6.6/x86_64/images/updates.img...
Retrieving http://10.32.64.2/install/rhels6.6/x86_64/images/product.img...
Retrieving http://10.32.64.2/install/rhels6.6/x86_64/images/install.img...
Running anaconda 13.21.229, the Red Hat Enterprise Linux system installer -
please wait.
Examining storage devices
In progress

The following errors occurred with your partitioning:

You have not created a /boot/efi partition.

This can happen if there is not enough space on your hard drive(s) for the
installation.

Press 'OK' to exit the installer.
The system will now reboot.
terminating anaconda...done
sending termination signals...done
sending kill signals...done
disabling swap...
unmounting filesystems...
          /mnt/runtime done
          disabling /dev/loop0
          /dev/pts done
          /selinux done
waiting for mdraid sets to become clean...
rebooting system
***************************

--
Rich Sudlow
University of Notre Dame
Center for Research Computing - Union Station
506 W. South St
South Bend, In 46601

(574) 631-7258 (office)
(574) 807-1046 (cell)

------------------------------------------------------------------------------
_______________________________________________
xCAT-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xcat-user

------------------------------------------------------------------------------
_______________________________________________
xCAT-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xcat-user





--
Rich Sudlow
University of Notre Dame
Center for Research Computing - Union Station
506 W. South St
South Bend, In 46601

(574) 631-7258 (office)
(574) 807-1046 (cell)
#[email protected]
#
#cmdline

lang en_US

network --bootproto dhcp
#
# Where's the source?
# nfs --server hostname.of.server or IP --dir /path/to/RH/CD/image
#
#nfs --server  --dir 
url --url http://10.32.64.2/install/rhels6.6/x86_64

#device ethernet em1
keyboard "us"

#
# Clear the MBR
#
zerombr yes

#
# Wipe out the disk
#
clearpart --all --drives=sda --initlabel
#clearpart --linux
key --skip

#
# Customize to fit your needs
#

#No RAID
#/boot really significant for this sort of setup nowadays?
#part /boot --size 50 --fstype ext3
#part swap --size 16384
part swap --recommended --ondisk sda
# Waffle,waffle - I'm now leaving this out so that one can increase the
# afs cachesize to be larger without having an issue with the partition size 
# RKS 3/13/2012
#part /usr/vice --size 8192 --fstype ext3
part /boot/efi --size 50 --ondisk sda --fstype vfat
part / --size 1 --grow --fstype ext4 --ondisk sda
#part /tmp --size 1 --grow --fstype ext4 --ondisk sdb

#RAID 0 /scr for performance
#part / --size 1024 --ondisk sda
#part swap --size 512 --ondisk sda
#part /var --size 1024 --ondisk sdb
#part swap --size 512 --ondisk sdb
#part raid.01 --size 1 --grow --ondisk sda
#part raid.02 --size 1 --grow --ondisk sdb
#raid /scr --level 0 --device md0 raid.01 raid.02

#Full RAID 1 Sample
#part raid.01 --size 50 --ondisk sda
#part raid.02 --size 50 --ondisk sdb
#raid /boot --level 1 --device md0 raid.01 raid.02
#
#part raid.11 --size 1024 --ondisk sda
#part raid.12 --size 1024 --ondisk sdb
#raid / --level 1 --device md1 raid.11 raid.12
#
#part raid.21 --size 1024 --ondisk sda
#part raid.22 --size 1024 --ondisk sdb
#raid /var --level 1 --device md2 raid.21 raid.22
#
#part raid.31 --size 1024 --ondisk sda
#part raid.32 --size 1024 --ondisk sdb
#raid swap --level 1 --device md3 raid.31 raid.32
#
#part raid.41 --size 1 --grow --ondisk sda
#part raid.42 --size 1 --grow --ondisk sdb
#raid /scr --level 1 --device md4 raid.41 raid.42

#
# bootloader config
# --append <args>
# --useLilo
# --md5pass <crypted MD5 password for GRUB>
#
bootloader

#
# install or upgrade
#
install

#
# text mode install (default is graphical)
#
text

#
# firewall
#
firewall --disabled

#
# Select a zone
# Add the --utc switch if your hardware clock is set to GMT
#
#timezone US/Hawaii
#timezone US/Pacific
#timezone US/Mountain
#timezone US/Central
#timezone US/Eastern
timezone --utc "America/New York"

#
# Don't do X
#
skipx


#
# To generate an encrypted root password use:
#
# perl -e 'print crypt("blah","Xa") . "\n";'p
# openssl passwd -apr1 -salt xxxxxxxx password
# 
# where "blah" is your root password.
#
#rootpw --iscrypted XaLGAVe1C41x2
#rootpw XaLGAVe1C41x2 --iscrypted
#rootpw --iscrypted $1$42DC1wXO$DrZkfvUQAIIOsMu4IRqOS1
rootpw --iscrypted $1$b.Dwj9Zq$OoYysnkHpPdVCg2F2oVdJ/
#
# NIS setup: auth --enablenis --nisdomain sensenet 
# --nisserver neptune --useshadow --enablemd5
#
# OR
auth --useshadow --enablemd5

#
# SE Linux
#
selinux --disabled

#
# Reboot after installation
#
reboot

#
#end of section
#
%packages
@base
@core
@development
@input-methods
@perl-runtime
@server-platform
@compatibility libraries
@security tools
openssl
krb5-workstation
ksh
binutils
tcsh
ntp
tftp
xinetd
m4
sendmail-cf
openssh-server
tcl
tcl-devel
expect
sysstat
compat-db
compat-glibc
compat-glibc-headers
sg3_utils
nfs-utils
libxslt
gedit
ImageMagick
tetex-latex
xfig 
gimp
binutils-devel
rsh
rsh-server
openmotif
openmotif-devel
openmotif22
unixODBC
unixODBC-devel
@Internet Browser
@X Window System
xterm
@Emacs
dos2unix
edac-utils
@ruby support
@debugging tools
gnuplot
imake
nmap
screen
telnet
units
tree
tk
boost
mcelog
ftp
lftp
nscd
jpackage-utils
alsa-lib.i686
libX11.i686
libXau.i686
libXext.i686
libXi.i686
libXtst.i686
libxcb.i686
perf
zsh
glib2-devel
PackageKit-gtk-module
finger
gcc-gfortran
glibc-utils
OpenIPMI
krb5-appl-servers
krb5-appl-clients
mesa-libGL-devel
mesa-libGLU-devel
python-devel
pam-devel
ncurses-devel
krb5-devel
libXp-devel
alsa-lib-devel
libXinerama-devel
libXaw-devel
unixODBC-devel
libX11-devel
dbus-devel
cyrus-sasl-devel
gtk2-devel
zlib-devel
libgpg-error-devel
db4-devel
libselinux-devel
libXrender-devel
libXmu-devel
libXScrnSaver-devel
libXxf86vm-devel
libgnomeui-devel
openmotif-devel
libIDL-devel
gnome-keyring-devel
xorg-x11-proto-devel
libXft-devel
libXdmcp-devel
libusb-devel
libxslt-devel
libxml2-devel
boost-devel
gmp-devel
libattr-devel
libXdamage-devel
libacl-devel
freetype-devel
openssl-devel
glibc-devel
ncurses-devel
bzip2-devel
libmng-devel
gmp-devel
libcap-devel
libXpm-devel
libbonobo-devel
libgnomecanvas-devel
libXdamage-devel
libXft-devel
libXext-devel
libXxf86misc-devel
libpng-devel
libXcursor-devel
ORBit2-devel
keyutils-libs-devel
libattr-devel
libtermcap-devel
elfutils-libelf-devel
libXrandr-devel
cairo-devel
libXaw-devel
libXcomposite-devel
libbonoboui-devel
binutils-devel
unixODBC-devel
expat-devel
openldap-devel
freetype-devel
rpm-devel
curl-devel
atk-devel
libXau-devel
libdrm-devel
readline-devel
elfutils-libelf-devel
libXext-devel
libSM-devel
startup-notification-devel
libglade2-devel
libXxf86misc-devel
libXtst-devel
libgcrypt-devel
SDL-devel
libstdc++-devel
nspr-devel
e2fsprogs-devel
libidn-devel
libart_lgpl-devel
libsepol-devel
libcap-devel
GConf2-devel
libXdmcp-devel
libXt-devel
openmotif-devel
nss-devel
ncurses-devel
libXt-devel
libpng-devel
sqlite-devel
selinux-policy-devel
gnome-vfs2-devel
libnotify-devel
libgnome-devel
libtiff-devel
#@ Everything
#
#
#%packages --resolvedeps
#@base-x
#@ruby
#@text-internet
#@admin-tools
#@java-development
#@engineering-and-scientific
%pre
if grep n8r /proc/cmdline > /dev/null 2>&1;
then
  stty crtscts
fi
for x in 0 1 2 3 4 5 6 7 8
do
        mknod /dev/vcs$x c 7 $x
        mknod /dev/vcsa$x c 7 $[$x+128]
done
chmod 644 /dev/vcs*
chown root /dev/vcs*
if [ -r /tmp/updates/etc/pki/tls/certs/ca-bundle.crt ]; then
        cp -f /tmp/updates/etc/pki/tls/certs/ca-bundle.crt /etc/pki/tls/certs/
fi



cat >/tmp/baz.py <<EOF
#!/usr/bin/python
import socket
import sys

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('10.32.64.2',3002))

print sys.argv[1]
response = sock.recv(100)
if(response == "ready\n"):
        sock.send(sys.argv[1]+"\n")
        response = sock.recv(100)

sock.close()
EOF



cat >/tmp/foo.py <<EOF
#!/usr/bin/python

import socket
import os
import linecache
import re

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('10.32.64.2',3002))

response = sock.recv(100)
if(response == "ready\n"):
        sock.send("installmonitor\n")
        response = sock.recv(100)

sock.close()

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

port = 3001
sock.bind(('', port))

sock.listen(5)

try:
        while 1:
                newSocket, address = sock.accept()
                while 1:
                        received = newSocket.recv(200)
                        if not received:
                                break
                        command = re.split('\s+',received)
                        if(command[0] == "stat"):
                                ilog = ""
                                firstline = ""
                                line = ""
                                post = 0
                                percent = 0
                                count = 0
                                numpack = 0
                                
if(os.path.isfile('/mnt/sysimage/root/install.log')):
                                        ilog = '/mnt/sysimage/root/install.log'
                                
if(os.path.isfile('/mnt/sysimage/tmp/install.log')):
                                        ilog = '/mnt/sysimage/tmp/install.log'
                                
if(os.path.isfile('/mnt/sysimage/root/post.log')):
                                        ilog = '/mnt/sysimage/root/post.log'
                                        post = 1
                                if(ilog):
                                        count = len(open(ilog).readlines())
                                        firstline = linecache.getline(ilog,1)
                                        line = linecache.getline(ilog,count)
                                        linecache.clearcache()
                                if(line and not post):
                                        r1 = re.compile("^Installing (\d+) ")
                                        m1 = r1.search(firstline)
                                        if m1:
                                                numpack = int(m1.group(1))
                                                if(numpack > 0):
                                                        percent = int(((count - 
2) * 100)/numpack + .5)
                                                if(percent > 100):
                                                        percent = 100
                                                if(percent < 0):
                                                        percent = 0
                                        r2 = re.compile("^Installing (.*)\.")
                                        m2 = r2.search(line)
                                        if m2:
                                                newline = m2.group(1)
                                                newline = newline + " ("
                                                newline = newline + str(percent)
                                                newline = newline + "%)"
#                                               newline = newline + " ["
#                                               count = count - 2
#                                               newline = newline + str(count)
#                                               newline = newline + "/"
#                                               newline = newline + str(numpack)
#                                               newline = newline + "]"
                                        else:
                                                newline = "prep"
                                        line = "installing " + newline
                                if(line and post):
                                        line = "installing " + line
                                if(not line):
                                        line = "installing prep"
                                newSocket.send(line)
                                break
#                       if(command[0] == "sh"): #DEBUG purposes only, wide open 
root priv command here.
#                               newcommand = ""
#                               for i in command[1:]:
#                                       newcommand = newcommand + i + " "
#                               output = os.popen(newcommand).read()
#                               newSocket.send(output)
#                               break
                        if(command[0] == "screendump"):
                                newcommand = "cat /dev/vcs"
                                for i in command[1:]:
                                        newcommand = newcommand + i
                                output = os.popen(newcommand).read()
                                newSocket.send(output)
                                break
                                
                newSocket.close()

finally:
        sock.close()
EOF

chmod 755 /tmp/foo.py
chmod 755 /tmp/baz.py

NODESTATUS=

if [ -z "$NODESTATUS" ] || [ "$NODESTATUS" != "0" -a   "$NODESTATUS" != "N"  -a 
 "$NODESTATUS" != "n" ]; then
   /tmp/baz.py "installstatus installing" &
fi



/tmp/foo.py >/foo.log 2>&1 &



#time to ascertain fstype and PReP/UEFI/legacy
#also, find first available block device (sda or vda likely)
#TODO: pick a likely non-SAN target if possible
shopt -s nullglob
for disk in /dev/vd*[^0-9];do
        if [ -z "$firstdirectdisk" ]; then firstdirectdisk=$disk; fi #remember 
first disk as a guess of medium resort
        eddname=$(/lib/udev/edd_id $disk 2> /dev/null)
        if [ ! -z "$eddname" -a "$eddname" = "int13_dev80" ]; then
                instdisk=$disk
                break
        fi
done

if [ -z "$instdisk" ]; then
        for disk in /dev/sd*[^0-9]; do
                eddname=$(/lib/udev/edd_id $disk 2> /dev/null)
                if [ ! -z "$eddname" -a "$eddname" = "int13_dev80" ]; then
                        instdisk=$disk
                        break
                fi
                currdriver=`udevadm info --attribute-walk --name $disk |grep 
DRIVERS|grep -v '""'|grep -v '"sd"'|head -n 1|sed -e 's/[^"]*"//' -e 's/"//'`
                case "$currdriver" in
                "ata_piix4"|"PMC MaxRAID"|"ahci"|"megaraid_sas") #certainly 
direct
                        if [ -z "$firstdirectdisk" ]; then 
firstdirectdisk=$disk; fi #remember first disk as a guess of medium resort
                        ;;
                "mptsas"|"mpt2sas") #*PROBABLY* not SAN, but SAS SAN is possible
                        if [ -z "$probablyfirstdirectdisk" ]; then 
probablyfirstdirectdisk=$disk; fi #remember first disk as a guess of medium 
resort
                        ;;
                *)
                        if [ -z "$firstdisk" ]; then firstdisk=$disk; fi 
#remember first disk as a guess of medium resort
                        ;;
                esac
        done
fi

if [ -z "$instdisk" ]; then
        if [ ! -z "$firstdirectdisk" ]; then
                instdisk=$firstdirectdisk
        elif [ ! -z "$probablyfirstdirectdisk" ]; then
                instdisk=$probablyfirstdirectdisk
        elif [ ! -z "$firstdisk" ]; then
                instdisk=$firstdisk
        fi
fi
                

modprobe ext4 >& /dev/null
modprobe ext4dev >& /dev/null
if grep ext4dev /proc/filesystems > /dev/null; then
        FSTYPE=ext3
elif grep ext4 /proc/filesystems > /dev/null; then
        FSTYPE=ext4
else
        FSTYPE=ext3
fi

if [ `uname -m` = "ppc64" ]; then
        echo 'part None --fstype "PPC PReP Boot" --ondisk '$instdisk' --size 8' 
>> /tmp/partitioning
fi
if [ -d /sys/firmware/efi ]; then
        echo 'part /boot/efi --size 50 --ondisk '$instdisk' --fstype vfat' >> 
/tmp/partitioning
fi

#TODO: ondisk detection, /dev/disk/by-id/edd-int13_dev80 for legacy maybe, and 
no idea about efi.  at least maybe blacklist SAN if mptsas/mpt2sas/megaraid_sas 
seen...
echo "part /boot --size 256 --fstype ext3 --ondisk $instdisk" >> 
/tmp/partitioning
echo "part swap --recommended --ondisk $instdisk" >> /tmp/partitioning
echo "part / --size 1 --grow --ondisk $instdisk --fstype $FSTYPE" >> 
/tmp/partitioning
        
#XCA_PARTITION_SCRIPT#


# The following code is to generate the repository for the installation
cat /proc/cmdline

NEXTSERVER=`cat /proc/cmdline | grep http | head -n 1`
NEXTSERVER=${NEXTSERVER#*http://}
NEXTSERVER=${NEXTSERVER%%:*}

export nextserver=$NEXTSERVER
echo 'url --url http://'$nextserver'//install/rhels6.6/x86_64' >> /tmp/repos


%post
#
# Setup hostname
#
# Updated 9/14/2013 since dhcp will not work with a prinic that is not 
# on the 10.32.64.0/18 subnet which the xcat server gives out dhcp addresses
# on - use hostname.crc.nd.edu as the address for the primary nic (which was
# always the case. RKS
#
# 10/21/2013 - Add for use in the 129.74.246/247 network - RKS
# 12//5/2014 - Change made due to FQDN that is used for RH7 
#
echo "RKS - post scripts NEW based on xcat 2.8.2" >/root/post.log
logger -t xcat "Starting RKS postscripts"
export PRINIC=p9p1
export INSTALLNIC=p9p1
echo "PRINIC: $PRINIC" >>/root/post.log
echo "INSTALLNIC: $INSTALLNIC" >>/root/post.log
echo "HOSTNAME: $HOSTNAME" >>/root/post.log
# Make sure that the hostname is the short version - breaks in RHELS7
export HOSTNAME=`echo $HOSTNAME | awk -F . '{ print $1 }'`
echo "HOSTNAME: $HOSTNAME" >>/root/post.log

if [ "$PRINIC" == "mac" ]
then
    export PRINIC='A0:36:9F:71:DF:30'
fi
if [ -z "$PRINIC" ]
then
    for karg in $(cat /proc/cmdline |sed -e 's/-/:/g' -e 's/ /\n/g'); do
        if  [ "${karg%%=*}" = "BOOTIF" ]; then
            export PRINIC=`ifconfig -a|grep -i "hwaddr ${karg#*=01:}"|awk 
'{print $1}'`
        fi
    done
    if [ -z "$PRINIC" ]; then
        export PRINIC=eth0
    fi
fi
if [ -z "$PRINIC" ]
then
    export PRINIC=eth0
elif [[ `echo "$PRINIC" | grep -sqE 
^[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+$ 
;echo $?` == "0" ]]; then
    export PRINIC=`ifconfig -a | grep -i "HWaddr $PRINIC" | awk '{print $1}'`
fi
IP=$(ifconfig $PRINIC | grep inet | awk '{print $2}' | awk -F: '{print $2}')
echo "$IP" >>/root/post.log
if [ -z $IP ]
then
        echo "prinic may be on another network port - let host set it below - 
RKS " >>/root/post.log
fi

# 11/2/09 RKS - We now no longer use a public / private interface we just use
# a single public network 10.32.64.0/18 or 129.74.85.0/24
#
# 1/19/09 RKS
# Now set up the "other" interface for the machine -
# (the one xcat's not using) and then let xcat's hardeths set them up 
permanently
# on a Dell 1435 eth0 is the private xcat interface and also the bmc
# so eth1 would be the "other" public interface used by AFS on a sc1435
#
# On A Sun X2200 eth1 is the private xcat interface and also the bmc (sp)
# so eth0 would be the "other" public interface used by AFS on a x2200
#

# The grep for "has address" is used in case the machine is an alias
echo "HOSTNAME: $HOSTNAME" >> /root/post.log
OTHERIP=$(host $HOSTNAME.crc.nd.edu | grep "has address" | awk '{print $4}')
echo OTHERIP1: $OTHERIP
echo OTHERIP2: $OTHERIP
SUBNET=$(host $HOSTNAME.crc.nd.edu | grep "has address" | awk '{print $4}' | 
awk -F. '{ print $1 }')
echo SUBNET1: $SUBNET
echo SUBNET2: $SUBNET

GATEWAY="10.32.127.254"
NETMASK="255.255.192.0"

if [ $SUBNET = "129" ] ; then

    THIRD=$(host $HOSTNAME.crc.nd.edu | grep "has address" | awk '{print $4}' | 
awk -F. '{ print $3 }')

    if [ $THIRD = "85" ] ; then
        GATEWAY="129.74.85.254"
        NETMASK="255.255.255.0"
    fi
    if [ $THIRD = "128" ] ; then
        GATEWAY="129.74.128.254"
        NETMASK="255.255.255.0"
    fi
    if [ $THIRD = "246" ] || [ $THIRD = "247" ] ; then
        GATEWAY="129.74.246.1"
        NETMASK="255.255.254.0"
    fi
fi

echo "OTHERIP: $OTHERIP" >>/root/post.log
echo "SUBNET: $SUBNET - THIRD: $THIRD - GATEWAY: $GATEWAY - NETMASK: $NETMASK" 
>>/root/post.log
INTERFACE=$PRINIC

echo "Primary NIC is $PRINIC - now setting $INTERFACE" >>/root/post.log
ifconfig $INTERFACE $OTHERIP netmask $NETMASK
OUT=$(ifconfig $INTERFACE)
echo $OUT >>/root/post.log
echo "GATEWAYDEV=$INTERFACE" >> /etc/sysconfig/network
echo "GATEWAY=$GATEWAY" >> /etc/sysconfig/network
echo "ROUTE: route add default gw $GATEWAY netmask $NETMASK dev $INTERFACE" 
>>/root/post.log
route add default gw $GATEWAY netmask $NETMASK dev $INTERFACE
ROUTE=$(netstat -r -n)
echo "route:$ROUTE" >>/root/post.log

unset OTHERIP
unset SUBNET
unset GATEWAY
unset NETMASK
unset INTERFACE
## END addition RKS

echo "search crc.nd.edu crccluster.crc.nd.edu nd.edu" >/etc/resolv.conf
for i in $(echo 10.32.64.2 | tr ',' ' ')
do
        echo "nameserver $i"
done >>/etc/resolv.conf
export HOSTNAME=$(host $IP 2>/dev/null | awk '{print $5}' | awk -F. '{print 
$1}')
hostname $HOSTNAME



if [ -f /boot/efi/efi/redhat/grub.conf ]; then #RedHat bug, grub.efi corrupts 
console unless we are careful...
        sed -i s/^terminal.*// /boot/efi/efi/redhat/grub.conf
        bootpart=$(sed -e 's/#.*//' /boot/efi/efi/redhat/grub.conf |grep 
root|grep -v kernel|head -n 1|awk '{print $2}')
        bootpart="${bootpart%\\n}"
        sed -i s!^serial.*!splashimage=$bootpart/boot/grub/splash.xpm.gz! 
/boot/efi/efi/redhat/grub.conf
fi
#
# Run xCAT post install
#
export MASTER_IP="10.32.64.2"
export MASTER_IPS="10.32.64.2"
export MASTER="10.32.64.2"
export NODESTATUS=""
export INSTALLDIR=/install
export TFTPDIR=/tftpboot
if [ -z "$INSTALLDIR" ]; then
    INSTALLDIR="/install"
fi
if [ -z "$TFTPDIR" ]; then

    TFTPDIR="/tftpboot"
fi

cd /tmp
RAND=$(perl -e 'print int(rand(50)). "\n"')
sleep $RAND
for t in $(seq 1 20)
do
        GOTIT=0
        for i in $MASTER_IPS
        do
      wget -l inf -N -r --waitretry=10 --random-wait --retry-connrefused  -e 
robots=off -nH --cut-dirs=2 --reject "index.html*" --no-parent -t 0 -T 60 
http://$i$INSTALLDIR/postscripts/ -P /xcatpost
                if [ "$?" = "0" ]
                then

         rm -rf /xcatpost/mypostscript
         export NODE=daccssfe
         wget -N --waitretry=10 --random-wait -T 60 
http://$i$TFTPDIR/mypostscripts/mypostscript.$NODE  -P /xcatpost 2> 
/tmp/wget.log
         mv /xcatpost/mypostscript.$NODE /xcatpost/mypostscript

         if [ ! -x /usr/bin/openssl ]; then #Stop if no openssl to help the 
next bit
            exit 1
         fi
         USEOPENSSLFORXCAT=1 #Though this is the only method going forward, 
flag to allow backward compatibility with 2.2 generated netboot images
         export USEOPENSSLFORXCAT
         XCATSERVER=$i:3001
         export XCATSERVER
         mv $i/postscripts /xcatpost
         rm -rf $i

         # If mypostscript doesn't exist, we will get it through 
getpostscript.awk
         if [ ! -x /xcatpost/mypostscript ]; then

         chmod +x /xcatpost/*
         /xcatpost/getpostscript.awk |sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed 
-e 's/^ *//' > /xcatpost/mypostscript
         

         MYCONT=`grep MASTER /xcatpost/mypostscript`
         MAX_RETRIES=10
         RETRY=0
         while [ -z "$MYCONT" ]; do
            RETRY=$(($RETRY+1))
            if [ $RETRY -eq $MAX_RETRIES ]
            then
                break
            fi

            let SLI=$RANDOM%10+10
            sleep $SLI
            /xcatpost/getpostscript.awk |sed -e 's/<[^>]*>//g'|egrep -v '^ 
*$'|sed -e 's/^ *//' > /xcatpost/mypostscript

            MYCONT=`grep MASTER /xcatpost/mypostscript`
         done

         fi
            
         chmod +x /xcatpost/mypostscript
                        GOTIT=1
                        break
                fi
        done
        if [ "$GOTIT" = "1" ]
        then
            #save the master to /opt/xcat/xcatinfo file
            if [ ! -f /opt/xcat/xcatinfo ]; then
                mkdir -p /opt/xcat
                touch /opt/xcat/xcatinfo
            fi
            echo "XCATSERVER=$i" > /opt/xcat/xcatinfo
            break
        fi
        RAND=$(perl -e 'print int(rand(5)). "\n"')
        sleep $RAND
done
echo "INSTALLDIR=$INSTALLDIR" >> /opt/xcat/xcatinfo

#echo "REBOOT=TRUE" >> /opt/xcat/xcatinfo
cd /xcatpost
#gunzip xcatpost.tar.gz
#tar -xvf xcatpost.tar
#/xcatpost/daccssfe
export PATH=$PATH:/xcatpost

# use the run_ps subroutine to run the postscripts
TMP=`sed "/postscripts-start-here/,/postscripts-end-here/ s/\(.*\)/run_ps 
\1/;s/run_ps\s*#/#/;s/run_ps\s*$//" /xcatpost/mypostscript`
echo "
# global value to store the running status of the postbootscripts,the value is 
non-zero if one postbootscript failed
return_value=0
# subroutine used to run postscripts
run_ps () {
 local ret_local=0
 logdir=\"/var/log/xcat\"
 mkdir -p \$logdir
 logfile=\"/var/log/xcat/xcat.log\"
 
 if [ -f \$1 ]; then
  echo "\"\`date\` Running postscript: \$@\"" | tee -a \$logfile
  #./\$@ 2>&1 1> /tmp/tmp4xcatlog
  #cat /tmp/tmp4xcatlog | tee -a \$logfile
  ./\$@ 2>&1 | tee -a \$logfile
  ret_local=\${PIPESTATUS[0]}
  if [ \"\$ret_local\" -ne \"0\" ]; then
     return_value=\$ret_local
  fi
 else
  echo "\"\`date\` Postscript \$1 does NOT exist.\"" | tee -a \$logfile
  return_value=-1
 fi

 return 0
}
# subroutine end

" > /xcatpost/mypostscript
echo "$TMP" >> /xcatpost/mypostscript
TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ 
s/\(.*\)/run_ps \1/;s/run_ps\s*#/#/;s/run_ps\s*$//" /xcatpost/mypostscript`
echo "$TMP" > /xcatpost/mypostscript


#save the postboot scripts to /xcatpost/mypostscript.post
TMP=`sed "/postscripts-start-here/,/postscripts-end-here/ d" 
/xcatpost/mypostscript`
echo "$TMP" > /xcatpost/mypostscript.post
chmod 755 /xcatpost/mypostscript.post

#create the post init 
cat >/etc/init.d/xcatpostinit1 << 'EOF'
#!/bin/sh
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
# chkconfig: 345 84 59
# description: service node postboot script hack
# processname: xcatpostinit

### BEGIN INIT INFO
# Provides: xcatpostinit
# Default-Start: 3 4 5
# Default-stop: 0 1 2 6
# Required-Start: $network $syslog
# Should-Start: cron
# Required-Stop:
# Short-Description: xCATpost
# Description: xCAT post boot script
### END INIT INFO

# Source function library.
if [ -x /etc/rc.d/init.d/functions ]; then
  . /etc/rc.d/init.d/functions
fi

case $1 in
restart)
  $0 stop
  $0 start
  ;;
status)
  echo -n "xcatpostinit1 runs only at boot, runs additional post scripts"
  ;;
stop)
  echo -n "nothing to stop "
  ;;
start)
  # check for the REBOOT specified in xcatinfo to run post boot scripts on 
reboot 
  if [ -f /opt/xcat/xcatinfo ]; then
    REBOOT=`grep 'REBOOT' /opt/xcat/xcatinfo |cut -d= -f2`
  fi
  # if the xcatdsklspost file exists and this is a reboot - run xcatdsklspost 
with a mode of 6
  if [ "$REBOOT" = "TRUE" -a -r /opt/xcat/xcatdsklspost ]; then
        /opt/xcat/xcatdsklspost 6
  else
    # run /opt/xcat/xcatinstallpost
    if [ -r /opt/xcat/xcatinstallpost ]; then
      /opt/xcat/xcatinstallpost
    fi
  fi
  ;;
esac
EOF
chmod 755 /etc/init.d/xcatpostinit1
ln -s /etc/init.d/xcatpostinit1 /etc/rc.d/rc3.d/S84xcatpostinit1
ln -s /etc/init.d/xcatpostinit1 /etc/rc.d/rc4.d/S84xcatpostinit1
ln -s /etc/init.d/xcatpostinit1 /etc/rc.d/rc5.d/S84xcatpostinit1
mkdir -p /opt/xcat
cat >/opt/xcat/xcatinstallpost << 'EOF'
#!/bin/sh
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
#################################################################
#
#   xCAT script for running postboot scripts for full install case.
#################################################################

if [ ! `uname` = Linux ]; then
   logger -t xcat -p local4.err "$0: the OS name is not Linux"
   exit
fi
SLI=$(awk 'BEGIN{srand(); printf("%d\n",rand()*10)}')
sleep $SLI

cd /xcatpost;
PATH=/xcatpost:$PATH
export PATH
chmod +x /xcatpost/*;

POST_IN_DIR="/xcatpost"

if [ -x /usr/bin/openssl ]; then
     SIP=`grep "^MASTER=" ${POST_IN_DIR}/mypostscript.post  |cut -d= -f2`
     XCATSERVER="$SIP:3001"
     export XCATSERVER
     USEOPENSSLFORXCAT=1 #Though this is the only method going forward, flag to 
allow backward compatibility with 2.2 generated netboot images
     export USEOPENSSLFORXCAT
fi

#  Regardless of where mypostscript.post was found, modify and run it in 
/xcatpost.

DHCP_TMP=`sed 's/\(DHCPINTERFACES=\)\(.*\)$/\1"\2"/' 
/xcatpost/mypostscript.post`
echo "$DHCP_TMP" > /xcatpost/mypostscript.post

#mark that the first reboot after installation is finished
echo "REBOOT=TRUE" >> /opt/xcat/xcatinfo

CNS=`grep NODESTATUS= /xcatpost/mypostscript.post |awk -F = '{print $2}'`
if [ -z "$CNS" ] || [ "$CNS" != "'0'" -a   "$CNS" != "'N'"  -a  "$CNS" != "'n'" 
]; then
#update the node status during the postbootscript running
#TMP=`sed "/postbootscripts-start-here/ i\updateflag.awk \\$MASTER 3002 
\\"installstatus configuring\\"" /xcatpost/mypostscript.post`
#echo "$TMP"> /xcatpost/mypostscript.post

echo "
if [ \"\$return_value\" -eq \"0\" ]; then
   updateflag.awk \$MASTER 3002 \"installstatus booted\"
else
   updateflag.awk \$MASTER 3002 \"installstatus failed\"
fi
" >> /xcatpost/mypostscript.post
fi

chmod +x /xcatpost/mypostscript.post
if [ -x /xcatpost/mypostscript.post ];then
   /xcatpost/mypostscript.post
fi
if [ -f /xcatpost/mypostscript.post ]; then
    RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /xcatpost/mypostscript.post |cut -d= 
-f2`
fi
if [ "$RUNBOOTSCRIPTS" != "'yes'" ]; then
    chkconfig xcatpostinit1 off
fi
#echo "REBOOT=TRUE" >> /opt/xcat/xcatinfo
EOF
chmod 755 /opt/xcat/xcatinstallpost

export OSVER=rhels6.6
if [[ $OSVER == sles* ]]; then
    if [[ $OSVER == sles10* ]];then
        /sbin/insserv xcatpostinit1
    else
        /sbin/insserv -p /etc/init.d xcatpostinit1
    fi
fi
#chkconfig --add xcatpostinit1
chkconfig xcatpostinit1 on

#create the dskls post 
cat >/opt/xcat/xcatdsklspost << 'EOF'
#!/bin/sh
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
#####################################################
#
#   Generic xCAT post script for diskless nodes
#   The syntax of this script:
#      xcatdsklspost {mode} {-m|-M} [postscripts] --tftp /tftpboot --installdir 
/install --nfsv4 no -c -V
#   This script is called in the following different places:
#      updatenode -P ... --> xcatdsklspost 1 -m/-M ...
#      updatenode -S --> xcatdsklspost 2 -m/-M otherpkgs
#      moncfg rmcmon --> xcatdsklspost 3 configrmcnodes
#      node deployment  --> xcatdsklspost
#      statelite mode   --> xcatdsklspost 4
#      update security  --> xcatdsklspost 5 -m/-M ...
#      node reboot - xcatpostinit1  --> xcatdsklspost 6 
# This script has a debug mode,  if XCATDEBUG env variable is set, then
#   /xcatpost becomes /xcatpost.<nodename>.  This allow running multiple 
#   instances of the script to simulate many node on one physical node
#
#####################################################

update_VPD()
{
    if [ -f /usr/sbin/vpdupdate ]; then
        vpdupdate
        logger -t xCAT -p local4.info "xcatdsklspost: updating VPD database"
    fi
}

# Run updatevpd only when necessary
if [ -f /usr/sbin/lsvpd ]; then
    /usr/sbin/lsvpd | grep -i cpu 2>&1 1>/dev/null
    if [ "$?" = "1" ]; then
      update_VPD
    fi
fi

download_postscripts()
{
    server=$1
    if [ -z $server ]; then
        return 1;
    fi

    if [ -f /opt/xcat/xcatinfo ]; then
       INSTALLDIR=`grep 'INSTALLDIR' /opt/xcat/xcatinfo |cut -d= -f2`
    fi
    if [ -z "$INSTALLDIR" ]; then
    INSTALLDIR="/install"
    fi
    max_retries=5
    retry=0
    rc=1  # this is a fail return
    while [ 0 -eq 0 ]; do
        
       export LANG=C; wget -l inf -nH -N -r --waitretry=10 --random-wait -e 
robots=off -T 60 -nH --cut-dirs=2 --reject "index.html*" --no-parent 
http://$server$INSTALLDIR/postscripts/ -P /$xcatpost 2> /tmp/wget.log
         rc=$?
         if [ $rc -eq 0 ]; then
           # return from wget was 0 but some OS do not return errors, so we
           # have additional checks for
           # failed: Connection httpd not running
           # 404: Not Found  - if directory does not exist
           grep -i -E "... failed: Connection refused.$" /tmp/wget.log
           rc1=$?
           grep -i -E "ERROR 404: Not Found.$" /tmp/wget.log
           rc2=$?
           # check to see no errors at all, grep returns 1
           if [ $rc1 -eq 1 ] && [ $rc2 -eq 1 ]; then
              return 0
           fi
         fi

        retry=$(($retry+1))
        logger -t xCAT -p local4.err "download_postscripts retry $retry"
        if [ $retry -eq $max_retries ]; then
            break
        fi

        SLI=$(awk 'BEGIN{srand(); printf("%d\n",rand()*20)}')
        sleep $SLI
    done
    return $rc
}


download_mypostscript()
{
    server=$1
    node=$2
    max_retries=$3
    TFTPDIR=$4
    if [ -z $server ]; then
        return 1;
    fi
    if [ -z "$TFTPDIR" ]; then
        TFTPDIR="/tftpboot"
    fi
    retry=0
    rc=1
 

    while [ 0 -eq 0 ]; do
        wget -N --waitretry=10 --random-wait -T 60 
http://$server$TFTPDIR/mypostscripts/mypostscript.$node  -P /$xcatpost 2>> 
/tmp/wget.log
        rc=$?
        # if no error and the file  was downloaded
        if [ $rc -eq 0 ] && [ -f /$xcatpost/mypostscript.$node ]; then
                mv /$xcatpost/mypostscript.$node /$xcatpost/mypostscript
                return 0;
        fi

        
        retry=$(($retry+1))
        if [ $retry -eq $max_retries ]; then
            break
        fi

    done
    return $rc
}



# pmatch determines if 1st argument string is matched by 2nd argument pattern

pmatch ()
{
  case $1 in
    $2) return 0;;  # zero return code means string matched by pattern
  esac

  return 1          # non-zero return code means string not matched by pattern
}
# Main 
# parse the arguments
ARGNUM=$#;
if [ -z $1 ]; then
  NODE_DEPLOYMENT=1
else
  NODE_DEPLOYMENT=0
  case $1 in
    1|2|5)
      MODE=$1
      if [ $ARGNUM -gt 1 ]; then
        if [ $2 = "-m" ]; then
          P_SIP=$3
        else
          if [ $2 = "-M" ]; then
            P_SIP=$3
            new_ms=$P_SIP    # -M means we will update xcatinfo file XCATSERVER
          fi
        fi
      fi
      if [ $ARGNUM -gt 3 ]; then
        POSTSCRIPTS=$4
      fi
      if [ $ARGNUM -gt 4 ]; then
        if [ $5 = "--tftp" ]; then
          TFTPDIR=$6
        fi
      fi
      if [ $ARGNUM -gt 6 ]; then
        if [ $7 = "--installdir" ]; then
          INSTALLDIR=$8
        fi
      fi
      if [ $ARGNUM -gt 8 ]; then
        if [ $9 = "--nfsv4" ]; then
          NFSV4=${10}
        fi
      fi
      if [ $ARGNUM -gt 10 ]; then
        if [ ${11} = "-c" ]; then
          CFLAG=${11}
        fi
      fi
      if [ $ARGNUM -gt 11 ]; then
        if [ ${12} = "-V" ]; then
         export VERBOSE=1
        fi
        if [ ${12} = "-F" ]; then
         export USEFLOWCONTROL=1
        fi
      fi
      if [ $ARGNUM -gt 12 ]; then
        if [ ${13} = "-V" ]; then
         export VERBOSE=1
        fi
      fi
      ;;
    3|4|6) MODE=$1;;
  esac
fi
# set the default path for the xcatpost directory
xcatpost="/xcatpost"
# Check for debug mode and you have nodename available you can change the path 
for debug

if [ -n "$XCATDEBUG" ]; then
  if [ -n "$NODE" ]; then
     xcatpost="/xcatpost.$NODE"
  fi
fi
#echo "xcatpost = $xcatpost"

useflowcontrol=0
if [ "$USEFLOWCONTROL" = "1" ]; then
  useflowcontrol=1
fi
# from install kcmdline
if [ "$FC" = "1" ] || [ "$FC" = "yes" ] || [ "$FC" = "YES" ]; then
  useflowcontrol=1
fi

 
# If on AIX node
if [ ! `uname` = Linux ]; then
   #Get a new copy of xcataixpost on the node
   mkdir -p  /$xcatpost;
   mkdir -p  /xcatmnt;
   if [ "$NFSV4" = "yes" ]; then
         mount -o vers=4 $P_SIP:$INSTALLDIR/postscripts /xcatmnt
   else
         mount $P_SIP:$INSTALLDIR/postscripts /xcatmnt
   fi
   cp /xcatmnt/xcataixpost /$xcatpost
   umount /xcatmnt
   rmdir /xcatmnt
  logger -t xCAT -p local4.err "Running xcataixpost $*"
  # note not supporting -F or -V on AIX
  echo "/$xcatpost/xcataixpost $1 $2 $3 '"$4"' $5 $6 $7 $8 $9 ${10} ${11}"
  exec /$xcatpost/xcataixpost $1 $2 $3 "$4" $5 $6 $7 $8 $9 ${10} ${11}
  exit
fi

#SLI=$(awk 'BEGIN{srand(); printf("%d\n",rand()*10)}')
#sleep $SLI

if [ ! -d /$xcatpost ]; then
    mkdir -p /$xcatpost;
fi

if [ ! -d /tmp/postage ]; then
    mkdir -p /tmp/postage
fi
rm -R -f /tmp/postage/*

#here we get all the postscripts.  Please do not change this behaviour because 
some scripts depend on others
cd /tmp/postage


if [ "$MODE" = "4" ]; then # for statelite mode
    # We have written the xCATSERVER info into the kernel command line!!
    for i in `cat /proc/cmdline`; do
        KEY=`echo $i | awk -F= '{print $1}'`
        if [ "$KEY" =  "XCAT" ]; then
            TMP=`echo $i | awk -F= '{print $2}'`
            XCATSERVER=`echo $TMP | cut -d: -f1`
            echo "XCATSERVER=$XCATSERVER" > /opt/xcat/xcatinfo
            break
        fi
    done

    if [ -f /opt/xcat/xcatinfo ]; then
        SIP=`grep 'XCATSERVER' /opt/xcat/xcatinfo |cut -d= -f2`
        if [ -n "$SIP" ]; then
            download_postscripts $SIP
            if [ $? -eq 0 ]; then
                downloaded=1
            fi
        fi
    else
        echo "xCAT management server IP can't be determined.";
        echo "exiting...";
        logger -t xCAT -p local4.err "xcatdsklspost:xCAT management server IP 
can't be determined.\nexiting...";
        exit;
    fi


else # for common mode  MODE=1,2,3,5 (updatenode,moncfg,node deployment)
     # non-Statelite MODE

     # If we have written the NODE info into the kernel command line,
     # put in in xcatinfo
     if [ ! -f /opt/xcat/xcatinfo ]; then
        mkdir -p /opt/xcat
        touch /opt/xcat/xcatinfo
     fi
     for i in `cat /proc/cmdline`; do
        KEY=`echo $i | awk -F= '{print $1}'`
        if [ "$KEY" =  "NODE" ]; then
            NODE=`echo $i | awk -F= '{print $2}'`
            break
        fi
     done
     grep 'NODE' /opt/xcat/xcatinfo 2>&1 > /dev/null
     if [ $? -eq 0 ]; then
        sed -i "s/NODE=.*/NODE=$NODE/" /opt/xcat/xcatinfo
     else
        echo "NODE=$NODE" >> /opt/xcat/xcatinfo
     fi

    downloaded=0;  #  have not downloaded the postscripts
    # try the -m/-M input (P_SIP) if it is specified,
    # -m/-M is passed in the updatenode command
    # and is the address of the xcatmaster for this node.  Using -M just means
    # also update the XCATSERVER in the /etc/xcat/xcatinfo file with this 
    # address
    if [ -n "$P_SIP" ]; then   # passed in with updatenode on -M/-m
        SIP=$P_SIP
        download_postscripts $SIP
        if [ $? -eq 0 ]; then
             downloaded=1
        fi
    fi
    # if the download failed then, if not updatenode 
    # open the xcatinfo file to look for an XCATSERVER address to try
    # if the address if not the same as the one on the -m/M flag then
    # try it
    if [ $downloaded -eq 0 ]; then

        # if this is an updatenode call, then stop trying and 
        # return an error
        if [ "$MODE" = "1" ] || [ "$MODE" = "2" ] || [ "$MODE" = "5" ]; then # 
updatenode
            hn=`hostname`
            echo "Cannot download the postscripts from $SIP  for $hn check 
/tmp/wget.log on the node."
            logger -t xCAT -p local4.err "xcatdsklspost:Cannot download the 
postscripts from the xCAT server $SIP for node $hn check /tmp/wget.log on the 
node."
            exit
        fi

        # if not updatenode, then look in xcatinfo for the xcatmaster
        if [ -f /opt/xcat/xcatinfo ]; then
            SIP=`grep 'XCATSERVER' /opt/xcat/xcatinfo |cut -d= -f2`
            if [ -n "$SIP" ]; then
                download_postscripts $SIP
                if [ $? -eq 0 ]; then
                    downloaded=1
                fi
            fi
        fi
    fi

    # download postscripts has not worked yet 
    if [ $downloaded -eq 0 ]; then

         # for the non-updatenode calls try the host in the XCAT kernel param.
         for i in `cat /proc/cmdline`; do
             KEY=`echo $i | awk -F= '{print $1}'`
             if [ "$KEY" =  "XCAT" ]; then
                 TMP=`echo $i | awk -F= '{print $2}'`
                 SIP=`echo $TMP | cut -d: -f1`
                 if [ -n "$SIP" ]; then
                     download_postscripts $SIP
                     if [ $? -eq 0 ]; then
                         downloaded=1
                         break
                     fi
                 fi
            fi
          done
    fi

    # download poscripts has not worked yet 
    #try the dhcp server, this is used for initial boot for the node.
    if [ $downloaded -eq 0 ]; then
        #setup $OSVER ,for SLES11
        if [ -e '/etc/SuSE-release' ]; then
            OSVER=`grep -h VERSION /etc/SuSE-release |awk '{print $3}'`
        fi
        SIPS=`grep -h dhcp-server-identifier 
/var/lib/dhclient/dhclient*eth*.leases 2> /dev/null|awk '{print $3}'|sed -e 
's/;//'`
        if [ -z "$SIPS" ]; then
            SIPS=`grep -h dhcp-server-identifier 
/var/lib/dhclient/dhclient*hf*.leases 2> /dev/null|awk '{print $3}'|sed -e 
's/;//'`
            if [ -z "$SIPS" ]; then
                SIPS=`grep -h DHCPSID /var/lib/dhcpcd/*.info 2> /dev/null|awk 
-F= '{print $2}'|sed -e s/\'//g`
            fi
        fi
        SIP=`echo $SIPS|awk '{printf $NF}' | tail -n 1` #Pick one for wget
        if [ -n "$SIP" ]; then
            download_postscripts $SIP
            if [ $? -eq 0 ]; then
                downloaded=1
            fi
        elif [ -x "/sbin/dhcpcd" ]; then
            # New dhcpcd doesn't creates *.info files.
            for lease in $(ls "/var/lib/dhcpcd/"); do
                iface="$(echo "$lease" | sed -n -e 
's/^dhcpcd-\(.*\)\.lease$/\1/p')"
                if [ -n "$iface" ]; then
                    SIP="$(dhcpcd -q -T "$iface" | sed -n -e 
'/new_dhcp_server_identifier/ s/.*=//p')"
                    if [ -n "$SIP" ]; then
                        download_postscripts $SIP
                        if [ $? -eq 0 ]; then
                            downloaded=1
                            break
                        fi
                    fi
                fi
            done
        fi
    fi
    
    #no hope to download postscripts, now let's get out of here.
    if [ $downloaded -eq 0 ]; then
        hn=`hostname`
        echo "Cannot download the postscripts from the xCAT server for node $hn"
        logger -t xCAT -p local4.err "xcatdsklspost:Cannot download the 
postscripts from the xCAT server for node $hn"
        exit
    fi

fi # finish the postscripts download

# remove the current mypostscript file
rm -rf /$xcatpost/mypostscript

# if NODE is exported ( updatenode call or from kernel parameter)
# use it as the nodename to get the mypostscript file. 
if [ -n "$NODE" ]; then
 node_short=$NODE
else
  #get node name and download the mypostscript.$node file
  #try to get the node ip address that connects to the server.
  #then resolve the name of the ip
  real_SIP=`getent hosts $SIP |awk {'print $1'}`
  if [ $? -ne 0 ]; then
    real_SIP=$SIP
  fi

 NIP=`ip route get $real_SIP | head -n 1 | sed 's/^.*src//g' | awk {'print $1'}`
 if [ $? -eq 0 ] && [ -n "$NIP" ]; then
    #resolve the name of the node from ip address
    result=`getent hosts $NIP`
    if [ $? -eq 0 ]; then
        node1=`echo $result | awk {'print $2'}`
        node2=`echo $result | awk {'print $3'}`
        if [ ${#node1} -gt ${#node2} ]; then
            node=$node1
            node_short=$node2
        else
            node=$node2
            node_short=$node1
        fi
        if [ -z "$node_short" ]; then
            node_short=`echo $node |awk -F. {'print $1'}`
        fi
    else
        if [ -z "$node" ]; then
            node=`hostname`
            node_short=`hostname -s`
        fi
    fi
  else
    node=`hostname`
    node_short=`hostname -s`
  fi
fi
    
max_retries=2
# try short hostname first
if [ -n "$node_short" ]; then
    download_mypostscript $SIP $node_short $max_retries $TFTPDIR
    if [ $? -ne 0 ]; then
        # try long hostname 
        if [ "$node" != "$node_short" ]; then
            download_mypostscript $SIP $node $postfix $max_retries $TFTPDIR
        fi
    fi
fi


# on reboot and shutdown, make sure /ro and /rw are not stuck mounted
if grep 'rw /rw tmpfs ' /proc/mounts  >/dev/null 2>&1; then
    touch /var/lock/subsys/xcatmounts
    echo '#!/bin/bash' > /etc/rc6.d/K10xcatmounts
    echo umount -l /ro >> /etc/rc6.d/K10xcatmounts
    echo umount -l /rw >> /etc/rc6.d/K10xcatmounts
    chmod 755 /etc/rc6.d/K10xcatmounts
    ln -sf /etc/rc6.d/K10xcatmounts /etc/rc0.d/K10xcatmounts
fi


chmod +x /$xcatpost/*;

cd /$xcatpost;
PATH=/$xcatpost:$PATH
export PATH

if [ -x /usr/bin/openssl ]; then
     XCATSERVER="$SIP:3001"
     export XCATSERVER
     USEOPENSSLFORXCAT=1 #Though this is the only method going forward, flag to 
allow backward compatibility with 2.2 generated netboot images
     export USEOPENSSLFORXCAT
fi

# if download of postscript failed, 
# probably  the /tftpboot/mypostcript/mypostscript.<nodename> does not exist.
# We need to call getpostscript.awk .

if [ ! -x /$xcatpost/mypostscript ]; then
  if [ $useflowcontrol = "1" ]; then
    # first contact daemon  xcatflowrequest <server> 3001
    logger -t xCAT -p local4.info "xcatdsklspost:sending xcatflowrequest $SIP 
3001"
   /$xcatpost/xcatflowrequest $SIP 3001
   rc=$?
   logger -t xCAT -p local4.info "xcatdsklspost:xcatflowrequest return=$rc"
   if [ $rc -ne 0 ]; then
      logger -t xCAT -p local4.info "xcatdsklspost: error from xcatflowrequest, 
will not use flow control"
      useflowcontrol=0
   fi
  fi
  /$xcatpost/getpostscript.awk | egrep  '<data>' | sed  -e 's/<[^>]*>//g'|egrep 
-v '^ *$'|sed -e 's/^ *//' >  /$xcatpost/mypostscript;


 MYCONT=`grep MASTER /$xcatpost/mypostscript`
 MAX_RETRIES=10
 RETRY=0
 while [ -z "$MYCONT" ]; do
    # not using flow control , need to sleep
    if [ $useflowcontrol = "0" ]; then
        let SLI=$RANDOM%10
        let SLI=SLI+10
        sleep $SLI
    fi

    RETRY=$(($RETRY+1))
    if [ $RETRY -eq $MAX_RETRIES ]
    then
        break
    fi

    if [ $useflowcontrol = "1" ]; then
      # contact daemon  xcatflowrequest <server> 3001
      logger -t xCAT -p local4.info "xcatdsklspost: sending xcatflowrequest 
$SIP 3001"
      /$xcatpost/xcatflowrequest $SIP 3001
      rc=$?
      logger -t xCAT -p local4.info "xcatdsklspost:xcatflowrequest return=$rc"
      if [ $rc -ne 0 ]; then
        logger -t xCAT -p local4.info "xcatdsklspost: error from 
xcatflowrequest, will not use flow control"
        useflowcontrol=0
      fi
    fi
    /$xcatpost/getpostscript.awk | sed  -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed 
-e 's/^ *//' >  /$xcatpost/mypostscript;
    MYCONT=`grep MASTER /$xcatpost/mypostscript`
    if [ ! -z "$MYCONT" ]; then
        break;
    fi
 done
fi

#save the MASTER into the xcatinfo file for node deployment case, 
#for updatenode case, only save it when -M is specified
if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" = "4" ]; then
    new_ms=`grep '^MASTER' /$xcatpost/mypostscript |cut -d= -f2`
fi
if [ -n "$new_ms" ]; then
    if [ ! -f /opt/xcat/xcatinfo ]; then
        mkdir -p /opt/xcat
        touch /opt/xcat/xcatinfo
    fi
    grep 'XCATSERVER' /opt/xcat/xcatinfo 2>&1 > /dev/null
    if [ $? -eq 0 ]; then
        sed -i "s/XCATSERVER=.*/XCATSERVER=$new_ms/" /opt/xcat/xcatinfo
    else
        echo "XCATSERVER=$new_ms" >> /opt/xcat/xcatinfo
    fi
fi

#save the USEFLOWCONTROL into the xcatinfo file  
#for updatenode case, passwd in with the -f flag 
if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" = "4" ]; then
    useflowcontrol=`grep '^USEFLOWCONTROL' /$xcatpost/mypostscript |cut -d= -f2`
fi
if [ ! -f /opt/xcat/xcatinfo ]; then
        mkdir -p /opt/xcat
        touch /opt/xcat/xcatinfo
fi
if [ -n "$useflowcontrol" ]; then
    # lets just put YES or NO in xcatinfo
    if [ "$useflowcontrol" = "1" ] || [ "$useflowcontrol" = "yes" ] || [ 
"$useflowcontrol" = "YES" ]; then
       new_fc="YES"
    else
       new_fc="NO"
    fi
    grep 'USEFLOWCONTROL' /opt/xcat/xcatinfo 2>&1 > /dev/null
    if [ $? -eq 0 ]; then
        sed -i "s/USEFLOWCONTROL=.*/USEFLOWCONTROL=$new_fc/" /opt/xcat/xcatinfo
    else
        echo "USEFLOWCONTROL=$new_fc" >> /opt/xcat/xcatinfo
    fi
# no setting means do not use flowcontrol
else
    echo "USEFLOWCONTROL=NO" >> /opt/xcat/xcatinfo
fi


# when called by the updatenode command  MODE=1,2
# the nodename is passed in by xdsh in the NODE environment variable by xdsh.

#modify the UPDATENODE flag to 1 
# put NODE in /opt/xcat/xcatinfo
if [ "$MODE" = "1" ] || [ "$MODE" = "2" ]; then
  TMP=`sed -e 's/UPDATENODE=0/UPDATENODE=1/g' /$xcatpost/mypostscript`;
  echo "$TMP" > /$xcatpost/mypostscript;
  if [ ! -f /opt/xcat/xcatinfo ]; then
        mkdir -p /opt/xcat
        touch /opt/xcat/xcatinfo
  fi
  grep 'NODE' /opt/xcat/xcatinfo 2>&1 > /dev/null
  if [ $? -eq 0 ]; then
        sed -i "s/NODE=.*/NODE=$NODE/" /opt/xcat/xcatinfo
  else
        echo "NODE=$NODE" >> /opt/xcat/xcatinfo
  fi
#echo "xcatdsklspost:my nodename in the database is $NODE"
fi
if [ "$MODE" = "5" ]; then
  TMP=`sed -e 's/UPDATENODE=0/UPDATENODE=1\nUPDATESECURITY=1\nexport 
UPDATESECURITY/g' /$xcatpost/mypostscript`;
  echo "$TMP" > /$xcatpost/mypostscript;
fi

#when a diskfull reboot mode 
if [ "$MODE" = "6" ]; then
  # remove the post scripts so that they are not run on reboot
  TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ d" 
/$xcatpost/mypostscript`
  echo "$TMP" > /$xcatpost/mypostscript
  # get the RUNBOOTSCRIPTS site variable
  if [ -f /$xcatpost/mypostscript ]; then
    RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /$xcatpost/mypostscript |cut -d= -f2`
  fi

  # if admin did not requested running of post boot scripts - then remove PBS
  if [ "$RUNBOOTSCRIPTS" != "'yes'" ]; then
  #remove all the postscripts
  TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ d" 
/$xcatpost/mypostscript`
  echo "$TMP" > /$xcatpost/mypostscript
 
  #TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ d" 
/$xcatpost/mypostscript.post`
  #echo "$TMP" > /$xcatpost/mypostscript.post
  fi
fi

# postscript name is specified with the updatenode
#cp /$xcatpost/mypostscript /$xcatpost/mypostscript.backup
# if the list has a postscript named *start-here* then we must rebuild the
# mypostscript file with only the matching *start-here stanza. 


if ( pmatch $POSTSCRIPTS  "*start-here*" ); then
  if ( pmatch $POSTSCRIPTS  "*osimage-postbootscripts-start-here" ); then
  # remove all sections but the osimage-postbootscripts section
    TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ d" 
/$xcatpost/mypostscript`
    echo "$TMP" > /$xcatpost/mypostscript
    TMP=`sed "/# defaults-postbootscripts-start-here/,/# 
defaults-postbootscripts-end-here/ d" /$xcatpost/mypostscript`
    echo "$TMP" > /$xcatpost/mypostscript
    TMP=`sed "/# node-postbootscripts-start-here/,/# 
node-postbootscripts-end-here/ d" /$xcatpost/mypostscript`
    echo "$TMP" > /$xcatpost/mypostscript
  fi
  if ( pmatch $POSTSCRIPTS  "*postscripts-start-here" ); then
    #remove all the postbootscripts 
    TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ d" 
/$xcatpost/mypostscript`
    echo "$TMP" > /$xcatpost/mypostscript
  fi
  if ( pmatch $POSTSCRIPTS  "*postbootscripts-start-here" ); then
    #remove all the postscripts 
    TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ d" 
/$xcatpost/mypostscript`
    echo "$TMP" > /$xcatpost/mypostscript
    
  fi
  if ( pmatch $POSTSCRIPTS  "*defaults-postscripts-start-here" ); then
  # remove all sections but the defaults-postscripts section
    TMP=`sed "/# osimage-postscripts-start-here/,/# 
osimage-postscripts-end-here/ d" /$xcatpost/mypostscript`
    echo "$TMP" > /$xcatpost/mypostscript
    TMP=`sed "/# node-postscripts-start-here/,/# node-postscripts-end-here/ d" 
/$xcatpost/mypostscript`
    echo "$TMP" > /$xcatpost/mypostscript
    TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ d" 
/$xcatpost/mypostscript`
    echo "$TMP" > /$xcatpost/mypostscript
  fi
  
  if ( pmatch $POSTSCRIPTS  "*node-postscripts-start-here" ); then
  # remove all sections but the node-postscripts section
    TMP=`sed "/# osimage-postscripts-start-here/,/# 
osimage-postscripts-end-here/ d" /$xcatpost/mypostscript`
    echo "$TMP" > /$xcatpost/mypostscript
    TMP=`sed "/# defaults-postscripts-start-here/,/# 
defaults-postscripts-end-here/ d" /$xcatpost/mypostscript`
    echo "$TMP" > /$xcatpost/mypostscript
    TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ d" 
/$xcatpost/mypostscript`
    echo "$TMP" > /$xcatpost/mypostscript
  fi

  if ( pmatch $POSTSCRIPTS  "*defaults-postbootscripts-start-here" ); then
  # remove all sections but the defaults-postbootscripts section
    TMP=`sed "/# osimage-postbootscripts-start-here/,/# 
osimage-postbootscripts-end-here/ d" /$xcatpost/mypostscript`
    echo "$TMP" > /$xcatpost/mypostscript
    TMP=`sed "/# node-postbootscripts-start-here/,/# 
node-postbootscripts-end-here/ d" /$xcatpost/mypostscript`
    echo "$TMP" > /$xcatpost/mypostscript
    TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ d" 
/$xcatpost/mypostscript`
    echo "$TMP" > /$xcatpost/mypostscript
  fi
  
  
  if ( pmatch $POSTSCRIPTS  "*node-postbootscripts-start-here" ); then
  # remove all sections but the node-postbootscripts section
    TMP=`sed "/# osimage-postbootscripts-start-here/,/# 
osimage-postbootscripts-end-here/ d" /$xcatpost/mypostscript`
    echo "$TMP" > /$xcatpost/mypostscript
    TMP=`sed "/# defaults-postbootscripts-start-here/,/# 
defaults-postbootscripts-end-here/ d" /$xcatpost/mypostscript`
    echo "$TMP" > /$xcatpost/mypostscript
    TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ d" 
/$xcatpost/mypostscript`
    echo "$TMP" > /$xcatpost/mypostscript
  fi
   
   
# check to see if input postscript list is not empty. If there is a list
# remove the built postscripts and only add the ones for the list.
else
   if [ -n "$POSTSCRIPTS" ]; then
    #remove all the postbootscripts, and replace with list provided 
    TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ d" 
/$xcatpost/mypostscript`
    echo "$TMP" > /$xcatpost/mypostscript
    #remove all the postscripts
    TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ d" 
/$xcatpost/mypostscript`
    echo "$TMP" > /$xcatpost/mypostscript
    echo "# postscripts-start-here" >> /$xcatpost/mypostscript
    #add requested postscripts in
    echo "$POSTSCRIPTS" | tr "," "\n" >> /$xcatpost/mypostscript
    echo "# postscripts-end-here" >> /$xcatpost/mypostscript
  
  fi
fi

#ADDSITEYUM is set by post.rh and post.rh.iscsi for full installtion
#if [[ "$ADDSITEYUM" = "1" ]]; then
#  TMP=`sed "/postscripts-start-here/ a addsiteyum" /$xcatpost/mypostscript`
#  echo "$TMP" > /$xcatpost/mypostscript
#fi

#MYCONT=`cat /$xcatpost/mypostscript`
#echo "$MYCONT"

# use the run_ps subroutine to run the postscripts
TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ s/\(.*\)/run_ps 
\1/;s/run_ps\s*#/#/;s/run_ps\s*$//" /$xcatpost/mypostscript`
echo "
# global value to store the running status of the postbootscripts,the value is 
non-zero if one postbootscript failed
return_value=0
# subroutine used to run postscripts
run_ps () {
 local ret_local=0
 logdir=\"/var/log/xcat\"
 mkdir -p \$logdir
 logfile=\"/var/log/xcat/xcat.log\"
 
 if [ -f \$1 ]; then
  echo \"\`date\` Running postscript: \$@\" | tee -a \$logfile
  ./\$@ 2>&1 | tee -a \$logfile
  ret_local=\${PIPESTATUS[0]}
  if [ \"\$ret_local\" -ne \"0\" ]; then
     return_value=\$ret_local
  fi
  echo \"Postscript: \$@ exited with code \$ret_local\" | tee -a \$logfile
 else
  echo \"\`date\` Postscript \$1 does NOT exist.\" | tee -a \$logfile
  return_value=-1
 fi

 return 0
}
# subroutine end

" > /$xcatpost/mypostscript
echo "$TMP" >> /$xcatpost/mypostscript
TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ 
s/\(.*\)/run_ps \1/;s/run_ps\s*#/#/;s/run_ps\s*$//" /$xcatpost/mypostscript`
echo "$TMP" > /$xcatpost/mypostscript

if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" = "4" ] || [ "$MODE" = "6" ]; then
  #notify the server that we are done with netbooting
  CNS=`grep NODESTATUS= /$xcatpost/mypostscript |awk -F = '{print $2}'`
  if [ -z "$CNS" ] || [ "$CNS" != "'0'" -a   "$CNS" != "'N'"  -a  "$CNS" != 
"'n'" ]; then
# TMP=`sed "/postscripts-start-here/ i\updateflag.awk \\$MASTER 3002 
\\"installstatus configuring\\"" /$xcatpost/mypostscript`
#       echo "$TMP"> /$xcatpost/mypostscript
        echo "
if [ \"\$return_value\" -eq \"0\" ]; then
   updateflag.awk \$MASTER 3002 \"installstatus booted\"
else
   updateflag.awk \$MASTER 3002 \"installstatus failed\"
fi
        " >> /$xcatpost/mypostscript
  fi
fi

DHCP_TMP=`sed 's/\(DHCPINTERFACES=\)\(.*\)$/\1"\2"/' /$xcatpost/mypostscript`
echo "$DHCP_TMP" > /$xcatpost/mypostscript

CLEANUPXCATPOST=`grep CLEANUPXCATPOST= /$xcatpost/mypostscript |awk -F = 
'{print $2}'`
if [ "$CLEANUPXCATPOST" = "'1'" ] || [ "$CLEANUPXCATPOST" = "'yes'" ]; then
  echo "cd /" >> /$xcatpost/mypostscript
  # /xcatpost might be read-only for statelite nodes
  echo "rm -rf /$xcatpost/*" >> /$xcatpost/mypostscript
fi



if [ "$MODE" = "1" ] || [ "$MODE" = "2" ] || [ "$MODE" = "5" ]; then
  echo "exit \$return_value" >> /$xcatpost/mypostscript
fi

chmod +x /$xcatpost/mypostscript
if [ -x /$xcatpost/mypostscript ];then
   /$xcatpost/mypostscript
   VRET_POST=$?
fi

#tell user it is done when this is called by updatenode command
if [ "$MODE" = "1" ] || [ "$MODE" = "2" ] || [ "$MODE" = "5" ]; then
  echo "returned from postscript"
fi

exit $VRET_POST
EOF
chmod 755 /opt/xcat/xcatdsklspost

#only run the prebooot scripts here
TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ d" 
/xcatpost/mypostscript`
echo "$TMP" > /xcatpost/mypostscript

export NODE=daccssfe
export ARCH=x86_64
addsiteyum
/xcatpost/mypostscript
sed -i 's/^serial/#serial/' /boot/grub/grub.conf
sed -i 's/^terminal/#terminal/' /boot/grub/grub.conf
if [ -z "$NODESTATUS" ] || [ "$NODESTATUS" != "0" -a   "$NODESTATUS" != "N"  -a 
 "$NODESTATUS" != "n" ]; then
        updateflag.awk $MASTER 3002
fi
cd /
#rm -Rf /xcatpost
#rm -f /xcatpost/mypostscript
exit 0

------------------------------------------------------------------------------
_______________________________________________
xCAT-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xcat-user

Reply via email to