#version=DEVEL标签:tmp,--,cfg,echo,ks,part,awk,IP,print From: https://blog.51cto.com/hequan/6031774
install
cmdline
lang en_US.UTF-8
keyboard us
rootpw --iscrypted $1$8_CHARAC$3G2QA50K.Cqd0wTxGPfs81
selinux --disabled
firewall --enabled
timezone Asia/Shanghai
reboot
%packages
@^minimal
@core
chrony
%end
%include /tmp/network.ks
%include /tmp/disk.txt
%include /tmp/part.ks
%pre
curTTY=$(tty)
exec < $curTTY > $curTTY 2> $curTTY
clear
echo -e "******************************* Please select network type ***********************************
\t1)dhcp
\t2)static"
read -t 60 -p "Your select (1 or 2) : " INPUT
echo
echo "******************************* Please select interface name *********************************"
for i in $(ip -br link|grep -v LOOPBACK|awk '{print $1}' ); do
echo "$(ip -br link show $i) $(ethtool $i|grep Speed)"|awk '{print "\t"$1"\t"$2"\t"$3"\t"$5,$6 }'
done
echo
while true; do
read -t 60 -p "select interface name(eth0 or eth1 or ...) : " INTERFACE
ip addr show $INTERFACE >/dev/null 2>&1 && break
done
echo
echo "**********************************************************************************************"
case $INPUT in
2)
ANSWER="n"
while [ x"$ANSWER" != "xy" ] && [ x"$ANSWER" != "xY" ] ; do
read -p "Enter IP Address : " IPADDR
read -p "Enter NetMask : " NETMASK
read -p "Enter Gateway : " GATEWAY
echo
echo "You entered:"
echo -e "\tIP Address: $IPADDR"
echo -e "\tNetMask: $NETMASK"
echo -e "\tGateway: $GATEWAY"
echo -n "Is this correct? [y/n] "; read ANSWER
done
sleep 1
echo "network --bootproto=static --gateway=$GATEWAY --ip=$IPADDR --netmask=$NETMASK --noipv6 --nodns --onboot=on ${INTERFACE:+--device=$INTERFACE}" >/tmp/network.ks
;;
*)
echo "Use dhcp ................."
echo "network --bootproto=dhcp ${INTERFACE:+--device=$INTERFACE}" > /tmp/network.ks
esac
%end
%pre
curTTY=$(tty)
exec < $curTTY > $curTTY 2> $curTTY
clear
echo "******************************* Please select install disk **************************************"
alldisk=$(lsblk -ldno name,size,type|awk '$3=="disk"{print $1,$2}'|cat -n)
echo "$alldisk"|awk '{printf "%-4s%-8s%4s\n", "\t"$1,$2,$3 }'
echo "*************************************************************************************************"
disknum=noselect
while echo $disknum |grep -q '[^0-9]';do
read -t 60 -p "select disk numbers(1 or 2 or ...) : " disknum
done
if [ -n "$disknum" ];then
DISK=$(echo -n "$alldisk"|awk '$1=='$disknum'{print $2}')
else
USB=$(lsblk -lno name,label|grep -i ydcos|awk 'NR==1{print $1}'|tr -d '0-9')
DISK=$(lsblk -lno name,label,type|grep -v $USB|grep -v fd|awk '$NF~/disk/{print $1}'|head -1)
fi
echo $DISK > /run/.disk
echo -e "bootloader --append=\"crashkernel=auto biosdevname=0 net.ifnames=1 rhgb quiet\" --location=mbr --driveorder=$DISK --boot-drive=$DISK\nignoredisk --only-use=$DISK\nclearpart --all --initlabel " > /tmp/disk.txt
parted -s /dev/$DISK mklabel gpt
echo "part biosboot --fstype=biosboot --size=1" >/tmp/part.ks
echo "part /boot --fstype=ext4 --size=1024 --label boot" >>/tmp/part.ks
size=$(awk '/'$DISK'/{print $3}' /proc/partitions|head -1)
if [ $size -gt 110100480 ]; then
echo "part / --fstype=ext4 --size=100000 --label root" >>/tmp/part.ks
else
echo "part / --fstype=ext4 --grow --size=1 --label root" >>/tmp/part.ks
fi
partprobe
%end
%post --log /dev/stdout
# add hwaddr to network scripts
for n in $(ip -br link|grep -v LOOPBACK|awk '{print $1}' ); do
echo "HWADDR=$(ip link show $n |grep ether|awk '{print $2}' )" >> /etc/sysconfig/network-scripts/ifcfg-$n
done
%end