本来想着这周把逻辑卷的实验做完,但要学的东西实在太多了,网络学的脑壳疼,吧第二版的reset脚本当作业吧
实际上还是有很多东西没有改完,而且整体也不美观,需要继续改进
比上一版本多的改进是
- 更新了yum源仓库两种配置 (可选基于本地光盘或者网络的)(重复执行脚本也不会出现问题)
- 更改回来了cat > << 的结束符(之前以为如果有多个追加重定向不可用同一个结束符)
- 增加了几个别名 (但有个问题并没有解决,source ~/.bashrc 只能在子进程里执行,并不能在当前进程生效,所以,需要重新退出,或手动source才可以,有待改进)
别名也搞得不好,下次试试用echo >> 把全部内容追加进去
其实主要就改进了repo源,让用户可以主动选择那种方式,下一版本要改成用户的.mailrc 的邮箱用$1 替换 ,网络的IP 也变成交互式,不然只能由一种可能,而且可以增加一个判断,如果已经由此网络那么,自动+1
还打算添加个心功能,显示主机的一些信息 主机名,版本号,内存,分区状况什么的
下周一定把逻辑卷的实验搞完
脚本看着很乱,全部完成之后,看看能不能让脚本看起来简洁些,现在自己看着都感觉乱
#!/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 <<EOF
set ts=4
set expandtab
set ignorecase
set cursorline
set nu
EOF
echo $COL ".vimrc Setup is complete" $END
#creat .vimrc
cat > .mailrc <<EOF
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
EOF
echo $COL ".mailrc Setup is complete" $END
#creat .mailrc
#try use echo >> ~/.bashrc
# alias next line
sed -i "/alias rm=/a alias la='ls -A'" ~/.bashrc
sed -i "/alias rm=/a alias dy='dnf -y' " ~/.bashrc
sed -i "/alias rm=/a alias yy='yum -y '" ~/.bashrc
#sed -i "/alias cdnet=cd /etc/sysconfig/network-scripts/" ~/.bashrc
# source ~/.bashrc
# cause script run in subshell so source cannot effect this should be solved
echo "Please "source ~/.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
export MIR=/mnt/cdrom
read -p "use local CD for yum repositories (y/n)" ANS
if [[ $ANS =~ [yY]|[Yy][Ee][Ss] ]] ;then
[ -d "$MIR" ] && echo "mount dir exist" ||
mkdir "$MIR" ; mount /dev/cdrom "$MIR" &> /dev/null &&
echo "` blkid /dev/cdrom |sed -En -e 's/"//g' -e 's/.*(UUID.*)LABEL.*/\1/p'` "$MIR" iso9660 defaults 0 0" >> /etc/fstab
if find $DIR/bak -type d &> /dev/null ;then
cd $DIR ; mv $DIR/*.repo bak
else cd $DIR ; mkdir bak ; mv $DIR/*.repo bak
fi
cat > $DIR/aliyum.repo <<EOF
[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
[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
EOF
echo " $COL done it make tow web yum repo two local yum repo $END "
exit 40
else
umount $MIR && sed -i '/iso9660/d' /etc/fstab
if find $DIR/bak -type d &> /dev/null ;then
cd $DIR ; mv $DIR/*.repo bak
else cd $DIR ; mkdir bak ; mv $DIR/*.repo bak
fi
cat > $DIR/aliyum.repo <<EOF
[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
EOF
echo " $COL done it make four web yum repo $END "
exit 41
fi
else
echo $COL "wrong input exit" $END
fi
exit 100
浙公网安备 33010602011771号