Skip to content

Commit 2b73cbc

Browse files
committed
update scripts
1 parent 90908bb commit 2b73cbc

15 files changed

Lines changed: 478 additions & 388 deletions

codes/linux/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Linux 傻瓜式运维脚本
1+
# Dunwu Shell 运维脚本
22

33
> **本项目脚本代码用于在 [CentOS](https://www.centos.org/) 机器上安装常用命令工具或开发软件。**
44

codes/linux/download.sh

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
###################################################################################
3+
# ---------------------------------------------------------------------------------
44
# 控制台颜色
55
BLACK="\033[1;30m"
66
RED="\033[1;31m"
@@ -10,11 +10,10 @@ BLUE="\033[1;34m"
1010
PURPLE="\033[1;35m"
1111
CYAN="\033[1;36m"
1212
RESET="$(tput sgr0)"
13-
###################################################################################
13+
# ---------------------------------------------------------------------------------
1414

15-
printf "${BLUE}"
15+
printf "${BLUE}\n"
1616
cat << EOF
17-
1817
###################################################################################
1918
# linux-tutorial 运维脚本工具集下载脚本
2019
# 下载 https://github.com/dunwu/linux-tutorial 中的所有脚本到当前服务器的
@@ -23,23 +22,27 @@ cat << EOF
2322
# @author: Zhang Peng
2423
# See: https://github.com/dunwu/linux-tutorial
2524
###################################################################################
26-
2725
EOF
28-
printf "${RESET}"
26+
printf "${RESET}\n"
27+
28+
root=/home/scripts/linux-tutorial
29+
printf "\n${GREEN}>>>>>>>> Download linux-tutorial to ${root} begin.${RESET}\n"
30+
command -v yum > /dev/null 2>&1 || {
31+
printf "\n${RED}Not detected yum.${RESET}";
32+
exit 1;
33+
}
2934

30-
path=/home/scripts/linux-tutorial
31-
printf "\n${GREEN}>>>>>>>> Download linux-tutorial to ${path} begin.${RESET}\n"
32-
command -v yum > /dev/null 2>&1 || { printf "${RED}Not detected yum.${RESET}";
33-
exit 1; }
34-
command -v git > /dev/null 2>&1 || { printf "${YELLOW}Not detected git. Install git.${RESET}\n";
35-
yum -y install git; }
35+
command -v git > /dev/null 2>&1 || {
36+
printf "\n${YELLOW}Not detected git. Install git.${RESET}\n";
37+
yum install -y git;
38+
}
3639

37-
if [[ -d ${path} ]]; then
38-
cd ${path}
40+
if [[ -d ${root} ]]; then
41+
cd ${root}
3942
git pull
4043
else
41-
mkdir -p ${path}
42-
git clone https://gitee.com/turnon/linux-tutorial.git ${path}
44+
mkdir -p ${root}
45+
git clone https://gitee.com/turnon/linux-tutorial.git ${root}
4346
fi
44-
chmod +x -R ${path}
45-
printf "\n${GREEN}<<<<<<<< Download linux-tutorial to ${path} end.${RESET}\n"
47+
chmod +x -R ${root}
48+
printf "\n${GREEN}<<<<<<<< Download linux-tutorial to ${root} end.${RESET}\n"

codes/linux/dunwu-ops.sh

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
###################################################################################
3+
# ---------------------------------------------------------------------------------
44
# 控制台颜色
55
BLACK="\033[1;30m"
66
RED="\033[1;31m"
@@ -10,82 +10,74 @@ BLUE="\033[1;34m"
1010
PURPLE="\033[1;35m"
1111
CYAN="\033[1;36m"
1212
RESET="$(tput sgr0)"
13-
###################################################################################
13+
# ---------------------------------------------------------------------------------
1414

1515
# 打印头部信息
1616
printHeadInfo() {
17-
printf "${BLUE}"
18-
cat << EOF
19-
20-
***********************************************************************************
21-
* 欢迎使用 Linux CentOS 环境运维脚本
22-
* @author: Zhang Peng
23-
***********************************************************************************
24-
17+
printf "${BLUE}\n"
18+
cat << EOF
19+
###################################################################################
20+
# 欢迎使用 Dunwu Shell 运维脚本
21+
# 适用于 Linux CentOS 环境
22+
# @author: Zhang Peng
23+
###################################################################################
2524
EOF
26-
printf "${RESET}"
25+
printf "${RESET}\n"
2726
}
2827

2928
# 打印尾部信息
3029
printFootInfo() {
31-
printf "${BLUE}"
32-
cat << EOF
33-
34-
***********************************************************************************
35-
* 脚本执行结束,感谢使用!
36-
***********************************************************************************
37-
30+
printf "${BLUE}\n"
31+
cat << EOF
32+
###################################################################################
33+
# 脚本执行结束,感谢使用!
34+
###################################################################################
3835
EOF
39-
printf "${RESET}"
36+
printf "${RESET}\n"
4037
}
4138

4239
# 检查操作系统环境
4340
checkOsVersion() {
4441
if (($1 == 1)); then
45-
echo -e "检查操作系统环境是否兼容本套脚本"
46-
4742
platform=`uname -i`
4843
if [[ ${platform} != "x86_64" ]]; then
49-
echo "脚本仅支持 64 位操作系统!"
44+
printf "\n${RED}脚本仅支持 64 位操作系统!${RESET}\n"
5045
exit 1
5146
fi
5247

5348
version=`cat /etc/redhat-release | awk '{print substr($4,1,1)}'`
5449
if [[ ${version} != 7 ]]; then
55-
echo "脚本仅支持 CentOS 7!"
50+
printf "\n${RED}脚本仅支持 CentOS 7!${RESET}\n"
5651
exit 1
5752
fi
58-
59-
echo -e "脚本可以在本环境运行!"
6053
fi
6154
}
6255

6356
menus=( "配置系统" "安装软件" "退出" )
64-
main() {
57+
selectAndExecTask() {
58+
printHeadInfo
6559
PS3="请输入命令编号:"
6660
select item in "${menus[@]}"
6761
do
6862
case ${item} in
69-
"配置系统")
70-
./dunwu-sys.sh
71-
main ;;
72-
"安装软件")
73-
./dunwu-soft.sh
74-
main ;;
75-
"退出")
76-
exit 0 ;;
77-
*)
78-
printf "输入项不支持!\n"
79-
main ;;
63+
"配置系统")
64+
./dunwu-sys.sh
65+
selectAndExecTask ;;
66+
"安装软件")
67+
./dunwu-soft.sh
68+
selectAndExecTask ;;
69+
"退出")
70+
printFootInfo
71+
exit 0 ;;
72+
*)
73+
printf "\n${RED}输入项不支持!${RESET}\n"
74+
selectAndExecTask ;;
8075
esac
8176
break
8277
done
8378
}
8479

