Annotation of pkgsrc/mk/scripts/pkg_path, revision 1.5

1.1       jlam        1: #!/bin/sh
                      2: #
1.5     ! maya        3: # $NetBSD: pkg_path,v 1.4 2007/10/31 19:20:08 rillig Exp $
1.1       jlam        4: #
                      5: # Copyright (c) 2006 The NetBSD Foundation, Inc.
                      6: # All rights reserved.
                      7: #
                      8: # This code is derived from software contributed to The NetBSD Foundation
                      9: # by Johnny C. Lam.
                     10: #
                     11: # Redistribution and use in source and binary forms, with or without
                     12: # modification, are permitted provided that the following conditions
                     13: # are met:
                     14: # 1. Redistributions of source code must retain the above copyright
                     15: #    notice, this list of conditions and the following disclaimer.
                     16: # 2. Redistributions in binary form must reproduce the above copyright
                     17: #    notice, this list of conditions and the following disclaimer in the
                     18: #    documentation and/or other materials provided with the distribution.
                     19: #
                     20: # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     21: # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     22: # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     23: # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     24: # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     25: # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     26: # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     27: # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     28: # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     29: # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     30: # POSSIBILITY OF SUCH DAMAGE.
                     31: #
                     32: 
                     33: ######################################################################
                     34: #
                     35: # NAME
                     36: #      pkg_path -- canonicalize directories into "package paths"
                     37: #
                     38: # SYNOPSIS
1.2       jlam       39: #      pkg_path [-s pkgsrcdir] dir ...
                     40: #
                     41: # OPTIONS
                     42: #      The following command line arguments are supported.
                     43: #
                     44: #      -s pkgsrcdir    Use the specified directory as the path to the
                     45: #                      pkgsrc directory tree.  By default, this is the
                     46: #                      value stored in the PKGSRCDIR environment variable.
1.1       jlam       47: #
                     48: # DESCRIPTION
                     49: #      pkg_path canonicalizes the specified directories into package
1.4       rillig     50: #      paths that are relative to the pkgsrc directory tree, and prints
1.2       jlam       51: #      each of them to standard output on a new line.  The specified
1.4       rillig     52: #      directories are taken to be relative to the current directory.
                     53: #      Directories that are not valid package directories or are not
                     54: #      found are skipped during processing.
1.1       jlam       55: #
                     56: # ENVIRONMENT
                     57: #      PKGSRCDIR       This is the location of the pkgsrc directory tree,
                     58: #                      which defaults to "/usr/pkgsrc".
                     59: #
                     60: ######################################################################
                     61: 
                     62: : ${ECHO=echo}
                     63: : ${PKGSRCDIR="/usr/pkgsrc"}
                     64: : ${PWD_CMD="pwd -P"}
                     65: 
                     66: self="${0##*/}"
                     67: 
1.2       jlam       68: usage() {
                     69:        ${ECHO} 1>&2 "usage: $self [-s pkgsrcdir] dir ..."
                     70: }
                     71: 
1.3       jlam       72: exitcode=0
                     73: 
1.2       jlam       74: # Process optional arguments
1.4       rillig     75: while [ $# -gt 0 ]; do
1.2       jlam       76:        case "$1" in
                     77:        -s)     PKGSRCDIR=$2; shift 2 ;;
                     78:        --)     shift; break ;;
                     79:        -*)     ${ECHO} 1>&2 "$self: unknown option -- ${1#-}"
                     80:                usage
                     81:                exit 1
                     82:                ;;
                     83:        *)      break ;;
                     84:        esac
                     85: done
                     86: 
                     87: # Process required arguments
1.1       jlam       88: startdir=`${PWD_CMD}`
1.4       rillig     89: while [ $# -gt 0 ]; do
1.1       jlam       90:        dir="$1"; shift
1.2       jlam       91:        case "$dir" in
1.1       jlam       92:        ${PKGSRCDIR}/*) ;;
                     93:        /*)      ${ECHO} 1>&2 "$self: \`\`$dir'' not a valid package directory"
1.3       jlam       94:                exitcode=1
1.1       jlam       95:                continue
                     96:                ;;
                     97:        esac
1.4       rillig     98:        if [ ! -d "$startdir/$dir" ]; then
1.1       jlam       99:                ${ECHO} 1>&2 "$self: \`\`$dir'' not found"
1.3       jlam      100:                exitcode=1
1.1       jlam      101:                continue
                    102:        fi
                    103:        pkgpath=`cd $startdir/$dir && ${PWD_CMD}`
                    104:        pkgpath="${pkgpath#${PKGSRCDIR}/}"
                    105:        ${ECHO} "$pkgpath"
                    106: done
                    107: 
1.3       jlam      108: exit $exitcode

CVSweb <webmaster@jp.NetBSD.org>