aboutsummaryrefslogtreecommitdiff
path: root/pkg_is_installed
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2017-08-23 02:41:40 -0400
committerB. Watson <yalhcru@gmail.com>2017-08-23 02:41:40 -0400
commit84dd81caf1359ebc341c0e6a28caf54acd8f9f51 (patch)
treee0124e13dd95141bd1e5da5250a77199f09fa4d0 /pkg_is_installed
parentf647eb20053df41b76de46a0f8b244315ff6495e (diff)
downloadsbostuff-84dd81caf1359ebc341c0e6a28caf54acd8f9f51.tar.gz
Add missing tool used by sbodeps
Diffstat (limited to 'pkg_is_installed')
-rwxr-xr-xpkg_is_installed45
1 files changed, 45 insertions, 0 deletions
diff --git a/pkg_is_installed b/pkg_is_installed
new file mode 100755
index 0000000..ecc8c5e
--- /dev/null
+++ b/pkg_is_installed
@@ -0,0 +1,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