--- trunk/core/include/mtools.sminc 2009/04/22 18:57:15 1113 +++ trunk/include/mtools.sminc 2013/10/09 13:09:29 19668 @@ -1,39 +1,13 @@ -# $Header: /magellan-cvs/smage/include/mtools.sminc,v 1.39 2008/04/20 08:28:23 niro Exp $ +# $Id$ # some special build tools -# automatical inherit mtools.minc -# this will provide the service management functions -INHERITS="${INHERITS} mtools" - -# installs initscripts -# minstallrc /path/to/rc-script {destfilename} -minstallrc() +# get the pname right with split-packages +mpname() { - local rcscript - local file - - [[ -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 + local pname="${PNAME}" + [[ ! -z ${SPLIT_PACKAGE_BASE} ]] && pname="${SPLIT_PACKAGE_BASE}" - if [[ -n "$2" ]] - 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 + echo "${pname}" } # installs environment files @@ -48,7 +22,7 @@ # if no fullpath given use file from sourcedir if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] then - file="${SOURCEDIR}/${PNAME}/$1" + file="${SOURCEDIR}/$(mpname)/$1" else file="$1" fi @@ -79,7 +53,7 @@ # if no fullpath given use file from sourcedir if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] then - file="${SOURCEDIR}/${PNAME}/$1" + file="${SOURCEDIR}/$(mpname)/$1" else file="$1" fi @@ -111,7 +85,7 @@ # if no fullpath given use file from sourcedir if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] then - file="${SOURCEDIR}/${PNAME}/$1" + file="${SOURCEDIR}/$(mpname)/$1" else file="$1" fi @@ -220,7 +194,7 @@ # if no fullpath given use file from sourcedir if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] then - file="${SOURCEDIR}/${PNAME}/$1" + file="${SOURCEDIR}/$(mpname)/$1" else file="$1" fi @@ -258,7 +232,7 @@ # if no fullpath given use file from sourcedir if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] then - file="${SOURCEDIR}/${PNAME}/$1" + file="${SOURCEDIR}/$(mpname)/$1" else file="$1" fi @@ -293,7 +267,7 @@ # if no fullpath given use file from sourcedir if [[ -z $(dirname $2) ]] || [[ $(dirname $2) = . ]] then - file="${SOURCEDIR}/${PNAME}/$2" + file="${SOURCEDIR}/$(mpname)/$2" else file="$2" fi @@ -314,7 +288,7 @@ # installs logrotate configuration files -# minstallpam /path/to/logrotatefile {destfilename} +# minstalllog /path/to/logrotatefile {destfilename} minstalllog() { local logfile @@ -325,7 +299,7 @@ # if no fullpath given use file from sourcedir if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] then - file="${SOURCEDIR}/${PNAME}/$1" + file="${SOURCEDIR}/$(mpname)/$1" else file="$1" fi @@ -372,7 +346,7 @@ if [[ $1 = -s ]] then - file="${SOURCEDIR}/${PNAME}/$2" + file="${SOURCEDIR}/$(mpname)/$2" dest="$3" if [[ -z $3 ]] then @@ -404,7 +378,7 @@ if [[ $1 = -s ]] then - file="${SOURCEDIR}/${PNAME}/$2" + file="${SOURCEDIR}/$(mpname)/$2" dest="$3" if [[ -z $3 ]] then @@ -431,12 +405,16 @@ { local file local dest + local verbose="-v" + + # check for busybox as it doesn't support 'ln -v' + [[ $(readlink $(which ln)) = */busybox ]] && verbose="" [[ -z $1 ]] && die "No file given" if [[ $1 = -s ]] then - file="${SOURCEDIR}/${PNAME}/$2" + file="${SOURCEDIR}/$(mpname)/$2" dest="$3" if [[ -z $3 ]] then @@ -456,20 +434,121 @@ # install our library install -v -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die - # create libtool symlinks - # 1. - library.so.1.0.0 -> library.so.1.0 - if [ "${file%.*}" != *.so ] + # prefer scanelf + if [[ -x $(type -P scanelf) ]] + then + local soname="$(scanelf -qBF '%S#p' ${file})" + ln ${verbose} -snf $(basename ${file}) ${BINDIR}/${dest}/${soname} || die + else + echo -e "${COLYELLOW}minstalllib(): Warning: scanelf not found, using fallback symlink method${COLDEFAULT}" + + # create libtool symlinks + # 1. - library.so.1.0.0 -> library.so.1.0 + if [ "${file%.*}" != *.so ] + then + ln ${verbose} -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*}) || die + fi + # 2. - library.so.1.0.0 -> library.so.1 + if [ "${file%.*.*}" != *.so ] + then + ln ${verbose} -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*.*}) || die + fi + # 3. - library.so.1.0.0.0 -> library.so.1 + if [ "${file%.*.*.*}" != *.so ] + then + ln ${verbose} -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*.*.*}) || die + fi + fi +} + +mcopy() +{ + local source="$1" + local dest="$2" + local opts + + # recursive + if [[ $1 = -r ]] || [[ $1 = -R ]] + then + opts="-R" + source="$2" + dest="$3" + fi + + # recursive + if [[ $1 = -rf ]] || [[ $1 = -fr ]] || [[ $1 = -Rf ]] || [[ $1 = -fR ]] + then + opts="-R -f" + source="$2" + dest="$3" + fi + + if [[ $1 = -a ]] + then + opts="-a" + source="$2" + dest="$3" + fi + + [[ -z ${source} ]] && die "No source given." + [[ -z ${dest} ]] && die "No dest given." + + cp -v ${opts} ${source} ${BINDIR}/${dest} || die +} + +mdelete() +{ + local dest="$1" + local opts + + # enforce + if [[ $1 = -f ]] then - ln -v -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*}) + opts="-f" + dest="$2" fi - # 2. - library.so.1.0.0 -> library.so.1 - if [ "${file%.*.*}" != *.so ] + + # recursive + if [[ $1 = -r ]] || [[ $1 = -R ]] + then + opts="-r" + dest="$2" + fi + + # recursive + if [[ $1 = -rf ]] || [[ $1 = -fr ]] || [[ $1 = -Rf ]] || [[ $1 = -fR ]] + then + opts="-r -f" + dest="$2" + fi + + [[ -z ${dest} ]] && die "No dest given." + [[ ! -e ${BINDIR}/${dest} ]] && die "${BINDIR}/${dest} does not exist." + + rm -v ${opts} ${BINDIR}/${dest} || die +} + +mmove() +{ + local source="$1" + local dest="$2" + local opts + + # force + if [[ $1 = -f ]] then - ln -v -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*.*}) + opts="-f" + source="$2" + dest="$3" fi + + [[ -z ${source} ]] && die "No source given." + [[ -z ${dest} ]] && die "No dest given." + + mv -v ${opts} ${source} ${BINDIR}/${dest} || die } -# mark directoris undeletable +# mark directories undeletable mkeepdir() { local keepdir @@ -504,7 +583,7 @@ # recursive if [[ $1 = -r ]] || [[ $1 = -R ]] then - local recursive="--recursive" + local recursive="-R" local owner="$2" local path="$3" fi @@ -524,7 +603,7 @@ # recursive if [[ $1 = -r ]] || [[ $1 = -R ]] then - local recursive="--recursive" + local recursive="-R" local posix="$2" local path="$3" fi @@ -539,9 +618,55 @@ { local symlink="$1" local pathto="$2" + local verbose="-v" + + # check for busybox as it doesn'tz support 'ln -v' + [[ $(readlink $(which ln)) = */busybox ]] && verbose="" [[ -z ${symlink} ]] && die "No symlink given." [[ -z ${pathto} ]] && die "No path given." - ln -v -snf ${symlink} ${BINDIR}/${pathto} || die + ln ${verbose} -snf ${symlink} ${BINDIR}/${pathto} || die +} + +mclearconfig() +{ + local confdir + local prefix="${BINDIR}" + [[ -z ${MCONFIG} ]] && die "No \$MCONFIG given!" + + # no bindir prefix if requested + case $1 in + -b|--no-bindir) prefix="";; + esac + + confdir="$(dirname ${MCONFIG})" + if [[ ! -d ${prefix}/${confdir} ]] + then + install -d ${prefix}/${confdir} || die + fi + : > ${prefix}/${MCONFIG} +} + +maddconfig() +{ + local argv="$1" + local confdir + local prefix="${BINDIR}" + + [[ -z ${MCONFIG} ]] && die "No \$MCONFIG given!" + + # no bindir prefix if requested + case $1 in + -b|--no-bindir) prefix=""; argv="$2" ;; + esac + + #[[ -z ${argv} ]] && die "No argument given!" + + confdir="$(dirname ${MCONFIG})" + if [[ ! -d ${prefix}/${confdir} ]] + then + install -d ${prefix}/${confdir} || die + fi + echo "${argv}" >> ${prefix}/${MCONFIG} || die }