forked from stec-inc/EnhanceIO
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Install-EIO
executable file
·266 lines (248 loc) · 7.48 KB
/
Install-EIO
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/bin/bash
# A script to simplify the instalation of EnhanceIO.
#
# Courtesy of T. "Luna" Ericson aka. CPT Gray Wolf and FSG,
# and distributed under the GPL along with EnhanceIO.
# Get the script command security prefix to esure no malicious
# scripts are executed by mistake.
if [ -d /usr/bin ]
then
BPREFIX='/usr/bin/'
SBPREFIX='/usr/sbin/'
else
BPREFIX='/bin/'
SBPREFIX='/sbin/'
fi
# Ensure that we're running as root.
if [ $(${BPREFIX}id -u) -ne 0 ]
then
${BPREFIX}echo "INSTALL-EIO: You need to be root to do that" >&2
exit 1
fi
# This is where any important preset variables will go.
PYTHON_VERSION=$(${BPREFIX}python -c 'import platform; python_version=platform.python_version(); print (python_version)')
SOURCE_DIR='./Driver/enhanceio/'
KERNEL_VERSION=''
PY_VERSION_CHECK=1; MAKE_MODS=1; INSTALL_MODS=1; CLEANUP=1; INSTALL_CLI=1; LOAD_MODS=1
# Use a complicated regex to check the installed python version.
_CheckPythonVersion ()
{
if [[ "$PYTHON_VERSION" =~ ^2\.(6\.([6-9]|[1-9][0-9]+)|([7-9]|[1-9][0-9]+)\.[0-9]+)(rc[0-9]+)?$ ]]
then
return 0
fi
return 1
}
# Install the command line interface.
_InstallCLI ()
{
if [ -e ./CLI/eio_cli ] && [ -e ./CLI/eio_cli.8 ]
then
(${BPREFIX}install -o root -g root -m 700 -D ./CLI/eio_cli /sbin/eio_cli > /dev/null 2>&1) &&
(${BPREFIX}install -o root -g root -m 644 -D ./CLI/eio_cli.8 /usr/share/man/man8/eio_cli.8 > /dev/null 2>&1) &&
return 0
return 2
fi
return 1
}
# Run make and build the EnhanceIO modules.
_RunMake ()
{
if ! [ -z "$1" ]
then
(cd ${SOURCE_DIR} && ${BPREFIX}make KERNEL_SOURCE_VERSION=${1} > /dev/null) &&
return 0
else
(cd ${SOURCE_DIR} && ${BPREFIX}make > /dev/null) &&
return 0
fi
return 1
}
# Run make install for the EnhanceIO modules.
_RunInstall ()
{
if ! [ -z "$1" ]
then
(cd ${SOURCE_DIR} && ${BPREFIX}make install KERNEL_SOURCE_VERSION=${1} > /dev/null) &&
return 0
else
(cd ${SOURCE_DIR} && ${BPREFIX}make install > /dev/null) &&
return 0
fi
return 1
}
# Cleanup files after make.
_RunCleanup ()
{
${BPREFIX}rm -f "${SOURCE_DIR}*.?(k)o"
${BPREFIX}rm -f "${SOURCE_DIR}*.mod.c"
${BPREFIX}rm -f "${SOURCE_DIR}.*.cmd"
${BPREFIX}rm -f "${SOURCE_DIR}*.symvers"
${BPREFIX}rm -f "${SOURCE_DIR}*.order"
${BPREFIX}rm -fr "${SOURCE_DIR}.tmp*"
return
}
# Load the EnhanceIO modules.
_LoadMods ()
{
${SBPREFIX}modprobe enhanceio &&
${SBPREFIX}modprobe enhanceio_rand &&
${SBPREFIX}modprobe enhanceio_fifo &&
${SBPREFIX}modprobe enhanceio_lru &&
return 0
return 1
}
#Display help options.
_DisplayHelp ()
{
${BPREFIX}echo -e "EnhanceIO Installation Script\n"
${BPREFIX}echo -e "Command options:\n"
${BPREFIX}echo " cleanup Remove files leftover from build process."
${BPREFIX}echo " install-cli Install the eio_cli utility, and it's manual."
${BPREFIX}echo " --help Display help."
${BPREFIX}echo " -k --kernel-version Chose what kernel version to compile for. Requires the"
${BPREFIX}echo " target kernel headers to be installed."
${BPREFIX}echo " -m --no-build Don't build the kernel modules."
${BPREFIX}echo " -i --no-install Don't install kernel modules."
${BPREFIX}echo " -p --no-py-check Don't check the installed python version. Has no effect"
${BPREFIX}echo " if --kernel-version or --no-cli are set."
${BPREFIX}echo " -c --no-cli Don't install eio_cli utility or manual. Has no effect"
${BPREFIX}echo " if --kernel-version is set."
${BPREFIX}echo " -l --no-load Don't load kernel modules after installation. Has no"
${BPREFIX}echo " effect if --kernel-version is set."
${BPREFIX}echo -e " -r --no-cleanup Don't run cleanup after building kernel modules.\n"
return
}
# Setup some shortcuts.
if [ $# -eq 1 ]
then
case "$1" in
cleanup)
_RunCleanup
${BPREFIX}echo "INSTALL-EIO: Cleaning up leftover build files"
exit 0
;;
install-cli)
_CheckPythonVersion &&
_InstallCLI &&
exit 0
${BPREFIX}echo "INSTALL-EIO: Failed to install eio_cli!" >&2
;;
--help)
_DisplayHelp
exit 0
;;
esac
fi
# Main program.
while ! [ -z "$1" ]
do
case "$1" in
-k|--kernel-version)
shift
if ! [[ "$1" =~ ^(3\.([7-9]|[1-9][0-9]+)|([4-9]|[1-9][0-9]+)\.[0-9]+)....*$ ]]
then
${BPREFIX}echo "INSTALL-EIO: Specified kernel is invalid or too old!" >&2
exit 1
else
KERNEL_VERSION="$1"
LOAD_MODS=0
PY_VERSION_CHECK=0
INSTALL_CLI=0
${BPREFIX}echo "INSTALL-EIO: Modules will be build and installed for kernel $1"
fi
;;
-r|--no-clean)
CLEANUP=0
;;
-p|--no-py-check)
PY_VERSION_CHECK=0
;;
-c|--no-cli)
PY_VERSION_CHECK=0
INSTALL_CLI=0
;;
-i|--no-install)
INSTALL_MODS=0
;;
-m|--no-build)
MAKE_MODS=0
;;
-l|--no-load)
LOAD_MODS=0
;;
*)
${BPREFIX}echo "INSTALL-EIO: Argument not understood \"$1\"" >&2
${BPREFIX}echo "INSTALL-EIO: Try running \"Install-EIO --help\""
exit 1
;;
esac
shift
done
if [ $MAKE_MODS -eq 1 ]
then
${BPREFIX}echo "INSTALL-EIO: Building kernel modules"
_RunMake $KERNEL_VERSION
if [ $? -eq 1 ]
then
${BPREFIX}echo "INSTALL-EIO: Failed to build modules!" >&2
${BPREFIX}echo "INSTALL-EIO: Try running \"Install-EIO cleanup\" to remove any leftover files"
exit 1
fi
fi
if [ $INSTALL_MODS -eq 1 ]
then
${BPREFIX}echo "INSTALL-EIO: Installing modules"
_RunInstall $KERNEL_VERSION
if [ $? -eq 1 ]
then
${BPREFIX}echo "INSTALL-EIO: Failed to install modules!" >&2
exit 1
fi
fi
if [ $PY_VERSION_CHECK -eq 1 ]
then
${BPREFIX}echo "INSTALL-EIO: Checking Python version"
_CheckPythonVersion
if [ $? -eq 1 ]
then
${BPREFIX}echo "INSTALL-EIO: Python version is $PYTHON_VERSION, eio_cli requires python2 version 2.6.6 or higher!" >&2
${BPREFIX}echo "INSTALL-EIO: eio_cli will not be installed" >&2
INSTALL_CLI=0
else
${BPREFIX}echo "INSTALL-EIO: Python version is $PYTHON_VERSION"
fi
fi
if [ $INSTALL_CLI -eq 1 ]
then
${BPREFIX}echo "INSTALL-EIO: Installing eio_cli"
_InstallCLI
if [ $? -eq 1 ]
then
${BPREFIX}echo "INSTALL-EIO: Could not fild eio_cli files!" >&2
${BPREFIX}echo "INSTALL-EIO: Failed to install eio_cli!" >2&
elif [ $? -eq 2 ]
then
${BPREFIX}echo "INSTALL-EIO: Failed to install eio_cli!" >2&
else
${BPREFIX}echo "INSTALL-EIO: Installed eio_cli, see \"man eio_cli\" for useage"
fi
fi
if [ $LOAD_MODS -eq 1 ]
then
${BPREFIX}echo "INSTALL-EIO: Loading EnhanceIO modules"
_LoadMods
if [ $? -eq 1 ]
then
${BPREFIX}echo "INSTALL-EIO: Failed to load kernel modules!" >&2
else
${BPREFIX}echo "INSTALL-EIO: Loaded EnhanceIO kernel modules"
fi
fi
if [ $CLEANUP -eq 1 ]
then
${BPREFIX}echo "INSTALL-EIO: Cleaning up build files..."
_RunCleanup
fi
${BPREFIX}echo "INSTALL-EIO: Complete!"
exit 0