Skip to content

Instantly share code, notes, and snippets.

@bekcpear
Last active April 7, 2024 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bekcpear/88645a919db53fed5918b1c9958196a3 to your computer and use it in GitHub Desktop.
Save bekcpear/88645a919db53fed5918b1c9958196a3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
set -e
PROFILE_PATH="$1"
: "${REPO:=${2:-/var/db/repos/gentoo}}"
if [[ ! $PROFILE_PATH =~ ^/ ]]; then
PROFILE_PATH="${REPO%%/}/profiles/${PROFILE_PATH}"
fi
if [[ ! -d "$PROFILE_PATH" ]] || [[ ! -x "$PROFILE_PATH" ]]; then
echo "'$PROFILE_PATH' is not a directory!" >&2
echo " or cannot execute!" >&2
exit 1
fi
declare -a PROFILE_STACK
push_to_stack() {
local p="$1" pa
pushd "$p" >/dev/null
trap '
PROFILE_STACK+=( "$(pwd)" )
popd >/dev/null
' RETURN
pa="$(pwd)/parent"
if [[ -f "$pa" ]]; then
while read -r line; do
push_to_stack "$line"
done < <(cat "$pa")
fi
}
push_to_stack "$PROFILE_PATH"
echo $'\n'"Priority decreases from top to bottom:"$'\n'
for (( i=$((${#PROFILE_STACK[@]}-1)); i>=0; i-- )); do
echo "${PROFILE_STACK[i]}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment