3

I have a kickstart file that takes a hostname in the %pre section. I cannot seem to figure out how to get it two the first. As you see it sends the server information to another device which then customizes the server based on another database. I need to figure out how to take the hostname parameter in pre however and send it to post.

%pre
#!/bin/sh
exec < /dev/tty6 > /dev/tty6
chvt 6
clear
echo "################################"
echo "# Running Pre Configuration    #"
echo "################################"
echo -n "Give hostname: "
read hostname
hostname $hostname
echo $hostname > /home/hostname
echo $hostname > /mnt/sysimage/home/hostname
exec < /dev/tty1 > /dev/tty1
chvt 1

%packages
@base
@core

%post
exec < /dev/tty6 > /dev/tty6
chvt 6
ip0=`ifconfig eth0 |grep -e addr:10.0|cut -d':' -f2|awk '{print $1}'`;
ip1=`ifconfig eth1 |grep -e addr:10.0|cut -d':' -f2|awk '{print $1}'`;
mac0=`ifconfig eth0 |grep HWaddr|awk '{print $5}'`;
mac1=`ifconfig eth1 |grep HWaddr|awk '{print $5}'`;
os=`cat /home/hostname` ;
hostname=`cat /home/hostname`;
service sshd start
echo "$ip0^$mac0^$ip1^$mac1^$os^$hostname^none"  >/dev/tcp/10.0.0.1/999
exec < /dev/tty1 > /dev/tty1
chvt 1

In the above the "hostname $hostname" does work for some O.S's but not all. I would like to make it dynamic based on the information submitted in pre but am having no luck.

ThatGuy
  • 293
  • 1
  • 2
  • 9
  • 1
    Not exactly what you're looking to solve, but I avoid this route altogether by just doing it all in the post. The `kssendmac` flag to anaconda can help going this route but I simply look for MAC addresses in /sys/class/net/*/address and call a cgi for each MAC addr in the post to return all the networking/hostname configuration. –  Jun 27 '14 at 22:34
  • Or you could use cobbler and be done with it :) – Jakov Sosic Jun 28 '14 at 06:49
  • Cobbler is going to give me the same issue. Yoonix, my goal is to make it so that I do it in the prescript. I basically want the hostname asked at the start of the install. I use this then "echo "$ip0^$mac0^$ip1^$mac1^$os^$hostname^none" >/dev/tcp/10.0.0.1/999" Which is a nother server that provisions out a lot of different machine types. The reason I want to prompt in pre and use the same value in post is that means an admin inserting during "pre" can insert, then is completely done with that install. My 10.0.0.1 handels everything else later on based on the hostname and other systems. – ThatGuy Jun 28 '14 at 16:50

1 Answers1

4

Make a nochroot %post snippet and move the hostname in there instead:

%post --nochroot 
echo $hostname > /mnt/sysimage/home/hostname

If $hostname variable changes, then echo the $hostname in %pre to temporary location, and then move the file in %post --nochroot instead.

This is because %pre takes place before you install, and you've got no /mnt/sysimage/home yet. That's why you want to work your magic after the OS is installed, and since %pre works outside of the chroot, and regular %post inside, you must do the move in nochroot %post.

Petter H
  • 3,443
  • 1
  • 16
  • 19
  • 2
    You may also have multiple %post sections. One with chroot, one without. – sivann Dec 11 '14 at 11:43
  • so how is the flow of anaconda ? %pre (only initrd) , installOS, %post-nochroot, %post-chroot-of-installedOS ? and $hostname is filled up by anaconda process itself ? - Thanks – resultsway Sep 28 '15 at 16:03