From 84dd81caf1359ebc341c0e6a28caf54acd8f9f51 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 23 Aug 2017 02:41:40 -0400 Subject: Add missing tool used by sbodeps --- pkg_is_installed | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 pkg_is_installed (limited to 'pkg_is_installed') 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 < + +Checks the Slackware package database in /var/log/packages and returns +true (0) if 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 " +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 -- cgit v1.2.3