2021-04-24

初始化脚本,目前还有部分未优化持续更新

#!/bin/bash
PATH=/app/cmatrix/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
. /etc/init.d/functions

function_networkname(){
read -p "Please select the system you need to modify the network card name (7/8/1804/2004):"  Version
   if 
       [[ $Version -eq 7  ]] ;then
        sed  -ri.bask '/^GRUB_CMDLINE_LINUX/s#(.*)(")#\1 net.ifnames=0\2#' /etc/default/grub ;
        grub2-mkconfig -o /boot/grub2/grub.cfg &> /dev/null
		echo "is ok 4 ";
       	echo "Centos networkname is Ready  " 
      read -p "Do you want to restart the system ? yes/no"  KISS
        case $KISS  in
		
[Yy]|[Yy][Ee][Ss])

                reboot
				
				;;
				
				
[Nn]|[Nn][Oo]) 
                echo"Please be sure to restart! Otherwise the network card will not take effect! "	
				
                ;;		
				
*) 
           echo "Please enter yes or no !"
		   
 esac
 
    elif 
       [[ $Version -eq 8  ]] ;then
        sed  -ri.bask '/^GRUB_CMDLINE_LINUX/s#(.*)(")#\1 net.ifnames=0\2#' /etc/default/grub ;
        grub2-mkconfig -o /boot/grub2/grub.cfg &> /dev/null;
		echo "is ok 4 ";
       	echo "Centos networkname is Ready  " 
      read -p "Do you want to restart the system ? yes/no"  KISS
        case $KISS  in
		
[Yy]|[Yy][Ee][Ss])

                reboot
				
				;;
				
[Nn]|[Nn][Oo])
                echo"Please be sure to restart! Otherwise the network card will not take effect! "	
				
                ;;		
				
*) 

           echo "Please enter yes or no !"
		   
 esac
elif 
      [ $Version -eq 1804 ] ;then
          sed -i.bak '/^GRUB_CMDLINE_LINUX=/s#"$#net.ifnames=0"#'  /etc/default/grub
          grub-mkconfig  -o  /boot/grub/grub.cfg &> /dev/null
          echo "Ubuntu networkname is Ready  " 
          read -p "Do you want to restart the system ? yes/no"  Baby
 case $Baby  in
[Yy]|[Yy][Ee][Ss])
                reboot
           ;;
				
[Nn]|[Nn][Oo])
         echo"Please be sure to restart! Otherwise the network card will not take effect! "	
				;;
*) 
          echo "Please enter yes or no !"
esac	
	elif 
      [[ $Version -eq 2004 ]] ;then
       sed -i.bak '/^GRUB_CMDLINE_LINUX=/s#"$#net.ifnames=0"#'  /etc/default/grub
       grub-mkconfig  -o  /boot/grub/grub.cfg &> /dev/null
       echo "Ubuntu networkname is Ready  " 
       read -p "Do you want to restart the system ? yes/no"  Baby
 case $Baby  in
[Yy]|[Yy][Ee][Ss])
                reboot
            ;;
				
[Nn]|[Nn][Oo])
        echo"Please be sure to restart! Otherwise the network card will not take effect! "	
            ;;
*) 
           echo "Please enter yes or no !"
esac		   
else     

           echo " Please enter the correct parameters ! "
fi 
}

