# # $Id: install.in,v 1.23 2004/05/13 18:24:36 jmmv Exp $ # Generic install functions. # # buildtool # Copyright (c) 2003, 2004 Julio M. Merino Vidal. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # 3. Neither the name of the author nor the names of contributors may # be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # btown_install_parse_args() { local group mode owner group="${1}"; mode="${2}"; owner="${3}"; shift 3 while [ $# -gt 0 ]; do case ${1} in -g) group=${2}; shift ;; -m) mode=${2}; shift ;; -o) owner=${2}; shift ;; *) if echo ${1} | grep '^-' >/dev/null; then btcmn_err "install: unknown option \`${1}'" else break fi ;; esac shift done echo ${group} ${mode} ${owner} $* } btown_install_files() { local dir f msg srcs target msg=${1}; shift if [ $# -eq 2 ]; then if [ -d ${BT_DESTDIR}${2} ]; then target=${BT_DESTDIR}${2}/${1##*/} else target=${BT_DESTDIR}${2} fi echo "[install] installing ${msg} file ${target}" cp -f ${1} ${target} || bt_die chmod ${mode} ${target} || bt_die if [ ${owner} != DEFAULT ]; then chown ${owner} ${target} || bt_die fi if [ ${group} != DEFAULT ]; then chgrp ${group} ${target} || bt_die fi else srcs= while [ $# -gt 1 ]; do srcs+=${1} shift done dir="${BT_DESTDIR}${1}" [ ! -d "${dir}" ] && \ btcmn_err "install: last argument must be a directory" for f in ${srcs}; do target=${dir}/${f##*/} echo "[install] installing ${msg} file ${target}" cp -f ${f} ${target} || bt_die chmod ${mode} ${target} || bt_die if [ ${owner} != DEFAULT ]; then chown ${owner} ${target} || bt_die fi if [ ${group} != DEFAULT ]; then chgrp ${group} ${target} || bt_die fi done fi } bt_install_bin() { local group mode owner set -- $(btown_install_parse_args ${BT_BIN_GROUP} ${BT_BIN_MODE} \ ${BT_BIN_OWNER} $*) group="${1}"; mode="${2}"; owner="${3}"; shift 3 btown_install_files binary $* } bt_install_data() { local group mode owner set -- $(btown_install_parse_args ${BT_DATA_GROUP} ${BT_DATA_MODE} \ ${BT_DATA_OWNER} $*) group="${1}"; mode="${2}"; owner="${3}"; shift 3 btown_install_files data $* } bt_install_dir() { local dir group mode owner set -- $(btown_install_parse_args ${BT_DIR_GROUP} ${BT_DIR_MODE} \ ${BT_DIR_OWNER} $*) group="${1}"; mode="${2}"; owner="${3}"; shift 3 while [ $# -gt 0 ]; do dir=${BT_DESTDIR}${1} if [ ! -d ${dir} ]; then echo "[install] creating missing directory ${dir}" mkdir -p ${dir} || bt_die chmod ${mode} ${dir} || bt_die if [ ${owner} != DEFAULT ]; then chown ${owner} ${dir} || bt_die fi if [ ${group} != DEFAULT ]; then chgrp ${group} ${dir} || bt_die fi fi shift done } bt_install_symlink() { bt_exec ln -fs $* || bt_die } # Local Variables: *** # mode: shell-script *** # End: *** # vim: syntax=sh