139 lines
3.8 KiB
Bash
Executable File
139 lines
3.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# vim: set sw=4 sts=4 et :
|
|
|
|
# Copyright (c) 2006 Stephen Bennett
|
|
#
|
|
# Based in part upon dohtml from Portage, which is Copyright 1995-2005
|
|
# Gentoo Foundation and distributed under the terms of the GNU General
|
|
# Public License v2.
|
|
#
|
|
# This file is part of the Paludis package manager. Paludis is free software;
|
|
# you can redistribute it and/or modify it under the terms of the GNU General
|
|
# Public License as published by the Free Software Foundation; either version
|
|
# 2 of the License, or (at your option) any later version.
|
|
#
|
|
# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
# details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License along with
|
|
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
# Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
source ${PALUDIS_EBUILD_DIR}/0/list_functions.bash
|
|
|
|
if [[ ! -d ${!PALUDIS_IMAGE_DIR_VAR} ]]; then
|
|
echo "${0}: \${${PALUDIS_IMAGE_DIR_VAR}} not valid; aborting" >&2
|
|
exit 247
|
|
fi
|
|
|
|
shopt -s dotglob
|
|
|
|
allowed_exts="css gif htm html jpeg jpg js png"
|
|
disallowed_dirs="CVS"
|
|
allowed_files=""
|
|
recurse=0
|
|
doc_prefix=""
|
|
args=( )
|
|
|
|
split_names() {
|
|
list=$1
|
|
if [[ ${list} == *,* ]]; then
|
|
echo -n "${list%%,*} "
|
|
split_names ${list#*,}
|
|
else
|
|
echo ${list}
|
|
fi
|
|
}
|
|
|
|
parse_args() {
|
|
while [[ ${#} -gt 0 ]]; do
|
|
case $1 in
|
|
-r)
|
|
recurse=1 ;;
|
|
-V)
|
|
verbose=1 ;;
|
|
-A)
|
|
allowed_exts="${allowed_exts} $(split_names $2)"
|
|
shift
|
|
;;
|
|
-a)
|
|
allowed_exts="$(split_names $2)"
|
|
shift
|
|
;;
|
|
-f)
|
|
allowed_files="$(split_names $2)"
|
|
shift
|
|
;;
|
|
-x)
|
|
disallowed_dirs="$(split_names $2)"
|
|
shift
|
|
;;
|
|
-p)
|
|
doc_prefix="$2"
|
|
shift
|
|
;;
|
|
*/)
|
|
args=( "${args[@]}" "$1"* );;
|
|
*)
|
|
args=( "${args[@]}" "$1" ) ;;
|
|
esac
|
|
shift
|
|
done
|
|
}
|
|
|
|
install_file() {
|
|
local bn=${1}
|
|
local dn=${2}
|
|
local prefix=${3}
|
|
local ret=0
|
|
|
|
path=${bn}
|
|
[[ -n ${prefix} ]] && path="${prefix}/${path}"
|
|
[[ -n ${dn} ]] && path="${dn}/${path}"
|
|
|
|
[[ -z ${DOCDESTTREE} ]] && DOCDESTTREE="html"
|
|
|
|
dir="${!PALUDIS_IMAGE_DIR_VAR}usr/share/doc/${!PALUDIS_NAME_VERSION_REVISION_VAR}/${DOCDESTTREE}/${doc_prefix}/${prefix}"
|
|
|
|
if [[ -f ${path} ]]; then
|
|
ext="$(basename ${path})"
|
|
ext="${ext##*.}"
|
|
if ([[ -n ${ext} ]] && has $ext $allowed_exts) || has $bn $allowed_files
|
|
then
|
|
[[ ! -d ${dir} ]] && install -d "${dir}"
|
|
echo "install -m0644 ${path} ${dir}"
|
|
install -m0644 "${path}" "${dir}/${bn}"
|
|
fi
|
|
elif [[ $recurse == 1 && -d ${path} ]]; then
|
|
if ! has "${bn}" ${disallowed_dirs}; then
|
|
for f in ${path}/*; do
|
|
[[ -e ${f} ]] || continue
|
|
pfx=${bn}
|
|
[[ -n ${prefix} ]] && pfx="${prefix}/${pfx}"
|
|
install_file "$(basename "${f}")" "${dn}" "${pfx}"
|
|
(( ret |= $? ))
|
|
done
|
|
fi
|
|
else
|
|
if [[ -d "${path}" ]] ; then
|
|
echo "!!! Directory '${path}' encountered, but -r not specified"
|
|
else
|
|
echo "!!! Don't know what to do with '${path}'"
|
|
fi
|
|
(( ret |= 1 ))
|
|
fi
|
|
return ${ret}
|
|
}
|
|
|
|
parse_args "$@"
|
|
|
|
retval=0
|
|
for i in "${args[@]}"; do
|
|
install_file "$(basename "${i}")" "$(dirname "${i}")"
|
|
(( retval += $? ))
|
|
done
|
|
|
|
exit $retval
|