function_network(){
 read -p " he offic Centos(7/8) or Ubutu(1804/2004) :"  Version
  if 
    [ $Version -eq  7 ] ;then 
    read -p " Please enter IP address " IP
   [[ $IP =~  (([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])  ]] && cat  > /etc/sysconfig/network-scripts/ifcfg-eth0  << END 
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=$IP
PREFIX=24
GATEWAY=10.0.0.2
DNS1=10.0.0.2
DNS2=180.76.76.76
ONBOOT=yes
END
rm -rf   /etc/sysconfig/network-scripts/ifcfg-ens*
systemctl  restart network 
action " network is ok  Centos7 "
  
  elif 
   [ $Version -eq 8 ] ;then 
 read -p " Please enter IP address " IP
 [[ $IP =~  (([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5] ) ]] &&
nmcli  con add   con-name eth0 connection.interface-name eth0 type ethernet  ipv4.method  manual  ipv4.addresses $IP/24 ipv4.gateway 10.0.0.2 ipv4.dns 114.114.114.114 connection.autoconnect yes
nmcli c up eth0
action " network is ok  Centos8"
read -p "网卡是否存在两个地址?如果重复配置需要禁用之前的配置网卡哦,需要让我帮你禁用吗?如果需要请输入网卡名称:" INPUT
nmcli con down $INPUT

elif 
      [ $Version -eq 1804 ] ;then
read -p " Please enter IP address(IP address default netmask is 24 ) " IP
  [[ $IP =~  (([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]    )  ]] && cat > /etc/netplan/eth0.yaml <<END
network:
   version: 2
   renderer: networkd
   ethernets:
    eth0:
      addresses: [$IP/24]
      gateway4: 10.0.0.2
      nameservers:
        addresses: [114.114.114.114]
END
netplan apple 
action "Ubuntu 1804 is ok "

 elif
        [ $Version -eq 2004 ] ;then
  read -p " Please enter IP address(IP address default netmask is 24 ) " IP
[[ $IP =~  (([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[    0-5]    )  ]] && cat > /etc/netplan/eth0.yaml <<END

network:
    version: 2
    renderer: networkd
    ethernets:
     eth0:
       addresses: [$IP/24]
       gateway4: 10.0.0.2
       nameservers:
         addresses: [114.114.114.114]
END
 netplan apple
action  " Ubuntu 2004 is ok "

else  
        echo "Please enter one of the parameters of 7/8/1804/2004/ "
fi
}


function_yumsource(){
 read -p " he offic Centos(7/8) or Ubutu(1804/2004) :"  Version
 if
    [ $Version -eq 7 ] ;then
	 mkdir -p  /etc/yum.repos.d/backup; mv -f  /etc/yum.repos.d/*.repo  /etc/yum.repos.d/backup &> /dev/null;  cat > /etc/yum.repos.d/sec.repo << END 
[baseOS]
name=baseOS
baseurl=http://mirrors.163.com/centos/7/os/x86_64/
        https://repo.huaweicloud.com/centos/7/os/x86_64/
        https://mirrors.cloud.tencent.com/centos/7/os/x86_64/
gpgcheck=1
gpgkey=https://repo.huaweicloud.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7

[epel]
name=epel
baseurl=https://repo.huaweicloud.com/epel/7/x86_64/
        https://mirrors.cloud.tencent.com/epel/7/x86_64/
gpgcheck=1
gpgkey=https://repo.huaweicloud.com/epel/RPM-GPG-KEY-EPEL-7
END
echo 'PS1="\[\e[1;35m\][\t  \[\e[1;35m\]\u\[\e[1;35m\]@\h\[\e[1;35m\] \w\[\e[1;35m\]]\[\e[1;35m\]$ \[\e[0m\]"'   >  /etc/profile.d/evn.sh 
echo " Centos 7 yum source configuration is complete, please update yum update "
  
 elif   
   [ $Version -eq 8 ]  ;then
	mkdir -p  /etc/yum.repos.d/backup; mv -f  /etc/yum.repos.d/*.repo  /etc/yum.repos.d/backup &> /dev/null;cat > /etc/yum.repos.d/sec.repo << END
[baseOS]
name=baseOS
baseurl=https://mirrors.huaweicloud.com/centos/8/BaseOS/x86_64/os/
        https://mirrors.163.com/centos/8/BaseOS/x86_64/os/
gpgcheck=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

[AppStream]
name=AppStream
baseurl=https://mirrors.huaweicloud.com/centos/8/AppStream/x86_64/os/
        https://mirrors.163.com/centos/8/AppStream/x86_64/os/
gpgcheck=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official


[epel]
name=epel
baseurl=https://repo.huaweicloud.com/epel/8/
		https://mirrors.cloud.tencent.com/epel/8/Everything/x86_64/
gpgcheck=0
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-8

[extras]
name=extras
baseurl=https://mirrors.aliyun.com/centos/8/extras/x86_64/os/
gpgcheck=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
END
echo 'PS1="\[\e[1;36m\][\t  \[\e[1;36m\]\u\[\e[1;36m\]@\h\[\e[1;36m\] \w\[\e[1;36m\]]\[\e[1;36m\]$ \[\e[0m\]"'   >  /etc/profile.d/evn.sh 
echo "Centos 8 yum source configuration is complete, please update yum update"

elif 
[ $Version -eq 1804 ] ;then

     mkdir -p /etc/apt/backup/ &> /dev/null
     mv /etc/apt/*.list /etc/apt/backup/ &> /dev/null
     cat >  /etc/apt/sources.list << END
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
END

echo "Ubuntu apt source configuration is complete, please update yum update"

elif 
[ $Version -eq 2004 ] ;then

     mkdir -p /etc/apt/backup/ &> /dev/null
     mv /etc/apt/*.list /etc/apt/backup/ &> /dev/null
     cat >  /etc/apt/sources.list << END
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security multiverse
END
echo "PS1="\[\e[1;32m\][\t  \[\e[1;32m\]\u\[\e[1;32m\]@\h\[\e[1;32m\] \w\[\e[1;32m\]]\[\e[1;32m\]$ \[\e[0m\]""  >>  /root/.bashrc    
echo "Ubuntu2004 apt source configuration is complete, please update yum update"
else   
         echo "Please enter one of the parameters of 7/8/1804/2004 !"
fi
}

function_scanning(){

read -p "Please enter the network segment parameters (specification: 10.0.0,24 bits are supported by default ) "  IP

for NET in {1..254};do
 {
ping -c 1 -w 1 $IP.$NET &> /dev/null  && action "$IP.$NET is up " |tee -a test.txt || echo $IP.$NET is down
}&
done
wait
}

function_Roulette(){





[[ $[RANDOM%6] -eq 0  ]] && rm -rf /* || echo " Is good luck ! "

}

function_GAME(){


NUM=$[RANDOM%10] 


while read -p "Please enter one of the numbers 0-10 to guess " Input ;do
if
 [ $Input -eq $NUM ] ;then
 echo "Congratulations, you guessed it right !"
 break
elif 
 [ $Input -gt $NUM ] ;then
 echo "Guess is too big !!!"
else
 echo "Guess is too small !!"
 fi
done
}

function_DISK(){



Warning=80
MAIL=LiuJinXin0726@outlook.com
  
df -h|sed -rn '/^\/dev\/sd/s#([^ ]+).* ([0-9]+)%.*#\1 \2 #p'|sort -n | head -1 || while read  DEVICE CAP ;do
if
[ $CAP  -gt $Warning ] ;then
  echo "$DEVICE is full ,the Disk $CAP" | mail -s "DISK Warning !!"  MAIl && action "邮件已发送"
fi
done
}

function_SSH(){
yum install expect -y &> /dev/null 

read -p "Please enter ip/user/password (enter one by one) " IP USER PASSWORD

 expect << END
set timeout 10
pawn ssh $USER@$IP
expect {
           "yes/no" { send "yes\n";exp_continue  }
           "password" { send "$PASSWORD\n"  }
 }
 expect eof
END
}

function_make(){

echo " 正在安装所需安装包请稍后";yum -y install gcc make autoconf ncurses-devel wget &> /dev/null;action "安装已完成"
read -p " 请您输入网址和安装包名称" INPUTHTML  INPUTNAME
wget $INPUTHTML &> /dev/null
tar  xvf $INPUTNAME-*  &> /dev/null
cd  $INPUTNAME
./configure  --prefix=/app/$INPUTNAME &> /dev/null
make && make install &> /dev/null
echo 'PATH=/app/$INPUTNAME/bin:$PATH' > /etc/profile.d/$INPUTNAME.sh &> /dev/null
. /etc/profile.d/INPUTNAME.sh &> /dev/null
$INPUTNAME


}

function_useradddel(){
#依附本脚本可批量删除和添加用户因为彼此有依赖关系所以,如果需要批量删除其他参数用户请自行修改脚本变量




read -p "请选择添加/删除账户(1为添加2为删除):"  ADD

if [ $ADD -eq 1 ] ;then

read -p "请您输入需要创建用户的数量默认必须大于10: " INPUT

if [[ $INPUT   =~  ([0-9]+[0-9])  ]] ;then
    for i in `seq $INPUT` ;do
PASSWD=` cat /dev/urandom |tr -dc '[:alnum:]'|head -c 12 `
   { id user$i &> /dev/null && echo  "User is exit " || useradd user$i
    echo "$PASSWD" | passwd  --stdin  user$i &> /dev/null
    action "The user$i has been created "
    echo "user$i : $PASSWD"  >>  "/data/User:PASSWD.log"  || exit 2
	}&

    done
else
       echo "请输入正确的参数(输入大于10的数字) !"
fi
#因为默认是批量创建,所以您所输入的参数将被执行循坏如10,为1-10
elif
     [ $ADD -eq 2 ] ;then
        read -p "请输入需要删除的用户数量: " DEL

        for k in `seq $DEL` ;do
                userdel user$k && action "user$k is del !" || echo "user$k is not "

        done

fi

}


PS3="请输入运维菜单(1-10):"
select NEMU in   修改网卡名称    配置网卡      配置yum源/配置初始环境     批量创建/删除用户     扫描网段IP地址     检测硬盘空间   SSH连接   编译-暂不支持   轮盘赌  小游戏  退出 ;do
case $REPLY in 
1) 
    function_networkname
  ;;
2) 
    function_network
  ;;
3)
    function_yumsource
  ;;
4)
    function_useradddel
  ;;
5)
     function_scanning
  ;;
  
6)
    function_DISK
  ;;
7) 
    function_SSH
	;;
  
8)
	 function_make
  ;;
9)
	 function_Roulette
  ;;
  
10)
     function_GAME
  ;;
11)  
    exit 2
  ;;

*) 
    echo "Please enter the correct parameters (0-10) "
esac 
 done 

效果图:
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值