Whitelisting could work like this. Recursive whitelisting could be difficult to implement.
#!/bin/bash
sort -u whitelist.txt -o whitelist.sorted.txt
colcon list -n 2> /dev/null | sort > list.sorted.txt
grep -v -f whitelist.sorted.txt list.sorted.txt
# this prints the packages that are not whitelisted, i.e., the ones that need to be removed
Whitelisting could work like this. Recursive whitelisting could be difficult to implement.