分类: LINUX
2010-02-25 11:58:16
#!/bin/bash
# Make a Customed Linux from the current OS.
awk '/^Installing/{print $2}' /root/install.log | sed 's/^[0-9]*://g' > /tmp/packlist.txt
FILE='/tmp/packlist.txt'
DDIR='/root/iso'
SDIR='/media/cdrom'
let COUNT=0
[ -e $DDIR ] && mv $DDIR $DDIR.old && mkdir -p $DDIR/{Server,VT,Cluster,ClusterStorage} 2>>/tmp/error.txt || mkdir -p $DDIR/{Server,VT,Cluster,ClusterStorage} 2>>/tmp/error.txt
echo -e "Starting to copy the packages..."
while read LINE
do
for I in Server VT Cluster ClusterStorage
do
if cp -r $SDIR/$I/$LINE.rpm $DDIR/$I/$LINE.rpm 2>>/tmp/cperr.txt ; then
COUNT=$[ $COUNT+1 ]
echo -e "${COUNT}. \033[
break
else
continue
fi
done
done < $FILE
echo -e "Total \033[
cp -r $SDIR/{images,isolinux,.treeinfo,.discinfo,EULA,GPL,TRANS.TBL,eula.en_US} $DDIR
[ -e /usr/bin/createrepo ] || rpm -i $SDIR/Server/createrepo-*.noarch.rpm &> /dev/null
#cre_repo() {
# case REPO in
# 'Server')
# createrepo -g $SDIR/$1/repodata/comps-rhel5-server-core.xml $DDIR/$I
# ;;
# 'VT')
# createrepo -g $SDIR/$1/repodata/comps-rhel5-vt.xml $DDIR/$I
# ;;
# 'Cluster')
# createrepo -g $SDIR/$1/repodata/comps-rhel5-cluster.xml $DDIR/$I
# ;;
# 'ClusterStorage')
# createrepo -g $SDIR/$1/repodata/comps-rhel5-cluster-st.xml $DDIR/$I
# ;;
#esac
#}
echo -e "\nStarting to create repodata..."
for REPODIR in Server VT Cluster ClusterStorage
do
createrepo -g $SDIR/$REPODIR/repodata/comps-rhel5-*.xml $DDIR/$REPODIR
echo -e "The repository of $REPODIR created successfully..."
done
find $DDIR/isolinux -name "*" -exec chmod u+w {} \;
echo "\nStarting to create ks.cfg..."
sed -i 's@^default linux@default linux ks=cdrom:/ks.cfg@g' $DDIR/isolinux/isolinux.cfg
if [ -e /root/anaconda-ks.cfg ]; then
cp /root/anaconda-ks.cfg $DDIR/ks.cfg
sed -i '/^# not g/,/^%packages/s/^#\([a-z].*\)/\1/g' $DDIR/ks.cfg
sed -i -e 's/^install$/text/g' -e '/^%packages/i \reboot' $DDIR/ks.cfg
sed -i -e 's/^url.*$/cdrom/g' -e 's/^nfs.*$/cdrom/g' $DDIR/ks.cfg
else
echo -e "The \033[31mks.cfg\033[
exit 1
fi
echo "ks.cfg file created successfully..."
if [ ! -e /usr/bin/mkisofs ]; then
rpm -i $SDIR/Server/mkisofs-*.i386.rpm &> /dev/null
fi
echo -e "\nStarting to create the iso, please wait for a moment..."
cd /root
mkisofs -o MyCustom_Redhat.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -T iso/
echo -e "\n\033[31mCongratulations, the Customed Linux created successfully, it's name is \033[32mMyCustom_Redhat.iso\033[