-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildFuncDefine.sh
executable file
·186 lines (166 loc) · 4.24 KB
/
buildFuncDefine.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
function gen_now_timestamp()
{
echo $(date "+%Y-%m-%d %H:%M:%S")
}
function get_now_timestamp()
{
time=`gen_now_timestamp`
echo ${time}
}
function print_warn()
{
printf "\033[33m[WARN ] `get_now_timestamp` --> $*\033[0m\n";
}
function print_info()
{
printf "\033[32m[INFO ] `get_now_timestamp` --> $*\033[0m\n";
}
function print_error()
{
printf "\033[31m[ERROR] `get_now_timestamp` --> $*\033[0m\n";
}
function error_exit() {
printf "\033[31m[ERROR] `get_now_timestamp` --> $*\033[0m\n";
exit 1;
}
# 获取linux发行版名称
function get_linux_distro()
{
if grep -Eq "Ubuntu" /etc/*-release; then
echo "Ubuntu"
elif grep -Eq "Deepin" /etc/*-release; then
echo "Deepin"
elif grep -Eq "LinuxMint" /etc/*-release; then
echo "LinuxMint"
elif grep -Eq "elementary" /etc/*-release; then
echo "elementaryOS"
elif grep -Eq "Debian" /etc/*-release; then
echo "Debian"
elif grep -Eq "Kali" /etc/*-release; then
echo "Kali"
elif grep -Eq "CentOS" /etc/*-release; then
echo "CentOS"
elif grep -Eq "fedora" /etc/*-release; then
echo "fedora"
elif grep -Eq "openSUSE" /etc/*-release; then
echo "openSUSE"
elif grep -Eq "Arch Linux" /etc/*-release; then
echo "ArchLinux"
elif grep -Eq "ManjaroLinux" /etc/*-release; then
echo "ManjaroLinux"
else
echo "Unknow"
fi
}
# 获取日期
function get_datetime()
{
time=$(date "+%Y%m%d%H%M%S")
echo $time
}
# 获取当前时间戳
function get_timestamp()
{
cur_sec_and_ns=`date '+%s-%N'`
echo ${cur_sec_and_ns%-*}
}
# 判断文件是否存在
function is_exist_file()
{
filename=$1
if [ -f $filename ]; then
echo 1
else
echo 0
fi
}
# 判断目录是否存在
function is_exist_dir()
{
dir=$1
if [ -d $dir ]; then
echo 1
else
echo 0
fi
}
# 获取ubuntu版本
function get_ubuntu_version()
{
line=$(cat /etc/lsb-release | grep "DISTRIB_RELEASE")
arr=(${line//=/ })
version=(${arr[1]//./ })
echo ${version[0]}
}
# 获取通用版本
function get_general_version()
{
version1=$(grep VERSION_ID /etc/os-release| sed 's/VERSION_ID=//')
version=$(echo ${version1:1:-1})
echo ${version}
}
# 获取Debian版本
function get_debian_version()
{
version=$(cat /etc/debian_version)
echo ${version}
}
# 获取centos版本
function get_centos_version()
{
version=`cat /etc/redhat-release | awk '{print $4}' | awk -F . '{printf "%s",$1}'`
echo $version
}
# 判断是否是macos10.14版本
function is_macos1014()
{
product_version=$(sw_vers | grep ProductVersion)
if [[ $product_version =~ "10.14" ]]; then
echo 1
else
echo 0
fi
}
function msg()
{
local text="$1"
local div_width="80"
printf "%${div_width}s\n" ' ' | tr ' ' -
printf "%s\n" "$text"
}
function confirm()
{
local question="$1"
while true; do
msg "$question"
read -p "[y]es or [n]o (default: no) : " -r answer
case "$answer" in
y | Y | yes | YES | Yes)
return 0
;;
n | N | no | NO | No | *[[:blank:]]* | "")
return 1
;;
*)
msg "Please answer [y]es or [n]o."
;;
esac
done
}
function print_logo()
{
cat <<'EOF'
___ ___ ___ ___ ___ ___
/ /\ / /\ / /\ / /\ / /\ / /\
/ /:/ / /::\ / /::\ / /::| / /::\ / /:/
/ /:/ / /:/\:\ / /:/\:\ / /:|:| / /:/\:\ / /:/
/ /::\____ / /::\ \:\ / /::\ \:\ / /:/|:|__ / /::\ \:\ / /:/
/__/:/\:::::\ /__/:/\:\ \:\ /__/:/\:\_\:\ /__/:/ |:| /\ /__/:/\:\ \:\ /__/:/
\__\/~|:|~~~~ \ \:\ \:\_\/ \__\/~|::\/:/ \__\/ |:|/:/ \ \:\ \:\_\/ \ \:\
| |:| \ \:\ \:\ | |:|::/ | |:/:/ \ \:\ \:\ \ \:\
| |:| \ \:\_\/ | |:|\/ |__|::/ \ \:\_\/ \ \:\
|__|:| \ \:\ |__|:|~ /__/:/ \ \:\ \ \:\
\__\| \__\/ \__\| \__\/ \__\/ \__\/
EOF
}