Run scripts after centos installed

If it doesn't fit in another category, ask it here.
allamiro
Posts: 21
Joined: 2009/07/30 20:43:36

Run scripts after centos installed

Post by allamiro » 2012/02/10 21:43:25

I need to run a script that mount and run a different installation script after centos installation I m using kickstart for the uinitial installation how can I do that

I tried to use the rc.local file but not sure if its the correct way since I might need to remove those lines or lese the installation will run every time the system reboots

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Run scripts after centos installed

Post by TrevorH » 2012/02/10 21:55:51

Yes, using /etc/rc.local is the way to go. If you edit that to add a line to it to invoke your script then the last thing that your script does should be to remove that line from /etc/rc.local on its way out.

User avatar
jlehtone
Posts: 4523
Joined: 2007/12/11 08:17:33
Location: Finland

Re: Run scripts after centos installed

Post by jlehtone » 2012/02/10 22:08:38

[b]sed[/b] is quite handy at changing lines.


Is this second script something that the %post section of kickstart cannot do?

allamiro
Posts: 21
Joined: 2009/07/30 20:43:36

Re: Run scripts after centos installed

Post by allamiro » 2012/02/10 23:16:59

Well i m using post to echo to that rc.local file for some reason post doesnt work
the installation requires that your dev/cdrom to be converted to iso file and that file needs to be mounted for that application to pull stuff from

so the process is as follows

## Create folder for the centos operating system
mkdir -p /mnt/centos
mount -r -o loop /isos/applogic/centos57.iso /mnt/centos
cp /mnt/centos/bfc* /isos/applogic/
echo "Adding ISO entry to /etc/yum.conf"
echo "[iso]" >> /etc/yum.conf
echo "name=iso" >> /etc/yum.conf
echo "baseurl=file:///mnt/centos" >>/etc/yum.conf
rpm --import /mnt/centos/RPM-GPG-KEY-5

mkdir -p /mnt/cdrom
mount -r -o loop /isos/applogic/bfcinstall.iso /mnt/cdrom
echo "/isos/applogic/centos57.iso /mnt/centos udf,iso9660 r,loop 0 0" >>/etc/fstab
echo "/isos/applogic/bfcinstall.iso /mnt/cdrom udf,iso9660 r,loop 0 0" >>/etc/fstab
echo "/isos/applogic/centos57.iso /mnt/centos udf,iso9660 r,loop 0 0" >>/etc/fstab
echo "/dev/cdrom /mnt/centos udf,iso9660 r,loop 0 0" >>/etc/fstab


mv /etc/yum.repos.d /etc/yum.repos.d.orig



# Create Startup Scripts

cp /etc/rc.d/rc.local /etc/rc.d/rc.local.bak
touch /etc/rc.d/rc.local
echo "dd if=/dev/cdrom of=/isos/applogic/centos57.iso" >> /etc/rc.d/rc.local
echo "chmod 755 /isos/applogic/centos57.iso" >> /etc/rc.d/rc.local
echo " mount -r -o loop /isos/applogic/centos57.iso /mnt/centos" >> /etc/rc.d/rc.local
echo "mount -r -o loop /isos/applogic/bfcinstall.iso /mnt/cdrom" >> /etc/rc.d/rc.local
echo "cp /mnt/centos/CentOS/bfc*.iso /isos/applogic/ " >> /etc/rc.d/rc.local
echo "cp /mnt/centos/interactive.txt /isos/applogic/ " >> /etc/rc.d/rc.local
echo "yum list" >> /etc/rc.d/rc.local
echo "/mnt/cdrom/fcinstall.sh -c /isos/applogic/interactive.txt -x /isos/applogic/bfcext.iso" >> /etc/rc.d/rc.local
echo "timout 800" >> /etc/rc.d/rc.local
echo "chown -R bfcadmin:bfc /home/bfcadmin/Download/">> /etc/rc.d/rc.local
echo "mount -r -o loop /isos/applogic/rsync.iso /home/bfcadmin/Download/" " >> /etc/rc.d/rc.local
echo "yum list" >> /etc/rc.d/rc.local
echo "rpm -ivh /mnt/centos/CentOS/tftp-server-*" >> /etc/rc.d/rc.local
echo "timeout 800" >> /etc/rc.d/rc.local

#mv /etc/rc.d/rc.local.bak /etc/rc.d/rc.local
mkisofs -r -o /isos/applogic/centos57.iso /dev/cdrom
echo "mount -a" >> /etc/rc.d/rc.local

allamiro
Posts: 21
Joined: 2009/07/30 20:43:36

Re: Run scripts after centos installed

Post by allamiro » 2012/02/10 23:18:50

I need to clean up the script offcourse there are some parts that does the same thing but I hope you got the idea if you have any idea on how to improve it including that script that will clean the rc.local after the second reboot It will be aprreciated
I m thinking to add a cron job but I m new to scripting so I m still learning any suggestions

