1

I'm trying to create a kickstart to automate the installation procedure but when the installation ends and I check to see the result nothing happened. I'm trying to debug it by putting read statements in different places to see if everything runs. It seems the all the variables are there but when the setMask function executes it restarts. Any help would be greatly appreciated.

%pre
#!/bin/sh
curTTY=`tty`
exec < $curTTY > $curTTY 2> $curTTY

echo 'Specify the hostname to assign: '; read hostname
echo -n "Enter ip of ips (separated by spaces): "; read ip
echo -n "Enter ipv6 address: "; read ipv6

#Saving data
echo $hostname > /tmp/hostname
echo $ip > /tmp/ip
echo $ipv6 > /tmp/ipv6

%end

%post --nochroot
#!/bin/sh
curTTY=`tty`
exec < $curTTY > $curTTY 2> $curTTY

#Transfering data to be used in the post phase
ip=$(cat /tmp/ip)
ipv6=$(cat /tmp/ipv6)
hostname=$(cat /tmp/hostname)
numips=$(echo $ip | wc -w)

numberOfIpAddresses () {

if [ numips > 1 ]; then

    ips=$(echo $ip | awk '{$1=""; print}' | cut -c 2-)
    ip=$(echo $ip | awk '{print $1}')

fi

 }

 ipv6GW () {

    echo $ipv6 | awk -F":" '{$(NF--); print}' | while read $output

    do

    do

            gwv6="$gwv6:$output"

    done

    gwv6="$gwv6:1"
}

numberOfIpAddresses
ipv6GW

setGateway () {
case prefix in

22|23|24)
    gateway=$(echo $ip | cut -d. -f1-3)".1"
;;

25)
if [ firstOcted -ne 65 ] || [ thirdOcted -eq 161 ]; then
            gateway=$(echo $ip | cut -d. -f1-3)".129"
elif [ thirdOcted -eq 162 ]; then
            gateway=$(echo $ip | cut -d. -f1-3)".129"
elif [ thirdOcted -eq 162 ]; then
            gateway=$(echo $ip | cut -d. -f1-3)".1"
fi
;;

26)
if [ firstOcted -ne 64 ]; then
            gateway=$(echo $ip | cut -d. -f1-3)".65"
elif [ firstOcted -ne 69 ]; then
            gateway=$(echo $ip | cut -d. -f1-3)".129"
fi
;;
esac
}

setMask () {
#Extracting necesery octeds
firstOcted=$(echo $ip | cut -d. -f1)
thirdOcted=$(echo $ip | cut -d. -f3)

case firstOcted in
8)
    prefix=24
    setGateway
64)
    echo "Aqui en setMask opcion 64"
    read algo
    if [ thirdOcted -ne 7 ] && [ thirdOcted -ne 19 ] && [ thirdOcted -ne 26         ] && [ thirdOcted -ne 30 ] && [ thirdOcted -ne 31 ]; then
            prefix=24
            setGateway
    elif [ thirdOcted -ne 7 ] || [ thirdOcted -ne 19 ]; then
            prefix=25
            setGateway
    elif [ thirdOcted -ne 30 ] || [ thirdOcted -ne 31 ]; then
            prefix=26
            setGateway
    fi
            setGateway
    fi
;;

65)
if [ thirdOcted -ge 164 ] && [ thirdOcted -le 175 ]; then
            prefix=22
            setGateway
elif [ thirdOcted -ge 176 ] && [ thirdOcted -le 185 ]; then
            prefix=23
            setGateway
    elif [ thirdOcted -ge 161 ] && [ thirdOcted -le 162 ]; then
            prefix=25
            setGateway
    elif [ thirdOcted -ge 187 ] && [ thirdOcted -le 190 ]; then
            prefix=24
            setGateway
    fi
;;

69)
    if [ thirdOcted -ge 116 ] && [ thirdOcted -le 123 ]; then
            prefix=22
            setGateway
    elif [ thirdOcted -ge 110 ] && [ thirdOcted -le 115 ]; then
            prefix=24
            setGateway
    elif [ thirdOcted -ge 98 ] && [ thirdOcted -le 109 ]; then
            prefix=24
            setGateway
    fi
