--- trunk/core/include/mtools.sminc 2009/06/12 10:56:41 2031 +++ branches/R11-unstable/include/mtools.sminc 2019/04/29 14:06:55 32899 @@ -1,39 +1,154 @@ -# $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" +# get the pname right with split-packages +mpname() +{ + local pname="${PNAME}" + [[ ! -z ${SPLIT_PACKAGE_BASE} ]] && pname="${SPLIT_PACKAGE_BASE}" + + echo "${pname}" +} + +# installs given directories +# minstalldir /path/to/dest/dir {/path/to/dest/dirN} +minstalldir() +{ + local argv="$@" + local dest + + [[ -z ${argv} ]] && die "No dest dir given" + for dest in ${argv} + do + [[ -d ${BINDIR}${dest} ]] && continue + install -v -d ${BINDIR}/${dest} || die + done +} -# installs initscripts -# minstallrc /path/to/rc-script {destfilename} -minstallrc() +# install files to given path (defaults to /usr/bin) +# minstallfile {-s} /path/to/file {/path/to/dest} +minstallfile() { - local rcscript local file + local dest - [[ -z "$1" ]] && die "No initscript given" + [[ -z $1 ]] && die "No etc file given" - # if no fullpath given use file from sourcedir - if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] + if [[ $1 = -s ]] then - file="${SOURCEDIR}/${PNAME}/$1" + file="${SOURCEDIR}/$(mpname)/$2" + dest="$3" + if [[ -z $3 ]] + then + dest=/usr/bin + install -d ${BINDIR}/${dest} || die + fi else file="$1" + dest="$2" + if [[ -z $2 ]] + then + dest=/usr/bin + install -d ${BINDIR}/${dest} || die + fi fi - if [[ -n "$2" ]] + # install our configfile + install -v -m 0644 -o root -g root ${file} ${BINDIR}/${dest} || die +} + +# installs executables to given path +# minstallexec {-s} /path/to/exec {/path/to/dest} +minstallexec() +{ + local file + local dest + + [[ -z $1 ]] && die "No file given" + + if [[ $1 = -s ]] then - rcscript="$2" + file="${SOURCEDIR}/$(mpname)/$2" + dest="$3" + if [[ -z $3 ]] + then + dest=/usr/bin + install -d ${BINDIR}/${dest} || die + fi else - rcscript="$(basename ${file})" + file="$1" + dest="$2" + if [[ -z $2 ]] + then + dest=/usr/bin + install -d ${BINDIR}/${dest} || die + fi fi - # needed directory - install -d ${BINDIR}/etc/rc.d/init.d || die + # install our configfile + install -v -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die +} + +# installs executables to given path +# minstalllib {-s} /path/to/exec {/path/to/dest} +minstalllib() +{ + 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}/$(mpname)/$2" + dest="$3" + if [[ -z $3 ]] + then + dest=/usr/$(mlibdir) + install -d ${BINDIR}/${dest} || die + fi + else + file="$1" + dest="$2" + if [[ -z $2 ]] + then + dest=/usr/$(mlibdir) + install -d ${BINDIR}/${dest} || die + fi + fi + + # install our library + install -v -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die + + # 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}" - # install our initscript - install -v -m 0755 -o root -g root ${file} ${BINDIR}/etc/rc.d/init.d/${rcscript} || die + # 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 } # installs environment files @@ -48,7 +163,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 +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 @@ -111,7 +226,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 @@ -137,35 +252,6 @@ install -v -m 0644 -o root -g root ${file} ${BINDIR}/${destdir}/${etcfile} || die } -minstalludev() -{ - local udevrule - local file - - [[ -z "$1" ]] && die "No udev rule given" - - # if no fullpath given use file from sourcedir - if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] - then - file="${SOURCEDIR}/${PNAME}/$1" - else - file="$1" - fi - - if [[ -n "$2" ]] - then - udevrule="$2" - else - udevrule="$(basename ${file})" - fi - - # needed directory - install -d ${BINDIR}/etc/udev/rules.d || die - - # install our initscript - install -v -m 0755 -o root -g root ${file} ${BINDIR}/etc/udev/rules.d/udevrule || die -} - # install man files to appropiate dirs # minstallman /path/to/manfile.foo minstallman() @@ -249,7 +335,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 @@ -287,7 +373,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 @@ -322,7 +408,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 @@ -343,7 +429,7 @@ # installs logrotate configuration files -# minstallpam /path/to/logrotatefile {destfilename} +# minstalllog /path/to/logrotatefile {destfilename} minstalllog() { local logfile @@ -354,7 +440,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 @@ -373,132 +459,100 @@ install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/logrotate.d/${logfile} || die } - -# installs given directories -# minstalldir /path/to/dest/dir {/path/to/dest/dirN} -minstalldir() +mcopy() { - local argv="$@" - local dest - - [[ -z ${argv} ]] && die "No dest dir given" - for dest in ${argv} - do - [[ -d ${BINDIR}${dest} ]] && continue - install -v -d ${BINDIR}/${dest} || die - done -} + local source="$1" + local dest="$2" + local opts + # recursive + if [[ $1 = -r ]] || [[ $1 = -R ]] + then + opts="-R" + source="$2" + dest="$3" + fi -# install files to given path (defaults to /usr/bin) -# minstallfile {-s} /path/to/file {/path/to/dest} -minstallfile() -{ - local file - local dest - - [[ -z $1 ]] && die "No etc file given" + # recursive + if [[ $1 = -rf ]] || [[ $1 = -fr ]] || [[ $1 = -Rf ]] || [[ $1 = -fR ]] + then + opts="-R -f" + source="$2" + dest="$3" + fi - if [[ $1 = -s ]] + if [[ $1 = -a ]] then - file="${SOURCEDIR}/${PNAME}/$2" + opts="-a" + source="$2" dest="$3" - if [[ -z $3 ]] - then - dest=/usr/bin - install -d ${BINDIR}/${dest} || die - fi - else - file="$1" - dest="$2" - if [[ -z $2 ]] - then - dest=/usr/bin - install -d ${BINDIR}/${dest} || die - fi fi - # install our configfile - install -v -m 0644 -o root -g root ${file} ${BINDIR}/${dest} || die + [[ -z ${source} ]] && die "No source given." + [[ -z ${dest} ]] && die "No dest given." + + cp -v ${opts} ${source} ${BINDIR}/${dest} || die } -# installs executables to given path -# minstallexec {-s} /path/to/exec {/path/to/dest} -minstallexec() +mdelete() { - local file - local dest + local dest="$1" + local opts - [[ -z $1 ]] && die "No file given" + # enforce + if [[ $1 = -f ]] + then + opts="-f" + dest="$2" + fi - if [[ $1 = -s ]] + # recursive + if [[ $1 = -r ]] || [[ $1 = -R ]] then - file="${SOURCEDIR}/${PNAME}/$2" - dest="$3" - if [[ -z $3 ]] - then - dest=/usr/bin - install -d ${BINDIR}/${dest} || die - fi - else - file="$1" + opts="-r" dest="$2" - if [[ -z $2 ]] - then - dest=/usr/bin - install -d ${BINDIR}/${dest} || die - fi fi - # install our configfile - install -v -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die + # recursive + if [[ $1 = -rf ]] || [[ $1 = -fr ]] || [[ $1 = -Rf ]] || [[ $1 = -fR ]] + then + opts="-r -f" + dest="$2" + fi + + [[ -z ${dest} ]] && die "No dest given." + for i in $(eval echo "${BINDIR}/${dest}") + do + if [[ -e ${i} ]] || [[ -L ${i} ]] + then + rm -v ${opts} ${i} || die + else + die "${i} does not exist." + fi + done } -# installs executables to given path -# minstalllib {-s} /path/to/exec {/path/to/dest} -minstalllib() +mmove() { - local file - local dest + local source="$1" + local dest="$2" + local opts - [[ -z $1 ]] && die "No file given" - - if [[ $1 = -s ]] + # force + if [[ $1 = -f ]] then - file="${SOURCEDIR}/${PNAME}/$2" + opts="-f" + source="$2" dest="$3" - if [[ -z $3 ]] - then - dest=/usr/$(mlibdir) - install -d ${BINDIR}/${dest} || die - fi - else - file="$1" - dest="$2" - if [[ -z $2 ]] - then - dest=/usr/$(mlibdir) - install -d ${BINDIR}/${dest} || die - fi fi - # install our library - install -v -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die + [[ -z ${source} ]] && die "No source given." + [[ -z ${dest} ]] && die "No dest given." - # create libtool symlinks - # 1. - library.so.1.0.0 -> library.so.1.0 - if [ "${file%.*}" != *.so ] - then - ln -v -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*}) - fi - # 2. - library.so.1.0.0 -> library.so.1 - if [ "${file%.*.*}" != *.so ] - then - ln -v -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*.*}) - fi + mv -v ${opts} ${source} ${BINDIR}/${dest} || die } -# mark directoris undeletable +# mark directories undeletable mkeepdir() { local keepdir @@ -533,7 +587,7 @@ # recursive if [[ $1 = -r ]] || [[ $1 = -R ]] then - local recursive="--recursive" + local recursive="-R" local owner="$2" local path="$3" fi @@ -553,7 +607,7 @@ # recursive if [[ $1 = -r ]] || [[ $1 = -R ]] then - local recursive="--recursive" + local recursive="-R" local posix="$2" local path="$3" fi @@ -568,9 +622,78 @@ { 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 +} + +mfilterflag() +{ + local type="$1" + local flag="$2" + local var + + for var in $(eval echo \${${type}}) + do + case "${var}" in + ${flag}) continue;; + *) echo -n "${var}"' ';; + esac + done + echo +} + +maddflag() +{ + local type="$1" + local flag="$2" + echo "$(eval echo \${${type}}) ${flag}" }