From b83c0257aa06c2ce63d289d42091f61a4865f7ea Mon Sep 17 00:00:00 2001 From: memdmp Date: Sun, 5 Jan 2025 05:03:26 +0100 Subject: fix: check for package existence --- pkg | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg b/pkg index 492b7cc..72cb5aa 100755 --- a/pkg +++ b/pkg @@ -1,20 +1,27 @@ #!/usr/bin/env zsh set -e +BIN="$0" OPERATION="$1" REPO="$2" PKG="$3" syntax() { - echo -e "\x1b[0;31mSyntax: $0 \x1b[0m" 1>&2; exit 1; + echo -e "\x1b[0;91mSyntax: $BIN \x1b[0m" 1>&2; exit 1; } if [[ "$REPO" == "" ]]; then syntax; fi if [[ "$PKG" == "" ]]; then syntax; fi +if ! [[ -f "src/$REPO/$PKG/APKBUILD" ]]; then + echo -e "\x1b[0;91mThe package $PKG does not exist in $REPO in the current source tree.\x1b[0m" 1>&2; exit 1; +fi +if ! [[ -f "target/$REPO/"*"/$PKG"*".apk" ]]; then + echo -e "\x1b[0;91mThe package $PKG does not exist in $REPO in the current target, yet does exist in the source tree. Try building it.\x1b[0m" 1>&2; exit 1; +fi if [[ "$OPERATION" == "readd" ]]; then sudo apk del "$PKG"; - sudo apk add --repository "$(busybox dirname "$(busybox realpath "$0")")/target/$REPO" "$PKG"; + sudo apk add --repository "$(busybox dirname "$(busybox realpath "$BIN")")/target/$REPO" "$PKG"; elif [[ "$OPERATION" == "del" ]]; then sudo apk del "$PKG"; elif [[ "$OPERATION" == "add" ]]; then - sudo apk add --repository "$(busybox dirname "$(busybox realpath "$0")")/target/$REPO" "$PKG"; + sudo apk add --repository "$(busybox dirname "$(busybox realpath "$BIN")")/target/$REPO" "$PKG"; else syntax; fi \ No newline at end of file -- cgit v1.2.3