Skip to content

Commit 952a95c

Browse files
committed
update codes
1 parent 06f51aa commit 952a95c

2 files changed

Lines changed: 244 additions & 18 deletions

File tree

codes/linux/dunwu-ops.sh

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

3-
#!/usr/bin/env bash
4-
53
# ------------------------------------------------------------------------------
64
# CentOS 常用软件一键安装脚本
75
# @author Zhang Peng
86
# ------------------------------------------------------------------------------
97

10-
# ------------------------------------------------------------------------------ libs
11-
# 装载其它库
12-
LINUX_SCRIPTS_DIR=$(cd `dirname $0`; pwd)
8+
# ------------------------------------------------------------------------------ env
9+
10+
# Regular Color
11+
export ENV_COLOR_BLACK="\033[0;30m"
12+
export ENV_COLOR_RED="\033[0;31m"
13+
export ENV_COLOR_GREEN="\033[0;32m"
14+
export ENV_COLOR_YELLOW="\033[0;33m"
15+
export ENV_COLOR_BLUE="\033[0;34m"
16+
export ENV_COLOR_MAGENTA="\033[0;35m"
17+
export ENV_COLOR_CYAN="\033[0;36m"
18+
export ENV_COLOR_WHITE="\033[0;37m"
19+
# Bold Color
20+
export ENV_COLOR_B_BLACK="\033[1;30m"
21+
export ENV_COLOR_B_RED="\033[1;31m"
22+
export ENV_COLOR_B_GREEN="\033[1;32m"
23+
export ENV_COLOR_B_YELLOW="\033[1;33m"
24+
export ENV_COLOR_B_BLUE="\033[1;34m"
25+
export ENV_COLOR_B_MAGENTA="\033[1;35m"
26+
export ENV_COLOR_B_CYAN="\033[1;36m"
27+
export ENV_COLOR_B_WHITE="\033[1;37m"
28+
# Underline Color
29+
export ENV_COLOR_U_BLACK="\033[4;30m"
30+
export ENV_COLOR_U_RED="\033[4;31m"
31+
export ENV_COLOR_U_GREEN="\033[4;32m"
32+
export ENV_COLOR_U_YELLOW="\033[4;33m"
33+
export ENV_COLOR_U_BLUE="\033[4;34m"
34+
export ENV_COLOR_U_MAGENTA="\033[4;35m"
35+
export ENV_COLOR_U_CYAN="\033[4;36m"
36+
export ENV_COLOR_U_WHITE="\033[4;37m"
37+
# Background Color
38+
export ENV_COLOR_BG_BLACK="\033[40m"
39+
export ENV_COLOR_BG_RED="\033[41m"
40+
export ENV_COLOR_BG_GREEN="\033[42m"
41+
export ENV_COLOR_BG_YELLOW="\033[43m"
42+
export ENV_COLOR_BG_BLUE="\033[44m"
43+
export ENV_COLOR_BG_MAGENTA="\033[45m"
44+
export ENV_COLOR_BG_CYAN="\033[46m"
45+
export ENV_COLOR_BG_WHITE="\033[47m"
46+
# Reset Color
47+
export ENV_COLOR_RESET="$(tput sgr0)"
48+
49+
# status
50+
export ENV_YES=0
51+
export ENV_NO=1
52+
export ENV_SUCCEED=0
53+
export ENV_FAILED=1
54+
55+
56+
# ------------------------------------------------------------------------------ functions
57+
58+
# 显示打印日志的时间
59+
SHELL_LOG_TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
60+
# 那个用户在操作
61+
USER=$(whoami)
62+
# 日志路径
63+
LOG_PATH=${ENV_LOG_PATH:-/var/log/shell.log}
64+
# 日志目录
65+
LOG_DIR=${LOG_PATH%/*}
66+
67+
createLogFileIfNotExists() {
68+
if [[ ! -x "${LOG_PATH}" ]]; then
69+
mkdir -p "${LOG_DIR}"
70+
touch "${LOG_PATH}"
71+
fi
72+
}
73+
74+
redOutput() {
75+
echo -e "${ENV_COLOR_RED} $@${ENV_COLOR_RESET}"
76+
}
77+
greenOutput() {
78+
echo -e "${ENV_COLOR_B_GREEN} $@${ENV_COLOR_RESET}"
79+
}
80+
yellowOutput() {
81+
echo -e "${ENV_COLOR_YELLOW} $@${ENV_COLOR_RESET}"
82+
}
83+
blueOutput() {
84+
echo -e "${ENV_COLOR_BLUE} $@${ENV_COLOR_RESET}"
85+
}
86+
magentaOutput() {
87+
echo -e "${ENV_COLOR_MAGENTA} $@${ENV_COLOR_RESET}"
88+
}
89+
cyanOutput() {
90+
echo -e "${ENV_COLOR_CYAN} $@${ENV_COLOR_RESET}"
91+
}
92+
whiteOutput() {
93+
echo -e "${ENV_COLOR_WHITE} $@${ENV_COLOR_RESET}"
94+
}
95+
96+
logInfo() {
97+
echo -e "${ENV_COLOR_B_GREEN}[INFO] $@${ENV_COLOR_RESET}"
98+
createLogFileIfNotExists
99+
echo "[${SHELL_LOG_TIMESTAMP}] [${USER}] [INFO] [$0] $@" >> "${LOG_PATH}"
100+
}
101+
logWarn() {
102+
echo -e "${ENV_COLOR_B_YELLOW}[WARN] $@${ENV_COLOR_RESET}"
103+
createLogFileIfNotExists
104+
echo "[${SHELL_LOG_TIMESTAMP}] [${USER}] [WARN] [$0] $@" >> "${LOG_PATH}"
105+
}
106+
logError() {
107+
echo -e "${ENV_COLOR_B_RED}[ERROR] $@${ENV_COLOR_RESET}"
108+
createLogFileIfNotExists
109+
echo "[${SHELL_LOG_TIMESTAMP}] [${USER}] [ERROR] [$0] $@" >> "${LOG_PATH}"
110+
}
13111

14-
if [[ ! -x ${LINUX_SCRIPTS_DIR}/lib/utils.sh ]]; then
15-
logError "必要脚本库 ${LINUX_SCRIPTS_DIR}/lib/utils.sh 不存在!"
16-
exit 1
17-
fi
112+
printInfo() {
113+
echo -e "${ENV_COLOR_B_GREEN}[INFO] $@${ENV_COLOR_RESET}"
114+
}
115+
printWarn() {
116+
echo -e "${ENV_COLOR_B_YELLOW}[WARN] $@${ENV_COLOR_RESET}"
117+
}
118+
printError() {
119+
echo -e "${ENV_COLOR_B_RED}[ERROR] $@${ENV_COLOR_RESET}"
120+
}
18121

19-
source ${LINUX_SCRIPTS_DIR}/lib/utils.sh
122+
callAndLog () {
123+
$*
124+
if [[ $? -eq ${ENV_SUCCEED} ]]; then
125+
logInfo "$@"
126+
return ${ENV_SUCCEED}
127+
else
128+
logError "$@ EXECUTE FAILED"
129+
return ${ENV_FAILED}
130+
fi
131+
}
20132

21133
# ------------------------------------------------------------------------------ functions
22134

codes/linux/dunwu-sys.sh

Lines changed: 122 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,130 @@
55
# @author Zhang Peng
66
# ------------------------------------------------------------------------------
77

8-
# ------------------------------------------------------------------------------ libs
9-
# 装载其它库
10-
LINUX_SCRIPTS_DIR=$(cd `dirname $0`; pwd)
8+
# ------------------------------------------------------------------------------ env
119

12-
if [[ ! -x ${LINUX_SCRIPTS_DIR}/lib/utils.sh ]]; then
13-
logError "必要脚本库 ${LINUX_SCRIPTS_DIR}/lib/utils.sh 不存在!"
14-
exit 1
15-
fi
10+
# Regular Color
11+
export ENV_COLOR_BLACK="\033[0;30m"
12+
export ENV_COLOR_RED="\033[0;31m"
13+
export ENV_COLOR_GREEN="\033[0;32m"
14+
export ENV_COLOR_YELLOW="\033[0;33m"
15+
export ENV_COLOR_BLUE="\033[0;34m"
16+
export ENV_COLOR_MAGENTA="\033[0;35m"
17+
export ENV_COLOR_CYAN="\033[0;36m"
18+
export ENV_COLOR_WHITE="\033[0;37m"
19+
# Bold Color
20+
export ENV_COLOR_B_BLACK="\033[1;30m"
21+
export ENV_COLOR_B_RED="\033[1;31m"
22+
export ENV_COLOR_B_GREEN="\033[1;32m"
23+
export ENV_COLOR_B_YELLOW="\033[1;33m"
24+
export ENV_COLOR_B_BLUE="\033[1;34m"
25+
export ENV_COLOR_B_MAGENTA="\033[1;35m"
26+
export ENV_COLOR_B_CYAN="\033[1;36m"
27+
export ENV_COLOR_B_WHITE="\033[1;37m"
28+
# Underline Color
29+
export ENV_COLOR_U_BLACK="\033[4;30m"
30+
export ENV_COLOR_U_RED="\033[4;31m"
31+
export ENV_COLOR_U_GREEN="\033[4;32m"
32+
export ENV_COLOR_U_YELLOW="\033[4;33m"
33+
export ENV_COLOR_U_BLUE="\033[4;34m"
34+
export ENV_COLOR_U_MAGENTA="\033[4;35m"
35+
export ENV_COLOR_U_CYAN="\033[4;36m"
36+
export ENV_COLOR_U_WHITE="\033[4;37m"
37+
# Background Color
38+
export ENV_COLOR_BG_BLACK="\033[40m"
39+
export ENV_COLOR_BG_RED="\033[41m"
40+
export ENV_COLOR_BG_GREEN="\033[42m"
41+
export ENV_COLOR_BG_YELLOW="\033[43m"
42+
export ENV_COLOR_BG_BLUE="\033[44m"
43+
export ENV_COLOR_BG_MAGENTA="\033[45m"
44+
export ENV_COLOR_BG_CYAN="\033[46m"
45+
export ENV_COLOR_BG_WHITE="\033[47m"
46+
# Reset Color
47+
export ENV_COLOR_RESET="$(tput sgr0)"
1648

17-
source ${LINUX_SCRIPTS_DIR}/lib/utils.sh
49+
# status
50+
export ENV_YES=0
51+
export ENV_NO=1
52+
export ENV_SUCCEED=0
53+
export ENV_FAILED=1
54+
55+
56+
# ------------------------------------------------------------------------------ functions
57+
58+
# 显示打印日志的时间
59+
SHELL_LOG_TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
60+
# 那个用户在操作
61+
USER=$(whoami)
62+
# 日志路径
63+
LOG_PATH=${ENV_LOG_PATH:-/var/log/shell.log}
64+
# 日志目录
65+
LOG_DIR=${LOG_PATH%/*}
66+
67+
createLogFileIfNotExists() {
68+
if [[ ! -x "${LOG_PATH}" ]]; then
69+
mkdir -p "${LOG_DIR}"
70+
touch "${LOG_PATH}"
71+
fi
72+
}
73+
74+
redOutput() {
75+
echo -e "${ENV_COLOR_RED} $@${ENV_COLOR_RESET}"
76+
}
77+
greenOutput() {
78+
echo -e "${ENV_COLOR_B_GREEN} $@${ENV_COLOR_RESET}"
79+
}
80+
yellowOutput() {
81+
echo -e "${ENV_COLOR_YELLOW} $@${ENV_COLOR_RESET}"
82+
}
83+
blueOutput() {
84+
echo -e "${ENV_COLOR_BLUE} $@${ENV_COLOR_RESET}"
85+
}
86+
magentaOutput() {
87+
echo -e "${ENV_COLOR_MAGENTA} $@${ENV_COLOR_RESET}"
88+
}
89+
cyanOutput() {
90+
echo -e "${ENV_COLOR_CYAN} $@${ENV_COLOR_RESET}"
91+
}
92+
whiteOutput() {
93+
echo -e "${ENV_COLOR_WHITE} $@${ENV_COLOR_RESET}"
94+
}
95+
96+
logInfo() {
97+
echo -e "${ENV_COLOR_B_GREEN}[INFO] $@${ENV_COLOR_RESET}"
98+
createLogFileIfNotExists
99+
echo "[${SHELL_LOG_TIMESTAMP}] [${USER}] [INFO] [$0] $@" >> "${LOG_PATH}"
100+
}
101+
logWarn() {
102+
echo -e "${ENV_COLOR_B_YELLOW}[WARN] $@${ENV_COLOR_RESET}"
103+
createLogFileIfNotExists
104+
echo "[${SHELL_LOG_TIMESTAMP}] [${USER}] [WARN] [$0] $@" >> "${LOG_PATH}"
105+
}
106+
logError() {
107+
echo -e "${ENV_COLOR_B_RED}[ERROR] $@${ENV_COLOR_RESET}"
108+
createLogFileIfNotExists
109+
echo "[${SHELL_LOG_TIMESTAMP}] [${USER}] [ERROR] [$0] $@" >> "${LOG_PATH}"
110+
}
111+
112+
printInfo() {
113+
echo -e "${ENV_COLOR_B_GREEN}[INFO] $@${ENV_COLOR_RESET}"
114+
}
115+
printWarn() {
116+
echo -e "${ENV_COLOR_B_YELLOW}[WARN] $@${ENV_COLOR_RESET}"
117+
}
118+
printError() {
119+
echo -e "${ENV_COLOR_B_RED}[ERROR] $@${ENV_COLOR_RESET}"
120+
}
121+
122+
callAndLog () {
123+
$*
124+
if [[ $? -eq ${ENV_SUCCEED} ]]; then
125+
logInfo "$@"
126+
return ${ENV_SUCCEED}
127+
else
128+
logError "$@ EXECUTE FAILED"
129+
return ${ENV_FAILED}
130+
fi
131+
}
18132

19133
# ------------------------------------------------------------------------------ functions
20134

0 commit comments

Comments
 (0)