Switch to src/dist as primary src location of pkg_install.

Adjust the Makefiles to be reachover Makefiles and remove
some unnecessary warning exceptions.

audit-packages.conf is stored redundantly in src/etc, not changed yet.
pkgsrc.7 is also kept in share/man/man7.

Add a comment in lib/nbcompat.h to make the file non-empty.
This commit is contained in:
joerg 2007-07-16 19:57:46 +00:00
parent f6afac53fa
commit 2ccbc1ff9d
5 changed files with 31 additions and 928 deletions

View File

@ -1,6 +1,36 @@
# $NetBSD: Makefile,v 1.2 2003/09/02 07:35:06 jlam Exp $
# $NetBSD: Makefile,v 1.3 2007/07/16 19:57:46 joerg Exp $
SCRIPTS= linkfarm.sh pkg_view.sh
MAN= linkfarm.1 pkg_view.1
.include <bsd.init.mk>
.PATH: ${DIST}/view
SUBST_PATTERNS= \
-e 's|@prefix@|/usr|' \
-e 's|@exec_prefix@|/usr|' \
-e 's|@sbindir@|/usr/sbin|' \
-e 's|@CHMOD@|/bin/chmod|' \
-e 's|@CMP@|/usr/bin/cmp|' \
-e 's|@CP@|/bin/cp|' \
-e 's|@ENV@|/usr/bin/env|' \
-e 's|@FIND@|/usr/bin/find|' \
-e 's|@GREP@|/usr/bin/grep|' \
-e 's|@LN@|/bin/ln|' \
-e 's|@MKDIR@|/bin/mkdir|' \
-e 's|@pax@|/bin/pax|' \
-e 's|@RM@|/bin/rm|' \
-e 's|@RMDIR@|/bin/rmdir|' \
-e 's|@SED@|/usr/bin/sed|' \
-e 's|@SORT@|/usr/bin/sort|' \
-e 's|@TOUCH@|/usr/bin/touch|'
CLEANFILES+= linkfarm.sh pkg_view.sh
linkfarm.sh: ${DIST}/view/linkfarm.sh.in
${TOOL_SED} ${SUBST_PATTERNS} ${DIST}/view/linkfarm.sh.in > ${.TARGET}
pkg_view.sh: ${DIST}/view/pkg_view.sh.in
${TOOL_SED} ${SUBST_PATTERNS} ${DIST}/view/pkg_view.sh.in > ${.TARGET}
.include <bsd.prog.mk>

View File

