summaryrefslogtreecommitdiff
path: root/is_built
blob: 60f24e95140762dfddc8012004c53f6a2686864f (plain)
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
#!/bin/bash
usage() {
    echo "$0 "
    echo
    echo "Detect is a package is installed or in a database"
    echo
    echo "Example usage: is_built \"pcre>=20\""
}

while getopts 'h' arg; do
    case $arg in
        h) usage; exit 0 ;;
        *) usage; exit 1 ;;
    esac
done

# Checks for package, if -T returns non-zero output, egrep will return 0
# because it finds it, so we negate the value to say it's not built.
# -Sp works backwards, it will print output only when the package already
# exists

!(sudo pacman -T "$1" | egrep "*" >/dev/null) || \
sudo pacman -Sp "$1" --print-format "%n-%v" 2>/dev/null | egrep "*" >/dev/null

exit $?