-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfio-bench.sh
148 lines (141 loc) · 4.84 KB
/
fio-bench.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
#!/bin/bash
#
# [FIO Benchmark]
#
# GitHub: https://github.com/amefs/fio-bench
# Author: Amefs
# Current version: v1.0.0
#################################################################################
EXTRACMD=${@:1}
################################################################################
# HELP FUNCTIONS
################################################################################
_norm=$(tput sgr0)
_red=$(tput setaf 1)
_green=$(tput setaf 2)
_tan=$(tput setaf 3)
_cyan=$(tput setaf 6)
function _print() {
printf "${_norm}%s${_norm}\n" "$@"
}
function _info() {
printf "${_cyan}➜ %s${_norm}\n" "$@"
}
function _success() {
printf "${_green}✓ %s${_norm}\n" "$@"
}
function _warning() {
printf "${_tan}⚠ %s${_norm}\n" "$@"
}
function _error() {
printf "${_red}✗ %s${_norm}\n" "$@"
}
################################################################################
# MAIN FUNCTIONS
################################################################################
function _iotest() {
python3 <(wget -qO- https://github.com/amefs/fio-bench/raw/master/fio-bench.py -o /dev/null) ${EXTRACMD}
}
function _getDistName()
{
if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then
DISTRO='CentOS'
PM='yum'
elif grep -Eqi "Red Hat Enterprise Linux" /etc/issue || grep -Eq "Red Hat Enterprise Linux" /etc/*-release; then
DISTRO='RHEL'
PM='yum'
elif grep -Eqi "Aliyun" /etc/issue || grep -Eq "Aliyun" /etc/*-release; then
DISTRO='Aliyun'
PM='yum'
elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; then
DISTRO='Fedora'
PM='yum'
elif grep -Eqi "Amazon Linux" /etc/issue || grep -Eq "Amazon Linux" /etc/*-release; then
DISTRO='Amazon'
PM='yum'
elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; then
DISTRO='Debian'
PM='apt'
elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; then
DISTRO='Ubuntu'
PM='apt'
elif grep -Eqi "Raspbian" /etc/issue || grep -Eq "Raspbian" /etc/*-release; then
DISTRO='Raspbian'
PM='apt'
elif grep -Eqi "Deepin" /etc/issue || grep -Eq "Deepin" /etc/*-release; then
DISTRO='Deepin'
PM='apt'
elif grep -Eqi "Mint" /etc/issue || grep -Eq "Mint" /etc/*-release; then
DISTRO='Mint'
PM='apt'
elif grep -Eqi "Kali" /etc/issue || grep -Eq "Kali" /etc/*-release; then
DISTRO='Kali'
PM='apt'
else
DISTRO='unknow'
fi
}
function _CentOS_Dependent()
{
_info "yum installing dependent packages..."
for packages in epel-release wget fio python3;
do yum -y install $packages > /dev/null 2>&1; done
_success "yum packages installation finished"
if ! $(which pip3 > /dev/null 2>&1); then
_info "安装 python3-pip..."
yum -y install python3-pip > /dev/null 2>&1
else
_success "python3-pip 已安装"
fi
_info "pip installing dependent packages..."
python3 -m pip install prettytable > /dev/null 2>&1
_success "pip packages installation finished"
}
function _Deb_Dependent()
{
_info "apt-get installing dependent packages..."
apt-get update -yqq > /dev/null 2>&1
apt-get autoremove -yqq > /dev/null 2>&1
apt-get -fy install > /dev/null 2>&1
export DEBIAN_FRONTEND=noninteractive
for packages in wget fio;
do apt-get install -yqq $packages > /dev/null 2>&1; done
if [[ "$(dpkg -s python3 2> /dev/null | grep -cow '^Status: install ok installed$')" -eq '1' ]];then
_success "python3 installed"
else
_info "installing python3"
apt-get install -yqq python3 > /dev/null 2>&1
_success "python3 installed"
fi
if ! $(which pip3 > /dev/null 2>&1); then
_info "installing python3-pip"
apt-get install -yqq python3-pip > /dev/null 2>&1
_success "python3-pip installed"
else
_success "python3-pip installed"
fi
_info "pip3 installing dependent packages..."
python3 -m pip install prettytable > /dev/null 2>&1
_success "pip3 packages installation finished"
}
function _checkdep() {
_getDistName
_info "Checking dependent packages"
if ( [ ! -f /usr/bin/fio ] || ! $(which pip3 > /dev/null 2>&1) || ! $(python3 -m pip freeze --disable-pip-version-check | grep -q 'prettytable' > /dev/null 2>&1)); then
_info "Installing dependent packages..."
if [ "$PM" = "yum" ]; then
_CentOS_Dependent
elif [ "$PM" = "apt" ]; then
_Deb_Dependent
else
_error "Unknown package manager!"
fi
else
_success "Dependency check passed"
fi
}
#################################################################################
# MAIN PROCESS
#################################################################################
_checkdep
_iotest