kiss/contrib/kiss-owns
Pratham cb9fe25776 kiss-owns: fix usage with KISS_ROOT (#86)
Co-authored-by: git-bruh <e817509a-8ee9-4332-b0ad-3a6bdf9ab63f@aleeas.com>
Reviewed-on: https://codeberg.org/kiss-community/kiss/pulls/86
2022-10-07 17:12:14 +02:00

37 lines
676 B
Bash
Executable File

#!/bin/sh -e
# Check which package owns a file
# Follow symlinks to any paths.
case $1 in
/*)
cd -P "${KISS_ROOT:-/}${1%/*}"
[ "$PWD" = / ] && KISS_ROOT=
;;
*/*)
cd -P "${1%/*}"
;;
*)
cd -P .
;;
esac
[ -f "$PWD/${1##*/}" ] || {
printf 'usage: kiss-owns [/path/to/file]\n' >&2
exit 1
}
# Print the full path to the manifest file which contains
# the match to our search.
pkg_owns=$(grep -lFx \
"${PWD#"$KISS_ROOT"}/${1##*/}" \
"$KISS_ROOT/var/db/kiss/installed/"*/manifest)
# Extract the package name from the path above.
pkg_owns=${pkg_owns%/*}
pkg_owns=${pkg_owns##*/}
printf '%s\n' "$pkg_owns"