-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpkgown
executable file
·50 lines (48 loc) · 1.72 KB
/
pkgown
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
#
# Written by: crossroads1112
# Purpose: Simple script that prints out what package owns a particular program.
#
#
#
#########################################33
distromsg="${0##*/} does not support your distrobution. Acceptable values are Arch, Ubuntu, Debian, Gentoo, Fedora, CentOS openSUSE. If your distro uses the same package manager as one of the above distros, you may specify it with the -d flag"
if [[ $# -lt 1 ]]; then
echo "${0##*/} requires at least one argument"
exit 1
else
if [[ $(echo $1 | head -c 1) == "-" ]]; then #Check for args
while [[ $(echo $1 | head -c 1) == "-" ]]; do
case $1 in
-d) DISTRIB_ID=${2,,}
shift 2
;;
*) echo "Unrecognized argument: $1"
exit 1
;;
esac
done
else
if [[ -f /etc/lsb-release ]]; then
. /etc/lsb-release #Get distro name
DISTRIB_ID=${DISTRIB_ID,,} #Make lower case
else
echo "lsb-release not found. Run ${0##*/} with the -d flag to manually specify distro."
exit 1
fi
fi
fi
case $DISTRIB_ID in
arch) pkgcmd="pacman -Qo" ;; #Set $pkgcmd to package manager command to determine ownership of a file depending on distro
ubuntu|debian)pkgcmd="dpkg -S" ;;
gentoo)pkgcmd="equery belongs -e" ;;
fedora|centos)pkgcmd="yum whatprovides" ;;
opensuse) pkgcmd="zypper what-provides" ;;
*) echo "$distromsg" && exit 1 ;;
esac
location=$(type -p $1) #Find location of binary
if [[ $location ]]; then
eval "$pkgcmd $location" #Evaluate the #pkgcmd on the file stored in $location
else
echo "Package $1 not found"
fi