系统相关
首页 > 系统相关> > centos、Ubuntu minimal install tuning shell script

centos、Ubuntu minimal install tuning shell script

作者:互联网

该版本仅支持centos7及Ubuntu1804,脚本内容:
  1 #!/bin/bash
  2 #
  3 #*************************************************************************************
  4 #Author:                                                      wanghaomiao
  5 #QQ:                                                          1074035975
  6 #Date:                                                        2022-04-19
  7 #FileName                                                     reset_1.sh
  8 #URL:                                                         wanghaomiao.com.cn
  9 #Description:                                                 The test script
 10 #Copyreght (C):                                               2022 All rightsreserved
 11 #*************************************************************************************
 12 COLOR='\e[1;31m'
 13 COLOR_END='\e[0m'
 14 NETWORK_NAME=`ip a | sed -nr '/^2/s#.* (.*): .*#\1#p'`
 15 Ubuntu_NETWORK_DIR="/etc/netplan/00-installer-config.yaml"
 16 Centos_NETWORK_DIR="/etc/sysconfig/network-scripts/ifcfg-$NETWORK_NAME"
 17 
 18 
 19 
 20 set_sshd(){
 21 #whoami | grep root &> /dev/null
 22 #if [ $? -eq 0 ]; then
 23 #if [[ `whoami` == "root" ]]; then
 24 #    sed -ri.bak -e 's/.*(UseDNS ).*/\1no/' -e 's/.*(GSSAPIAuthentication ).*/\1no/' -e 's/.*(PermitRootLogin ).*/\1yes/' /etc/ssh/sshd_config
 25 #else
 26     sudo  sed -ri.bak -e 's/.*(UseDNS ).*/\1no/' -e 's/.*(GSSAPIAuthentication ).*/\1no/' -e 's/.*(PermitRootLogin ).*/\1yes/' /etc/ssh/sshd_config
 27 #fi
 28 if [ $? -eq 0 ]; then
 29     echo -e "$COLOR ssh service setup completed!restart the service! $COLOR_END"
 30 else
 31     echo -e "$COLOR SSH service setting failed, please try again,exit! $COLOR_END"
 32 fi
 33 sudo systemctl restart sshd
 34 }
 35 
 36 set_vimrc(){
 37 echo -ne "$COLOR"
 38 echo -e "Please enter relevant information to set vimrc file"
 39 read -p "pleace enter your UserName:" UserName
 40 read -p "pleace enter your QQ:" QQ
 41 read -p "pleace enter your UserURL:" UserURL
 42 echo -ne "$COLOR_END"
 43 #
 44 #if [[ `whoami` == "root" ]]; then
 45 #cat >~/.vimrc <<EOF
 46 #set ts=4
 47 #set expandtab
 48 #set ignorecase
 49 #autocmd BufNewFile *.sh exec ":call SetTitile()"
 50 #func SetTitile()
 51 #    if expand("%:e") == 'sh'
 52 #    call setline(1,"#!/bin/bash")
 53 #    call setline(2,"#")
 54 #    call setline(3,"#*************************************************************************************")
 55 #    call setline(4,"#Author:                                                       $UserName")
 56 #    call setline(5,"#QQ:                                                           $QQ")
 57 #    call setline(6,"#Date:                                                         ".strftime("%Y-%m-%d"))
 58 #    call setline(7,"#FileName                                                      ".expand("%"))
 59 #    call setline(8,"#URL:                                                          $UserURL")
 60 #    call setline(9,"#Description:                                                  The test script")
 61 #    call setline(10,"#Copyreght (C):                                                ".strftime("%Y")." All rightsreserved")
 62 #    call setline(11,"#*************************************************************************************")
 63 #    call setline(12,"")
 64 #    endif
 65 #endfunc
 66 #autocmd BufNewFile * normal G
 67 #EOF
 68 #else
 69 sudo cat >~/.vimrc <<EOF
 70 set ts=4
 71 set expandtab
 72 set ignorecase
 73 autocmd BufNewFile *.sh exec ":call SetTitile()"
 74 func SetTitile()
 75     if expand("%:e") == 'sh'
 76     call setline(1,"#!/bin/bash")
 77     call setline(2,"#")
 78     call setline(3,"#*************************************************************************************")
 79     call setline(4,"#Author:                                                       $UserName")
 80     call setline(5,"#QQ:                                                           $QQ")
 81     call setline(6,"#Date:                                                         ".strftime("%Y-%m-%d"))
 82     call setline(7,"#FileName                                                      ".expand("%"))
 83     call setline(8,"#URL:                                                          $UserURL")
 84     call setline(9,"#Description:                                                  The test script")
 85     call setline(10,"#Copyreght (C):                                                ".strftime("%Y")." All rightsreserved")
 86     call setline(11,"#*************************************************************************************")
 87     call setline(12,"")
 88     endif
 89 endfunc
 90 autocmd BufNewFile * normal G
 91 EOF
 92 #fi
 93 if [ $? -eq 0 ]; then
 94     echo -e "$COLOR .vimrc setup completed! $COLOR_END"
 95 else
 96     echo -e "$COLOR .vimrc setting failed,please try again,exit! $COLOR_END"
 97     exit
 98 fi
 99 }