User avatar
jlehtone
Posts: 4523
Joined: 2007/12/11 08:17:33
Location: Finland

Re: Run scripts after centos installed

Post by jlehtone » 2012/02/12 12:47:58

Whoa, it takes a while to get a grip of all that.

[quote]echo "Adding ISO entry to /etc/yum.conf"
echo "[iso]" >> /etc/yum.conf
echo "name=iso" >> /etc/yum.conf
echo "baseurl=file:///mnt/centos" >>/etc/yum.conf
rpm --import /mnt/centos/RPM-GPG-KEY-5

mv /etc/yum.repos.d /etc/yum.repos.d.orig[/quote]
This is not what you want. You want your iso.repo in the etc/yum.repos.d.
[code]# Disable all repositories (but why?)
sed -i "s/enabled=1/enabled=0/" /etc/yum.repos.d/*.repo

# Create a file with the "here document" feature
cat > /etc/yum.repos.d/iso.repo <<EOF
[iso]
name=iso
baseurl=file:///mnt/centos
enabled=1
EOF[/code]
But why do you want to disable the base and updates?
Perhaps you could adapt the /etc/yum.repos.d/CentOS-Media.repo instead?

[quote]cp /etc/rc.d/rc.local /etc/rc.d/rc.local.bak
touch /etc/rc.d/rc.local
echo ...
#mv /etc/rc.d/rc.local.bak /etc/rc.d/rc.local
mkisofs -r -o /isos/applogic/centos57.iso /dev/cdrom
echo "mount -a" >> /etc/rc.d/rc.local[/quote]
Lets keep the /etc/rc.d/rc.local almost intact.
[code]# Enable a call to your script
echo "BCFINSTALL=1 ; /etc/rc.d/bcfinstall.sh" >> /etc/rc.d/rc.local

# Create your script
cat > /etc/rc.d/bcfinstall.sh <<EOF
#!/bin/bash
#Your install script commands here

# Disable the call to this script
sed -i "s/BCFINSTALL/#BCFINSTALL/" /etc/rc.d/rc.local
EOF

chmod +x /etc/rc.d/bcfinstall.sh[/code]

[quote]echo "/isos/applogic/centos57.iso /mnt/centos udf,iso9660 r,loop 0 0" >>/etc/fstab
echo "/isos/applogic/bfcinstall.iso /mnt/cdrom udf,iso9660 r,loop 0 0" >>/etc/fstab
echo "/isos/applogic/centos57.iso /mnt/centos udf,iso9660 r,loop 0 0" >>/etc/fstab
echo "/dev/cdrom /mnt/centos udf,iso9660 r,loop 0 0" >>/etc/fstab[/quote]
This is a really confusing part. What did create the /isos/applogic path?
Why is /isos/applogic/centos57.iso mounted twice? Typo?
Why is /isos/applogic/bfcinstall.iso mounted to /mnt/cdrom and then /mnt/cdrom to /mnt/centos, conflicting with the centos57.iso mount?

[quote]echo "dd if=/dev/cdrom of=/isos/applogic/centos57.iso" >> /etc/rc.d/rc.local
echo "chmod 755 /isos/applogic/centos57.iso" >> /etc/rc.d/rc.local
echo " mount -r -o loop /isos/applogic/centos57.iso /mnt/centos" >> /etc/rc.d/rc.local
echo "mount -r -o loop /isos/applogic/bfcinstall.iso /mnt/cdrom" >> /etc/rc.d/rc.local
echo "cp /mnt/centos/CentOS/bfc*.iso /isos/applogic/ " >> /etc/rc.d/rc.local
echo "cp /mnt/centos/interactive.txt /isos/applogic/ " >> /etc/rc.d/rc.local[/quote]
More odd things.
1. You copy image from cd to /isos/applogic/
2. You mount the image as /mnt/centos
3. You mount image bfcinstall.iso that has not been seen before.
4. Then you copy CentOS/bfc*.iso and interactive.txt from centos57.iso
Is here an error in order? What do these files do in the apparent "iso" repository?


[quote]echo "yum list" >> /etc/rc.d/rc.local
...
echo "timout 800" >> /etc/rc.d/rc.local
...
echo "rpm -ivh /mnt/centos/CentOS/tftp-server-*" >> /etc/rc.d/rc.local[/quote]
What is the purpose of the "yum list"?
"timeout"? Is it a command that you install?
Why rpm? Why not "yum install"? Why the tftp-server has not been installed by the kickstart?

allamiro
Posts: 21
Joined: 2009/07/30 20:43:36

Re: Run scripts after centos installed

Post by allamiro » 2012/02/13 17:20:16

Sorry for the late reply and thanks for your help to answer your questions Its required to disable that feature but yes I can adopt the repo file under that folder



Yes that line is reapeated I removed it doesnt make sense I was copying and forgot to remove that sorry for confusion


This is a really confusing part. What did create the /isos/applogic path? the path is creeated as partion from the kicksstart partition information
Why is /isos/applogic/centos57.iso mounted twice? Typo? this is a typo
Why is /isos/applogic/bfcinstall.iso mounted to /mnt/cdrom and then /mnt/cdrom to /mnt/centos, conflicting with the centos57.iso mount? it should be only monuted to cdrom



More odd things.
1. You copy image from cd to /isos/applogic/
2. You mount the image as /mnt/centos
3. You mount image bfcinstall.iso that has not been seen before.
4. Then you copy CentOS/bfc*.iso and interactive.txt from centos57.iso
Is here an error in order? What do these files do in the apparent "iso" repository?


Yes I have to create that iso of centos that will be used permenantly by the application as repo thats why I m leaving a copy at the system as an iso image
ok mounted
the third step is order issue yes I agree



What is the purpose of the "yum list"? its just to make sure that the iso is mounted as loop back and I ma ble to get the repo not that importantn


"timeout"? Is it a command that you install? hmmm Iafter the bfcinstall runs I dont get to see the installation process and suddenly it went to the login screen banner

Why rpm? Why not "yum install"? Why the tftp-server has not been installed by the kickstart? yes it was there under packages for some reason didnt install

thats why I m using rpm

this what I have under packages please let me know where is the mistake here
@base
@core
@editors
@text-internet
@gnome-desktop
@ X Window System
@ GNOME Desktop Environment
@ Graphical Internet
@base-x
@graphical-internet
bind
ntp
OpenIPMI-tools
tcpdump
device-mapper-multipath
telnet
tftp
tftp-server-*
time
xinetd
system-config-netboot-*

allamiro
Posts: 21
Joined: 2009/07/30 20:43:36

Re: Run scripts after centos installed

Post by allamiro » 2012/02/13 17:34:33

# backup the rc local file
# Enable a call to your script
echo "BCFINSTALL=1 ; /etc/rc.d/bcfinstall.sh" >> /etc/rc.d/rc.local

# Create your script
cat > /etc/rc.d/bcfinstall.sh > /etc/rc.d/rc.local
mount -r -o loop /isos/applogic/centos57.iso /mnt/centos
rpm --import /mnt/centos/RPM-GPG-KEY-5
rpm -ivh /mnt/centos/CentOS/tftp-server-*
yum list
cp /mnt/centos/CentOS/bfc*.iso /isos/applogic/
cp /mnt/centos/interactive.txt /isos/applogic/
mount -r -o loop /isos/applogic/bfcinstall.iso /mnt/cdrom
/mnt/cdrom/fcinstall.sh -c /isos/applogic/interactive.txt -x /isos/applogic/bfcext.iso

# Disable the call to this script
sed -i "s/BCFINSTALL/#BCFINSTALL/" /etc/rc.d/rc.local
EOF
chmod +x /etc/rc.d/bcfinstall.sh

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

Run scripts after centos installed

Post by pschaff » 2012/02/13 21:12:06

You really should learn to use quotes for context. It is very difficult to separate your responses from the sections of the previous post to which they apply.

[quote]
allamiro wrote:
...

this what I have under packages please let me know where is the mistake here
...
tftp
tftp-server-*[/quote]
[b]tftp-server[/b] would not have been installed due to the trailing "-". You could have just used "tftp*" in place of the two lines.
[code]# yum list tftp\*
Loaded plugins: fastestmirror, priorities
Loading mirror speeds from cached hostfile
Excluding Packages from CentOS-5 - Extras
Finished
Available Packages
tftp.i386 0.49-2.el5.centos base
tftp-server.i386 0.49-2.el5.centos updates[/code]
Similar issue for [b]system-config-netboot[/b] which would not be installed, unless it was pulled in because of a [b]system-config-netboot-cmd[/b] dependency.
[code]# yum list system-config-netboot\*
Loaded plugins: fastestmirror, priorities
Loading mirror speeds from cached hostfile
Excluding Packages from CentOS-5 - Extras
Finished
Available Packages
system-config-netboot.noarch 0.1.45.1-3.el5 base
system-config-netboot-cmd.noarch 0.1.45.1-3.el5 base
[/code]
Should have been "system-config-netboot*" if you wanted to get both.

allamiro
Posts: 21
Joined: 2009/07/30 20:43:36

Re: Run scripts after centos installed

Post by allamiro » 2012/02/13 22:17:09

Hi sorry for that

I m not familiar yet with forum use thanks for that

I m not using yum install I m using automated kickstart scriipt install

to install the tftp server
tftp-server-*
system-config-netboot-*


So do you sugeest instead of using that should I use tftp-server* ?

Post Reply