-   Linux - General (
-   -   How to automate installation of a list of packages in redhat (like kickstart) (

hgg2002 07-24-2009 07:59 AM

How to automate installation of a list of packages in redhat (like kickstart)
I have a kickstart file for RedHat, but I can't remake the os installation, so I just need to ensure that the packages included in the kickstart file are installed automatically if required.

Any idea about how to do it?


unSpawn 08-17-2009 09:26 AM

The packages section of your kickstart file is marked by the tags "%packages" and "%end", so if 'egrep -m2 -n "%(packages|end)" /path/to/kickstart.ks' should return two line numbers (say 19 and 121), so if you sed -n '20,120p' /path/to/kickstart.ks|grep -ie "^[a-z0-9@-]" you'll have the groups (prefixed by the "at" sign), deinstallations (prefixed with a minus sign) and package names. Tying it together it could look something like:

# Path and name of kickstart file.
# Determination of section start and end.
SECTION=($(egrep -m2 -n "%(packages|end)" ${KS}|awk -F':' '{print $1}'))
# Retrieve package list.
eval echo "sed -n '$[${SECTION[0]}+1],$[${SECTION[1]}-1]p' ${KS}"|sh|grep -ie "^[a-z0-9@-]" | while read LINE; do
 # What to do if LINE does not match expectation.
 ARRAY=(${LINE}); [ ${#ARRAY[@]} -eq 1 ] || { echo "Line \"${LINE}\" contains  ${#ARRAY[@]} items, skipping."; break; }
 # LINE now should contain single item of groupname or packagename.
 case "${LINE}" in
  @*) # For groups check name.
      GROUP=$(grep -m1 -i "${LINE:1:255}" /usr/share/doc/rpm-*/GROUPS||echo "${LINE:1:255}")
      echo rpm -i -g \"${GROUP}\"
  -*) # For ausradierung we dont check anything!
      echo rpm -e "${LINE}"
    *) # Just install.
      echo rpm -i "${LINE}"

...which would only echo commands. Once you have determined it would be OK to run (I'm not sure about the group names, haven't checked with F10/F11) change "echo rpm" to "rpm" or "yum -y" (I wonder if that should be 'yum groupinstall' for groups?).

As always YMMV(VM).

All times are GMT -5. The time now is 04:04 PM.