#!/bin/sh

# Script that takes a package as an argument and returns installed packages
# that are dependent on it

[ $# -eq 1 ] || echo "usage: who-depends package"
apt list --installed | tail -n+2 | cut -d '/' -f 1 > /tmp/whodepends
pkg="$1"
deps_all=$(apt-cache rdepends $pkg | tail -n+3 | sed "s/^\s*//")
for dep in $deps_all
do
		grep -lq "$dep" /tmp/whodepends && echo "$dep"
done