--- trunk/core/include/mtools.sminc 2009/04/22 18:57:15 1113 +++ branches/magellan-next/include/mtools.sminc 2012/01/13 19:21:26 9862 @@ -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 @@ -137,6 +146,151 @@ install -v -m 0644 -o root -g root ${file} ${BINDIR}/${destdir}/${etcfile} || die } +minstalludevrule() +{ + 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}/$(mpname)/$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 udev rule + install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/udev/rules.d/${udevrule} || die +} + +minstalludevhelper() +{ + local udevhelper + local file + + [[ -z "$1" ]] && die "No udev helper 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 + udevhelper="$2" + else + udevhelper="$(basename ${file})" + fi + + # needed directory + install -d ${BINDIR}/lib/udev || die + + # install our udev-helper + install -v -m 0755 -o root -g root ${file} ${BINDIR}/lib/udev/${udevhelper} || die +} + +minstallhalinformation() +{ + local halrule + local file + + [[ -z "$1" ]] && die "No hal rule 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 + halrule="$2" + else + halrule="$(basename ${file})" + fi + + # needed directory + install -d ${BINDIR}/usr/share/hal/fdi/information/20thirdparty || die + + # install our udev rule + install -v -m 0644 -o root -g root ${file} ${BINDIR}/usr/share/hal/fdi/information/20thirdparty/${halrule} || die +} + +minstallhalpolicy() +{ + local halrule + local file + + [[ -z "$1" ]] && die "No hal rule 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 + halrule="$2" + else + halrule="$(basename ${file})" + fi + + # needed directory + install -d ${BINDIR}/usr/share/hal/fdi/policy/20thirdparty || die + + # install our udev rule + install -v -m 0644 -o root -g root ${file} ${BINDIR}/usr/share/hal/fdi/policy/20thirdparty/${halrule} || die +} + +minstallhalpreprobe() +{ + local halrule + local file + + [[ -z "$1" ]] && die "No hal rule 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 + halrule="$2" + else + halrule="$(basename ${file})" + fi + + # needed directory + install -d ${BINDIR}/usr/share/hal/fdi/preprobe/10osvendor || die + + # install our udev rule + install -v -m 0644 -o root -g root ${file} ${BINDIR}/usr/share/hal/fdi/preprobe/10osvendor/${halrule} || die +} + # install man files to appropiate dirs # minstallman /path/to/manfile.foo minstallman() @@ -220,7 +374,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 +412,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 +447,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 +468,7 @@ # installs logrotate configuration files -# minstallpam /path/to/logrotatefile {destfilename} +# minstalllog /path/to/logrotatefile {destfilename} minstalllog() { local logfile @@ -325,7 +479,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 +526,7 @@ if [[ $1 = -s ]] then - file="${SOURCEDIR}/${PNAME}/$2" + file="${SOURCEDIR}/$(mpname)/$2" dest="$3" if [[ -z $3 ]] then @@ -404,7 +558,7 @@ if [[ $1 = -s ]] then - file="${SOURCEDIR}/${PNAME}/$2" + file="${SOURCEDIR}/$(mpname)/$2" dest="$3" if [[ -z $3 ]] then @@ -431,12 +585,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 @@ -460,16 +618,71 @@ # 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 } -# mark directoris undeletable +mcopy() +{ + local source="$1" + local dest="$2" + local opts + + # recursive + if [[ $1 = -r ]] || [[ $1 = -R ]] + then + opts="--recursive" + source="$2" + dest="$3" + fi + + # recursive + if [[ $1 = -rf ]] || [[ $1 = -fr ]] || [[ $1 = -Rf ]] || [[ $1 = -fR ]] + then + opts="--recursive --force" + source="$2" + dest="$3" + fi + + if [[ $1 = -a ]] + then + opts="--archive" + source="$2" + dest="$3" + fi + + [[ -z ${source} ]] && die "No source given." + [[ -z ${dest} ]] && die "No dest given." + + cp -v ${opts} ${source} ${BINDIR}/${dest} || die +} + +mmove() +{ + local source="$1" + local dest="$2" + local opts + + # force + if [[ $1 = -f ]] + then + opts="--force" + 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 directories undeletable mkeepdir() { local keepdir @@ -539,9 +752,117 @@ { 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 + + [[ -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}/lib/systemd/system || die + + # install our initscript + install -v -m 0644 -o root -g root ${file} ${BINDIR}/lib/systemd/system/${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 }