yum加IP
#!/bin/bash
#自动配置
echo -e "\033[31mxiaozhen的自动脚本,版本:4.0\033[0m"
echo -e "\033[31m作者联系方式QQ2491267482\033[0m"
YUM()
{
banb=`cat /etc/redhat-release |awk '{print $4}' | awk -F. '{print $1}'`
awget=`rpm -qa | grep wget|awk -F- '{print $1}'`
#yum原始文件备份
yumbf()
{
echo -e "\033[31myum配置文件备份\033[0m" >> /etc/sh/file.txt
read -p "原始yum配置文件是否保存?(y/n)" yumpz
if [ $yumpz = n ];then
cd /etc/yum.repos.d >> /etc/sh/file.txt
rm -rf * >> /etc/sh/file.txt
elif [ $yumpz = y ];then
cd /etc/yum.repos.d >> /etc/sh/file.txt
mkdir bf >> /etc/sh/file.txt
mv *.repo bf >> /etc/sh/file.txt
fi
}
#yumCD/DVD连接函数
yumCD/DVD()
{
echo -e "\033[31mCD\DVD连接本地yum\033[0m" >> /etc/sh/file.txt
read -p "您使用的CD/DVD是第一个吗?(y/n)" CDa
echo -e "\033[31m请确保CD/DVD镜像已连接\033[0m"
if [ $CDa = y ];then
mount /dev/sr0 /mnt >> /etc/sh/file.txt
cd /etc/yum.repos.d >> /etc/sh/file.txt
echo "[yum]
name=yum
baseurl=file:///mnt
gpgcheck=0
enabled=1" > yum.repo
yum clean all >> /etc/sh/file.txt
yum makecache >> /etc/sh/file.txt
elif [ $CDa = n ];then
echo -e "\033[31m暂时只支持第一个连接\033[0m"
fi
}
#yumcentos
yumcentos()
{
yumbf
echo -e "\033[31m本地镜像yum\033[0m" >> /etc/sh/file.txt
echo -e "\033[31m----------------------------------------------------------------------\033[0m"
find / -name '*.iso' |grep Cen
echo -e "\033[31m----------------------------------------------------------------------\033[0m"
read -p "您使用的镜像是那个?(1或2):" isolx
isoname4=`find / -name '*.iso' |sed ''$isolx'd'`
umount $isoname4 >> /etc/sh/file.txt
read -p "请提供挂载点位置,(例:/mnt):" isoname2
mkdir $isoname2/cenos >> /etc/sh/file.txt
mount $isoname4 $isoname2/cenos >> /etc/sh/file.txt
cd /etc/yum.repos.d >> /etc/sh/file.txt
echo "[centos]
name=yum
baseurl=file://$isoname2/cenos
gpgcheck=0
enabled=1" > centos.repo
yum clean all >> /etc/sh/file.txt
yum makecache >> /etc/sh/file.txt
}
#本地yum配置主函数
bdiyum()
{
read -p "您是使用CD/DVD连接的镜像吗?(y/n)" CD
if [ $CD = y ];then
yumCD/DVD
elif [ $CD = n ];then
yumcentos
fi
}
#网络yum配置函数
wlyum()
{
echo -e "\033[0m网络yum相关\033[0m" >> /etc/sh/file.txt
read -p "原始yum配置文件是否保存?(y/n)" yumpz
if [ $yumpz = n ];then
cd /etc/yum.repos.d >> /etc/sh/file.txt
rm -rf * >> /etc/sh/file.txt
elif [ $yumpz = y ];then
cd /etc/yum.repos.d >> /etc/sh/file.txt
mkdir bf >> /etc/sh/file.txt
mv *.repo bf >> /etc/sh/file.txt
fi
if [ $banb = 6 ];then
if [ $awget = wget ];then
read -p "你需要那个版本的网络yum,1:网易源 2:阿里源 " yumy
if [$yumy = 2 ];then
echo "站点升级维护中,自动选择网易源"
#cd /etc/yum.repos.d
#wget
#yum clean all
#yum makecache
yumy=1
elif [ $yumy = 1 ];then
cd /etc/yum.repos.d >> /etc/sh/file.txt
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo >> /etc/sh/file.txt
yum clean all >> /etc/sh/file.txt
yum makecache >> /etc/sh/file.txt
fi
else
echo -e "\033[31m找不到下载命令(wget),请先配置本地yum,安装wget后,在创建网络yum\033[0m"
fi
elif [ $banb = 7 ];then
if [ $awget = wget ];then
read -p "你需要那个版本的网络yum,1:网易源 2:阿里源 " yumy
if [$yumy = 2 ];then
echo "站点升级维护中,自动选择网易源"
#cd /etc/yum.repos.d
#wget
#yum clean all
#yum makecache
cd /etc/yum.repos.d >> /etc/sh/file.txt
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo >> /etc/sh/file.txt
yum clean all >> /etc/sh/file.txt
yum makecache >> /etc/sh/file.txt
elif [ $yumy = 1 ];then
cd /etc/yum.repos.d >> /etc/sh/file.txt
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo >> /etc/sh/file.txt
yum clean all >> /etc/sh/file.txt
yum makecache >> /etc/sh/file.txt
fi
else
echo -e "\033[31m找不到下载命令(wget),请先配置本地yum,安装wget后,在创建网络yum\033[0m"
fi
fi
}
#yum配置启动主程序
hansyum()
{
read -p "选择yum方式(1:本地yum;2:网络yum)" yuma
if [ $yuma = 1 ];then
bdiyum
elif [ $yuma = 2 ];then
wlyum
fi
}
#启动yum配置主程序
hansyum
echo -e "\033[31myum配置已结束\033[0m"
}
IP()
{
STATIC()
{
mkdir /etc/sh > 28956230
rm -rf 28956230
cp /etc/sysconfig/network-scripts/$IPname1 /etc/sh/
echo -e "\033[31m该操作不可逆!!\033[0m"
echo -e "\033[31m请输入填入的IP地址(例:192.168.245.100)\033[0m"
read ipADDR
echo -e "\033[31m请输入子网掩码(例:255.255.255.0)\033[0m"
read ipNETMASK
echo -e "\033[31m请输入网关(例:192.168.245.2)\033[0m"
read ipGATEWAY
echo -e "\033[31m请输入DNS地址(例:114.114.114.114)\033[0m"
read ipDNS
#删除IP配置相关行
sed -i '/BOOTPROTO/d' /etc/sysconfig/network-scripts/$IPname1
sed -i '/IPADDR/d' /etc/sysconfig/network-scripts/$IPname1
sed -i '/NETMASK/d' /etc/sysconfig/network-scripts/$IPname1
sed -i '/GATEWAY/d' /etc/sysconfig/network-scripts/$IPname1
sed -i '/DNS1/d' /etc/sysconfig/network-scripts/$IPname1
sed -i '/ONBOOT/d' /etc/sysconfig/network-scripts/$IPname1
#添加IP配置文件相关行
echo "
BOOTPROTO="static"
ONBOOT="yes"
IPADDR="$ipADDR"
NETMASK="$ipNETMASK"
GATEWAY="$ipGATEWAY"
DNS1="$ipDNS"
">> /etc/sysconfig/network-scripts/$IPname1
service network restart
## 完成后查看IP
echo -e "\033[31m相关配置完成,已为你查看ip相关内容\033[0m"
ip a
}
DHCP()
{
mkdir /etc/sh > 28956230
rm -rf 28956230
cp /etc/sysconfig/network-scripts/$IPname1 /etc/sh/
echo -e "\033[31m该操作不可逆!!\033[0m"
#删除IP配置相关行
sed -i '/BOOTPROTO/d' /etc/sysconfig/network-scripts/$IPname1
echo "
BOOTPROTO="dhcp"
">> /etc/sysconfig/network-scripts/$IPname1
service network restart
## 完成后查看IP
echo -e "\033[31m相关配置完成,已为你查看ip相关内容\033[0m"
ip a
}
IPnamehq()
{
echo -e "\033[31m您当前可配置的网卡有\033[0m"
echo -e "\033[31m----------------------------------------------------------------------\033[0m"
ip a |grep BROADCAST,MULTICAST,UP,LOWER_UP |awk '{print $2}'|awk -F: '{print $1}'
echo -e "\033[31m----------------------------------------------------------------------\033[0m"
echo -e "\033[31m请您选择需要配置的网卡(请写网卡名字):\033[0m"
read IPname1
IPname2=`ip a |grep BROADCAST,MULTICAST,UP,LOWER_UP |awk '{print $2}'|awk -F: '{print $1}' | grep $IPname1`
if [ $IPname1 = $IPname2 ];then
echo "你选择的网卡是$IPname1"
else
echo -e "\033[31m您填写的网卡名称不对!!请再次填写!!注意名称大小写!\033[0m"
kill `ps -ef |grep 1.sh|grep /bin/bash |awk '{print $2}'`
fi
read -p "IP配置方式(1:dhcp 2:static):" fx
if [ $fx = 1 ];then
echo -e "\033[31m您选择的网卡是"$IPname1"配置方式是dhcp\033\033[0m"
DHCP
elif [ $fx = 2 ];then
echo -e "\033[31m您选择的网卡是"$IPname1"配置方式是static\033\033\033[0m"
STATIC
fi
}
#执行IP配置主程序
IPnamehq
}
## 脚本启动主语句
xiaozhen()
{
read -p "目的1:yum 2:ip配置:" lx
if [ $lx = 1 ];then
echo -e "\033[31m你选择的是yum配置脚本\033[0m"
echo -e "\033[31m日志文件在/etc/sh/file.txt\033[0m"
echo -e "\033[31m您执行的是yum配置执行时间\n`date`\033[0m" > /etc/sh/file.txt
YUM
elif [ $lx = 2 ];then
echo -e "\033[31m你选择的是IP配置脚本\033[0m"
echo -e "\033[31m备份文件在/etc/sh/\033[0m"
IP
fi
}
#启动程序
xiaozhen