100 
101 set_selinux_firewalld(){
102 sudo sed -ri.bak 's/(SELINUX=).*/\1disabled/' /etc/selinux/config
103 sudo systemctl disable --now firewalld
104 if [ $? -eq 0 ];then
105     echo -e "$COLOR SElinux and firewalld are turend off! $COLOR_END"
106 else
107     echo -e "$COLOR SELinux and firewall shutdown failed. Please try again,exit! $COLOR_END"
108     exit
109 fi
110 }
111 
112 set_hostname(){
113 read -p "Please enter the host name to set: " HostName
114 sudo hostnamectl set-hostname $HostName
115 if [ $? -eq 0 ];then
116     echo -e "$COLOR Hostname setting completed,pleace re login! $COLOR_END"
117 else
118     echo -e "$COLOR Hostname setting failed,please try again,exit! $COLOR_END"
119     exit
120 fi
121 }
122 
123 set_date(){
124 read -p "Please enter the time zone to set: " ZONE
125 sudo timedatectl set-timezone $ZONE
126 if [ $? -eq 0 ];then
127     echo -e "$COLOR Time zone $ZONE settings completed! $COLOR_END"
128 else
129     echo -e "$COLOR Time zone $ZONE setting failed, please try again,exit! $COLOR_END"
130     exit
131 fi
132 }
133 
134 set_yum(){
135 sudo yum repolist
136 sudo yum -y install wget
137 sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.buckup
138 sudo wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
139 sudo yum makecache
140 
141 if [ $? -eq 0 ];then
142     echo -e "$COLOR Alibaba cloud Yum source settings completed! $COLOR_END"
143 else
144     echo -e "$COLOR Alibaba colod Yum source settings failed,please try again,exit! $COLOR_END"
145     exit
146 fi
147 }
148 
149 set_apt(){
150 #echo $PASSWD | sudo -S cat > /etc/apt/source.list << EOF
151 #deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
152 #deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
153 #
154 #deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
155 #deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
156 #
157 #deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
158 #deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
159 #
160 #deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
161 #deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
162 #
163 #deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
164 #deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
165 #EOF
166 sudo sed -ri.bak 's/cn.archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
167 if [ $? -eq 0 ];then
168     echo -e "$COLOR Alibaba cloud Yum source settings completed! $COLOR_END"
169 else
170     echo -e "$COLOR Alibaba colod Yum source settings failed,please try again,exit! $COLOR_END"
171     exit
172 fi
173 sudo apt update
174 }
175 
176 set_epel(){
177 sudo mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup &> /dev/null
178 sudo mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup &> /dev/null
179 sudo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
180 if [ $? -eq 0 ];then
181     echo -e "$COLOR Alibaba cloud epel source settings completed! $COLOR_END"
182 else
183     echo -e "$COLOR Alibaba colod epel source settings failed,please try again,exit! $COLOR_END"
184     exit
185 fi
186 }
187 
188 set_Ubuntu1804_software_install(){
189 sudo apt -y purge ufw lxd lxd-client lxcfs lxc-common
190 if [ $? -eq 0 ];then
191     sudo apt -y install iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev ntpdate tcpdump telnet traceroute gcc openssh-server lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev ntpdate tcpdump telnet traceroute iotop unzip zip
192     if [ $? -eq 0 ];then
193         echo -e "$COLOR software installation completed! $COLOR_END"
194     else
195         echo -e "$SOLOR sofrware installation failed,please try again,exit! $COLOR_END"
196         exit
197     fi
198 else
199     echo -e "$SOLOR sofrware installation failed,please try again,exit! $COLOR_END"
200     exit
201 fi
202 }
203 
204 set_Centos7_software_install(){
205 sudo yum -y install gcc make 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 redhat-lsb-core postfix mailx bash-completion man-pages
206 if [ $? -eq 0 ];then
207     echo -e "$COLOR software installation completed! $COLOR_END"
208 else
209     echo -e "$SOLOR sofrware installation failed,please try again,exit! $COLOR_END"
210     exit
211 fi
212 }
213 
214 set_Ubuntu1804_eth0(){
215 eval sudo sed -ri.bak 's/$NETWORK_NAME/eth0/g' $Ubuntu_NETWORK_DIR
216 sudo sed -i -r 's/(GRUB_CMDLINE_LINUX=.*)"/\1net.ifnames=0 biosdevname=0"/g' /etc/default/grub
217 sudo update-grub
218 if [ $? -eq 0 ];then
219     echo -e "$COLOR The network card name has been changed.about to reboot! $COLOR_END"
220     sudo reboot
221 else
222     echo -e "$COLOR The network card name change failed, please try again,exit! $COLOR_END"
223     exit
224 fi
225 }
226 
227 set_Centos7_eth0(){
228 sudo mv /etc/sysconfig/network-scripts/ifcfg-$NETWORK_NAME $Centos_NETWORK_DIR /dev/null
229 sudo sed -ri.bak 's/(GRUB_CMDLINE_LINUX=.*quiet).*/\1 net.ifnames=0 biosdevname=0"/' /etc/default/grub
230 eval sudo sed -ri.bak 's/${NETWORK_NAME}/eth0/g' $Centos_NETWORK_DIR
231 sudo grub2-mkconfig -o /boot/grub2/grub.cfg
232 if [ $? -eq 0 ];then
233     echo -e "$COLOR The network card name has been changed. about to reboot! $COLOR_END"
234     sudo reboot
235 else
236     echo -e "$COLOR The network card name change failed, please try again,exit! $COLOR_END"
237     exit
238 fi
239 }
240 
241 
242 set_Ubuntu1804_ip(){
243 read -p "Please enter ip address and netmask(IP/NETMASK): " IP
244 read -p "Please enter gateway address: " GATEWAY
245 read -p "Please enter dns address(DNS1;DNS2;...): " DNS
246 sudo chmod 666 /etc/netplan/00-installer-config.yaml
247 sudo cat > $Ubuntu_NETWORK_DIR << EOF
248 # This is the network config written by 'subiquity'
249 network:
250   ethernets:
251     eth0:
252       dhcp4: no
253       addresses: [$IP]
254       gateway4: $GATEWAY
255       nameservers:
256               addresses: [$DNS]
257   version: 2
258 EOF
259 if [ $? -eq 0 ]; then
260     echo -e "$COLOR IP address settings completed,the network service will be restarted soon.SSH users need to reconnect $COLOR_END"
261 else
262     echo -e "$COLOR IP address settings failed,please try again!exit $COLOR_END"
263     exit
264 fi
265 sudo netplan apply
266 sudo chmod 644 /etc/netplan/00-installer-config.yaml
267 }
268 
269 set_Centos7_ip(){
270 read -p "please input ip address: " IP
271 read -p "please input netmask address: " NETMASK
272 read -p "please input gateway address: " GATEWAY
273 read -p "Please input DNS address: " DNS1
274 sudo cat > $Centos_NETWORK_DIR << EOF
275 TYPE="Ethernet"
276 BOOTPROTO="static"
277 DEFROUTE="yes"
278 NAME="eth0"
279 DEVICE="eth0"
280 ONBOOT="yes"
281 IPADDR="$IP"
282 NETMASK="$NETMASK"
283 GATEWAY="$GATEWAY"
284 DNS1="$DNS1"
285 EOF
286 if [ $? -eq 0 ]; then
287     echo -e "$COLOR IP address settings completed,the network service will be restarted soon.SSH users need to reconnect $COLOR_END"
288 else
289     echo -e "$COLOR IP address settings failed,please try again!exit $COLOR_END"
290     exit
291 fi
292 sudo systemctl restart network
293 }
294 
295 
296 set_di(){
297 sudo sed -ri.bak 's/#set bell-style none/set bell-style none/' /etc/inputrc | sudo  grep '#set bell-style none' /etc/inputrc
298 if [ $? -eq 1 ];then
299     echo -e "$COLOR Mainboard alarm turned off,about to reboot! $COLOR_END"
300     sudo reboot
301 else
302     echo -e "$COLOR Mainboard alarm closing failed,please try again,exit! $COLOR_END"
303     exit
304 fi
305 }
306 
307 set_env(){
308 sudo echo 'PS1="[\[\e[1;32m\]\t\[\e[0m\] \u@\h \W]\\\$"' >> ~/.bashrc
309 if [ $? -eq 0 ]; then
310     echo -e "$COLOR The command prompt is modified. Please log in again! $COLOR_END"
311 else
312     echo -e "$COLOR Command prompt modification failed, please try again! $COLOR_END"
313 fi
314 }
315 
316 set_sudoers(){
317 echo -ne "$COLOR"
318 read -p "Please enter the name of the user to be authorized: " USERNAME
319 echo -ne "$COLOR_END"
320 cat > /etc/sudoers.d/$USERNAME <<EOF
321 $USERNAME ALL=(ALL) NOPASSWD: ALL
322 EOF
323 if [ $? -eq 0 ];then
324     echo -e "$COLOR The user authorization is completed and needs to log in again! $COLOR_END"
325 else
326     echo -e "$COLOR User authorization failed, please try again! $COLOR_END"
327 fi
328 }
329 
330 ubuntu_run(){
331 #PS3="Please enter the number(1-11):"
332 #MENU="
333 #优化sshd服务
334 #设置.vimrc文件
335 #设置主机名
336 #时间同步
337 #更改apt源
338 #常用软件安装
339 #设置网卡名称为eth0
340 #设置IP地址
341 #关闭主板报警
342 #设置命令提示符
343 #退出
344 #"
345 
346 
347 echo -ne "$COLOR"
348 cat << EOF
349 1) 优化sshd服务
350 2) 设置.vimrc文件
351 3) 设置主机名
352 4) 时间同步
353 5) 更改apt源
354 6) 常用软件安装
355 7) 设置网卡名称为eth0
356 8) 设置IP地址
357 9) 关闭主板报警
358 10) 设置命令提示符
359 11) 退出
360 EOF
361 echo -ne "$COLOR_END"
362 
363 read -p "Please enter the number(1-11): " MENU
364 #select menu in $MENU;do
365 case $MENU in
366 1)
367 #    if [[ `whoami` == "root" ]];then
368 #    set_sshd
369 #    ubuntu_run
370 #    else
371 #    systempasswd
372     set_sshd
373     ubuntu_run
374 #    fi
375     ;;
376 2)
377 #    if [[ `whoami` == "root" ]];then
378 #    set_vimrc
379 #    ubuntu_run
380 #    else
381 #    systempasswd
382     set_vimrc
383     ubuntu_run
384 #    fi
385     ;;
386 3)
387 #    if [[ `whoami` == "root" ]];then
388 #    set_hostname
389 #    ubuntu_run
390 #    else
391 #    systempasswd
392     set_hostname
393     ubuntu_run
394 #    fi
395     ;;
396 4)
397 #    if [[ `whoami` == "root" ]];then
398 #    set_date
399 #    ubuntu_run
400 #    else
401 #    systempasswd
402     set_date
403     ubuntu_run
404 #    fi
405     ;;
406 5)
407 #    if [[ `whoami` == "root" ]];then
408 #    set_apt
409 #    ubuntu_run
410 #    else
411 #    systempasswd
412     set_apt
413     ubuntu_run
414 #    fi
415     ;;
416 6)
417 #    if [[ `whoami` == "root" ]];then
418 #    set_Ubuntu1804_software_install
419 #    ubuntu_run
420 #    else
421 #    systempasswd
422     set_Ubuntu1804_software_install
423     ubuntu_run
424 #    fi
425     ;;
426 7)
427 #    if [[ `whoami` == "root" ]];then
428 #    set_Ubuntu1804_eth0
429 #    else
430 #    systempasswd
431     set_Ubuntu1804_eth0
432 #    fi
433     ;;
434 8)
435 #    if [[ `whoami` == "root" ]];then
436 #    set_Ubuntu1804_ip
437 #    ubuntu_run
438 #    else
439 #    systempasswd
440     set_Ubuntu1804_ip
441     ubuntu_run
442 #    fi
443     ;;
444 9)
445 #    if [[ `whoami` == "root" ]];then
446 #    set_di
447 #    ubuntu_run
448 #    else
449 #    systempasswd
450     set_di
451 #    fi
452     ;;
453 10)
454 #    if [[ `whoami` == "root" ]];then
455 #    set_env
456 #    ubuntu_run
457 #    else
458 #    systempasswd
459     set_env
460     ubuntu_run
461 #    fi
462     ;;
463 11)
464 ##    break
465 #    exit
466     ;;
467 *)
468     echo -e "$COLOR Input error, please re-enter! $COLOR_END"
469 esac
470 #done
471 }
472 
473 centos_root_run(){
474 #PS3="Please enter the number(1-12):"
475 #MENU="
476 #优化sshd服务
477 #设置.vimrc文件
478 #关闭Selinux及防火墙
479 #设置主机名
480 #时间同步
481 #更改yum源
482 #常用软件安装
483 #设置网卡名称为eth0
484 #设置IP地址
485 #关闭主板报警
486 #设置命令提示符
487 #退出
488 #"
489 
490 
491 echo -ne "$COLOR"
492 cat << EOF
493 1) 优化sshd服务
494 2) 设置.vimrc文件
495 3) 关闭Selinux及防火墙
496 4) 设置主机名
497 5) 时间同步
498 6) 更改yum源
499 7) 常用软件安装
500 8) 设置网卡名称为eth0
501 9) 设置IP地址
502 10) 关闭主板报警
503 11) 设置命令提示符
504 12) 设置epel源
505 13) 设置普通用户sudo权限
506 14) 退出
507 EOF
508 echo -ne "$COLOR_END"
509 
510 read -p "Please enter the number(1-14): " MENU
511 #select menu in $MENU;do
512 case $MENU in
513 1)
514 #    if [[ `whoami` == "root" ]];then
515 #    set_sshd
516 #    centos_run
517 #    else
518 #    systempasswd
519     set_sshd
520     centos_root_run
521 #    fi
522     ;;
523 2)
524 #    if [[ `whoami` == "root" ]];then
525 #    set_vimrc
526 #    centos_run
527 #    else
528 #    systempasswd
529     set_vimrc
530     centos_root_run
531 #    fi
532     ;;
533 3)
534 #    if [[ `whoami` == "root" ]];then
535 #    set_selinux_firewalld
536 #    centos_run
537 #    else
538 #    systempasswd
539     set_selinux_firewalld
540     centos_root_run
541 #    fi
542     ;;
543 4)
544 #    if [[ `whoami` == "root" ]];then
545 #    set_hostname
546 #    centos_run
547 #    else
548 #    systempasswd
549     set_hostname
550     centos_root_run
551 #    fi
552     ;;
553 5)
554 #    if [[ `whoami` == "root" ]];then
555 #    set_date
556 #    centos_run    
557 #    else
558 #    systempasswd
559     set_date
560     centos_root_run
561 #    fi
562     ;;
563 6)
564 #    if [[ `whoami` == "root" ]];then
565 #    set_yum
566 #    centos_run
567 #    else
568 #    systempasswd
569     set_yum
570     centos_root_run
571 #    fi
572     ;;
573 7)
574 #    if [[ `whoami` == "root" ]];then
575 #    set_Centos7_software_install
576 #    centos_run
577 #    else
578 #    systempasswd
579     set_Centos7_software_install
580     centos_root_run
581 #    fi
582     ;;
583 8)
584 #    if [[ `whoami` == "root" ]];then
585 #    set_Centos7_eth0
586 #    centos_run
587 #    else
588 #    systempasswd
589     set_Centos7_eth0
590 #    fi
591     ;;
592 9)
593 #    if [[ `whoami` == "root" ]];then
594 #    set_Centos7_ip
595 #    else
596 #    systempasswd
597     set_Centos7_ip
598 #    fi
599     ;;
600 10)
601 #    if [[ `whoami` == "root" ]];then
602 #    set_di
603 #    centos_run
604 #    else
605 #    systempasswd
606     set_di
607 #    fi
608     ;;
609 11)
610 #    if [[ `whoami` == "root" ]];then
611 #    set_env
612 #    centos_run
613 #    else
614 #    systempasswd
615     set_env
616     centos_root_run
617 #    fi
618    ;;
619 12)
620     set_epel
621     centos_root_run
622     ;;
623 13)
624     set_sudoers
625     centos_root_run
626     ;;
627 14)
628 #    break
629     exit
630     ;;
631 *)
632     echo -e "$COLOR Input error, please re-enter! $COLOR_END"
633 esac
634 #done
635 }
636 
637 centos_user_run(){
638 #PS3="Please enter the number(1-12):"
639 #MENU="
640 #优化sshd服务
641 #设置.vimrc文件
642 #关闭Selinux及防火墙
643 #设置主机名
644 #时间同步
645 #更改yum源
646 #常用软件安装
647 #设置网卡名称为eth0
648 #设置IP地址
649 #关闭主板报警
650 #设置命令提示符
651 #退出
652 #"
653 
654 
655 echo -ne "$COLOR"
656 cat << EOF
657 1) 优化sshd服务
658 2) 设置.vimrc文件
659 3) 关闭Selinux及防火墙
660 4) 设置主机名
661 5) 时间同步
662 6) 更改yum源
663 7) 常用软件安装
664 8) 设置网卡名称为eth0
665 9) 设置IP地址
666 10) 关闭主板报警
667 11) 设置命令提示符
668 12) 设置epel源
669 13) 退出
670 EOF
671 echo -ne "$COLOR_END"
672 
673 read -p "Please enter the number(1-14): " MENU
674 #select menu in $MENU;do
675 case $MENU in
676 1)
677 #    if [[ `whoami` == "root" ]];then
678 #    set_sshd
679 #    centos_run
680 #    else
681 #    systempasswd
682     set_sshd
683     centos_user_run
684 #    fi
685     ;;
686 2)
687 #    if [[ `whoami` == "root" ]];then
688 #    set_vimrc
689 #    centos_run
690 #    else
691 #    systempasswd
692     set_vimrc
693     centos_user_run
694 #    fi
695     ;;
696 3)
697 #    if [[ `whoami` == "root" ]];then
698 #    set_selinux_firewalld
699 #    centos_run
700 #    else
701 #    systempasswd
702     set_selinux_firewalld
703     centos_user_run
704 #    fi
705     ;;
706 4)
707 #    if [[ `whoami` == "root" ]];then
708 #    set_hostname
709 #    centos_run
710 #    else
711 #    systempasswd
712     set_hostname
713     centos_user_run
714 #    fi
715     ;;
716 5)
717 #    if [[ `whoami` == "root" ]];then
718 #    set_date
719 #    centos_run    
720 #    else
721 #    systempasswd
722     set_date
723     centos_user_run
724 #    fi
725     ;;
726 6)
727 #    if [[ `whoami` == "root" ]];then
728 #    set_yum
729 #    centos_run
730 #    else
731 #    systempasswd
732     set_yum
733     centos_user_run
734 #    fi
735     ;;
736 7)
737 #    if [[ `whoami` == "root" ]];then
738 #    set_Centos7_software_install
739 #    centos_run
740 #    else
741 #    systempasswd
742     set_Centos7_software_install
743     centos_user_run
744 #    fi
745     ;;
746 8)
747 #    if [[ `whoami` == "root" ]];then
748 #    set_Centos7_eth0
749 #    centos_run
750 #    else
751 #    systempasswd
752     set_Centos7_eth0
753 #    fi
754     ;;
755 9)
756 #    if [[ `whoami` == "root" ]];then
757 #    set_Centos7_ip
758 #    else
759 #    systempasswd
760     set_Centos7_ip
761 #    fi
762     ;;
763 10)
764 #    if [[ `whoami` == "root" ]];then
765 #    set_di
766 #    centos_run
767 #    else
768 #    systempasswd
769     set_di
770 #    fi
771     ;;
772 11)
773 #    if [[ `whoami` == "root" ]];then
774 #    set_env
775 #    centos_run
776 #    else
777 #    systempasswd
778     set_env
779     centos_user_run
780 #    fi
781    ;;
782 12)
783     set_epel
784     centos_user_run
785     ;;
786 13)
787 #    break
788     exit
789     ;;
790 *)
791     echo -e "$COLOR Input error, please re-enter! $COLOR_END"
792 esac
793 #done
794 }
795 
796 systempasswd(){
797 read -p "Pleace enter your system password: " PASSWD
798 echo $PASSWD | sudo -S echo ****** &> /dev/null
799 if [ $? -eq 0 ] ;then
800     set_run
801 else
802     echo -ne "$COLOR Please add sudo permission and try again! $COLOR_END"
803     exit
804 fi
805 }
806 
807 system_os(){
808 sudo sed -nr '/^ID=/s#ID="?([[:alpha:]]+)"?#\1#p' /etc/os-release
809 }
810 
811 set_run(){
812 if [[ `system_os` == 'centos' ]];then
813     if [[ `whoami` == 'root' ]];then
814         centos_root_run
815     else
816         centos_user_run
817     fi
818 elif [[ `system_os` == 'ubuntu' ]];then
819     ubuntu_run
820 else
821     echo -ne "$COLOR 无法识别该系统,请重试! $COLOR_END"
822 fi
823 }
824 
825 
826 if [[ `whoami` == "root" ]];then
827     set_run
828 else
829     systempasswd
830     set_run
831 fi

 

标签:shell,END,tuning,centos,COLOR,sudo,echo,etc,exit
来源: https://www.cnblogs.com/Honey-Hao/p/16173648.html