--- trunk/core/include/mtools.sminc 2009/12/25 18:32:07 4579 +++ trunk/include/mtools.sminc 2012/06/26 16:15:58 12655 @@ -5,6 +5,15 @@ # this will provide the service management functions INHERITS="${INHERITS} mtools" +# get the pname right with splitpackages +mpname() +{ + local pname="${PNAME}" + [[ ! -z ${SPLIT_PACKAGE_BASE} ]] && pname="${SPLIT_PACKAGE_BASE}" + + echo "${pname}" +} + # installs initscripts # minstallrc /path/to/rc-script {destfilename} minstallrc() @@ -17,7 +26,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 @@ -48,7 +57,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 +88,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 +120,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 @@ -141,13 +150,14 @@ { local udevrule local file + local udevrulesddir="/usr/lib/udev/rules.d" [[ -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" + file="${SOURCEDIR}/$(mpname)/$1" else file="$1" fi @@ -160,23 +170,24 @@ fi # needed directory - install -d ${BINDIR}/etc/udev/rules.d || die + install -d ${BINDIR}${udevrulesddir} || die # install our udev rule - install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/udev/rules.d/${udevrule} || die + install -v -m 0644 -o root -g root ${file} ${BINDIR}${udevrulesddir}/${udevrule} || die } minstalludevhelper() { local udevhelper local file + local udevdir="/usr/lib/udev" [[ -z "$1" ]] && die "No udev helper given" # 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 @@ -189,10 +200,10 @@ fi # needed directory - install -d ${BINDIR}/lib/udev || die + install -d ${BINDIR}${udevdir} || die # install our udev-helper - install -v -m 0755 -o root -g root ${file} ${BINDIR}/lib/udev/${udevhelper} || die + install -v -m 0755 -o root -g root ${file} ${BINDIR}${udevdir}/${udevhelper} || die } minstallhalinformation() @@ -205,7 +216,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 @@ -234,7 +245,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 @@ -263,7 +274,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 @@ -365,7 +376,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 @@ -403,7 +414,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 @@ -438,7 +449,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 @@ -459,7 +470,7 @@ # installs logrotate configuration files -# minstallpam /path/to/logrotatefile {destfilename} +# minstalllog /path/to/logrotatefile {destfilename} minstalllog() { local logfile @@ -470,7 +481,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 @@ -517,7 +528,7 @@ if [[ $1 = -s ]] then - file="${SOURCEDIR}/${PNAME}/$2" + file="${SOURCEDIR}/$(mpname)/$2" dest="$3" if [[ -z $3 ]] then @@ -549,7 +560,7 @@ if [[ $1 = -s ]] then - file="${SOURCEDIR}/${PNAME}/$2" + file="${SOURCEDIR}/$(mpname)/$2" dest="$3" if [[ -z $3 ]] then @@ -576,12 +587,16 @@ { local file local dest + local verbose="-v" + + # check for busybox as it doesn'tz 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 @@ -605,12 +620,12 @@ # 1. - library.so.1.0.0 -> library.so.1.0 if [ "${file%.*}" != *.so ] then - ln -v -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*}) + ln ${verbose} -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%.*.*}) + ln ${verbose} -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*.*}) fi } @@ -623,7 +638,7 @@ # recursive if [[ $1 = -r ]] || [[ $1 = -R ]] then - opts="--recursive" + opts="-R" source="$2" dest="$3" fi @@ -631,7 +646,14 @@ # recursive if [[ $1 = -rf ]] || [[ $1 = -fr ]] || [[ $1 = -Rf ]] || [[ $1 = -fR ]] then - opts="--recursive --force" + opts="-R -f" + source="$2" + dest="$3" + fi + + if [[ $1 = -a ]] + then + opts="-a" source="$2" dest="$3" fi @@ -642,6 +664,31 @@ cp -v ${opts} ${source} ${BINDIR}/${dest} || die } +mdelete() +{ + local dest="$1" + local opts + + # 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" @@ -651,7 +698,7 @@ # force if [[ $1 = -f ]] then - opts="--recursive" + opts="-f" source="$2" dest="$3" fi @@ -697,7 +744,7 @@ # recursive if [[ $1 = -r ]] || [[ $1 = -R ]] then - local recursive="--recursive" + local recursive="-R" local owner="$2" local path="$3" fi @@ -717,7 +764,7 @@ # recursive if [[ $1 = -r ]] || [[ $1 = -R ]] then - local recursive="--recursive" + local recursive="-R" local posix="$2" local path="$3" fi @@ -732,9 +779,118 @@ { 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 +} + +# installs systemd units +# minstallunit /path/to/unit-file {destfilename} +minstallunit() +{ + local unit + local file + local systemdunitdir="/usr/lib/systemd/system" + + [[ -z "$1" ]] && die "No unit given" + + # if no fullpath given use file from sourcedir + if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] + then + file="${SOURCEDIR}/$(mpname)/$1" + else + file="$1" + fi + + if [[ -n "$2" ]] + then + unit="$2" + else + unit="$(basename ${file})" + fi + + # needed directory + install -d ${BINDIR}${prefix}${systemdunitdir} || die + + # install our initscript + install -v -m 0644 -o root -g root ${file} ${BINDIR}${prefix}${systemdunitdir}/${unit} || die +} + +# installs systemd tmp configs to /etc/tmpfiles.d +# minstalltmp /path/to/tmpdfile {destfilename} +minstalltmp() +{ + local tmpdfile + local file + + [[ -z "$1" ]] && die "No tmpd file given" + + # if no fullpath given use file from sourcedir + if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]] + then + file="${SOURCEDIR}/$(mpname)/$1" + else + file="$1" + fi + + if [[ -n "$2" ]] + then + tmpdfile="$2" + else + tmpdfile="$(basename ${file})" + fi + + # needed directory + install -d ${BINDIR}/etc/tmpfiles.d || die + + # install our tmpdfile + install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/tmpfiles.d/${tmpdfile} || 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 }