aboutsummaryrefslogtreecommitdiff
path: root/paludis/repositories/e/ebuild/utils/dohtml
blob: 6733e6e549065f5dc3e64c5b9bec19c2901da0e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/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

allowed_exts="png gif html htm jpg css jps"
disallowed_dirs=""
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/${PF}/${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} ]] &&
            ! has "${bn}" ${disallowed_dirs}; then
        for f in ${path}/*; do
            pfx=${bn}
            [[ -n ${prefix} ]] && pfx="${prefix}/${pfx}"
            install_file "$(basename "${f}")" "${dn}" "${pfx}"
            (( ret += $? ))
        done
    else
        (( ++ret ))
    fi
    return ${ret}
}

parse_args "$@"

retval=0
for i in "${args[@]}"; do
    install_file "$(basename "${i}")" "$(dirname "${i}")"
    (( retval += $? ))
done

exit $retval