aboutsummaryrefslogtreecommitdiff
path: root/pkg_is_installed
blob: ecc8c5e91b3e54d8b1f4cc2ed6b8bac5765786a6 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh

die() {
	if [ "$*" ]; then
		echo "$*" 1>&2
	fi
	exit 2
}

TARGET=$1
case "$TARGET" in
	-*|'') cat <<EOF
Usage: $0 <pkgname>

Checks the Slackware package database in /var/log/packages and returns
true (0) if <pkgname> is installed, false (1) otherwise.

If there's an error, the return status will be 2, which is still false,
but the caller can check for this by examining the \$? variable.

If standard output is a terminal, the full installed package
name (package-version-arch-build_tag) will be printed to stdout,
or "no package" if no such package is installed.

Like Slackware's installpkg, $0 respects the environment
variable ROOT, to operate on a mounted partition other than /.
EOF
	       ;;
esac

if [ "$2" != "" ]; then
	die "Usage: $0 <pkgname|--help>"
fi

cd $ROOT/var/log/packages || die "Are you sure this is Slackware?"
for i in ${TARGET}-*; do
	j=$(echo $i | rev | cut -d- -f4- | rev)
	if [ "$TARGET" = "$j" ]; then
		[ -t 1 ] && echo $i
		exit 0
	fi
done

[ -t 1 ] && echo "no package '$TARGET' installed"
exit 1