Skip to content

Instantly share code, notes, and snippets.

@d630
Last active March 14, 2019 05:33
Show Gist options
  • Save d630/1855b2dae2b31828c825197300625d5d to your computer and use it in GitHub Desktop.
Save d630/1855b2dae2b31828c825197300625d5d to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
declare -A Pack
function callback {
Pack[$2]=
}
mapfile -t -c 1 -C callback < "${1?error: file missing}"
suite=${2?error: chroot of suite missing}
for i in "${MAPFILE[@]}"
do
arr=($(
sudo apt-rdepends \
-r \
-o Dir::Cache="$suite"/var/cache/apt \
-o Dir::State="$suite"/var/lib/apt "$i" 2>/dev/null |
grep -o -e '^[^ ]*'
)
)
unset -v arr[0]
is_dep=false
for j in "${arr[@]}"
do
[[ -v Pack[$j] ]] && is_dep=true && break
done
$is_dep || keep+=("$i")
done
printf '%s\n' "${keep[@]}"
# vim: set ft=sh
@d630
Copy link
Author

d630 commented Mar 14, 2019

declare -A Pack

function callback {
	Pack[$2]=
}

mapfile -t -c 1 -C callback < "${1?error: file missing}"
suite=${2?error: chroot of suite missing}

for i in "${MAPFILE[@]}"
do
	is_dep=false
	while
		IFS= read -r
	do
		[[ -v Pack[$REPLY] ]] && is_dep=true && break
	done < <(
		sudo apt-rdepends \
			-r \
			-o Dir::Cache="$suite"/var/cache/apt \
			-o Dir::State="$suite"/var/lib/apt "$i" 2>/dev/null |
		grep -o -e '^[^ ]*' |
		tail +2
	)
	$is_dep || keep+=("$i")
done

printf '%s\n' "${keep[@]}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment