# $Id$ # some special build tools # get the pname right with split-packages mpname() { local pname="${PNAME}" [[ ! -z ${SPLIT_PACKAGE_BASE} ]] && pname="${SPLIT_PACKAGE_BASE}" echo "${pname}" } # installs environment files # minstallenv /path/to/envdfile {destfilename} minstallenv() { local envdfile local file [[ -z "$1" ]] && die "No envd 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 envdfile="$2" else envdfile="$(basename ${file})" fi # needed directory install -d ${BINDIR}/etc/env.d || die # install our envfile install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/env.d/${envdfile} || die } # installs system configuration files # minstallconf /path/to/confdfile {destfilename} minstallconf() { local confdfile local file [[ -z "$1" ]] && die "No confd 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 confdfile="$2" else confdfile="$(basename ${file})" fi # needed directory install -d ${BINDIR}/etc/conf.d || die # install our configfile install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/conf.d/${confdfile} || die } # installs system configuration files to etc # minstalletc /path/to/etcfile {destfilename} {destdir path} minstalletc() { local etcfile local file local destdir [[ -z "$1" ]] && die "No etc 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 etcfile="$2" else etcfile="$(basename ${file})" fi if [[ -n "$3" ]] then destdir="$3" else destdir="/etc" fi # needed directory install -d ${BINDIR}/${destdir} || die # install our configfile install -v -m 0644 -o root -g root ${file} ${BINDIR}/${destdir}/${etcfile} || die } # install man files to appropiate dirs # minstallman /path/to/manfile.foo minstallman() { local manfile local mandir local file [[ -z "$@" ]] && die "No man file given" for file in $@ do manfile="$(basename ${file})" mandir="man${manfile##*.}" install -d ${BINDIR}/usr/share/man/${mandir} || die install -v -m0644 ${file} ${BINDIR}/usr/share/man/${mandir}/${manfile} || die done } # install info files to appropiate dirs # minstallinfo /path/to/infofile.foo minstallinfo() { local file [[ -z "$@" ]] && die "No info file given" for file in $@ do install -d ${BINDIR}/usr/share/info || die install -v -m0644 ${file} ${BINDIR}/usr/share/info/$(basename ${file}) || die done } # install html files to appropiate dirs # minstallhtml /path/to/infofile.foo minstallhtml() { local file local subfile local prefix local subprefix # handle prefix case "$1" in --prefix|-p) shift; prefix="$1"; shift ;; esac [[ -z "$@" ]] && die "No html file given" for file in $@ do install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/html${prefix} || die if [[ -d ${file} ]] then for subfile in ${file}/* do subprefix="$(dirname ${subfile/$(dirname ${file})/})" subprefix="${prefix}${subprefix}/" minstallhtml --prefix ${subprefix} ${subfile} || die done else install -v -m0644 ${file} ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/html/${prefix}$(basename ${file}) || die fi done } # install pixmaps to appropiate dirs # minstallpixmap srcname destname {/path/to} minstallpixmap() { local file local destdir local destfile [[ -z "$1" ]] && die "No pixmap 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 destfile="$2" else destfile="$(basename ${file})" fi if [[ -n "$3" ]] then destdir="$3" else destdir="/usr/share/pixmaps" fi # needed directory install -d ${BINDIR}/${destdir} || die # install our pixmap install -v -m 0644 -o root -g root ${file} ${BINDIR}/${destdir}/${destfile} || die } # installs pam configuration files # minstallpam /path/to/pamfile {destfilename} minstallpam() { local pamfile local file [[ -z "$1" ]] && die "No pam 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 pamfile="$2" else pamfile="$(basename ${file})" fi # needed directory install -d ${BINDIR}/etc/pam.d || die # install our configfile install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/pam.d/${pamfile} || die } # installs cronjobs # minstallcron [hourly|daily|weekly|monthly] /path/to/cronfile {destfilename} minstallcron() { local cronfile local loop local file [[ -z "$1" ]] && die "No loop rythem given [hourly|daily|weekly|monthly]" [[ -z "$2" ]] && die "No cronfile given" loop="$1" # if no fullpath given use file from sourcedir if [[ -z $(dirname $2) ]] || [[ $(dirname $2) = . ]] then file="${SOURCEDIR}/$(mpname)/$2" else file="$2" fi if [[ -n "$3" ]] then cronfile="$3" else cronfile="$(basename ${file})" fi # needed directory install -m0750 -d ${BINDIR}/etc/cron.${loop} || die # install our cronfile install -v -m 0750 -o root -g root ${file} ${BINDIR}/etc/cron.${loop}/${cronfile} || die } # installs logrotate configuration files # minstalllog /path/to/logrotatefile {destfilename} minstalllog() { local logfile local file [[ -z "$1" ]] && die "No logrotate 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 logfile="$2" else logfile="$(basename ${file})" fi # needed directory install -d ${BINDIR}/etc/logrotate.d || die # install our configfile 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() { 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 } # 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" if [[ $1 = -s ]] then 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 # 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 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 # 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}" # 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 opts="-f" dest="$2" fi # 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 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 directories undeletable mkeepdir() { local keepdir [[ -z "$1" ]] && die "No directory given" keepdir="$1" install -v -d ${BINDIR}/${keepdir} || die touch ${BINDIR}/${keepdir}/.keep || die } # creates empty files memptyfile() { local file local path [[ -z "$1" ]] && die "No file given" file="$1" path="$(dirname ${file})" install -d ${BINDIR}/${path} || die touch ${BINDIR}/${file} || die } mchown() { local owner="$1" local path="$2" local recursive # recursive if [[ $1 = -r ]] || [[ $1 = -R ]] then local recursive="-R" local owner="$2" local path="$3" fi [[ -z ${owner} ]] && die "No owner given." [[ -z ${path} ]] && die "No path given." chown -v ${recursive} ${owner} ${BINDIR}/${path} || die } mchmod() { local posix="$1" local path="$2" local recursive # recursive if [[ $1 = -r ]] || [[ $1 = -R ]] then local recursive="-R" local posix="$2" local path="$3" fi [[ -z ${posix} ]] && die "No posix given." [[ -z ${path} ]] && die "No path given." chmod -v ${recursive} ${posix} ${BINDIR}/${path} || die } mlink() { 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 ${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 }