#!/bin/sh
#
# $Id$
#
# Copyright 2019-2020, Juniper Networks, Inc
# All Rights Reserved
#

VERIEXEC=/sbin/veriexec

if ! type is_verified > /dev/null 2>&1; then
    # we'll override this below if appropriate
    is_verified() { return 0; }

    if test -s $VERIEXEC; then
        if $VERIEXEC -i active > /dev/null 2>&1; then
            is_verified() { $VERIEXEC -x $1; }
        fi
    fi
fi

# avoid multiple inclusion and duplicate effort
_VDOT_SH=:

# current state of O_VERIFY
o_verify() {
    set -o | sed -n '/^verify/s,.*[[:space:]],,p'
}

# check if set -o verify is supported
case `o_verify` in
"") skip_o_verify=: ;;
*) skip_o_verify= ;;
esac

##
# o_verify_set want [save]
#
# record current state of verify in $save
# and set it to $want if different
#
o_verify_set() {
    local x=`$skip_o_verify o_verify`

    test -z "$x" && return 0
    test -z "$2" || eval $2=$x
    test "$x" = "$1" && return 0
    case "$1" in
    on) set -o verify;;
    off) set +o verify;;
    esac
}

# in case we want to avoid repeats
dotted=
# try not to include things we cannot verify
vdot() {
    local f rc=0 verify

    o_verify_set on verify
    for f in "$@"
    do
        test -f $f -a -s $f || continue
        if is_verified $f 2> /dev/null; then
            dotted="$dotted $f"
	    . $f
        else
            rc=80               # EAUTH
        fi
    done
    o_verify_set $verify
    return $rc
}

vdot_once() {
    local f rc=0

    for f in "$@"
    do
        case " $dotted " in
        *" $f "*) continue;;
        esac
        vdot $f || rc=$?
    done
    return $rc
}

# for unverified things
dot() {
    local f verify

    o_verify_set off verify
    for f in "$@"
    do
        if test -f $f -a -s $f; then
            dotted="$dotted $f"
            . $f
        fi
    done
    o_verify_set $verify
}

dot_once() {
    local f

    for f in "$@"
    do
        case " $dotted " in
        *" $f "*) continue;;
        esac
        dot $f
    done
}

# unit test
case "/$0" in
*/vdot*) vdot "$@";;
esac
#!/bin/sh
#
# Copyright (c) 2019-2024, Juniper Networks, Inc.
# All rights reserved.
#

# facilitate testing
PKGTOOLS=${PKGTOOLS:-/usr/libexec}
PKGSMNT=${PKGSMNT:-$PKGROOT/mnt}

vdot $PKGDIR/scripts/pkg_funcs.sh
get_features ${PKGSETS:-/packages/sets}/${PKGSET:-active}/os-runtime
if test -z "$feature_xml_output_e"; then
    # os-runtime has xml-output without -E
    # we need to tweak the version of package we use
    make_symlink /packages/mnt/$PKG_BASENAME/usr/libexec/ui/packagexf /usr/libexec/ui/package
fi
if test -c /dev/gpt/disktest; then
    # ensure this is not in /etc/fstab
    if egrep -q '/dev/gpt/(disktest|p[0-9])' /etc/fstab; then
	sed -i "" -e '/gpt.disktest/d' -e '/gpt.p[0-9][[:space:]]/d' /etc/fstab 2> /dev/null
    fi
fi
