diff options
fix: check for package existence
-rwxr-xr-x | pkg | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -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 <add|del|readd> <REPONAME> <PKG>\x1b[0m" 1>&2; exit 1; + echo -e "\x1b[0;91mSyntax: $BIN <add|del|readd> <REPONAME> <PKG>\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 |