Joshua Kinard wrote:
> Basically what I am suggesting is finding a sane way to politely tell users
> who set INSTALL_MASK locally that specific to systemd/udev packages, they
> risk breaking their system if using it or migrating to it.  Optionally,
> telling them the same thing if they install a package that also installs
> unit files.
> 
> TBH, expanding on the idea, it doesn't even have to be specific to
> systemd/udev, but a generic framework that can be used by ebuilds to warn
> the user of invalid configurations that could render a system package (or
> their system) unusable unless they change their configuration.
> 
> This still leaves the power in the hands of the user to configure things how
> they want (E.g., setting INSTALL_MASK).  It also allows us devs to avoid
> adding another variable into an already complex equation (having to decide
> on INSTALL_MASK_ORDER settings for all archs/profiles).  Package maintainers
> are free to check for known problematic settings in make.conf or the envvars
> and warn the user appropriately in their packages.  If the user chooses to
> proceed anyways, well, they were warned...
> 
> W/o grepping the tree, I wouldn't be surprised if some ebuilds already do
> this in some form.  Basic grep on make.conf, ewarn or eerror if a problem
> setting is discovered.  Setup some function in eutils instead to do this:
> 
> echeck_var_warn("INSTALL_MASK", "/usr/lib/systemd")
> echeck_var_error("INSTALL_MASK", "/usr/lib/systemd")
> 
> Etc...
> 
> Brainstorming.  If the idea is silly or nonsensical, well, then someone
> propose something better.

No, it makes a lot of sense. Though you don't use parentheses or commas
in bash ;)

I'd use something like:
# echeck_warn -s : INSTALL_MASK /usr/lib/systemd
echeck_warn(){
        echeck_var warn "$@"
}

echeck_error(){
        echeck_var error "$@"
}

echeck_var(){
        local v n i f x r=0 s=' '
        case $1 in
        warn) f=ewarn
;;      error) f=eerror
;;      *) die "bad use of: '$FUNCNAME $*'"
        esac
        shift
        [[ $1 = -s ]] && {
                s=$2; shift 2;
                # handle PATH style
                [[ $s = : ]] && x='/*'
        }
        v="$s${!1}$s" || die "bad var: $1"
        n=$1
        shift
        for i; do
                if [[ $v = *"$s$i$s"* ]]; then
                        :
                elif [[ $x ]]; then
                        if [[ $v = *"$s$i$x$s"* ]]; then
                                :
                        elif [[ $i = */ ]] && [[ $v = *"$s$i*$s"* ]]; then
                                :
                        else continue
                        fi
                else continue
                fi
                "$f" "$n contains: '$i'"
                r=1
        done
        if ((r)) && [[ $f = eerror ]]; then
                die "Bad $n"
        else
                return $r
        fi
}

eg:
$ INSTALL_MASK='/lib/udev/*:/usr/lib/systemd/*'
$ echeck_error -s : INSTALL_MASK /lib/udev /usr/lib/systemd/
!! INSTALL_MASK contains: '/lib/udev'
!! INSTALL_MASK contains: '/usr/lib/systemd/'
!! die: Bad INSTALL_MASK

You'd replace literal * in: [[ $v = *"$s$i*$s"* ]] with: ${x#/}
for something more complex. And you might prefer simple return
and use echeck_error .. || die ..
HTH as a start.

Regards,
steveL
-- 
#friendly-coders -- We're friendly, but we're not /that/ friendly ;-)

Reply via email to