@ -1,147 +0,0 @@
.\" $NetBSD: linkfarm.1,v 1.6 2003/11/12 13:31:07 grant Exp $
.\"
.\" Copyright (c) 2003 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the NetBSD
.\" Foundation, Inc. and its contributors.
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
.\" contributors may be used to endorse or promote products derived
.\" from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd September 2, 2003
.Dt LINKFARM 1
.Os
.Sh NAME
.Nm linkfarm
.Nd manage symbolic links to package files
.Sh SYNOPSIS
.Nm
.Op Fl cDnRVv
.Op Fl d Ar stowdir
.Op Fl s Ar subdir
.Op Fl t Ar target
.Ar package
.Sh DESCRIPTION
The
.Nm
command is used to manage a "linkfarm", a directory tree of symbolic links in
.Ar target
to the files in the
.Ar package
sub-directory of
.Ar stowdir .
The default action is to create a linkfarm to a package.
.Pp
The following command-line options are supported:
.Bl -tag -width indent
.It Fl c
Check whether a package contains a linkfarm in
.Ar target .
If
.Ar package
has no symbolic links in
.Ar target
that correspond to its files, then return 0, otherwise return 1.
.It Fl D
Delete the linkfarm for
.Ar package .
.It Fl d Ar stowdir
Set
.Ar stowdir
as the directory in which
.Ar package
can be found.
The default
.Ar stowdir
is the
.Pa packages
sub-directory in the default
.Ar target
directory.
.It Fl n
Don't actually execute the commands for removing and creating the symbolic
links and directories.
.It Fl R
Delete and re-create the linkfarm for
.Ar package .
.It Fl s Ar subdir
The root of the package hierarchy for the linkfarm is the
.Ar subdir
sub-directory in the package.
By default, assume the root of the package hierarchy is simply the
.Ar package
directory.
.It Fl t Ar target
Set
.Ar target
as the directory in which to create and delete the linkfarm for
.Ar package .
The default
.Ar target
directory is
.Pa /usr/pkg
but may be overridden by the
.Ev LOCALBASE
environment variable.
.It Fl V
Print version number and exit.
.It Fl v
Turn on verbose output.
Specifying
.Fl v
multiple times increases the level of verbosity.
.El
.Sh ENVIRONMENT
.Bl -tag -width indent
.It Ev LOCALBASE
The standard packages directory,
.Pa /usr/pkg ,
can be overridden by specifying an alternative directory in the
.Ev LOCALBASE
environment variable. This affects the default
.Ar target
and
.Ar stowdir
directories.
.It Ev PLIST_IGNORE_FILES
This can be used to specify files in
.Ar package
that should ignored when creating and deleting symbolic links in
.Ar target .
.Ev PLIST_IGNORE_FILES
is a space-separated list of shell glob patterns that match files relative
to the
.Ar package
directory, and it defaults to "info/dir *[~#] *.OLD *.orig *,v".
.El
.Sh SEE ALSO
.Xr lndir 1 ,
.Xr pkg_view 1
.Sh AUTHORS
The
.Nm
utility was written by
.An Alistair G. Crooks Aq agc@NetBSD.org .

View File