80+
8581
######################################## MAIN ########################################
86-
path=$(cd "$(dirname "$0")";
87-
pwd)
88-
printHeadInfo
89-
checkOsVersion 0
90-
main
91-
printFootInfo
82+
checkOsVersion 1
83+
selectAndExecTask

codes/linux/dunwu-soft.sh

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
###################################################################################
3+
# ---------------------------------------------------------------------------------
44
# 控制台颜色
55
BLACK="\033[1;30m"
66
RED="\033[1;31m"
@@ -10,52 +10,57 @@ BLUE="\033[1;34m"
1010
PURPLE="\033[1;35m"
1111
CYAN="\033[1;36m"
1212
RESET="$(tput sgr0)"
13-
###################################################################################
13+
# ---------------------------------------------------------------------------------
1414

1515
printf "${BLUE}\n"
1616
cat << EOF
17-
18-
***********************************************************************************
19-
* 欢迎使用 Linux CentOS 软件安装配置脚本
20-
* @author: Zhang Peng
21-
***********************************************************************************
22-
17+
###################################################################################
18+
# 欢迎使用 Dunwu Shell 软件安装脚本
19+
# 适用于 Linux CentOS 环境
20+
# @author: Zhang Peng
21+
###################################################################################
2322
EOF
23+
printf "${RESET}\n"
2424

2525
# print menu
26-
printf "${PURPLE}"
27-
menus=( docker fastdfs gitlab jdk8 jenkins kafka maven mongodb mysql nacos nexus nginx nodejs redis rocketmq tomcat8
28-
zookeeper zsh exit )
29-
for i in "${!menus[@]}"; do
30-
index=`expr ${i} + 1`
31-
val=`expr ${index} % 2`
32-
printf "[%02d] %-20s" "${index}" "${menus[$i]}"
33-
if [[ ${val} -eq 0 ]]; then
34-
printf "\n"
35-
fi
36-
done
37-
printf "\n${RESET}请输入需要安装的软件编号:\n"
26+
printMenu() {
27+
printf "${PURPLE}"
28+
menus=( docker fastdfs gitlab jdk8 jenkins kafka maven mongodb mysql nacos nexus nginx nodejs redis rocketmq tomcat8 zookeeper zsh exit )
29+
for i in "${!menus[@]}"; do
30+
index=`expr ${i} + 1`
31+
val=`expr ${index} % 2`
32+
printf "[%02d] %-20s" "${index}" "${menus[$i]}"
33+
if [[ ${val} -eq 0 ]]; then
34+
printf "\n"
35+
fi
36+
done
37+
38+
printf "\n\n${BLUE}请选择需要安装的软件:${RESET}"
39+
}
3840

