终于搞出一个reset脚本,但是还有地方需要改,比如邮箱地址改成自动输入,ip地址自动输入并检测是不是合法ip,还要考虑通用性,目前只能在centos8上执行
先来看看脚本把
#!/bin/bash
#this scirpt for reset a new machine
COL=`echo -e "\e[1;$[RANDOM%7+31]m"`
END=`echo -e "\e[0m"`
echo $COL "
1:install toolkits
2:setup .vimrc .mailrc \$PS1
3:setup etho firewalld
4:setup yum.repo
$END "
#show the Options and make random color
KITS="gcc make autoconf gcc-c++ glibc glibc-devel pcre pcre-devel openssl
openssl-devel systemd-devel zlib-devel vim lrzsz tree tmux lsof tcpdump wget
net-tools iotop bc bzip2 zip unzip nfs-utils man-pages autofs "
#add anthing in $KITS to install
read -p"$COL Pick one (1-4) $END" FUN
if
[ $FUN = 1 ] ;then
echo $COL "please be patient it's might gonna take a while" $END
echo "$KITS "|xargs yum -y install &&
systemctl start autofs ; systemctl enable autofs
# updatedb
mandb &> /dev/null
echo $COL "installed toolkits" $END
exit 10
#install toolkits and start /misc/cd
elif
[ $FUN = 2 ] ;then
echo 'PS1="\e[1;$[RANDOM%7+31]m[\u@\t \W]\#\\$\e[0m"' > /etc/profile.d/env.sh &&
echo $COL "\$PS1 Setup is complete" $END
cat > .vimrc <<WID
set ts=4
set expandtab
set ignorecase
set cursorline
set nu
WID
echo $COL ".vimrc Setup is complete" $END
#creat .vimrc
cat > .mailrc <<QUS
set from=yuhang997@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=yuhang997@qq.com
set smtp-auth-password=esvnhbnqocirbicf
set smtp-auth=login
set ssl-verify=ignore
QUS
echo $COL ".mailrc Setup is complete" $END
#creat .mailrc
# alias next line
echo "`sed -i.bak "7a\alias la='ls -A'" .bashrc `"
exit 20
#setup PS1 .mailrc .vimrc alias
elif
[ $FUN = 3 ] ;then
systemctl stop firewalld ;systemctl disable firewalld && echo "$COL Colsed firewalld $END"
#stop firewalld
cd /etc/sysconfig/network-scripts
mv * /data
cat > ifcfg-eth0 <<EOF
NAME="eth0"
DEVICE="eth0"
IPADDR=10.0.0.11
BOOTPROTO="static"
PREFIX=24
GATEWAY=10.0.0.2
DNS1=180.76.76.76
DNS2=223.6.6.6
ONBOOT="yes"
EOF
sed -Ei.bak '6s/(.*)"$/\1 net.ifnames=0\"/' /etc/default/grub
sed -Ei.bak '7s/(SELINUX=).*/\1disabled/' /etc/selinux/config
grub2-mkconfig -o /boot/grub2/grub.cfg
#setup ipaddr network name
read -p "$COL Effective after restart restart now $END ? (y/n)" CHOOSE
if [[ $CHOOSE =~ [yY]|[Yy][Ee][Ss] ]] ;then
reboot ;echo "$COL Rebooooooooooting $END "
else
echo "$COL Please restart manually later $END"
exit 30
fi
elif
[ $FUN = 4 ] ;then
DIR=/etc/yum.repos.d
if find $DIR/bak -type d &> /dev/null ;then
echo "$COL DIR is already there$END"
else cd $DIR ; mkdir bak ; mv $DIR/*.repo bak
fi
if [ -d "/mnt/cdrom/" ] ;then
echo "DIR exist"
else mkdir /mnt/cdrom ; mount /dev/cdrom /mnt/cdrom &> /dev/null
echo "` blkid /dev/cdrom |sed -En -e 's/"//g' -e 's/.*(UUID.*)LABEL.*/\1/p'` /mnt/cdrom iso9660 defaults 0 0" >> /etc/fstab
fi
#if you don't want to use local repo , Comment out the above two lines
cat > $DIR/aliyum.repo <<RPG
[AppStream]
name=local Appstream
baseurl=file:///mnt/cdrom/AppStream/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
#enable=0
[BaseOS]
name=local baseos
baseurl=file:///mnt/cdrom/BaseOS/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
#enable=0
#If you want to use internet repositories, Uncomment "enable=0" above tow repo and make below of tow repo "enable=1"
[Base]
name=alibaseos
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
baseurl=https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/
https://mirrors.huaweicloud.com/centos/8/BaseOS/x86_64/os/
https://mirrors.cloud.tencent.com/centos/8/BaseOS/x86_64/os/
enabled=0
[Appstream]
name=aliappstream
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
baseurl=https://mirrors.aliyun.com/centos/8/AppStream/x86_64/os/
https://mirrors.huaweicloud.com/centos/8/AppStream/x86_64/os/
https://mirrors.cloud.tencent.com/centos/8/AppStream/x86_64/os/
enabled=0
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/8/Everything/x86_64/
gpgcheck=1
[extras]
name=extras
baseurl=https://mirrors.aliyun.com/centos/8/extras/x86_64/os/
gpgcheck=1
RPG
echo " $COL done it $END "
exit 40
else
echo $COL "wrong input exit" $END
fi
exit 100
脚本就四个功能,安装一些出场软件,改一下.vimrc .mailrc 关闭防火墙,改一下网卡名,ip地址,设置一下yum源
虽然是个没含量的脚本,但在写完之后仍然改了近40版(笑尿
最近学习任务很重,学磁盘管理学的脑袋疼,而且每天明明没干什么还感觉自己很忙的样子
下次打算搞个编译安装新版内核
浙公网安备 33010602011771号