From 14fb0183155f2316f035ea885363428a8949153c Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Thu, 11 Apr 2024 20:30:18 +0200 Subject: [PATCH] add: __package_xbps Introduce support for XBPS, the void-linux package manager. --- type/__package_xbps/explorer/state | 36 +++++++++++++ type/__package_xbps/gencode-remote | 49 ++++++++++++++++++ type/__package_xbps/man.rst | 57 +++++++++++++++++++++ type/__package_xbps/manifest | 31 +++++++++++ type/__package_xbps/nonparallel | 0 type/__package_xbps/parameter/default/state | 1 + type/__package_xbps/parameter/optional | 3 ++ 7 files changed, 177 insertions(+) create mode 100755 type/__package_xbps/explorer/state create mode 100755 type/__package_xbps/gencode-remote create mode 100644 type/__package_xbps/man.rst create mode 100755 type/__package_xbps/manifest create mode 100644 type/__package_xbps/nonparallel create mode 100644 type/__package_xbps/parameter/default/state create mode 100644 type/__package_xbps/parameter/optional diff --git a/type/__package_xbps/explorer/state b/type/__package_xbps/explorer/state new file mode 100755 index 0000000..ca4e7d2 --- /dev/null +++ b/type/__package_xbps/explorer/state @@ -0,0 +1,36 @@ +#!/bin/sh +# +# 2019 Nico Schottelius (nico-cdist at schottelius.org) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# Retrieve the status of a package - parsed apk output +# + +if [ -f "$__object/parameter/name" ] +then name="$(cat "$__object/parameter/name")" +else name="$__object_id" +fi + +# Remove the @.. repo tag for finding out whether it is installed +# f.i. pass@testing => pass +name="$(echo "$name" | sed 's/@.*//')" + +if xbps-query -S "$name" | grep -q 'state: installed' +then echo present +else echo absent +fi diff --git a/type/__package_xbps/gencode-remote b/type/__package_xbps/gencode-remote new file mode 100755 index 0000000..9d97589 --- /dev/null +++ b/type/__package_xbps/gencode-remote @@ -0,0 +1,49 @@ +#!/bin/sh -e +# +# 2024 Romain Dartigues (romain.dartigues@gmail.com) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +if [ -f "$__object/parameter/name" ] +then name="$(cat "$__object/parameter/name")" +else name="$__object_id" +fi + +state_should="$(cat "$__object/parameter/state")" +state_is="$(cat "$__object/explorer/state")" + +# Nothing to be done +[ "$state_is" = "$state_should" ] && exit 0 + +case "$state_should" in +present) + echo "xbps-install '$name'" + echo "installed" >> "$__messages_out" + ;; +absent) + echo "xbps-remove '$name'" + echo "removed" >> "$__messages_out" + ;; +*) + echo "Unknown state: $state_should" >&2 + exit 1 + ;; +esac + +if [ -s "$__object/parameter/onchange" ] +then cat "$__object/parameter/onchange" +fi diff --git a/type/__package_xbps/man.rst b/type/__package_xbps/man.rst new file mode 100644 index 0000000..89aadd2 --- /dev/null +++ b/type/__package_xbps/man.rst @@ -0,0 +1,57 @@ +cdist-type__package_xbps(7) +=========================== + +NAME +---- +cdist-type__package_xbps - Manage packages with XBPS + + +DESCRIPTION +----------- +The X Binary Package System (XBPS) is a fast package manager that has is usually used on the Void Linux distribution. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +name + If supplied, use the name and not the object id as the package name. + +state + Either "present" or "absent", defaults to "present" + +onchange + The code to run if line is added, removed or updated. + +EXAMPLES +-------- + +.. code-block:: sh + + # Ensure zsh in installed + __package_xbps zsh --state present + + # Remove package + __package_xbps apache --state absent + + +SEE ALSO +-------- +:strong:`cdist-type__package`\ (7) + + +AUTHORS +------- +Romain Dartigues + + +COPYING +------- +Copyright \(C) 2024 Romain Dartigues. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/type/__package_xbps/manifest b/type/__package_xbps/manifest new file mode 100755 index 0000000..a0aa064 --- /dev/null +++ b/type/__package_xbps/manifest @@ -0,0 +1,31 @@ +#!/bin/sh -e +# +# 2024 Romain Dartigues (romain.dartigues@gmail.com) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + + +os=$(cat "$__global/explorer/os") + +case "$os" in +void) ;; +*) + printf "Your operating system (%s) is currently not supported by this type (%s)\n" "$os" "${__type##*/}" >&2 + printf "Please contribute an implementation for it if you can.\n" >&2 + exit 1 + ;; +esac diff --git a/type/__package_xbps/nonparallel b/type/__package_xbps/nonparallel new file mode 100644 index 0000000..e69de29 diff --git a/type/__package_xbps/parameter/default/state b/type/__package_xbps/parameter/default/state new file mode 100644 index 0000000..e7f6134 --- /dev/null +++ b/type/__package_xbps/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/type/__package_xbps/parameter/optional b/type/__package_xbps/parameter/optional new file mode 100644 index 0000000..4cd69d7 --- /dev/null +++ b/type/__package_xbps/parameter/optional @@ -0,0 +1,3 @@ +name +onchange +state