#!/bin/bash # # Install Cobbler(Kickstart) Tools for CentOS-6/7 # Created by OceanHo(gzhehai@foxmail.com) AT 2017-10-22 # # 操作系统发型主版本 os_release_ver=`sed -r 's#[a-zA-Z ]+(5|6|7)..*#1#g' /etc/redhat-release` # # cobbler settings 文件中的server参数 # auto:表示自动 从 net_bind_device 指定的设备中获取 # 也可以手动指定 cobbler_server_ip="auto" # # cobbler settings 文件中的next-server参数 # auto:表示自动 从 net_bind_device 指定的设备中获取 # 也可以手动指定 cobbler_next_server_ip="auto" # # cobbler 安装系统可以使用的默认密码(盐 / 密码:123456) password_salt="`openssl rand -base64 32`" default_password_crypted=`openssl passwd -1 -salt "${password_salt}" '123456'` # 123456 # # 定义一个变量,用来表示cobbler涉及到网络参数自动获取网卡设备名称 # 比如:dhcpd,cobbler的settings文件中涉及到的IP地址等等 # net_auto_dev="eth1" dhcpd_template_geturl="https://raw.githubusercontent.com/oceanho/my-shell/master/scripts/cobbler/dhcpd_172-16-1-0_24.template" dhcpd_bind_net_prefix="172.16.1" dhcpd_bind_net_subnet="172.16.1.0" dhcpd_bind_net_netmask="255.255.255.0" # 显示帮助 function help() { echo -e ` clear cat <<EOF 033[36m 功能 实现Cobbler程序一键安装和部署 参数 cobbler-server-ip,指定cobbler settings的server-ip参数,默认从net-auto-dev网卡设备中自动获取 cobbler-next-server-ip,指定cobbler settings的next-server-ip参数,默认从net-auto-dev网卡设备中自动获取 net-auto-dev,指定自动获取cobbler网络参数相关的配置参数网卡设备,默认eth1 举例 1、使用ens34网卡设备安装并绑定cobbler的服务(dhcp/tftp) ---------------------------------------------------- sh $# cobbler-server-ip=auto cobbler-next-server-ip=auto net-auto-dev=ens34 2、手动指定cobbler-server-ip 与 next-server-ip,dhcp.template 的子网,掩码等信息自动从eth1网卡上获取 -------------------------------------------------------------------------------------------------------- sh $# cobbler-server-ip=172.16.1.200 cobbler-next-server-ip=172.16.1.200 net-auto-dev=ens34 033[0m EOF ` } case "$1" in -h|--help|help|-help ) help exit 0 ;; esac # # 处理参数 # 参数格式要求 # key=value,比如 net-auto-dev=eth1 until [ $# -eq 0 ] do if egrep -q "[a-z-]+=.*"<<<"$1" then k=$(sed -r 's#([a-z-]+)=.*#1#g' <<<"$1") v=$(sed -r 's#[a-z-]+=(.*)#1#g' <<<"$1") case "$k" in "cobbler-server-ip" ) cobbler_server_ip=$v ;; "cobbler-next-server-ip" ) cobbler_next_server_ip=$v ;; "net-auto-dev" ) net_auto_dev=$v ;; esac fi shift done # # 根据传入的参数,初始化一些必须的参数,比如绑定dhcpd服务的网段地址,cobbler settings配置文件中涉及到的server的ip地址等参数的初始化 function init_param() { str=`ip addr show $net_auto_dev | awk -F"[ ]+" 'NR==3{print $3}'` if [ $? -ne 0 ] then echo -e "