-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_shell
301 lines (272 loc) · 10.3 KB
/
common_shell
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#!/bin/sh
# Common shell routines used by the top level install script (SDK and driver
# disks) and also from the OS specific scripts in the SDK (also contains
# uninstall routines used in multiple places)
#
# Copyright © 2006-2008 Ciprico Inc. All rights reserved.
# Copyright © 2008-2013 Dot Hill Systems Corp. All rights reserved.
#
# Use of this software is subject to the terms and conditions of the written
# software license agreement between you and DHS (the "License"),
# including, without limitation, the following (as further elaborated in the
# License): (i) THIS SOFTWARE IS PROVIDED "AS IS", AND DHS DISCLAIMS
# ANY AND ALL WARRANTIES OF ANY KIND, WHETHER EXPRESS, IMPLIED, STATUTORY,
# BY CONDUCT, OR OTHERWISE; (ii) this software may be used only in connection
# with the integrated circuit product and storage software with which it was
# designed to be used; (iii) this source code is the confidential information
# of DHS and may not be disclosed to any third party; and (iv) you may not
# make any modification or take any action that would cause this software,
# or any other Dot Hill software, to fall under any GPL license or any other
# open source license.
#
# defines for SWL (Software Licensing) - SATA chipsets on motherboards
# that are supported by RAIDCore(tm)
SWL_SUPPORTED="ahci lsi1068 lsi2008"
SWL_MODULE_ahci=ahci
SWL_MODULE_lsi1068=mptsas
SWL_MODULE_lsi2008=mpt2sas
# WARNING: these need to be kept in sync with RC_SWL_TYPE_XXX in bc_adapter.h
SWL_TYPE_ahci=0x00000002
SWL_TYPE_lsi1068=0x00000004
SWL_TYPE_lsi2008=0x00000008
function usage_suse() {
echo "usage: `basename $0` [<options>][<kernel>]" >&2
echo " options:" >&2
echo " USE_SWL=[none,ahci,lsi1068,lsi2008] - comma seperated list of onboard chips RAIDCore " >&2
echo " should use. Default is all." >&2
echo " ex: `basename $0` USE_SWL=ahci 2.6.16.21-0.25-smp" >&2
exit 1
}
function usage_rh() {
echo "usage: `basename $0` [<options>][<kernel>] [<smp|hugemem|largesmp|PAE>]" >&2
echo " options:" >&2
echo " USE_SWL=[none,ahci,lsi1068,lsi2008] - comma seperated list of onboard chips RAIDCore " >&2
echo " should use. Default is all." >&2
echo " ex: `basename $0` USE_SWL=ahci 2.6.20-1.2933.fc6 uni smp" >&2
exit 1
}
# return 1 if two lists intersect
function lists_intersect() {
local list1=$1
local list2=$2
local elem1
local elem2
for elem1 in ${list1}; do
for elem2 in ${list2}; do
if [ "$elem1" == "$elem2" ]; then
return 1
fi
done
done
return 0
}
# $kernel and $flavors if they are not already set
function set_kernel_flavors_rh() {
# If no kernel version is provided then installing for all flavors
# of currently running version
if [ -z "$kernel" ] ; then
kernel=`uname -r | awk '{sub("BOOT","",$0)
sub("hugemem","",$0)
sub("largesmp","",$0)
sub("smp","",$0)
sub("PAE","",$0)
print $0}'`
else
# 2.6.15-1.2054_FC5smp should be manipulated as kernel=2.6.15-1.2054_FC5
# and flavors=smp
kernelstr=$kernel
kernel=`echo $kernel | awk '{sub("BOOT","",$0)
sub("hugemem","",$0)
sub("largesmp","",$0)
sub("smp","",$0)
sub("PAE","",$0)
print $0}'`
flavor=`echo $kernelstr | sed "s/"$kernel"//"`
if [ -n "$flavor" ] ; then
flavors="$flavor"
else
flavors="uni"
fi
fi
if [ -z "$flavors" ] ; then
# Check for installed versions of requested kernel
base=$kernel
installed=`find /lib/modules -maxdepth 1 -name ${base}* -type d -printf "%f "`
# If that dosen't work get installed versions of currently running
# kernel.
if [ -z "$installed" ] ; then
base=$kernel
installed=`find /lib/modules -maxdepth 1 -name ${base}* -type d -printf "%f "`
fi
for i in $installed ; do
flavor=`echo $i | sed -e s/$base//`
if [ -z "$flavor" ]; then
flavor="uni"
fi
flavors="$flavors $flavor"
done
fi
}
# check if $1 scsi_hostadapater is already in module config file $2
function check_module_config() {
local driver=$1
local mod_conf=$2
egrep ^[[:space:]]*alias[[:space:]]+scsi_hostadapter[[:digit:]]*[[:space:]]+$driver $mod_conf > /dev/null 2>&1
return $?
}
# Add driver $1 scsi_hostadapter entry to module configuration file $2
function add_module_config() {
local driver=$1
local mod_conf=$2
local use_swl=$3
local swl
local module
local add_first=0
# in an attempt to not cause disk reordering if possile, rcraid is added
# to the front only if any USE_SWL module exists, otherwise it is added
# at the end.
if ! check_module_config ${driver} ${mod_conf} ; then
# ${driver} is not already there, so it will need to be added
for swl in ${use_swl}; do
module=SWL_MODULE_${swl}
if check_module_config ${!module} ${mod_conf}; then
# a ${use_swl} module exists, so add ${driver} first
add_first=1
fi
done
if [ ${add_first} = 1 ]; then
# add RAIDCore driver first
echo "alias scsi_hostadapter $driver" > ${mod_conf}.tmp
cat ${mod_conf} >> ${mod_conf}.tmp
mv ${mod_conf}.tmp ${mod_conf}
else
# add RAIDCore driver last
echo "alias scsi_hostadapter $driver" >> ${mod_conf}
fi
fi
}
# Remove driver $1 from module configuration file $2
function del_module_config() {
local driver=$1
local mod_conf=$2
if [ -f ${mod_conf} ] ; then
if check_module_config ${driver} ${mod_conf} ; then
sed -r "/^[[:space:]]*alias[[:space:]]+scsi_hostadapter[[:space:]]+${driver}/d" ${mod_conf} > ${mod_conf}.tmp
mv -f ${mod_conf}.tmp ${mod_conf}
fi
fi
}
# Add use_swl support option for driver $1 to module configuration file $2
# if needed
function add_swl_option() {
local driver=$1
local mod_conf=$2
local use_swl=$3
local swl_flag
local swl
local type
if [ "${driver}" == "rcraid" ]; then
# first remove any existing use_swl setting in case of a reinstall
del_swl_option ${driver} ${mod_conf}
# calculate new use_swl flag value
swl_flag=1 # 0x00000001 represents all RAIDCore cards
for swl in ${use_swl}; do
type=SWL_TYPE_${swl}
swl_flag=$(( ${swl_flag} + ${!type} ))
done
# add new value
echo "options ${driver} use_swl=${swl_flag}" >> ${mod_conf}
fi
}
# Remove use_swl support option for driver $1 from module configuration file $2
function del_swl_option() {
local driver=$1
local mod_conf=$2
if [ "${driver}" == "rcraid" ]; then
if [ -f ${mod_conf} ] ; then
if egrep ^[[:space:]]*options[[:space:]]+${driver}[[:space:]]+use_swl* ${mod_conf} > /dev/null ; then
sed -r "/^[[:space:]]*options[[:space:]]+${driver}[[:space:]]+use_swl*/d" ${mod_conf} > ${mod_conf}.tmp
mv -f ${mod_conf}.tmp ${mod_conf}
fi
# remove legacy use_roc name
if egrep ^[[:space:]]*options[[:space:]]+${driver}[[:space:]]+use_roc* ${mod_conf} > /dev/null ; then
sed -r "/^[[:space:]]*options[[:space:]]+${driver}[[:space:]]+use_roc*/d" ${mod_conf} > ${mod_conf}.tmp
mv -f ${mod_conf}.tmp ${mod_conf}
fi
fi
fi
}
# Add an initrd module for SuSE systems
# Note: INITRD_MODULES comes from the $kernel_cfg file
add_initrd_mod_suse() {
local driver=$1
local kernel_cfg=$2
local use_swl=$3
local swl
local updated=0
local add_first=0
local module
if [ -f $kernel_cfg ] ; then
source $kernel_cfg
else
echo "invalid kernel config file: $kernel_cfg"
exit 1
fi
if [ -z "$INITRD_MODULES" ] ; then
INITRD_MODULES=${driver}
updated=1
else
# if USE_SWL is set AND one of the USE_SWL modules is already being
# used, then, and only then, we need the RAIDCore driver to load first,
# but the RAIDCore configuration device should still always be last
if echo $INITRD_MODULES | grep -v ${driver} > /dev/null ; then
for swl in ${use_swl}; do
module=SWL_MODULE_${swl}
if ! echo $INITRD_MODULES | grep -v ${!module} > /dev/null; then
add_first=1
fi
done
if [ ${add_first} = 1 ]; then
INITRD_MODULES="${driver} $INITRD_MODULES"
else
INITRD_MODULES="$INITRD_MODULES ${driver}"
fi
updated=1
fi
fi
if [ $updated = 1 ] ; then
if [ -f $kernel_cfg ] ; then
if grep INITRD_MODULES $kernel_cfg > /dev/null ; then
cat $kernel_cfg | sed -e s/^INITRD_MODULES=.*$/INITRD_MODULES=\""$INITRD_MODULES"\"/ > $kernel_cfg.tmp
mv $kernel_cfg.tmp $kernel_cfg
else
echo INITRD_MODULES=\"$INITRD_MODULES\" >> $kernel_cfg
fi
else
echo INITRD_MODULES=\"$INITRD_MODULES\" >> $kernel_cfg
fi
fi
}
# Remove an initrd module for SuSE systems
# Note: INITRD_MODULES comes from the $kernel_cfg file
del_initrd_mod_suse() {
local driver=$1
local kernel_cfg=$2
local updated=0
if [ -f $kernel_cfg ] ; then
source $kernel_cfg
if [ -n "$INITRD_MODULES" ] ; then
if echo $INITRD_MODULES | grep ${driver} > /dev/null; then
INITRD_MODULES=${INITRD_MODULES//${driver}/}
updated=1
fi
fi
else
echo "invalid kernel config file: $kernel_cfg"
exit 1
fi
if [ $updated = 1 ] ; then
cat $kernel_cfg | sed -e s/^INITRD_MODULES=.*$/INITRD_MODULES=\""$INITRD_MODULES"\"/ > $kernel_cfg.tmp
mv $kernel_cfg.tmp $kernel_cfg
fi
}