-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
executable file
·367 lines (315 loc) · 9.88 KB
/
install.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
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2010, K.Q. Infotech Pvt. Ltd. #
# #
# Licensed under Open-source License ; you may not use this file except in #
# compliance with the License. You may obtain a copy of the License as part #
# of the software distribution. #
# Unless agreed to in writing, software distributed under the #
# License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES #
# OR CONDITIONS OF ANY KIND, either express or implied. See the #
# License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
# zfs source dir
HOME_DIR=`pwd`
# pre-execution dir
PREV_DIR=`pwd`
# zfs to be compiled with
KERNEL_VERSION=`uname -r`
# spl zfs lzfs configuration params
CONFIG_PARAM=''
# message colors
txtred='\e[0;31m' # err
txtgrn='\e[0;32m' # echo
txtrst='\e[0m' # reset
function capture_spin {
trap "stop_spin" SIGINT SIGTERM
}
function stdin_stdout_to_log {
exec 6>&1
exec &> $LOG
}
# show spinnig bar during installation
function start_spin {
(while true
do
echo -en '/\010' ; sleep .1
echo -en '-\010' ; sleep .1
echo -en '\\\010' ; sleep .1
echo -en '|\010' ; sleep .1
done) &
SPIN_PID=$!
}
# stop spinnig bar
function stop_spin {
kill $SPIN_PID
# cd pre-execution dir
cd $PREV_DIR
echo ' '
}
function exits {
stop_spin
exit $1
}
# CONFIGURATION
function Message {
echo -e "################################################"
echo -e $*
echo -e "################################################"
}
function select_deployment {
msg "Select deployment type (press '0' to exit):"
msg "1) ZFS on Ubuntu 10.04"
msg "2) ZFS on Ubuntu 10.10"
msg "3) ZFS on Fedora 13"
msg "4) ZFS on Fedora 14"
msg "5) ZFS on Redhat 6"
msg "6) ZFS on Gentoo"
read DEPLOYMENT
case $DEPLOYMENT in
1)
# start ops
;;
2)
# start ops
;;
3)
# start ops
;;
4)
# start ops
;;
5)
# start ops
;;
6)
# start ops
;;
*)
exits 1
;;
esac
msg ""
}
function ask_configuration {
msg "You have selected an XXX deployment. Do you want automatic configuration"
echo -n "(y/n) " >&6
read OPT
case $OPT in
y*|Y*)
OPT='yes'
;;
*) OPT='no'
;;
esac
msg ""
if [ "$OPT" = 'yes' ]; then
msg "input YYY"
read IP
fi
msg ""
}
function install_Ubuntu_pkg {
# check for package availability
if dpkg -s $1 ; then
echo -e "${txtgrn}package available: " $1 "${txtrst}"
else
echo -e "${txtgrn}going to install $1 tool...${txtrst}"
if apt-get install $1
then
echo -e "${txtgrn}$1 installed successfully${txtrst}"
else
Message "${txtred}failure. Try $1 manual installation${txtrst}"
exits 1
fi
fi
}
function install_Fedora_pkg {
# check for package availability
if yum list installed $1 ; then
echo -e "${txtgrn}package available: " $1 "${txtrst}"
else
echo -e "${txtgrn}going to install $1...${txtrst}"
if yum install $1
then
echo -e "${txtgrn}$1 installed successfully${txtrst}"
else
Message "${txtred}failure. Try $1 manual installation${txtrst}"
exits 1
fi
fi
}
function install_Ubuntu_dependencies {
DEP_LIST="gawk zlib1g-dev uuid-dev linux-headers-`uname -r`"
for pkg in $DEP_LIST
do
install_Ubuntu_pkg $pkg
done
}
function install_Fedora_dependencies {
DEP_LIST="gcc kernel-devel-`uname -r` zlib-devel libuuid-devel"
for pkg in $DEP_LIST
do
install_Fedora_pkg $pkg
done
}
function resolve_dependencies {
for OS in `cat /etc/issue` ; do echo -e "${txtgrn}Operating system: " $OS `uname -r` ${txtrst} ; break ; done
case $OS in
'Fedora')
install_Fedora_dependencies
;;
'Ubuntu')
install_Ubuntu_dependencies
;;
'Red')
# assume red hat dependencies same as fedora
install_Fedora_dependencies
;;
*)
Message "${txtred}failure. unexpected distro found. Resolve dependencies manually.${txtrst}"
;;
esac
}
function startups {
for OS in `cat /etc/issue` ; do echo -e "${txtgrn}Operating system: " $OS `uname -r` ${txtrst} ; break ; done
case $OS in
'Fedora')
if cp $HOME_DIR/lzfs/etc/init.d/initd.redhat /etc/init.d/zfsload ; then
echo -e "${txtgrn}${txtrst}"
else
echo -e "${txtred}can not copy init file ${txtrst}"
fi
if chkconfig --add zfsload ; then
echo -e "${txtgrn}init script applied successfully${txtrst}"
else
echo -e "${txtred}init script initialization error ${txtrst}"
fi
;;
'Ubuntu')
if cp $HOME_DIR/lzfs/etc/init.d/initd.debian /etc/init.d/zfsload ; then
echo -e "${txtgrn}${txtrst}"
else
echo -e "${txtred}can not copy init file ${txtrst}"
fi
if update-rc.d zfsload defaults ; then
echo -e "${txtgrn}init script applied successfully${txtrst}"
else
echo -e "${txtred}init script initialization error ${txtrst}"
fi
;;
*)
Message "failure. unexpected distro found. Resolve dependencies manually."
;;
esac
}
function make_configure {
if cd $HOME_DIR/$1 ; then
echo -e "${txtgrn}configure $1 ${txtrst}"
if ./configure $CONFIG_PARAM ; then
echo -e "${txtgrn}lzfs configured successfully : ${txtrst}"
else
Message "${txtred}lzfs Configure error ${txtrst}"
exits 1
fi
if make ; then
echo -e "${txtgrn}lzfs make successful : ${txtrst}"
else
Message "${txtred}lzfs Make error ${txtrst}"
exits 1
fi
else
Message "${txtred}can not cd to $HOME_DIR/zfs ${txtrst}"
fi
}
function load_zfs_modules_stack {
if cd $HOME_DIR/$1 ; then
echo -e "${txtgrn}loading zfs module stack ${txtrst}"
if ./zfs.sh -v ; then
echo -e "${txtgrn}zfs module stack loaded successfully : ${txtrst}"
else
echo -e "${txtred}error while loading zfs module stack ${txtrst}"
fi
else
Message "${txtred}can not cd to $HOME_DIR/zfs ${txtrst}"
fi
}
function insert_lzfs {
if insmod $HOME_DIR/$1 ; then
echo -e "${txtgrn}insmod lzfs successful${txtrst}"
else
echo -e "${txtred}insmod lzfs failure${txtrst}"
fi
}
function make_install {
# make install
if cd $HOME_DIR/$1 ; then
echo -e "${txtgrn}starting $1 make install ${txtrst}"
if make install ; then
echo -e "${txtgrn}$1 make install successful : ${txtrst}"
else
Message "${txtred}$1 make install error ${txtrst}"
exits 1
fi
else
Message "${txtred}can not cd to $HOME_DIR/zfs ${txtrst}"
fi
}
function main {
# check for superuser permissions
capture_spin
start_spin
echo -e "${txtgrn}starting zfs installation : ${txtrst}"
echo -e "${txtgrn}HOME_DIR : $HOME_DIR ${txtrst}"
echo -e "${txtgrn}KERNEK_VERSION : $KERNEL_VERSION ${txtrst}"
#check for super user permission
[ $UID -ne 0 ] && Message "${txtred}Error : Superuser previllages required${txtrst}" && exits
echo -e "${txtgrn}super user previllages available... ${txtrst}";
# if args are not provided then get pwd as HOME_DIR
[ $# -gt 0 ] && HOME_DIR=$1
cd $HOME_DIR || ( Message "${txtred}can not cd to repo home ${txtrst}" && exits )
echo -e "${txtgrn} cd to repo home done ... ${txtrst}";
# pull source repositories if not available
pullRepos
# check if zfs module allready loaded
lsmod | grep zfs ;
[ $? -eq 0 ] && Message "${txtred}remove zfs module first to proceed ${txtrst}" && exits
# check for linux distro / version and resolve dependencies accordingly
resolve_dependencies
# configure and make spl
CONFIG_PARAM="--with-linux=/lib/modules/$KERNEL_VERSION/build"
make_configure spl
# configure and make zfs
CONFIG_PARAM=$CONFIG_PARAM" --with-spl=$HOME_DIR/spl/"
make_configure zfs
# configure and make lzfs
CONFIG_PARAM=$CONFIG_PARAM" --with-zfs=$HOME_DIR/zfs/"
make_configure lzfs
load_zfs_modules_stack "zfs/scripts/"
insert_lzfs "lzfs/module/lzfs.ko"
make_install spl
make_install zfs
make_install lzfs
# ldpath
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
ldconfig
# add startup routine ( init scripts )
startups
stop_spin
Message "${txtgrn}zfs installation done ${txtrst}"
sleep 2
}
# pull source repositories if not available
function pullRepos {
# check spl dir
[ -a ./spl ] || ( echo "pulling zfs spl repo.." ; git clone https://github.com/zfs-linux/spl.git || ( echo "${txtred} spl pull failed ... ${txtrst}"; exits ))
echo -e "${txtgrn} spl available ... ${txtrst}";
# check zfs dir
[ -a ./zfs ] || ( echo "pulling zfs spl repo.." ; git clone https://github.com/zfs-linux/zfs.git || ( echo "${txtred} zfs pull failed ... ${txtrst}"; exits ))
echo -e "${txtgrn} zfs available ... ${txtrst}";
# check spl dir
[ -a ./lzfs ] || ( echo "pulling lzfs spl repo.." ; git clone https://github.com/zfs-linux/lzfs.git || ( echo "${txtred} lzfs pull failed ... ${txtrst}"; exits ))
echo -e "${txtgrn} lzfs available ... ${txtrst}";
}
main $*