summaryrefslogtreecommitdiffstats
path: root/scripts/whodepends.sh
blob: e0b6441028ed089cb1a3799220cc617f56c8f2f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# whodepends - show maintainers a package depends upon
# by Moshe Zadka <moshez@debian.org> and
# modified by Joshua Kwan <joshk@triplehelix.org>
# This script is in the public domain.

set -e

PROGNAME=${0##*/}

usage() {
	cat <<EOF
Usage: $PROGNAME [package] [package] ... [options]
  Check which maintainers a particular package depends on.
  $PROGNAME options:
    --source, -s      Show source packages instead of binary ones.
    --help, -h        Show this help screen.
    --version         Show version and copyright information.
EOF
}

version() {
	cat <<EOF
This is $PROGNAME, from the Debian devscripts package, version ###VERSION###
This code is by Moshe Zadka <moshez@debian.org>, and is in the public domain.
EOF
}

if [ -z "$1" ]; then
	usage
	exit 1
fi

while [ -n "$1" ]; do
	case "$1" in
		-s | --source) source=true ;;
		-h | --help) usage; exit 0 ;;
		--version) version; exit 0 ;;
		*)
			echo "Dependent maintainers for $1:"
			for package in $(apt-cache showpkg $1 | sed -n '/Reverse Depends:/,/Dependencies/p' | grep '^ '|sed 's/,.*//'); do
				if [ $source ]; then
					apt-cache showsrc $package |
					awk '/^Maintainer:/ {maint=$0} /^Package:/ {pkg=$0} END {print maint, pkg}' |
					sed 's/Maintainer: //;s/Package: //'
				else
					apt-cache show $package |
					awk '/^Maintainer:/ {maint=$0} END {print maint, "'$package'"}' |
					sed 's/Maintainer: //'
				fi
			done | sort -u | awk -F'>' '{ pack[$1]=pack[$1] $2 } END {for (val in pack) print val ">", "(" pack[val] ")"}' | sed 's/( /(/'
			echo
		;;
	esac
	shift
done