#!/bin/sh -e # Check which package owns a file ## SYNOPSIS: ## .Nm ## .Op Ar file ## DESCRIPTION: ## .Nm ## searches package manifests to determine which package owns ## .Ar file . ## If the ## .Ar file ## is not a realpath, ## .Nm ## will first check if the file exists as a relative path, and then it will ## check if it exists as an executable ## in ## .Ev PATH . ## ## .Nm ## does not check directories, as they can be used by multiple packages at the ## same time. # Source the package manager library. # shellcheck disable=1091 . cpt-lib case "$1" in ''|--help|-h) out "usage: ${0##*/} [file]"; exit 0; esac # If full path is not specified, use either the current directory, or look for a # command. case "$1" in /*) ;; *) if [ -f "$1" ]; then set -- "$PWD/$1" else set -- "$(command -v "$1")" fi esac # Strip 'CPT_ROOT' from the file path if passed and follow symlinks. file="${1#$CPT_ROOT}" dirname=$(_readlinkf "$CPT_ROOT/${file%/*}") file="$dirname/${file##*/}" # Check if the file exists and exit if it is not. [ -f "$file" ] || { [ -d "$file" ] && die "please specify a file instead of a directory" die "file '$1' doesn't exist." } pkg_owner -lFx "$file" || die "Cannot determine which package owns '$file'"