1 |
# $Header: /magellan-cvs/smage/include/mtools.sminc,v 1.39 2008/04/20 08:28:23 niro Exp $ |
# $Id$ |
2 |
# some special build tools |
# some special build tools |
3 |
|
|
4 |
# automatical inherit mtools.minc |
# get the pname right with split-packages |
5 |
# this will provide the service management functions |
mpname() |
|
INHERITS="${INHERITS} mtools" |
|
|
|
|
|
# installs initscripts |
|
|
# minstallrc /path/to/rc-script {destfilename} |
|
|
minstallrc() |
|
6 |
{ |
{ |
7 |
local rcscript |
local pname="${PNAME}" |
8 |
local file |
[[ ! -z ${SPLIT_PACKAGE_BASE} ]] && pname="${SPLIT_PACKAGE_BASE}" |
|
|
|
|
[[ -z "$1" ]] && die "No initscript given" |
|
|
|
|
|
# if no fullpath given use file from sourcedir |
|
|
if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] |
|
|
then |
|
|
file="${SOURCEDIR}/${PNAME}/$1" |
|
|
else |
|
|
file="$1" |
|
|
fi |
|
9 |
|
|
10 |
if [[ -n "$2" ]] |
echo "${pname}" |
|
then |
|
|
rcscript="$2" |
|
|
else |
|
|
rcscript="$(basename ${file})" |
|
|
fi |
|
|
|
|
|
# needed directory |
|
|
install -d ${BINDIR}/etc/rc.d/init.d || die |
|
|
|
|
|
# install our initscript |
|
|
install -v -m 0755 -o root -g root ${file} ${BINDIR}/etc/rc.d/init.d/${rcscript} || die |
|
11 |
} |
} |
12 |
|
|
13 |
# installs environment files |
# installs environment files |
22 |
# if no fullpath given use file from sourcedir |
# if no fullpath given use file from sourcedir |
23 |
if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] |
if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] |
24 |
then |
then |
25 |
file="${SOURCEDIR}/${PNAME}/$1" |
file="${SOURCEDIR}/$(mpname)/$1" |
26 |
else |
else |
27 |
file="$1" |
file="$1" |
28 |
fi |
fi |
53 |
# if no fullpath given use file from sourcedir |
# if no fullpath given use file from sourcedir |
54 |
if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] |
if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] |
55 |
then |
then |
56 |
file="${SOURCEDIR}/${PNAME}/$1" |
file="${SOURCEDIR}/$(mpname)/$1" |
57 |
else |
else |
58 |
file="$1" |
file="$1" |
59 |
fi |
fi |
85 |
# if no fullpath given use file from sourcedir |
# if no fullpath given use file from sourcedir |
86 |
if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] |
if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] |
87 |
then |
then |
88 |
file="${SOURCEDIR}/${PNAME}/$1" |
file="${SOURCEDIR}/$(mpname)/$1" |
89 |
else |
else |
90 |
file="$1" |
file="$1" |
91 |
fi |
fi |
194 |
# if no fullpath given use file from sourcedir |
# if no fullpath given use file from sourcedir |
195 |
if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] |
if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] |
196 |
then |
then |
197 |
file="${SOURCEDIR}/${PNAME}/$1" |
file="${SOURCEDIR}/$(mpname)/$1" |
198 |
else |
else |
199 |
file="$1" |
file="$1" |
200 |
fi |
fi |
232 |
# if no fullpath given use file from sourcedir |
# if no fullpath given use file from sourcedir |
233 |
if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] |
if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] |
234 |
then |
then |
235 |
file="${SOURCEDIR}/${PNAME}/$1" |
file="${SOURCEDIR}/$(mpname)/$1" |
236 |
else |
else |
237 |
file="$1" |
file="$1" |
238 |
fi |
fi |
267 |
# if no fullpath given use file from sourcedir |
# if no fullpath given use file from sourcedir |
268 |
if [[ -z $(dirname $2) ]] || [[ $(dirname $2) = . ]] |
if [[ -z $(dirname $2) ]] || [[ $(dirname $2) = . ]] |
269 |
then |
then |
270 |
file="${SOURCEDIR}/${PNAME}/$2" |
file="${SOURCEDIR}/$(mpname)/$2" |
271 |
else |
else |
272 |
file="$2" |
file="$2" |
273 |
fi |
fi |
288 |
|
|
289 |
|
|
290 |
# installs logrotate configuration files |
# installs logrotate configuration files |
291 |
# minstallpam /path/to/logrotatefile {destfilename} |
# minstalllog /path/to/logrotatefile {destfilename} |
292 |
minstalllog() |
minstalllog() |
293 |
{ |
{ |
294 |
local logfile |
local logfile |
299 |
# if no fullpath given use file from sourcedir |
# if no fullpath given use file from sourcedir |
300 |
if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] |
if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] |
301 |
then |
then |
302 |
file="${SOURCEDIR}/${PNAME}/$1" |
file="${SOURCEDIR}/$(mpname)/$1" |
303 |
else |
else |
304 |
file="$1" |
file="$1" |
305 |
fi |
fi |
346 |
|
|
347 |
if [[ $1 = -s ]] |
if [[ $1 = -s ]] |
348 |
then |
then |
349 |
file="${SOURCEDIR}/${PNAME}/$2" |
file="${SOURCEDIR}/$(mpname)/$2" |
350 |
dest="$3" |
dest="$3" |
351 |
if [[ -z $3 ]] |
if [[ -z $3 ]] |
352 |
then |
then |
378 |
|
|
379 |
if [[ $1 = -s ]] |
if [[ $1 = -s ]] |
380 |
then |
then |
381 |
file="${SOURCEDIR}/${PNAME}/$2" |
file="${SOURCEDIR}/$(mpname)/$2" |
382 |
dest="$3" |
dest="$3" |
383 |
if [[ -z $3 ]] |
if [[ -z $3 ]] |
384 |
then |
then |
405 |
{ |
{ |
406 |
local file |
local file |
407 |
local dest |
local dest |
408 |
|
local verbose="-v" |
409 |
|
|
410 |
|
# check for busybox as it doesn't support 'ln -v' |
411 |
|
[[ $(readlink $(which ln)) = */busybox ]] && verbose="" |
412 |
|
|
413 |
[[ -z $1 ]] && die "No file given" |
[[ -z $1 ]] && die "No file given" |
414 |
|
|
415 |
if [[ $1 = -s ]] |
if [[ $1 = -s ]] |
416 |
then |
then |
417 |
file="${SOURCEDIR}/${PNAME}/$2" |
file="${SOURCEDIR}/$(mpname)/$2" |
418 |
dest="$3" |
dest="$3" |
419 |
if [[ -z $3 ]] |
if [[ -z $3 ]] |
420 |
then |
then |
434 |
# install our library |
# install our library |
435 |
install -v -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die |
install -v -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die |
436 |
|
|
437 |
# create libtool symlinks |
# prefer scanelf |
438 |
# 1. - library.so.1.0.0 -> library.so.1.0 |
if [[ -x $(type -P scanelf) ]] |
439 |
if [ "${file%.*}" != *.so ] |
then |
440 |
|
local soname="$(scanelf -qBF '%S#p' ${file})" |
441 |
|
ln ${verbose} -snf $(basename ${file}) ${BINDIR}/${dest}/${soname} || die |
442 |
|
else |
443 |
|
echo -e "${COLYELLOW}minstalllib(): Warning: scanelf not found, using fallback symlink method${COLDEFAULT}" |
444 |
|
|
445 |
|
# create libtool symlinks |
446 |
|
# 1. - library.so.1.0.0 -> library.so.1.0 |
447 |
|
if [ "${file%.*}" != *.so ] |
448 |
|
then |
449 |
|
ln ${verbose} -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*}) || die |
450 |
|
fi |
451 |
|
# 2. - library.so.1.0.0 -> library.so.1 |
452 |
|
if [ "${file%.*.*}" != *.so ] |
453 |
|
then |
454 |
|
ln ${verbose} -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*.*}) || die |
455 |
|
fi |
456 |
|
# 3. - library.so.1.0.0.0 -> library.so.1 |
457 |
|
if [ "${file%.*.*.*}" != *.so ] |
458 |
|
then |
459 |
|
ln ${verbose} -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*.*.*}) || die |
460 |
|
fi |
461 |
|
fi |
462 |
|
} |
463 |
|
|
464 |
|
mcopy() |
465 |
|
{ |
466 |
|
local source="$1" |
467 |
|
local dest="$2" |
468 |
|
local opts |
469 |
|
|
470 |
|
# recursive |
471 |
|
if [[ $1 = -r ]] || [[ $1 = -R ]] |
472 |
|
then |
473 |
|
opts="-R" |
474 |
|
source="$2" |
475 |
|
dest="$3" |
476 |
|
fi |
477 |
|
|
478 |
|
# recursive |
479 |
|
if [[ $1 = -rf ]] || [[ $1 = -fr ]] || [[ $1 = -Rf ]] || [[ $1 = -fR ]] |
480 |
|
then |
481 |
|
opts="-R -f" |
482 |
|
source="$2" |
483 |
|
dest="$3" |
484 |
|
fi |
485 |
|
|
486 |
|
if [[ $1 = -a ]] |
487 |
|
then |
488 |
|
opts="-a" |
489 |
|
source="$2" |
490 |
|
dest="$3" |
491 |
|
fi |
492 |
|
|
493 |
|
[[ -z ${source} ]] && die "No source given." |
494 |
|
[[ -z ${dest} ]] && die "No dest given." |
495 |
|
|
496 |
|
cp -v ${opts} ${source} ${BINDIR}/${dest} || die |
497 |
|
} |
498 |
|
|
499 |
|
mdelete() |
500 |
|
{ |
501 |
|
local dest="$1" |
502 |
|
local opts |
503 |
|
|
504 |
|
# enforce |
505 |
|
if [[ $1 = -f ]] |
506 |
then |
then |
507 |
ln -v -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*}) |
opts="-f" |
508 |
|
dest="$2" |
509 |
fi |
fi |
510 |
# 2. - library.so.1.0.0 -> library.so.1 |
|
511 |
if [ "${file%.*.*}" != *.so ] |
# recursive |
512 |
|
if [[ $1 = -r ]] || [[ $1 = -R ]] |
513 |
|
then |
514 |
|
opts="-r" |
515 |
|
dest="$2" |
516 |
|
fi |
517 |
|
|
518 |
|
# recursive |
519 |
|
if [[ $1 = -rf ]] || [[ $1 = -fr ]] || [[ $1 = -Rf ]] || [[ $1 = -fR ]] |
520 |
|
then |
521 |
|
opts="-r -f" |
522 |
|
dest="$2" |
523 |
|
fi |
524 |
|
|
525 |
|
[[ -z ${dest} ]] && die "No dest given." |
526 |
|
[[ ! -e ${BINDIR}/${dest} ]] && die "${BINDIR}/${dest} does not exist." |
527 |
|
|
528 |
|
rm -v ${opts} ${BINDIR}/${dest} || die |
529 |
|
} |
530 |
|
|
531 |
|
mmove() |
532 |
|
{ |
533 |
|
local source="$1" |
534 |
|
local dest="$2" |
535 |
|
local opts |
536 |
|
|
537 |
|
# force |
538 |
|
if [[ $1 = -f ]] |
539 |
then |
then |
540 |
ln -v -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*.*}) |
opts="-f" |
541 |
|
source="$2" |
542 |
|
dest="$3" |
543 |
fi |
fi |
544 |
|
|
545 |
|
[[ -z ${source} ]] && die "No source given." |
546 |
|
[[ -z ${dest} ]] && die "No dest given." |
547 |
|
|
548 |
|
mv -v ${opts} ${source} ${BINDIR}/${dest} || die |
549 |
} |
} |
550 |
|
|
551 |
# mark directoris undeletable |
# mark directories undeletable |
552 |
mkeepdir() |
mkeepdir() |
553 |
{ |
{ |
554 |
local keepdir |
local keepdir |
583 |
# recursive |
# recursive |
584 |
if [[ $1 = -r ]] || [[ $1 = -R ]] |
if [[ $1 = -r ]] || [[ $1 = -R ]] |
585 |
then |
then |
586 |
local recursive="--recursive" |
local recursive="-R" |
587 |
local owner="$2" |
local owner="$2" |
588 |
local path="$3" |
local path="$3" |
589 |
fi |
fi |
603 |
# recursive |
# recursive |
604 |
if [[ $1 = -r ]] || [[ $1 = -R ]] |
if [[ $1 = -r ]] || [[ $1 = -R ]] |
605 |
then |
then |
606 |
local recursive="--recursive" |
local recursive="-R" |
607 |
local posix="$2" |
local posix="$2" |
608 |
local path="$3" |
local path="$3" |
609 |
fi |
fi |
618 |
{ |
{ |
619 |
local symlink="$1" |
local symlink="$1" |
620 |
local pathto="$2" |
local pathto="$2" |
621 |
|
local verbose="-v" |
622 |
|
|
623 |
|
# check for busybox as it doesn'tz support 'ln -v' |
624 |
|
[[ $(readlink $(which ln)) = */busybox ]] && verbose="" |
625 |
|
|
626 |
[[ -z ${symlink} ]] && die "No symlink given." |
[[ -z ${symlink} ]] && die "No symlink given." |
627 |
[[ -z ${pathto} ]] && die "No path given." |
[[ -z ${pathto} ]] && die "No path given." |
628 |
|
|
629 |
ln -v -snf ${symlink} ${BINDIR}/${pathto} || die |
ln ${verbose} -snf ${symlink} ${BINDIR}/${pathto} || die |
630 |
|
} |
631 |
|
|
632 |
|
mclearconfig() |
633 |
|
{ |
634 |
|
local confdir |
635 |
|
local prefix="${BINDIR}" |
636 |
|
[[ -z ${MCONFIG} ]] && die "No \$MCONFIG given!" |
637 |
|
|
638 |
|
# no bindir prefix if requested |
639 |
|
case $1 in |
640 |
|
-b|--no-bindir) prefix="";; |
641 |
|
esac |
642 |
|
|
643 |
|
confdir="$(dirname ${MCONFIG})" |
644 |
|
if [[ ! -d ${prefix}/${confdir} ]] |
645 |
|
then |
646 |
|
install -d ${prefix}/${confdir} || die |
647 |
|
fi |
648 |
|
: > ${prefix}/${MCONFIG} |
649 |
|
} |
650 |
|
|
651 |
|
maddconfig() |
652 |
|
{ |
653 |
|
local argv="$1" |
654 |
|
local confdir |
655 |
|
local prefix="${BINDIR}" |
656 |
|
|
657 |
|
[[ -z ${MCONFIG} ]] && die "No \$MCONFIG given!" |
658 |
|
|
659 |
|
# no bindir prefix if requested |
660 |
|
case $1 in |
661 |
|
-b|--no-bindir) prefix=""; argv="$2" ;; |
662 |
|
esac |
663 |
|
|
664 |
|
#[[ -z ${argv} ]] && die "No argument given!" |
665 |
|
|
666 |
|
confdir="$(dirname ${MCONFIG})" |
667 |
|
if [[ ! -d ${prefix}/${confdir} ]] |
668 |
|
then |
669 |
|
install -d ${prefix}/${confdir} || die |
670 |
|
fi |
671 |
|
echo "${argv}" >> ${prefix}/${MCONFIG} || die |
672 |
} |
} |