Skip to content

prun: Add ptype and pman #19

Merged
merged 1 commit into from
Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ install_data nvidiactl/nvidia.service "$DESTDIR$systemdunitdir/nvidi
install_exec pdist/pdist "$DESTDIR$usrlocal_bindir/pdist"
install_exec pmirror/pmirror "$DESTDIR$usrlocal_bindir/pmirror"
install_exec prun/prun "$DESTDIR$usr_bindir/prun"
install_exec prun/ptype "$DESTDIR$usr_bindir/ptype"
install_exec prun/pman "$DESTDIR$usr_bindir/pman"
install_exec put_websafe/put_websafe "$DESTDIR$usrlocal_bindir/put_websafe"
install_exec switch-passwd/switch-passwd "$DESTDIR$root_sbindir/switch-passwd"
install_data switch-passwd/switch-passwd.service "$DESTDIR$systemdunitdir/switch-passwd.service"
Expand Down
79 changes: 79 additions & 0 deletions prun/pman
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#! /bin/bash

# pman: a package aware variant of the 'man' command

function nop() { :; } # does nothing

function exec_help() {
cat <<__HELP

usage:

pman [man options...] name

The given NAME is tested if it relates to a 'pwrap' binary,
if so, the path is set and 'man NAME' is tried.

environment honored:

PMAN_VERBOSE

__HELP
exit
}


PMAN_DEBUG=${PMAN_DEBUG:-''}
PMAN_VERBOSE=${PMAN_VERBOSE:-''}
ROOT="$PMAN_DEBUG/usr/local/package"
CFG="$ROOT/admin/config"

if [ -z "$1" ] ; then
exec_help
fi

SHOW=nop

if [ -n "$PMAN_VERBOSE" ] ; then
SHOW=echo
fi

# last arg
QUERY=${@: -1}

PWRAPBIN=`type -p $QUERY`

# expect wrappers only in /usr/local/package/bin
if [[ -n "$PWRAPBIN" && $PWRAPBIN =~ ^${ROOT}/bin ]] ; then

# extract 'FooBar' out of '. /usr/local/package/lib/FooBar.profile'
PACKAGE=`sed -n -e '/^\.\s*\/usr/ s,^.*lib/\(.*\).profile$,\1,p' $PWRAPBIN`

$SHOW "# package: '$PACKAGE'"

if [ -n "$PACKAGE" ] ; then

if [ -f "${ROOT}/lib/${PACKAGE}.profile" ] ; then
BN=`basename $PWRAPBIN`
source "${ROOT}/lib/${PACKAGE}.profile"

# wrappers might still exist, but not the packagedirs
PATH_ADD=`echo $PATH | cut -f1 -d:`
$SHOW "# path: '$PATH'"
[ -n "$PATH_ADD" -a -d $PATH_ADD ] || echo "# Note: directory '$PATH_ADD' is missing."

# ANSWER=`type -p $BN`
# echo "$QUERY is $ANSWER (${ROOT}/lib/${PACKAGE}.profile)";
exec man "$@"
else
echo "# Error: Profile missing: ${ROOT}/lib/${PACKAGE}.profile"
fi
else
# take former output
echo "$QUERY is $PWRAPBIN (no package wrapper found)"
fi
fi

# try it anyway
man "$@"

86 changes: 86 additions & 0 deletions prun/ptype
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#! /bin/bash

# ptype: a package aware variant of the 'type' command

function nop() { :; } # does nothing

function exec_help() {
cat <<__HELP

usage:

ptype name [name ...]

Each NAME is tested if it is a 'pwrap' binary,
if so, the real binary is shown, otherwise you
get the regular type output.

environment honored:

PTYPE_VERBOSE

__HELP
exit
}


PTYPE_DEBUG=${PTYPE_DEBUG:-''} # || '/dev/shm/makebintest';
PTYPE_VERBOSE=${PTYPE_VERBOSE:-''}
ROOT="$PTYPE_DEBUG/usr/local/package"
CFG="$ROOT/admin/config"

if [ -z "$1" ] ; then
exec_help
fi

SHOW=nop

if [ -n "$PTYPE_VERBOSE" ] ; then
SHOW=echo
fi

while [ -n "$1" ] ; do
QUERY=$1; shift

PWRAPBIN=`type -p $QUERY`
# PWRAPBIN=`which $QUERY` # alternative ?

# expect wrappers only in /usr/local/package/bin
if [ -n "$PWRAPBIN" ] ; then
if [[ $PWRAPBIN =~ ^${ROOT}/bin ]] ; then

# extract 'FooBar' out of '. /usr/local/package/lib/FooBar.profile'
PACKAGE=`sed -n -e '/^\.\s*\/usr/ s,^.*lib/\(.*\).profile$,\1,p' $PWRAPBIN`

$SHOW "# package: '$PACKAGE'"

if [ -n "$PACKAGE" ] ; then

if [ -f "${ROOT}/lib/${PACKAGE}.profile" ] ; then
(
BN=`basename $PWRAPBIN`
source "${ROOT}/lib/${PACKAGE}.profile"

# wrappers might still exist, but not the packagedirs
PATH_ADD=`echo $PATH | cut -f1 -d:`
$SHOW "# path: '$PATH'"
[ -n "$PATH_ADD" -a -d $PATH_ADD ] || echo "# Note: directory '$PATH_ADD' is missing."

ANSWER=`type -p $BN`
echo "$QUERY is $ANSWER (${ROOT}/lib/${PACKAGE}.profile)";
)
else
echo "# Error: Profile missing: ${ROOT}/lib/${PACKAGE}.profile"
fi
else
# take former output
echo "$QUERY is $PWRAPBIN (no package wrapper found)"
fi
else
echo "$QUERY is $PWRAPBIN (not in package path)"
fi
else
echo "ptype: $QUERY: not found";
fi
done