pkgsrc-wip/pkg_summary-utils/files/pkg_list_all_pkgs.in

119 lines
2.7 KiB
Text
Raw Normal View History

#!@SH@
2008-10-26 12:06:19 +01:00
#-*-mode: sh -*-
# Copyright (c) 2007-2008 Aleksey Cheusov <vle@gmx.net>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
set -e
. pipestatus
############################################################
usage (){
cat 1>&2 <<EOF
pkg_list_all_pkgs - outputs all packages in pkgsrc tree
usage: pkg_list_all_pkgs [OPTIONS]
OPTIONS:
-h|--help display this help message
EOF
}
while test $# -ne 0; do
case "$1" in
-h|--help)
usage
exit 0;;
--)
shift
break;;
-*)
echo "Unrecognized option " $1 ". Type --help to see usage" 1>&2
exit 1;;
*)
break;;
esac
shift
done
############################################################
# user settable variables
if test -z "$PKGSRCDIR"; then
PKGSRCDIR=/usr/pkgsrc
fi
if test -z "$BMAKE"; then
BMAKE=make
fi
############################################################
cd $PKGSRCDIR
tmp_dir="/tmp/pkg_list_all_pkgs.$$"
trap "rm -rf $tmp_dir" 0 1 2 15
mkdir -m 700 "$tmp_dir"
############################################################
############################################################
#### get all available packages
enrich_Makefile (){
cat <<EOF
.PHONY: my-show-var
my-show-var:
@echo \${\${VARNAME}:Q}
2008-04-09 23:31:51 +02:00
.include "./Makefile"
EOF
}
get_SUBDIR (){
subdir_fn=$tmp_dir/subdirs
runpipe0 \
enrich_Makefile '|' \
${BMAKE} -f - my-show-var VARNAME=SUBDIR > $subdir_fn
cat $subdir_fn
}
prepand (){
awk -v prefix="$1" '{print prefix $0}'
}
space_to_NL () {
tr ' ' '
'
}
list_all_packages (){
categories="`get_SUBDIR`"
for c in $categories; do
(
cd $c &&
runpipe0 \
get_SUBDIR '|' \
space_to_NL '|' \
prepand "$c/"
)
done
}
list_all_packages