#!/usr/bin/env zsh set -e BIN="$0" OPERATION="$1" REPO="$2" PKG="$3" syntax() { 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 ! ls "target/$REPO/"*"/$PKG"*".apk" > /dev/null 2>/dev/null; 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 "$BIN")")/target/$REPO" "$PKG"; elif [[ "$OPERATION" == "del" ]]; then sudo apk del "$PKG"; elif [[ "$OPERATION" == "add" ]]; then sudo apk add --repository "$(busybox dirname "$(busybox realpath "$BIN")")/target/$REPO" "$PKG"; else syntax; fi