From da8327a3dd7889447c4b52b5d5a098fd1f486956 Mon Sep 17 00:00:00 2001 From: Swindles McCoop <65102316+swindlesmccoop@users.noreply.github.com> Date: Wed, 5 Oct 2022 18:23:17 -0400 Subject: [PATCH] Add FreeBSD pkg (#66) * Add FreeBSD functionality * Fix logic * Update README Co-authored-by: swindlesmccoop --- README.md | 2 +- cpm | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 99e2d0b..70db4dd 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ sudo make install - urpmi (Mageia) - xbps (Void) - zypper (OpenSUSE) -- pkg (OpenBSD) +- pkg (FreeBSD and OpenBSD) ## Explicitly unsupported package managers diff --git a/cpm b/cpm index 25f0b6a..4a96671 100755 --- a/cpm +++ b/cpm @@ -1,6 +1,5 @@ #!/bin/sh # vim: set ai ts=2 et sw=2 tw=80: - # MIT License # # Copyright (c) 2022 Will Eccles @@ -162,7 +161,7 @@ su_do() { if [ "$(id -u)" != 0 ]; then if command -v sudo >/dev/null; then sudo "$@" - elif command -v doas >/dev/null && [ -f /etc/doas.conf ]; then + elif command -v doas >/dev/null && ([ -f /etc/doas.conf ] || [ -f /usr/local/etc/doas.conf ]); then doas "$@" else su root -c '"$@"' -- sh "$@" @@ -442,6 +441,22 @@ _pkg_() { esac } +_pkg() { + case "$OP" in + install) su_do pkg install "$@";; + remove) su_do pkg delete "$@";; + list) pkg info;; + count) pkg info | tot;; + update) su_do pkg update;; + upgrade) su_do pkg upgrade;; + search) pkg search "$@";; + show) pkg info "$@";; + files) pkg info -l "$@";; + from) pkg which "$@";; + clean) su_do pkg autoremove;; + esac +} + # Use pm=PKG_MANAGER cpm COMMAND to force a specific cpm function # ie.: pm=portage cpm list if [ "$pm" ] && has "_$pm"; then @@ -489,6 +504,9 @@ elif ! [ "$(uname -s)" = "Darwin" ]; then elif has pkg_info; then # openbsd _pkg_ "$@" + elif has pkg; then + # freebsd + _pkg "$@" elif has snap; then pem "Snapd is not supported [wontfix]" exit 1