Skip to content

Commit

Permalink
Add FreeBSD pkg (#66)
Browse files Browse the repository at this point in the history
* Add FreeBSD functionality

* Fix logic

* Update README

Co-authored-by: swindlesmccoop <[email protected]>
  • Loading branch information
swindlesmccoop and swindlesmccoop authored Oct 5, 2022
1 parent de14bca commit da8327a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ sudo make install
- urpmi (Mageia)
- xbps (Void)
- zypper (OpenSUSE)
- pkg (OpenBSD)
- pkg (FreeBSD and OpenBSD)

## Explicitly unsupported package managers

Expand Down
22 changes: 20 additions & 2 deletions cpm
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/sh
# vim: set ai ts=2 et sw=2 tw=80:

# MIT License
#
# Copyright (c) 2022 Will Eccles
Expand Down Expand Up @@ -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 "$@"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit da8327a

Please sign in to comment.