add: __package_xbps

Introduce support for XBPS, the void-linux package manager.
This commit is contained in:
romain-dartigues 2024-04-11 20:30:18 +02:00
parent f01f110463
commit 14fb018315
7 changed files with 177 additions and 0 deletions

View file

@ -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 <http://www.gnu.org/licenses/>.
#
#
# 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

View file

@ -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 <http://www.gnu.org/licenses/>.
#
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

View file

@ -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 <romain.dartigues@gmail.com>
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.

31
type/__package_xbps/manifest Executable file
View file

@ -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 <http://www.gnu.org/licenses/>.
#
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

View file

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1,3 @@
name
onchange
state