4
\$\begingroup\$

Let me be the first one to post a Gentoo ebuild for review, as suggested by this meta post answer and comments. See also the corresponding issue on Gentoo Bugzilla.

The ebuild installs proprietary PPDs and Cups filter for Kyocera 1x2x MPF printers, it works on my machine. (Unfortunately, I can only test a single model, not all of them.)

# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

EAPI=6

DESCRIPTION="Printer descriptions (PPDs) and filters for Kyocera 1x2x MFP"
HOMEPAGE="http://www.kyoceramita.it/"
SRC_URI="LinuxDrv_${PV}_FS-1x2xMFP.zip"

LICENSE="kyocera-mita-ppds"
SLOT="0"

# TODO: Someone please test the ebuild on ~x86.
KEYWORDS="-* ~amd64 ~x86"

IUSE_LINGUAS=(ar cs de el en es fr he hu it ko pl pt ro ru th tr vi zh_CN zh_TW)
IUSE="+rastertokpsl-fix ${IUSE_LINGUAS[@]/#/linguas_}"
REQUIRED_USE="|| ( ${IUSE_LINGUAS[@]/#/linguas_} )"

RDEPEND="net-print/cups"
DEPEND="app-arch/unzip"
RESTRICT="fetch"

S="${WORKDIR}/Linux"

function archSubdirectory {
    if use x86 && ! use amd64
    then echo "32bit"
    else echo "64bit" ; fi
}

function languageArchiveName {
    # Note the capitalisation inconsistency. Don't "fix" that.
    case "$1" in
        ar)    echo arabic      ;;
        cs)    echo czech       ;;
        de)    echo German      ;;
        el)    echo greek       ;;
        en)    echo English     ;;
        es)    echo Spanish     ;;
        fr)    echo French      ;;
        he)    echo hebrew      ;;
        hu)    echo hungarian   ;;
        it)    echo Italian     ;;
        ko)    echo Korean      ;;
        pl)    echo polish      ;;
        pt)    echo Portuguese  ;;
        ro)    echo romanian    ;;
        ru)    echo russian     ;;
        th)    echo thai        ;;
        tr)    echo turkish     ;;
        vi)    echo vietnamese  ;;
        zh_CN) echo simplified  ;;
        zh_TW) echo traditional ;;
    esac
}

pkg_nofetch() {
    einfo "Please, navigate your browser to the following URL and manually"
    einfo "download the file named '$A', then put it into '$DISTDIR'."
    einfo "http://www.kyoceradocumentsolutions.eu/index/service/dlc.false.driver.FS1025MFP._.EN.html"
    einfo ""
    einfo "Consider keeping a local copy of the file since there're chances"
    einfo "the company is going to eventually stop hosting it for whatever"
    einfo "reason."
}

src_prepare() {
    eapply_user

    function patchFilterPath {
        local orig="/usr/lib/cups/filter/rastertokpsl"
        local repl="/usr/libexec/cups/filter/rastertokpsl"
        use rastertokpsl-fix &&
            repl="${repl}-fix.sh"

        sed -i "s|$orig|$repl|g" "$@"
    }

    local g="$S/$(archSubdirectory)/Global"
    local lingua
    for lingua in "${IUSE_LINGUAS[@]}"; do
        use linguas_$lingua || continue

        local language="$(languageArchiveName "$lingua")"

        unpack "$g/$language.tar.gz"
        patchFilterPath "$language"/Kyocera*.ppd

        # The upstream contains a number of files named 'rastertokpsl',
        # each having the same content.
        mv --no-clobber "$language/rastertokpsl" "$S/rastertokpsl"
    done

    if use rastertokpsl-fix; then
        cp "$FILESDIR"/rastertokpsl-fix.sh .
    fi
}

src_install() {

    function installWithLinguaSuffix {
        local lingua="$1"; shift
        for file in "$@"; do
            local dn="$(dirname "$file")"
            local bn="$(basename "$file" .ppd)"
            newins "$dn/$bn.ppd" "${bn}_$lingua.ppd"
        done
    }

    insinto /usr/share/cups/model/KyoceraMita
    local lingua
    for lingua in "${IUSE_LINGUAS[@]}"; do
        use linguas_$lingua || continue

        local language="$(languageArchiveName "$lingua")"
        installWithLinguaSuffix "$lingua" \
            "$language"/Kyocera*.ppd
    done

    exeinto /usr/libexec/cups/filter
    doexe rastertokpsl
    use rastertokpsl-fix &&
        doexe rastertokpsl-fix.sh

    dodoc "Readme.htm"

    einfo "This packages installs Kyocera's 'Readme.htm' file (see package"
    einfo "documentation directory) which lists several common problems and"
    einfo "workarounds. You might want to have a look on it."
}

Please, tell me about anything you find wrong or suspicious in regard to both bash scripting or established Gentoo practices. However, I would be grateful if you answer some of the below (metaphysical) questions:

  1. Is someone interested in this ebuild being in the main tree? Does somebody else uses these buggy printers? (opinion based)
  2. Did I choose the correct name for the package? Are PPDs, technically, "drivers"?
  3. Is it okay to use IUSE_LINGUAS as a list, not a string?
  4. How should I deal with the situation when user have no LINGUAS set, or their language are not supported by the upstream package?
  5. I used function blah { syntax instead blah() { for may helper functions (not build phases, though). Is it acceptable?
  6. Is it okay to declare top-level functions at all?
  7. Should I put the wrapper script rastertokpsl-fix.sh into files/, or just create it during src_prepare with echo?
\$\endgroup\$
  • \$\begingroup\$ I don't know much about make, however you've stylized the code in the question as bash. Is this by any chance a bash script rather than a make script? \$\endgroup\$ – Peilonrayz Aug 14 '17 at 10:16
  • \$\begingroup\$ @Peilonrayz: makefile was the closest tag I was able to find. Changed it to newly created ebuild tag. \$\endgroup\$ – firegurafiku Aug 14 '17 at 10:50
1
\$\begingroup\$

I can only comment on the Bash part.

  1. Is it okay to use IUSE_LINGUAS as a list, not a string?

You mean array. The answer will come down to whether it's ok to use Bash. Arrays have been supported in Bash for a very long time, only obsolete systems would use such version that doesn't support arrays.

  1. I used function blah { syntax instead blah() { for may helper functions (not build phases, though). Is it acceptable?

The script has a mixture of both styles. That's clearly not good. It would be better to stick to one style consistently. The blah() { is recommended in Bash.

You can safely replace this:

for file in "$@"; do

With the simpler:

for file; do

Because "$@" is the default value used by for in loops.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.