;;
*)
    echo "The ip was wrongly typed"        read ip
    echo -n "Type the prefix to use: "
    read prefix
    echo -n "Type the gateway: "
    read gateway
    numberOfIpAddresses
    ipv6GW
;;
esac
}

setMask 

counter=0
ls /sys/class/net/ | grep ^e | while read output;
do

    echo    'SUBSYSTEM=="net", ACTION=="add", KERNEL=="'$output'", NAME="eth'$counter'"' \
    >> /etc/udev/rules.d/70-persistent-net.rules;
    ((counter++));

done

if [ -f /etc/debian_version ]; then

else
    echo DEVICE=eth0 >> /etc/sysconfig/network-scripts/ifcfg-eth0
    echo BOOTPROTO=none >> /etc/sysconfig/network-scripts/ifcfg-eth0
    echo ONBOOT=yes  >> /etc/sysconfig/network-scripts/ifcfg-eth0
    echo PREFIX=$prefix >> /etc/sysconfig/network-scripts/ifcfg-eth0
    echo IPADDR=$ip >> /etc/sysconfig/network-scripts/ifcfg-eth0
    echo GATEWAY=$gateway >> /etc/sysconfig/network-scripts/ifcfg-eth0
    echo DNS1=69.60.123.201 >> /etc/sysconfig/network-scripts/ifcfg-eth0
    echo DNS2=69.60.125.254 >> /etc/sysconfig/network-scripts/ifcfg-eth0
    echo #IPv6 Conf >> /etc/sysconfig/network-scripts/ifcfg-eth0
    echo IPV6INIT=yes >> /etc/sysconfig/network-scripts/ifcfg-eth0
    echo IPV6ADDR=$ipv6 >> /etc/sysconfig/network-scripts/ifcfg-eth0
    echo IPV6_DEFAULTGW=$gwv6 >> /etc/sysconfig/network-scripts/ifcfg-eth0
    echo IPV6ADDR=$ipv6 >> /etc/sysconfig/network-scripts/ifcfg-eth0
    echo IPV6_DEFAULTGW=$gwv6 >> /etc/sysconfig/network-scripts/ifcfg-eth0


if [ -n ips ]; then
    counter=0
    for subip in ips; do
            cat ifcfg-eth0 | sed 's/DEVICE=eth0/DEVICE=eth0:$counter/' | sed         's/IPADDR=$ip/IPADDR=$subip/' >> ifcfg-eth0:$counter

    done


%end
MadHatter
  • 78,442
  • 20
  • 178
  • 229
  • Is it safe to assume that there are some parts that were omitted from this kickstart file for brevity or some other reason? If that is not a safe assumption I do not see anything other than `%pre` and `%post` sections, which would be its own problem. – Matt Jul 14 '15 at 14:11

1 Answers1

0

Based on the functions it seems like the --no-chroot option may be causing the issue in this case. Alternately the path where the root image is located may need to be appended to some of the paths where data is redirected typically something like /mnt/sysimage/root with CentOS. So it would be possible to set a variable like this and append it where necessary

rootfs=/mnt/sysimage/root
...
echo DEVICE=eth0 >> $rootfs/etc/sysconfig/network-scripts/ifcfg-eth0
...

In addition to removing the --no-chroot option adding a log option might help get more info about the failure.

%post --log=/path/to/post/install/log.log 

In addition to logging if chrooted and non-chrooted portions of post are necessary it is possible to have multiple %post sections as outlined from Redhat here. In cases with complex %post sections splitting the tasks into multiple post scripts with separate logs can be valuable to determine the root cause of an issue with kickstart files.

In addition to splitting %post if you have access to a file server or shared storage of some sort you can write scripts containing the functions used in post, then mount/copy them during the post section and call the relevant functions. This will give you the opportunity to test some of the scripts without having to rebuild/reinstall with the kickstart file constantly while debugging which can save a lot of time.

Matt
  • 2,711
  • 1
  • 13
  • 20