3941
# exec shell to install soft
40-
doInstall() {
42+
main() {
43+
printMenu
4144
read -t 30 index
4245
if [[ -n ${index} ]]; then
4346
no=`expr ${index} - 1`
4447
len=${#menus[*]}
4548
if [[ ${index} -gt ${len} ]]; then
46-
echo "输入项不支持!"
49+
printf "${RED}输入项不支持!\n${RESET}"
4750
exit -1
4851
fi
4952
key=${menus[$no]}
50-
if [[ key == 'exit' ]]; then
53+
if [[ ${key} == 'exit' ]]; then
54+
printf "${GREEN}退出 Dunwu 软件安装脚本。\n${RESET}"
5155
exit 0
5256
fi
53-
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/${key}-install.sh | bash
54-
doInstall
57+
sh soft/${key}-install.sh
58+
printf "\n"
59+
main
5560
else
56-
echo "输入项不支持!"
61+
printf "${RED}输入项不支持!\n${RESET}"
5762
exit -1
5863
fi
5964
}
6065

61-
doInstall
66+
main

codes/linux/dunwu-sys.sh

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,61 @@
11
#!/usr/bin/env bash
22

3-
cat << EOF
3+
# ---------------------------------------------------------------------------------
4+
# 控制台颜色
5+
BLACK="\033[1;30m"
6+
RED="\033[1;31m"
7+
GREEN="\033[1;32m"
8+
YELLOW="\033[1;33m"
9+
BLUE="\033[1;34m"
10+
PURPLE="\033[1;35m"
11+
CYAN="\033[1;36m"
12+
RESET="$(tput sgr0)"
13+
# ---------------------------------------------------------------------------------
414

15+
printf "${BLUE}\n"
16+
cat << EOF
517
###################################################################################
6-
# Linux CentOS 环境初始化脚本(设置环境配置、安装基本的命令工具)
18+
# 欢迎使用 Dunwu Shell 环境初始化脚本(设置环境配置、安装基本的命令工具)
19+
# 适用于 Linux CentOS 环境
720
# @author: Zhang Peng
821
###################################################################################
9-
1022
EOF
23+
printf "${RESET}\n"
1124

1225
menus=( "替换yum镜像" "安装基本的命令工具" "安装常用libs" "系统配置" "全部执行" "退出" )
1326
main() {
1427
PS3="请输入命令编号:"
1528
select item in "${menus[@]}"
1629
do
1730
case ${item} in
18-
"替换yum镜像")
19-
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/change-yum-repo.sh | bash
20-
main ;;
21-
"安装基本的命令工具")
22-
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/install-tools.sh | bash
23-
main ;;
24-
"安装常用libs")
25-
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/install-libs.sh | bash
26-
main ;;
27-
"系统配置")
28-
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/sys-settings.sh | bash
29-
main ;;
30-
"全部执行")
31-
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/change-yum-repo.sh | bash
32-
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/install-tools | bash
33-
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/install-libs.sh | bash
34-
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/sys-settings.sh | bash
35-
printf "执行完毕,退出。\n" ;;
36-
"退出")
37-
exit 0 ;;
38-
*)
39-
printf "输入项不支持!\n"
40-
main ;;
31+
"替换yum镜像")
32+
sh ${root}/sys/change-yum-repo.sh
33+
main ;;
34+
"安装基本的命令工具")
35+
sh ${root}/sys/install-tools.sh
36+
main ;;
37+
"安装常用libs")
38+
sh ${root}/sys/install-libs.sh
39+
main ;;
40+
"系统配置")
41+
sh ${root}/sys/sys-settings.sh ${root}/sys
42+
main ;;
43+
"全部执行")
44+
sh ${root}/sys/change-yum-repo.sh
45+
sh ${root}/sys/install-tools.sh
46+
sh ${root}/sys/install-libs.sh
47+
sh ${root}/sys/sys-settings.sh ${root}/sys
48+
printf "${GREEN}执行完毕,退出。${RESET}\n" ;;
49+
"退出")
50+
exit 0 ;;
51+
*)
52+
printf "${RED}输入项不支持!${RESET}\n"
53+
main ;;
4154
esac
4255
break
4356
done
4457
}
4558

4659
######################################## MAIN ########################################
60+
root=$(pwd)
4761
main

0 commit comments

Comments
 (0)