#!/bin/bash
function localYumBuild(){
echo "正在安装本地yum仓库"
umount /dev/sr0 &>/dev/null
[ -d /media/cdrom ] || mkdir -p /media/cdrom
mount /dev/sr0 /media/cdrom &>/dev/null
[ $? -eq 0 ] || echo "请插入光盘"
[ -d /etc/yum.repos.d ] || mkdir -p /etc/yum.repos.d &>/dev/null
cd /etc/yum.repos.d
mv * /tmp/
cat > /etc/yum.repos.d/localyum.repo << EEE
[local]
name=localrepo
baseurl=file:///media/cdrom/
gpgcheck=0
enabled=1
EEE
yum -y clean all &> /dev/null
yum makecache &> /dev/null
[ $? -eq 0 ] && echo "本地yum 仓库搭建成功" || (echo "本地yum仓库搭建失败" && exit)
}
which wget &>/dev/null || yum -y install wget &>/dev/null
localYumBuild
yum -y install wget &>/dev/null || (echo "系统错误" &&exit)
function yunYumBuild(){
echo "正在安装云yum仓库"
cd /etc/yum.repos.d
wget -O /etc/yum.repos.d/epel.repo
http://mirrors.aliyun.com/repo/epel-6.repo &>/dev/null
yum -y clean all &>/dev/null
yum makecache &>/dev/null
[ $? -eq 0 ] && echo "云yum 仓库搭建成功" || (echo "云yum仓库搭建失败" && exit)
}
echo "网络连接检查中..."
ping www.baidu.com -c2 &>/dev/null || (echo"无网络连接,无法运行脚本" && exit)
which sshpass &>/dev/null || yum -y install sshpass &>/dev/null
if [ $? -ne 0 ];then
yunYumBuild
yum -y install sshpass &>/dev/null || ( echo "安装失败" && exit)
fi
[ -d ~/.ssh ] || mkdir -p ~/.ssh;chmod 700 ~/.ssh
echo "正在创建密钥对。。。"
rm -rf ~/.ssh/id_dsa ~/.ssh/id_dsa.pub
ssh-keygen -t dsa -f ~/.ssh/id_dsa -P "" &>/dev/null
for ip in 192.168.200.{1..254}
do
ping $ip -c 2 -i 0.1 &>/dev/null
if [ $? -eq 0 ];then
echo "$ip 存活"
sshpass -p "666666" ssh-copy-id -i ~/.ssh/id_dsa.pub "-o StrictHostKeyChecking=no root@$ip" &>/dev/null && echo "密钥分发成功"
else
echo "$ip 不存活"
fi