#!/bin/sh - # # Oliver Fromme # # BSD-style copyright and standard disclaimer applies. # # This is a quick hack script that handles various things # related to FreeBSD port/package dependencies. Most of # this can be done with the usual /usr/ports Makefile # framework, too, but i wrote it for two reasons: # # -1- This script is a _lot_ faster. # -2- It works on other platforms (such as Solaris), # too, provided that you have GNU awk installed. # # The latter was important to me because I needed it on # an FreeBSD FTP mirror that was running Solaris, and I # wasn't exactly in the mood to port the whole FreeBSD # ports infrastructure to Solaris. All that this script # needs is an awk version that supports ENVIRON (GNU awk # is fine) and the ports INDEX file. # # For usage information, just type "pkg_dep" without # arguments. # if [ "`uname`" = FreeBSD ]; then AWK=awk # FreeBSD's awk is GNU awk else AWK=gawk # Solaris' old /usr/bin/awk won't work! fi INDEX=/usr/ports/INDEX FETCH=no PACKS=no PKDIR=ftp://ftp7.de.freebsd.org/pub/FreeBSD/ports/i386/packages-4.3-release/All # XXX: Should $PKDIR be picked up from /etc/make.conf on FreeBSD? if [ ! -f "$INDEX" ]; then if [ -f INDEX ]; then INDEX="`pwd`/INDEX" elif [ -f ../INDEX ]; then INDEX="`pwd`/../INDEX" fi fi Usage() { cat <<-tac >&2 Usage: $0 [-f] [-p] [-i ] package [package ...] This script prints all dependencies (recusrively) of the specified packages, and the categories which these packages are in. Example: \`\`$0 docproj-1.1''. Options: -i Specify index file, default: $INDEX -f print shell commands that fetch all distfiles -p print package file names If neither -f nor -p is specified, print package names and categories. If both -f and -p are specified, fetch packages via FTP to the current dir. tac exit 1 } while expr "x$1" : "x-" >/dev/null; do case "$1" in -i) INDEX="$2"; shift 2;; -f) FETCH=yes; shift;; -p) PACKS=yes; shift;; *) Usage; exit 1;; esac done if [ $# -lt 1 ]; then Usage; exit 1 fi if [ ! -f "$INDEX" ]; then echo "${0}: index file \"$INDEX\" does not exist!" >&2 echo "Type \"$0 -h\" for help." >&2 exit 1 fi PKGS="$@" export PKGS FETCH PACKS PKDIR $AWK -F '|' < "$INDEX" ' { dep[$1] = $9; cat[$1] = $7; dir[$1] = $2; } function printdep(x, _nd, _d, _i){ if (!have[x]) { have[x] = 1; if (x ~ /^XFree86-3\.3/) return; if (fetch) if (packs) flist = flist " " ftpbase x ".tgz"; else printf "cd %s; make fetch\n", dir[x]; else if (packs) printf "%s.tgz\n", x; else printf "%-35s %s\n", x, cat[x]; _nd = split(dep[x], _d, / /); for (_i = 1; _i <= _nd; _i++) printdep(_d[_i]); } } END{ ftpbase = ENVIRON["PKDIR"] "/"; fetch = (ENVIRON["FETCH"] == "yes"); packs = (ENVIRON["PACKS"] == "yes"); numpkgs = split(ENVIRON["PKGS"], pkg, / /); for (i = 1; i <= numpkgs; i++) { if (dir[pkg[i]]) { pkgs = pkgs " " pkg[i]; } else { found = 0; for (n in dep) if (n ~ "^" pkg[i]) { found = 1; pkgs = pkgs " " n; } if (!found) { print "Package \"" pkg[i] "\" not found!" \ > "/dev/stderr"; exit 1; } } } delete pkg; numpkgs = split(pkgs, pkg, / /); ecode = 0; for (i = 1; i <= numpkgs; i++) { flist = ""; if (pkg[i] ~ /[a-z]/) printdep(pkg[i]); if (flist && fetch && packs) { flist = "/usr/bin/fetch -m" flist; if (system(flist)) { ecode = 1; print "Fetch command returned error code!" \ > "/dev/stderr"; } } } exit ecode; } ' #--