-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·529 lines (496 loc) · 14.3 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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
#!/usr/bin/env sh
############################################################################
#
# Name: install.sh
# Version: 0.56
# Authors: Rene Uittenbogaard
# Date: 2017-07-17
# Usage: sh install.sh
# Description: Un*x-like systems can be very diverse.
# This script is meant as an example how pfm dependencies
# can be downloaded and installed, but Your Mileage May Vary.
# Suggestions for improvement are welcome!
#
############################################################################
# helper functions
install_prepare() {
echo
echo "This script will try to guide you through the process of"
echo "installing pfm together with its dependencies."
echo
VERSION=$(cat pfm | perl -ne '
/^[^@]*\@\(#\)\D+(?:\d{4}-\d{2}-\d{2}\s*)?v?([[:alnum:].]+).*$/
and print $1;
')
if [ "$PFMRC" -a -e "$PFMRC" ]; then
pfmrc="$PFMRC"
else
pfmrc=~/.pfm/.pfmrc
fi
if echo -n '' | grep n >/dev/null; then
# echo -n does not suppress newline
n=
else
n='-n'
fi
sudo=
if [ `whoami` != root ]; then
echo $n "Do you want to use sudo during this installation? (Yes/No) "
read answer
answer=$(echo $answer | cut -c1 | tr A-Z a-z)
if [ "x$answer" = xy ]; then
sudo=sudo
fi
fi
echo
}
init_package_commands() {
case "$1" in
hpux)
packagelistcmd=swlist
packageinstallcmd='swinstall -s \`pwd\`/${packagename}\*depot ${packagename}'
packageurls='http://hpux.connect.org.uk/'
ncursessuggestion='http://hpux.connect.org.uk/ftp/hpux/Sysadmin/ncurses-5.7/ncurses-5.7-hppa-11.23.depot.gz'
readlinesuggestion='http://hpux.connect.org.uk/hppd/hpux/Gnu/readline-6.0.004/'
;;
sunos|solaris)
packagelistcmd=pkginfo
packageinstallcmd='pkgadd -d ${packagename}\*pkg all'
packageurls='ftp://ftp.sunfreeware.com/'
ncursessuggestion='ftp://ftp.sunfreeware.com/pub/freeware/sparc/10/ncurses-5.7-sol10-sparc-local.gz'
readlinesuggestion='ftp://ftp.sunfreeware.com/pub/freeware/sparc/10/readline-5.2-sol10-sparc-local.gz'
;;
aix)
packagelistcmd='lslpp -L'
packageinstallcmd='installp -d \`pwd\`/${packagename}\*bff all'
packageurls='http://www.bullfreeware.com/'
ncursessuggestion=
readlinesuggestion='http://www.bullfreeware.com/download/aix43/gnu.readline-4.1.0.1.exe'
;;
darwin)
if port version >/dev/null 2>&1; then
packagelistcmd='port installed'
packageinstallcmd='port install ${packagename}'
packageurls='http://www.macports.org/'
elif brew --version >/dev/null 2>&1; then
packagelistcmd='brew list'
packageinstallcmd='brew install ${packagename}'
packageurls='http://braumeister.org/'
else
packagelistcmd='dpkg -l'
packageinstallcmd='apt-get install ${packagename}'
packageurls='http://www.finkproject.org/'
fi
;;
*bsd)
packagelistcmd=pkg_info
packageinstallcmd='pkg_add ${packagename}'
packageurls='http://www.freebsd.org/ports/,ftp://ftp.openbsd.org/pub/OpenBSD/'
;;
rpm)
packagelistcmd='rpm -qa'
packageinstallcmd='rpm -ivh ${packagename}\*.rpm'
packageurls='http://www.rpmfind.net/,http://www.rpm.org/'
;;
deb)
packagelistcmd='dpkg -l'
packageinstallcmd='apt-get install ${packagename}'
packageurls='http://packages.ubuntu.com/,http://packages.debian.org/'
;;
slackware)
packagelistcmd='ls -1 /var/log/packages'
packageinstallcmd='installpkg ${packagename}'
packageurls='http://packages.slackware.it/'
;;
gentoo)
packagelistcmd='emerge -s'
packageinstallcmd='emerge ${packagename}'
packageurls='http://www.gentoo.org/main/en/mirrors2.xml'
;;
*)
packagelistcmd=
packageinstallcmd=
packageurls=
;;
esac
}
check_distro() {
# http://linuxmafia.com/faq/Admin/release-files.html
# http://goc.grid.sinica.edu.tw/gocwiki/How_to_publish_the_OS_name
#
uname=`uname | tr A-Z a-z`
lsb="`lsb_release -i 2>/dev/null | awk '{print $NF}' | tr A-Z a-z`"
if [ "$uname" != 'linux' ]; then
distro=
init_package_commands $uname
elif [ -e /etc/ubuntu-release -o "$lsb" = ubuntu ]; then
distro=ubuntu
init_package_commands deb
elif [ -e /etc/redhat-release -o "$lsb" = redhat ]; then
distro=redhat
init_package_commands rpm
elif [ -e /etc/fedora-release -o "$lsb" = fedora ]; then
distro=fedoracore
init_package_commands rpm
elif [ -e /etc/mandrake-release -o "$lsb" = mandrake ]; then
distro=mandrake
init_package_commands rpm
elif [ -e /etc/debian_version -o "$lsb" = debian ]; then
distro=debian
init_package_commands deb
elif [ -e /etc/SuSE-release -o "$lsb" = suse \
-o -e /etc/UnitedLinux-release -o "$lsb" = unitedlinux ]; then
distro=suse
init_package_commands rpm
elif [ -e /etc/slackware-version -o "$lsb" = slackware ]; then
distro=slackware
init_package_commands slackware
elif [ -e /etc/knoppix_version -o "$lsb" = knoppix ]; then
distro=knoppix
init_package_commands deb
elif [ -e /etc/gentoo-release -o "$lsb" = gentoo ]; then
distro=gentoo
init_package_commands gentoo
else
distro=unknown
init_package_commands ''
fi
}
enkader() {
# usage : cmd | enkader [ indent [ footer_yesno ] ]
# example: dpkg -l | grep libncurses | enkader
indent="${1:-4}"
footer="${2:-yes}"
awk '
BEGIN {
indent="'"$indent"'"
if ("'"$footer"'" == "no") footer=0; else footer=1
maxlength=77-indent;
indentstr=substr(" ", 1, indent);
minusstr=substr( \
"--------------------------------------------------------------------------------", \
1, maxlength + 1);
printf("%s+%-s+\n", indentstr, minusstr);
}
{
printf("%s| %-" maxlength "s|\n", indentstr, substr($0, 1, maxlength));
}
END {
if (footer) printf("%s+%-s+\n", indentstr, minusstr);
}'
}
enkadercmd() {
command="$@"
test "$command" || return
echo "Command: $command" | enkader 4 no
eval "$command" | enkader 4
}
make_minusC() {
# 'make -C' is not portable
cd "$1"
shift
make "$@"
cd ..
}
############################################################################
# main functions
check_package() {
packagename="$1"
if [ "$uname" = linux ]; then
question="Have lib$packagename and lib$packagename-dev"
else
question="Has lib$packagename"
fi
question="${question} successfully been installed\non your system? (Yes/No/Tell me) "
answer=n
echo $n "$question"
read answer
answer=$(echo $answer | cut -c1 | tr A-Z a-z)
while [ "x$answer" != xy ]; do
if [ "x$answer" = xt ]; then
if [ "x$packagelistcmd" = x ]; then
echo "I don't know how to list installed packages for your system, sorry!"
else
enkadercmd "$packagelistcmd|grep -i '$packagename'||echo not found"
fi
elif [ "x$answer" != xy ]; then
download_and_install "$packagename"
fi
echo $n "$question"
read answer
answer=$(echo $answer | cut -c1 | tr A-Z a-z)
done
}
download_and_install() {
packagename="$1"
echo $n "You will need to download $packagename "
if [ "$uname" = darwin -a $packagename = readline ]; then
echo "(for Fink: readline5,"
echo "for Macports: readline or readline-5),"
else
echo "(sometimes called lib$packagename),"
fi
if [ "x$packageurls" != x ]; then
echo "perhaps from:"
for url in $(echo $packageurls | tr , " "); do
echo "- $url"
done
if [ "x$ncursessuggestion" != x -a $packagename = ncurses ]; then
echo "(maybe: $ncursessuggestion)"
fi
if [ "x$readlinesuggestion" != x -a $packagename = readline ]; then
echo "(maybe: $readlinesuggestion)"
fi
fi
echo $n "and install it"
if [ "x$packageinstallcmd" != x ]; then
echo " using a command like:"
eval "echo $packageinstallcmd"
fi
echo
if [ "$uname" = darwin -a $packagename = readline ]; then
echo "Alternatively, you may try to compile it using something like:"
echo
echo '#!/usr/bin/sh'
echo 'VERSION=6.1'
echo 'curl -O ftp://ftp.gnu.org/pub/gnu/readline/readline-$VERSION.tar.gz'
echo 'tar zxvf readline-$VERSION.tar.gz'
echo 'cd readline-$VERSION'
echo 'perl -i.bak -p -e "s{SHLIB_LIBS=.*}'
echo ' {SHLIB_LIBS='\''-lSystem -lncurses -lcc_dynamic'\''}g" support/shobj-conf'
echo './configure'
echo 'make'
echo 'sudo make install'
echo
fi
}
check_readline_gnu_wanted() {
if [ -z "$PERL_RL" ]; then
return
fi
variant=`echo $PERL_RL | cut -f1 -d' '`
if [ "$variant" = Gnu ]; then
return
fi
echo "Your environment variable PERL_RL seems configured to run"
echo "Term::ReadLine::$variant. Do you want to continue installing"
echo $n "Term::ReadLine::Gnu (strongly advised)? (Yes/No) "
read answer
answer=$(echo $answer | cut -c1 | tr A-Z a-z)
if [ "x$answer" = xn ]; then
return 1
fi
}
check_cpan() {
echo
if check_perl_module CPAN; then
cpan_available=1
else
cpan_available=
fi
}
check_perl_module() {
mod="$1"
wantver="$2"
echo "Checking module $mod..."
if perl -M"$mod" -e1; then
gotver=`perl -M"$mod" -e'print $'"$mod"'::VERSION;'`
if perl -e"exit (\"$gotver\" lt \"$wantver\");"; then
echo "Module $mod found (version $gotver)."
else
echo "Module $mod found (version $gotver), but we need $wantver."
return 1
fi
else
echo "Module $mod not found"
return 1
fi
}
check_perl_module_term_readline_gnu() {
check_readline_gnu_wanted || return
mod=Term::ReadLine
variant=Gnu
wantver="$1"
PERL_RL=$variant; export PERL_RL
echo "Checking module $mod::$variant..."
if perl -M$mod -e "
\$t = new $mod '';
exit (\$t->ReadLine ne '$mod::$variant')";
then
gotver=`perl -M$mod -e'print $'"$mod::$variant"'::VERSION;'`
if perl -e"exit (\"$gotver\" lt \"$wantver\");"; then
echo "Module $mod::$variant found (version $gotver)."
else
echo "Module $mod::$variant found (version $gotver), but we need $wantver."
return 1
fi
else
echo "Module $mod::$variant not found"
return 1
fi
}
download_and_install_perl_module() {
packagename="$1"
if [ "$cpan_available" ]; then
install_opt=
while [ "x$install_opt" != xb -a "x$install_opt" != xc ]; do
echo "Do you want to install the bundled version (B), or "
echo $n "download the latest version from CPAN (C)? "
read install_opt
install_opt=$(echo $install_opt | cut -c1 | tr A-Z a-z)
done
else
install_opt=b
fi
if [ "x$install_opt" = xc ]; then
$sudo perl -MCPAN -e"install '$packagename'"
else
target="$(echo $packagename | sed -es/::/-/g)"
SUDO=$sudo make_minusC modules $target
fi
}
download_and_install_perl_module_term_readline_gnu() {
packagename=Term::ReadLine::Gnu
if [ $uname != darwin ]; then
download_and_install_perl_module $packagename
return
fi
# # Term::RL::Gnu gives a lot of compilation trouble on MacOSX.
# # Offer to install it from macports/fink.
# perlver=`perl -e'print $]'`
# finkpkg=
# if [ $perlver = 5.010000 ]; then
# finkpkg=term-readline-gnu-pm5100
# elif [ $perlver = 5.008008 ]; then
# finkpkg=term-readline-gnu-pm588
# elif [ $perlver = 5.008006 ]; then
# finkpkg=term-readline-gnu-pm586
# fi
# if [ "$finkpkg" ]; then
# finkalternative=" or Finkproject (F)"
# fi
install_opt=
while [ "x$install_opt" != xb -a "x$install_opt" != xc \
-a "x$install_opt" != xm -a "x$install_opt" != xf ]
do
echo $n "Do you want to install the bundled version (B)"
# echo $n ", download the version from Macports (M)${finkalternative}"
if [ "$cpan_available" ]; then
echo ","
echo $n "or download the latest version from CPAN (C)"
fi
echo "?"
read install_opt
install_opt=$(echo $install_opt | cut -c1 | tr A-Z a-z)
done
if [ "x$install_opt" = xc ]; then
$sudo perl -MCPAN -e"install '$packagename'"
# elif [ "x$install_opt" = xm ]; then
# $sudo port install p5-term-readline-gnu
# elif [ "x$install_opt" = xf ]; then
# perlver=`perl -e'print $]'`
# if [ $perlver = 5.010000 ]; then
# $sudo apt-get install term-readline-gnu-pm5100
# elif [ $perlver = 5.008008 ]; then
# $sudo apt-get install term-readline-gnu-pm588
# elif [ $perlver = 5.008006 ]; then
# $sudo apt-get install term-readline-gnu-pm586
# fi
else # bundled
target="$(echo $packagename | sed -es/::/-/g)"
SUDO=$sudo make_minusC modules $target
fi
}
check_download_and_install_perl_module() {
# the module version may not be identical to the filename version.
# e.g. File-Stat-Bits-1.01 provides File::Stat::Bits 0.19
#
check_perl_module "$@" || \
download_and_install_perl_module "$1"
}
check_download_and_install_perl_module_term_readline_gnu() {
check_perl_module_term_readline_gnu "$1" || \
download_and_install_perl_module_term_readline_gnu
}
install_pfm() {
echo
env MAKEFILE_PL_CALLED_FROM_INSTALL_SH=1 \
perl Makefile.PL && \
make && \
make test && \
$sudo make install && \
for oldfile in \
/usr/local/bin/pfmrcupdate \
/usr/local/man/man1/pfmrcupdate.1;
do
test -f $oldfile && $sudo mv $oldfile $oldfile.old
done
}
check_listwhite() {
echo
echo "Do you use a filesystem which makes use of whiteout files,"
echo "such as: aufs, unionfs, tfs (translucent filesystem),"
echo "ovlfs (overlay filesystem) or ifs (inheriting filesystem)?"
echo $n "If you don't know what this is about, say no. (Yes/No) "
read answer
answer=$(echo $answer | cut -c1 | tr A-Z a-z)
if [ "x$answer" != xy ]; then
return
fi
echo
echo "Proceeding with installation of listwhite..."
cd helpers/listwhite
./configure
make all test
$sudo make install
cd -
}
check_hasacl() {
echo
echo "Do you use a filesystem which makes use of access control lists (ACLs)?"
echo $n "If you don't know what this is about, say no. (Yes/No) "
read answer
answer=$(echo $answer | cut -c1 | tr A-Z a-z)
if [ "x$answer" != xy ]; then
return
fi
echo
check_package acl
echo
echo "Proceeding with installation of hasacl..."
cd helpers/hasacl
./configure
make all test
$sudo make install
cd -
}
check_helpers() {
check_listwhite
check_hasacl
}
############################################################################
# main
install_prepare
check_distro
check_package ncurses
check_package readline
# Check, download and install the Perl modules.
# Check with the minimum required version.
# The bundled versions are more recent.
check_cpan
check_download_and_install_perl_module HTML::Parser 3.59
check_download_and_install_perl_module File::Temp 0.22
check_download_and_install_perl_module File::Stat::Bits 0.19
check_download_and_install_perl_module LWP 5.827
check_download_and_install_perl_module Module::Load 0.16
check_download_and_install_perl_module Term::Screen 1.06
check_download_and_install_perl_module Term::ScreenColor 1.20
check_download_and_install_perl_module_term_readline_gnu 1.09
# install the application
install_pfm
# check the need for helpers
check_helpers
echo
echo "Installation done."
echo
# vim: set tabstop=8 shiftwidth=8 noexpandtab: