#!/bin/sh # SPDX-License-Identifier: 0BSD set -eu usage() { printf '%s\n' 'Usage: pkg install|remove|info PACKAGE ...' \ ' pkg search QUERY ... | pkg search --exact PACKAGE' \ ' pkg list|update|upgrade' } require_root() { if [ "$(id -u)" != 0 ]; then printf '%s\n' 'pkg: package changes require root' >&2 exit 1 fi } check_query() { for query do case "$query" in ''|-*) printf 'pkg: invalid query %s\n' "$query" >&2; exit 1 ;; esac done } check_package() { case "$1" in ''|-*|*[!a-zA-Z0-9._+-]*) printf 'pkg: invalid package name %s\n' "$1" >&2 exit 1 ;; esac } case "${1:-}" in help|-h|--help) usage; exit 0 ;; '') usage >&2; exit 1 ;; esac command=$1 shift case "$command" in install|add|remove|delete|del|info) if [ "$#" -eq 0 ]; then usage >&2; exit 1; fi for package do shift check_package "$package" if [ "$package" = x11 ]; then package=vinix-release-x11; fi set -- "$@" "$package" done case "$command" in install|add) require_root; exec /usr/bin/vpac i --needed --noconfirm "$@" ;; remove|delete|del) require_root; exec /usr/bin/vpac r --recursive --noconfirm "$@" ;; info) exec /usr/bin/vpac q --noconfirm "$@" ;; esac ;; search) if [ "$#" -eq 0 ]; then usage >&2; exit 1; fi if [ "$1" = --exact ]; then shift if [ "$#" -ne 1 ]; then usage >&2; exit 1; fi check_package "$1" name=$1 if [ "$name" = x11 ]; then name=vinix-release-x11; fi matches=$(/usr/bin/vpac s --remote --quiet --noconfirm "$name") if printf '%s\n' "$matches" | grep -Fxq "$name"; then printf '%s\n' "$1"; fi exit 0 fi check_query "$@" exec /usr/bin/vpac s --remote --noconfirm "$@" ;; list|update|upgrade) if [ "$#" -ne 0 ]; then usage >&2; exit 1; fi case "$command" in list) exec /usr/bin/vpac s --local --quiet ;; update) require_root; exec /usr/bin/vpac s --remote --sync --quiet --noconfirm >/dev/null ;; upgrade) require_root; exec /usr/bin/vpac u --sync --noconfirm ;; esac ;; *) printf 'pkg: unknown command %s\n' "$command" >&2 usage >&2 exit 1 ;; esac