--- smage/trunk/include/mtools.sminc 2011/08/29 20:03:18 2792 +++ smage/trunk/include/mtools.sminc 2012/07/09 17:43:04 3577 @@ -150,6 +150,7 @@ { local udevrule local file + local udevrulesddir="/usr/lib/udev/rules.d" [[ -z "$1" ]] && die "No udev rule given" @@ -169,16 +170,17 @@ 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" @@ -198,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() @@ -468,7 +470,7 @@ # installs logrotate configuration files -# minstallpam /path/to/logrotatefile {destfilename} +# minstalllog /path/to/logrotatefile {destfilename} minstalllog() { local logfile @@ -636,7 +638,7 @@ # recursive if [[ $1 = -r ]] || [[ $1 = -R ]] then - opts="--recursive" + opts="-R" source="$2" dest="$3" fi @@ -644,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 @@ -655,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" @@ -664,7 +698,7 @@ # force if [[ $1 = -f ]] then - opts="--force" + opts="-f" source="$2" dest="$3" fi @@ -710,7 +744,7 @@ # recursive if [[ $1 = -r ]] || [[ $1 = -R ]] then - local recursive="--recursive" + local recursive="-R" local owner="$2" local path="$3" fi @@ -730,7 +764,7 @@ # recursive if [[ $1 = -r ]] || [[ $1 = -R ]] then - local recursive="--recursive" + local recursive="-R" local posix="$2" local path="$3" fi @@ -755,3 +789,108 @@ 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 +}