#!/bin/bash
#
#Shell name:
# auto_install_cobbler.sh
#
#Program:
# auto install cobbler
#
#Author:
# perofu
#
#Email:
# perofu.com@gmail.com
#
#History:
# 2014-04-11
#
#Note:
# If you have any opinions please contact me
#
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:.
export PATH
default_root_password=123456
cobbler_config=/etc/cobbler/settings
rsync_config=/etc/xinetd.d/rsync
tftp_config=/etc/xinetd.d/tftp
cobbler_dhcp=/etc/cobbler/dhcp.template
dhcpd_config=/etc/dhcp/dhcpd.conf
md5_mun=$(openssl passwd -1 -salt ‘'asdj hnuqhwoienoqcwhoexnndjasdgqiuwgeuhcljn' "${default_root_password}")
#check network
check_network()
{
ping www.baidu.com -c2 &> /dev/null
[ $? -ne 0 ] && echo -e "\e[40;31;1m Sorry,your PC can't connect Internet... Please check again \e[0m" && exit 7
}
#default is first NIC
get_ip=$(ifconfig |grep 'inet addr:'|grep Bcast|head -1|awk '{print $2}'|awk -F':' '{print $2}')
network_ip=$(echo ${get_ip%.*})
gateway_ip=$(route |grep default|awk '{print $2}')
mask_ip=$(ifconfig |grep 'inet addr:'|grep Bcast|head -1|awk '{print $4}'|awk -F':' '{print $2}')
dns_ip='8.8.8.8'
#main
check_network
wget http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
yum install cobbler httpd rsync tftp-server xinetd dhcp python-ctypes koan cobbler-web -y
/etc/init.d/httpd start
/etc/init.d/cobblerd start
chkconfig --add httpd
chkconfig httpd on
chkconfig --add cobblerd
chkconfig cobblerd on
chkconfig dhcpd on
chkconfig xinetd on
chkconfig tftp on
###just a how to config cobbler,can't running in shell script
#cobbler check
cp -af ${cobbler_config} ${cobbler_config}.bak
sed -i "/server/ s/127.0.0.1/${get_ip}/" ${cobbler_config}
sed -i '/manage_dhcp/ s/0/1/' ${cobbler_config}
sed -i '/disable/ s/yes/no/' ${rsync_config}
sed -i '/disable/ s/yes/no/' ${tftp_config}
sed -i "s#default_password_crypted: .*#default_password_crypted: \"${md5_mun}\"#" ${cobbler_config}
cobbler get-loaders
cp -af ${cobbler_dhcp} ${cobbler_dhcp}.bak
>${cobbler_dhcp}
cat <<EOF > ${cobbler_dhcp}
# ******************************************************************
# Cobbler managed dhcpd.conf file
#
# generated from cobbler dhcp.conf template ($date)
# Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
# in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
# overwritten.
#
# ******************************************************************
ddns-update-style interim;
allow booting;
allow bootp;
ignore client-updates;
set vendorclass = option vendor-class-identifier;
option pxe-system-type code 93 = unsigned integer 16;
subnet ${network_ip}.0 netmask 255.255.255.0 {
option routers ${gateway_ip};
option domain-name-servers ${dns_ip};
option subnet-mask 255.255.255.0;
range dynamic-bootp ${network_ip}.100 ${network_ip}.254;
default-lease-time 21600;
max-lease-time 43200;
next-server \$next_server;
filename "/pxelinux.0";
}
EOF
cp -af ${dhcpd_config} ${dhcpd_config}.bak
> ${dhcpd_config}
cat <<EOF > ${cobbler_dhcp}
# ******************************************************************
# Cobbler managed dhcpd.conf file
#
# generated from cobbler dhcp.conf template ($date)
# Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
# in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
# overwritten.
#
# ******************************************************************
ddns-update-style interim;
allow booting;
allow bootp;
ignore client-updates;
set vendorclass = option vendor-class-identifier;
option pxe-system-type code 93 = unsigned integer 16;
subnet ${network_ip}.0 netmask 255.255.255.0 {
option routers ${gateway_ip};
option domain-name-servers ${dns_ip};
option subnet-mask 255.255.255.0;
range dynamic-bootp ${network_ip}.100 ${network_ip}.254;
default-lease-time 21600;
max-lease-time 43200;
next-server ${get_ip};
filename "/pxelinux.0";
}
EOF
#restart some services
/etc/init.d/cobblerd restart
/etc/init.d/xinetd restart
/etc/init.d/dhcpd restart
#sync some config_files
cobbler sync
if [ $? -eq 0 ]
then
echo -e "\e[40;32;1m Congratulations... Cobbler was installed finish ,enjoy the cobbler and import some mirrors or DVD like this [cobbler import --path=/mnt/ --name=centos5.5] \e[0m"
else
echo -e "\e[40;31;1m Sorry , cobbler sync was error , please fix [cobbler sync] output info \e[0m"
fi
转载于:https://my.oschina.net/fufangchun/blog/222097