@ -1,228 +0,0 @@
#! /bin/sh
# $NetBSD: linkfarm.sh,v 1.5 2004/06/03 13:13:42 uebayasi Exp $
#
# Copyright (c) 2002 Alistair G. Crooks. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by Alistair G. Crooks.
# 4. The name of the author may not be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# set -x
# set up program definitions
findprog=/usr/bin/find
grepprog=/usr/bin/grep
lnprog=/bin/ln
mkdirprog=/bin/mkdir
pkginfoprog=/usr/sbin/pkg_info
rmprog=/bin/rm
rmdirprog=/bin/rmdir
sedprog=/usr/bin/sed
sortprog=/usr/bin/sort
usage() {
echo 'Usage: linkfarm [options] package'
exit 1
}
version() {
$pkginfoprog -V
exit 0
}
checkdir() {
if [ ! -d "$1" ]; then
echo "linkfarm: \`$1' doesn't exist"
exit 1
fi
}
ignorefiles=${PLIST_IGNORE_FILES:-"info/dir *[~#] *.OLD *.orig *,v"}
linktype=-s
# default action: create a linkfarm in $target from $stowdir/$1
# i.e. linkfarm --target=${prefix}/${view} --dir=${prefix}/packages $1
#
doit=""
target=${LOCALBASE:-/usr/pkg}
stowdir=${target}/packages
subdir=""
verbose=0
# default action is to create
check=no
delete=no
create=yes
# process args - can't use getopt(1) because of '--' style args
while [ $# -gt 0 ]; do
case "$1" in
-D) delete=yes; create=no ;;
-R) delete=yes; create=yes ;;
-V) version ;;
-c) check=yes; doit=":" ;;
-d) stowdir=$2; shift ;;
-d*) stowdir=`echo $1 | $sedprog -e 's|-d||'` ;;
-s) subdir=$2; shift ;;
-s*) subdir=`echo $1 | $sedprog -e 's|-s||'` ;;
-t) target=$2; shift ;;
-t*) target=`echo $1 | $sedprog -e 's|-t||'` ;;
-n) doit=":" ;;
-v) verbose=`expr $verbose + 1` ;;
--delete) delete=yes; create=no ;;
--dir=*) stowdir=`echo $1 | $sedprog -e 's|--dir=||'` ;;
--restow) delete=yes; create=yes ;;
--subdir=*) subdir=`echo $1 | $sedprog -e 's|--subdir=||'` ;;
--target=*) target=`echo $1 | $sedprog -e 's|--target=||'` ;;
--version) version ;;
--) shift; break ;;
*) break ;;
esac
shift
done
# set the package name
package=$1
# make sure stowdir has a full pathname
case $stowdir in
/*) ;;
*) stowdir=`pwd`/$stowdir ;;
esac
# Set the directory from which we symlink.
case $subdir in
"") fromdir=$stowdir/$package ;;
*) fromdir=$stowdir/$package/$subdir ;;
esac
# Set the directory to which we symlink.
case $target in
/*) todir=$target ;;
*) todir=`pwd`/$target ;;
esac
# if we're checking the entries, check, then exit
case $check in
yes)
checkdir $fromdir
(cd $fromdir
ex=0
$findprog . ! -type d -print | \
$sedprog -e 's|^\./||' | \
while read f; do
if [ -e $todir/$f ]; then
ignore=no
for i in $ignorefiles; do
case $f in
$i) ignore=yes; break ;;
esac
done
case $ignore in
no)
echo "${f}"; ex=1 ;;
esac
fi
done
exit $ex) || exit 1
;;
esac
# if we need to get rid of old linkfarms, do it
case $delete in
yes)
checkdir $fromdir
(cd $fromdir
$findprog . ! -type d -print | \
$sedprog -e 's|^\./||' | \
while read f; do
ignore=no
for i in $ignorefiles; do
case $f in
$i) ignore=yes; break ;;
esac
done
case $ignore in
no)
if [ $verbose -gt 0 ]; then
echo "$rmprog -f $todir/$f"
fi
$doit $rmprog -f $todir/$f ;;
esac
done
$findprog . -type d -print | \
$sedprog -e 's|^\./||' | \
$sortprog -r | \
while read d; do
if [ $verbose -gt 0 ]; then
echo "$rmdirprog $todir/$d"
fi
$doit $rmdirprog $todir/$d > /dev/null 2>&1
done)
;;
esac
# if we need to create new linkfarms, do it
case $create in
yes)
checkdir $fromdir
(cd $fromdir
$findprog . -type d -print | \
$sedprog -e 's|^\./||' | \
while read d; do
case "$d" in
"") continue ;;
esac
if [ $verbose -gt 0 ]; then
echo "$mkdirprog -p $todir/$d"
fi
$doit $mkdirprog -p $todir/$d > /dev/null 2>&1
done
$findprog . ! -type d -print | \
$sedprog -e 's|^\./||' | \
while read f; do
ignore=no
for i in $ignorefiles; do
case $f in
$i) ignore=yes; break ;;
esac
done
case $ignore in
no)
if [ $verbose -gt 0 ]; then
echo "$lnprog ${linktype} $fromdir/$f $todir/$f"
fi
$doit $lnprog ${linktype} $fromdir/$f $todir/$f ;;
esac
done)
;;
esac
exit 0

View File

@ -1,280 +0,0 @@
.\" $NetBSD: pkg_view.1,v 1.12 2005/02/26 14:09:58 grant Exp $
.\"
.\" Copyright (c) 2003 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the NetBSD
.\" Foundation, Inc. and its contributors.
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
.\" contributors may be used to endorse or promote products derived
.\" from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd September 8, 2003
.Dt PKG_VIEW 1
.Os
.Sh NAME
.Nm pkg_view
.Nd add and delete instances of depoted packages in views
.Sh SYNOPSIS
.Nm
.Op Fl nVv
.Op Fl d Ar stowdir
.Op Fl i Ar ignore
.Op Fl k Ar pkg_dbdir
.Op Fl W Ar viewbase
.Op Fl w Ar view
.Ar command
.Ar package ...
.Sh DESCRIPTION
The
.Nm
command is used to add and delete instances of depoted packages in
.Ar stowdir
in a
.Ar view
in the
.Ar viewbase
directory.
.Sh WARNING
.Bf -emphasis
Since the
.Nm
command may execute scripts or programs provided by a package file,
your system may be susceptible to
.Dq Trojan horses
or other subtle
attacks from miscreants who create dangerous package files.
.Pp
You are advised to verify the competence and identity of those who
provide installable package files.
For extra protection, examine all the package control files in the
package database directory
.Pa ( /usr/pkg/packages/\*[Lt]pkg-name\*[Gt]/ ) .
Pay particular attention to any
.Pa +INSTALL ,
.Pa +DEINSTALL ,
.Pa +REQUIRE ,
or
.Pa +MTREE_DIRS
files, and inspect the
.Pa +CONTENTS
file for
.Cm @cwd ,
.Cm @mode
(check for setuid),
.Cm @dirrm ,
.Cm @exec ,
and
.Cm @unexec
directives, and/or use the
.Xr pkg_info 1
command to examine the installed package control files.
.Ef
.Sh OPTIONS
The following command-line options are supported:
.Bl -tag -width indent
.It Fl d Ar stowdir
Set
.Ar stowdir
as the directory in which the depoted packages can be found.
If this option isn't specified, then the
.Ar stowdir
is taken from the value of the environment variable
.Ev DEPOTBASE
if it's set, otherwise the default
.Ar stowdir
is the path to the
.Pa packages
directory under
.Ar viewbase .
.It Fl i Ar ignore
Add
.Ar ignore
to the list of files in
.Ar package
that should ignored when adding or removing the package instance from
.Ar view .
.It Fl k Ar pkg_dbdir
Set
.Ar pkg_dbdir
as the package database directory for the default (empty) view.
If this option isn't specified, then the package database directory is
taken from the value of the environment variable
.Ev PKG_DBDIR ,
otherwise it defaults to
.Pa /var/db/pkg .
.It Fl n
Don't actually execute the commands for manipulating the package instances.
.It Fl V
Print the version number and exit.
.It Fl v
Turn on verbose output.
Specifying
.Fl v
multiple times increases the level of verbosity.
.It Fl W Ar viewbase
Set
.Ar viewbase
as the directory in which all the views are managed.
The default
.Ar viewbase
directory is
.Pa /usr/pkg
but may be overridden by the
.Ev LOCALBASE
environment variable.
.It Fl w Ar view
Set
.Ar view
as the directory in
.Ar viewbase
in which the package instances should be added or deleted.
The default
.Ar view
is the empty view but may be overridden by the
.Ev PKG_VIEW
environment variable.
.El
.Pp
The following commands are supported:
.Bl -tag -width indent
.It Cm add
Add the listed package instances into
.Ar view .
.It Cm check
Check whether the listed package instances are present in
.Ar view .
If they are not present, then return 0, otherwise return 1.
.It Cm delete
Delete the listed package instances from
.Ar view .
.El
.Sh ENVIRONMENT
.Bl -tag -width indent
.It Ev DEPOTBASE
This is the location of the
.Ar stowdir
directory inside which all depoted packages are kept.
The default
.Ar stowdir
is the
.Pa packages
directory under
.Ar viewbase .
.It Ev LOCALBASE
This is the location of the
.Ar viewbase
directory in which all the views are managed.
The default
.Ar viewbase
directory is
.Pa /usr/pkg .
.It Ev PKG_DBDIR
If the
.Fl k
flag isn't given, then the value of the environment variable
.Ev PKG_DBDIR
is the package database directory for the default view,
otherwise it defaults to
.Pa /var/db/pkg .
.It Ev PLIST_IGNORE_FILES
This can be used to specify files in
.Ar package
that should ignored when adding or removing the package instance from
.Ar view .
.Ev PLIST_IGNORE_FILES
is a space-separated list of shell glob patterns that match files relative
to the
.Ar package
depot directory, and it defaults to "info/dir *[~#] *.OLD *.orig *,v".
This is overridden by any
.Ev _PLIST_IGNORE_FILES
setting in a package's
.Ar build-info-file
(see
.Xr pkg_create 1 )
if it exists.
.It Ev PKG_VIEW
The default view can be specified in the
.Ev PKG_VIEW
environment variable.
.El
.Sh FILES
.Bl -tag -width indent
.It Pa \*[Lt]pkg-dbdir\*[Gt]/\*[Lt]package\*[Gt]/+INSTALL
If the package contains an
.Ar install
script (see
.Xr pkg_create 1 ) ,
then after the package instance is added into a view, the script is
executed with the following arguments:
.Bl -tag -width package
.It Ar package
The name of the package instance being added.
.It Cm VIEW-INSTALL
Keyword denoting that the script is to perform any actions needed after
the package instance is added to a view.
.El
.Pp
If the
.Ar install
script exits with a non-zero status code, the installation is terminated.
.It Pa \*[Lt]pkg-dbdir\*[Gt]/\*[Lt]package\*[Gt]/+DEINSTALL
If the package contains an
.Ar deinstall
script (see
.Xr pkg_create 1 ) ,
then before the package instance is deleted from a view, the script is
executed with the following arguments:
.Bl -tag -width package
.It Ar package
The name of the package instance being deleted.
.It Cm VIEW-DEINSTALL
Keyword denoting that the script is to perform any actions needed before
the package instance is deleted from a view.
.El
.Pp
If the
.Ar deinstall
script exits with a non-zero status code, the de-installation is terminated.
.El
.Pp
The
.Ar install
and
.Ar deinstall
scripts are called with the environment variable
.Ev PKG_PREFIX
set to the path to the
.Ar view
directory.
.Sh SEE ALSO
.Xr linkfarm 1 ,
.Xr pkg_delete 1
.Sh AUTHORS
The
.Nm
utility was written by
.An Alistair G. Crooks Aq agc@NetBSD.org .

View File

@ -1,272 +0,0 @@
#! /bin/sh
# $NetBSD: pkg_view.sh,v 1.6 2006/06/27 23:33:21 hubertf Exp $
#
# Copyright (c) 2001 Alistair G. Crooks. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by Alistair G. Crooks.
# 4. The name of the author may not be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# set -x
# set up program definitions
chmodprog=/bin/chmod
cmpprog=/usr/bin/cmp
cpprog=/bin/cp
envprog=/usr/bin/env
findprog=/usr/bin/find
grepprog=/usr/bin/grep
linkfarmprog=/usr/sbin/linkfarm
lnprog=/bin/ln
mkdirprog=/bin/mkdir
paxprog=/bin/pax
pkgadminprog=/usr/sbin/pkg_admin
pkginfoprog=/usr/sbin/pkg_info
rmprog=/bin/rm
rmdirprog=/bin/rmdir
sedprog=/usr/bin/sed
touchprog=/usr/bin/touch
usage() {
echo 'Usage: pkg_view [-nVv] [-d stowdir] [-i ignore] [-k pkg_dbdir] [-W viewbase]'
echo ' [-w viewname] add|check|delete pkgname...'
exit 1
}
version() {
$pkginfoprog -V
exit 0
}
checkpkg() {
if [ ! -d "$2/$1" ]; then
echo "pkg_view: \`$1' doesn't exist in \`$2'" 1>&2
exit 1
fi
}
#########################################
# Initialization and Options Processing #
#########################################
doit=""
stowdir=""
viewbase=${LOCALBASE:-/usr/pkg}
view=${PKG_VIEW:-""}
dflt_ignorefiles=${PLIST_IGNORE_FILES:-"info/dir *[~#] *.OLD *.orig *,v"}
dflt_pkg_dbdir=${PKG_DBDIR:-/var/db/pkg}
ignorefiles=""
verbose=0
while [ $# -gt 0 ]; do
case "$1" in
-d) stowdir=$2; shift ;;
-d*) stowdir=`echo $1 | $sedprog -e 's|^-d||'` ;;
-i) ignorefiles="$ignorefiles $2"; shift ;;
-i*) ignorefiles="$ignorefiles `echo $1 | $sedprog -e 's|^-i||'`" ;;
-k) dflt_pkg_dbdir="$2"; shift ;;
-k*) dflt_pkg_dbdir=`echo $1 | $sedprog -e 's|^-k||'` ;;
-n) doit=":" ;;
-V) version ;;
-v) verbose=`expr $verbose + 1` ;;
-W) viewbase=$2; shift ;;
-W*) viewbase=`echo $1 | $sedprog -e 's|^-p||'` ;;
-w) view=$2; shift ;;
--view=*) view=`echo $1 | $sedprog -e 's|--view=||'` ;;
--) shift; break ;;
*) break ;;
esac
shift
done
if [ $# -lt 1 ]; then
usage
fi
# echoN will actually give output if ${verbose} > N.
echo1=":"
echo2=":"
if [ ${verbose} -gt 0 ]; then echo1=echo; fi
if [ ${verbose} -gt 1 ]; then echo2=echo; fi
action=""
case "$1" in
add) action=add ;;
check) action=check ;;
delete|rm) action=delete ;;
*) usage ;;
esac
shift
# if standard view, put package info into ${dflt_pkg_dbdir}
# if not standard view, put package info into view's pkgdb
case "$view" in
"")
pkg_dbdir=${dflt_pkg_dbdir}
targetdir=${viewbase}
viewstr="the standard view"
;;
*)
pkg_dbdir=${viewbase}/${view}/.pkgdb
targetdir=${viewbase}/${view}
viewstr="view \"${view}\""
;;
esac
# Use stowdir if it's given, else fall back to ${DEPOTBASE} or else
# default to ${viewbase}/packages.
#
depot_pkg_dbdir=${stowdir:-${DEPOTBASE:-${viewbase}/packages}}
case "${depot_pkg_dbdir}" in
${pkg_dbdir})
echo "pkg_view: the depot and the view package database directories are the same" 1>&2
exit 1
;;
esac
##########################
# Shell helper functions #
##########################
# symlinks check|add|delete <pkg>
#
# Calls linkfarm(1) to check, add or delete the symlink farm in
# ${targetdir}. We also ignore the right set of files when doing the
# linkfarm operations.
#
symlinks() {
pkg=$2
case "$1" in
add) linkfarmflags="" ;;
check) linkfarmflags="-c" ;;
delete) linkfarmflags="-D" ;;
esac
if [ -f ${depot_pkg_dbdir}/$pkg/+BUILD_INFO ]; then
ignore=`$grepprog "^_PLIST_IGNORE_FILES=" ${depot_pkg_dbdir}/$pkg/+BUILD_INFO | $sedprog -e 's|^_PLIST_IGNORE_FILES=[ ]*||'`
fi
case "$ignore" in
"") ignore="${dflt_ignorefiles}" ;;
esac
dbs=`(cd ${depot_pkg_dbdir}/$pkg; echo +*)`
ignore="${ignore} ${ignorefiles} $dbs"
$doit $envprog PLIST_IGNORE_FILES="${ignore}" $linkfarmprog $linkfarmflags --target=${targetdir} --dir=${depot_pkg_dbdir} $pkg
}
#############
# Main Loop #
#############
while [ $# -gt 0 ]; do
case $action in
add)
checkpkg $1 ${depot_pkg_dbdir}
if [ -f ${pkg_dbdir}/$1/+DEPOT ]; then
echo "pkg_view: \`$1' already exists in $viewstr" 1>&2
exit 1
fi
$echo1 "Adding $1 to ${targetdir}."
symlinks add $1
$doit $mkdirprog -p ${depot_pkg_dbdir}/$1
temp=${depot_pkg_dbdir}/$1/+VIEWS.$$
$doit $touchprog ${depot_pkg_dbdir}/$1/+VIEWS
$doit $cpprog ${depot_pkg_dbdir}/$1/+VIEWS ${temp}
case "$doit" in
"") ($grepprog -v '^'${pkg_dbdir}'$' ${temp} || true; echo ${pkg_dbdir}) > ${depot_pkg_dbdir}/$1/+VIEWS ;;
esac
$doit $rmprog ${temp}
$doit $mkdirprog -p ${pkg_dbdir}/$1
#
# Copy all of the metadata files except for +VIEWS,
# which is only for the depoted package, and
# +REQUIRED_BY, which is irrelevant for a package in
# a view.
#
case "$doit" in
"") (cd ${depot_pkg_dbdir}/$1; $paxprog -rwpe '-s|\./+VIEWS$||' '-s|\./+REQUIRED_BY$||' ./+* ${pkg_dbdir}/$1)
$sedprog -e 's|'${depot_pkg_dbdir}/$1'|'${targetdir}'|g' < ${depot_pkg_dbdir}/$1/+CONTENTS > ${pkg_dbdir}/$1/+CONTENTS
echo "${depot_pkg_dbdir}/$1" > ${pkg_dbdir}/$1/+DEPOT
;;
esac
$doit $pkgadminprog -K ${pkg_dbdir} add $1
if [ -f ${pkg_dbdir}/$1/+INSTALL ]; then
$doit $chmodprog +x ${pkg_dbdir}/$1/+INSTALL
$doit $envprog -i PKG_PREFIX=${targetdir} ${pkg_dbdir}/$1/+INSTALL $1 VIEW-INSTALL
ec=$?
if [ $ec != 0 ]; then
echo "pkg_view: install script returned an error." 1>&2
exit $ec
fi
fi
;;
check)
checkpkg $1 ${depot_pkg_dbdir}
$echo1 "Checking $1 in ${targetdir}."
symlinks check $1
exit $?
;;
delete)
checkpkg $1 ${depot_pkg_dbdir}
if [ ! -f ${pkg_dbdir}/$1/+DEPOT ]; then
echo "pkg_view: \`$1' doesn't exist in $viewstr" 1>&2
exit 1
fi
$echo1 "Deleting $1 from ${targetdir}."
if [ -f ${pkg_dbdir}/$1/+REQUIRED_BY ]; then
if $cmpprog -s ${pkg_dbdir}/$1/+REQUIRED_BY /dev/null; then
: # not really required by another pkg
else
(echo "pkg_view: \`$1' is required by other packages:"
$sedprog -e 's|^| |' ${pkg_dbdir}/$1/+REQUIRED_BY) 1>&2
exit 1
fi
fi
if [ -f ${pkg_dbdir}/$1/+DEINSTALL ]; then
$doit $chmodprog +x ${pkg_dbdir}/$1/+DEINSTALL
$doit $envprog -i PKG_PREFIX=${targetdir} ${pkg_dbdir}/$1/+DEINSTALL $1 VIEW-DEINSTALL
ec=$?
if [ $ec != 0 ]; then
echo "pkg_view: de-install script returned an error." 1>&2
exit $ec
fi
fi
symlinks delete $1
temp=${depot_pkg_dbdir}/$1/+VIEWS.$$
$doit $cpprog ${depot_pkg_dbdir}/$1/+VIEWS ${temp}
case "$doit" in
"") ($grepprog -v '^'${pkg_dbdir}'$' ${temp} || true) > ${depot_pkg_dbdir}/$1/+VIEWS ;;
esac
$doit $rmprog ${temp}
$doit $rmprog -rf ${pkg_dbdir}/$1
$doit $pkgadminprog -K ${pkg_dbdir} delete $1
;;
esac
shift
done
exit 0