aboutsummaryrefslogtreecommitdiff
path: root/lib/util/pkg.bash
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2022-04-19 15:32:55 +0200
committerPatrick Spek <p.spek@tyil.nl>2022-04-19 15:32:55 +0200
commit685ccfd9e0d0d89b404129eb4ec068c923b375bc (patch)
treebadeca675a972e07315642f570da0bb6fee82c47 /lib/util/pkg.bash
parent9376473a6ff9ca276aa4650a7103d631005affd9 (diff)
Add documentation
Diffstat (limited to 'lib/util/pkg.bash')
-rw-r--r--lib/util/pkg.bash64
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/util/pkg.bash b/lib/util/pkg.bash
new file mode 100644
index 0000000..618ce6a
--- /dev/null
+++ b/lib/util/pkg.bash
@@ -0,0 +1,64 @@
+#!/usr/bin/env bash
+
+# OS independent package management
+pkg() {
+ local system="bashtard/pkg"
+ local action=$1 ; shift
+ local pkg
+
+ pkg="$(config "pkg.$1")" ; shift
+
+ if [[ -z $pkg ]]
+ then
+ crit "$system" "No package name for $pkg"
+ return 1
+ fi
+
+ if [[ "$(type -t "pkg_$action")" != "function" ]]
+ then
+ crit "$system" "Invalid package manager action $action"
+ return 1
+ fi
+
+ "pkg_$action" "$pkg"
+}
+
+pkg_install() {
+ local system="bashtard/pkg/install"
+
+ local app=$1 ; shift
+
+ case "${BASHTARD_PLATFORM[key]}" in
+ freebsd) set -- /usr/sbin/pkg install -y "$app" ;;
+ linux-debian*) set -- apt install -y "$app" ;;
+ linux-gentoo) set -- emerge --ask=n --update "$app" ;;
+ *)
+ crit "$system" "No package manager configured for ${BASHTARD_PLATFORM[key]}"
+ return 1
+ ;;
+ esac
+
+ notice "$system" "$*"
+ # shellcheck disable=SC2068
+ $@
+}
+
+pkg_uninstall() {
+ local system="bashtard/pkg/uninstall"
+
+ local app=$1 ; shift
+
+ case "${BASHTARD_PLATFORM[key]}" in
+ freebsd) set -- /usr/sbin/pkg uninstall -y "$app" ;;
+ linux-debian*) set -- apt remove -y "$app" ;;
+ linux-gentoo) set -- emerge --ask=n --unmerge "$app" ;;
+ *)
+ crit "$system" "No package manager configured for ${BASHTARD_PLATFORM[key]}"
+ return 1
+ ;;
+ esac
+
+ notice "$system" "$*"
+ # shellcheck disable=SC2068
+ $@
+}