Kickstart File Post Scripting

ScottSerino

New member
Joined
Feb 23, 2010
Messages
2
I want to design a kickstart file that creates an unattended installation (I've passed that part). After it installs, I want it to automatically read the device's MAC address and change the hostname to match the MAC address with the separators removed. (For example if the MAC address is 01-02-03-04-05-06, the prompt after login should read "root@010203040506")

I know this is entered in the "%post" section of the kickstart file, and I know I'm supposed to use the "cut" and "sed" commands, but I have no idea what I'm doing or how to do it.

Can someone give me the script so I can copy/paste it into my kickstart file?
 
I'm sorry...I was Google searching forums that could help me with my problem and didn't research them properly. I took the board header too literally and assumed "DirectAdmin" was just the name of the website.

Can anyone still answer my question or refer me to where I can find the answer myself? The documentation I've found on my own so far isn't telling me quite what I need to know.
 
I've moved the thread; it's an Off-Topic discussion.

While I've used kickstart files in the past to automate installs, it's been years since I've done so, as when doing DirectAdmin installs I simply don't install anything beyond a basic CentOS install. I left DirectAdmin and yum install only what I really need.

I once belonged to a Linux group where there was a guy who actually wrote an entire mini distro based on RHL. He had a lot of kickstart knowledge. Based on that, I'd recommend you look for people working on small RH-based distros; they'll know as much as anyone about kickstart.

Jeff
 
I want to design a kickstart file that creates an unattended installation (I've passed that part). After it installs, I want it to automatically read the device's MAC address and change the hostname to match the MAC address with the separators removed. (For example if the MAC address is 01-02-03-04-05-06, the prompt after login should read "root@010203040506")

I know this is entered in the "%post" section of the kickstart file, and I know I'm supposed to use the "cut" and "sed" commands, but I have no idea what I'm doing or how to do it.

Can someone give me the script so I can copy/paste it into my kickstart file?

i am using kickstart files to get my servers working. (ks / ks.cfg)
i too had some specific whishes that i wanted to automate like:

- add an useraccount admin with the initial filled in root password
- modify ssh to disable root logins
- add nameserver and set ntp right
- and do some updates

example kickstart file:
the interactive option is set here because i want to make changes to the default if needed.

---
# Kickstart file by [email protected]

reboot
#text
install
interactive

url --url http://mirror.leaseweb.com/centos/5.5/os/i386
lang en_US.UTF-8
keyboard us
network --bootproto=query

firewall --enabled --port=22:tcp
authconfig --enableshadow --enablemd5
selinux --disabled
services --disabled bluetooth,cups
timezone --utc Europe/Amsterdam
bootloader --location=mbr --driveorder=sda
zerombr
clearpart --all --initlabel

#autopart
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
#clearpart --linux --drives=sda
#part /boot --fstype ext3 --size=100 --ondisk=sda
#part pv.2 --size=0 --grow --ondisk=sda
#volgroup VolGroup00 --pesize=32768 pv.2
#logvol / --fstype ext3 --name=LogVol00 --vgname=VolGroup00 --size=500000
#logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=1000 --grow --maxsize=5024
firstboot --disable

%packages
@development-libs
@editors
@system-tools
@text-internet
@core
@base
@development-tools
audit
device-mapper-multipath
imake
%post
mkdir /install
# Modify /etc/resolv.conf - add DNS servers
cat > /etc/resolv.conf << EOF1
search <YOURDOMAINNAME>
nameserver <YOURNAMESERVER>
nameserver <YOURNAMESERVER>
EOF1
#add profiles
cat >> /etc/profile << EOF2
export LS_COLORS=
EOF2
cat > /install/postinstall.sh << EOF3
#!/bin/sh
/bin/cat /etc/shadow | /bin/grep -i root | /bin/cut -d ":" -f 2 > /install/tmppass1
adminpass=\`/bin/cat /install/tmppass1\`
/bin/rm -f /install/tmppass1
/usr/sbin/useradd -p \`echo \$adminpass\` -c "admin" admin
/bin/sed -e 's/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config > /etc/ssh/sshd_config.new
/bin/mv -f /etc/ssh/sshd_config.new /etc/ssh/sshd_config
/bin/sed -e 's/#MaxAuthTries 6/MaxAuthTries 3/' /etc/ssh/sshd_config >> /etc/ssh/sshd_config.new
/bin/mv -f /etc/ssh/sshd_config.new /etc/ssh/sshd_config
/bin/sed -e 's/#PermitTunnel no/#PermitTunnel no\nAllowUsers sysadmin/' /etc/ssh/sshd_config >> /etc/ssh/sshd_config.new
/bin/mv -f /etc/ssh/sshd_config.new /etc/ssh/sshd_config
/etc/init.d/sshd restart
/bin/sed -e 's/server 0.centos.pool.ntp.org/#server 0.centos.pool.ntp.org\nserver 0.nl.pool.ntp.org/' /etc/ntp.conf >> /etc/ntp.conf.new
/bin/mv -f /etc/ntp.conf.new /etc/ntp.conf
/bin/sed -e 's/server 1.centos.pool.ntp.org/#server 1.centos.pool.ntp.org\nserver 1.nl.pool.ntp.org/' /etc/ntp.conf >> /etc/ntp.conf.new
/bin/mv -f /etc/ntp.conf.new /etc/ntp.conf
/bin/sed -e 's/server 2.centos.pool.ntp.org/#server 2.centos.pool.ntp.org/' /etc/ntp.conf >> /etc/ntp.conf.new
/bin/mv -f /etc/ntp.conf.new /etc/ntp.conf
/usr/sbin/ntpdate 62.212.76.57
/usr/sbin/ntpdate 83.149.80.111
/sbin/chkconfig ntpd on
/sbin/service ntpd start
/usr/bin/yum install iptraf sysstat mc -y
/usr/bin/yum update -y
/bin/echo '#!/bin/sh' > /etc/rc.local
/bin/echo 'touch /var/lock/subsys/local' >> /etc/rc.local
# change hostname to eth0 macdress
NEWHOSTNAME=\`/sbin/ifconfig eth0 | /bin/grep -i eth0 | /bin/sed 's/HWaddr /,/g' | /bin/cut -d "," -f 2 | /bin/sed 's/://g'\`
/bin/sed -e 's/HOSTNAME/d' /etc/sysconfig/network >> /etc/sysconfig/network.NEW
/bin/mv -f /etc/sysconfig/network.new /etc/sysconfig/network
echo HOSTNAME=\$NEWHOSTNAME\` >> /etc/sysconfig/network
#destroy the config script after 1 go uncomment after testing
#/bin/echo '#!/bin/sh' > /install/postinstall.sh
EOF3
cat >> /etc/rc.local << EOF4
/bin/chmod +x /install/postinstall.sh
cd /install
/bin/sh /install/postinstall.sh
EOF4
----

i think this should do the trick, test it on a test server ;)
and i guess learn also what is going on here

to give you some insight the \' are extra escapes that are needed within the script. these \' escape you would not need when executing from a normal bash or command line.

also dotn forget to change <YOURDOMAINNAME> and <YOURNAMESERVER>
also modify the 0.nl.pool.ntp.org if needed

Soul.

ps: if there is a more easy way, i would like to know about it too :)
 
Last edited:
Back
Top