Skip to content

Instantly share code, notes, and snippets.

@mcoffin
Created March 11, 2021 17:37
Show Gist options
  • Select an option

  • Save mcoffin/ed7759924c4ff85288889e6a33dc1deb to your computer and use it in GitHub Desktop.

Select an option

Save mcoffin/ed7759924c4ff85288889e6a33dc1deb to your computer and use it in GitHub Desktop.
#!/usr/bin/bash
set -e
protected_packages=(linux-amd-staging-drm-next)
protect_packages() {
local pkg_name
for pkg_name; do
protected_packages+=({,lib32-}"$pkg_name"{,-bin,-git,-hg})
done
}
protect_packages \
amdvlk \
radeontop
declare -a base_dirs
declare -a ignored_packages
while getopts ":d:i:I:p" opt; do
case ${opt} in
d)
base_dirs+=("$OPTARG")
;;
i)
ignored_packages+=("$OPTARG")
;;
I)
ignored_packages+=({,lib32-}"$OPTARG"{,-bin,-git,-hg})
;;
p)
ignored_packages+=("${protected_packages[@]}")
;;
\?)
echo "Unknown argument: -$OPTARG" >&2
exit 1
;;
:)
printf 'Invalid argument: -%s requires an argument\n' "$OPTARG" >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
[ ${#base_dirs[@]} -ge 1 ] || base_dirs=(.)
find_build_dirs() {
if [ $# -lt 1 ]; then
echo 'Usage: find_build_dirs BASE_DIR' >&2
return 1
fi
local d
for d in src pkg; do
find "$1" -mindepth 2 -maxdepth 3 -type d -name "$d"
done
}
filter_ignored() {
if [ $# -lt 1 ]; then
echo 'Usage: filter_ignored BASE_DIR' >&2
return 1
fi
if [ ${#ignored_packages[@]} -lt 1 ]; then
tee /dev/null
return $?
fi
local pattern="^$1/("
local pkg_name
for pkg_name in "${ignored_packages[@]}"; do
pattern="$pattern($pkg_name)|"
done
pattern="${pattern%|})/"
grep -vE "$pattern"
}
for d in "${base_dirs[@]}"; do
find_build_dirs "$d" | filter_ignored "$d"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment