blob: 14338158872c83b09627e51b3a23a6ab10e0f57d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2022 Patrick Spek <p.spek@tyil.nl>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# OS independent package management
pkg() {
local system="bashtard/pkg"
local action=$1 ; shift
local pkg
pkg="$(config "pkg.$1")"
if [[ -z $pkg ]]
then
warn "$system" "No explicit package name for $1"
pkg="$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-alpine_linux) set -- apk add --no-cache "$app" ;;
linux-debian*) set -- apt install -y "$app" ;;
linux-gentoo) set -- emerge --ask=n --update "$app" ;;
linux-ubuntu) set -- apt install -y "$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-alpine_linux) set -- apk del "$app" ;;
linux-debian*) set -- apt remove -y "$app" ;;
linux-gentoo) set -- emerge --ask=n --unmerge "$app" ;;
linux-ubuntu) set -- apt remove -y "$app" ;;
*)
crit "$system" "No package manager configured for ${BASHTARD_PLATFORM[key]}"
return 1
;;
esac
notice "$system" "$*"
# shellcheck disable=SC2068
$@
}
|