forked from ungleich-public/cdist
		
	Merge branch 'type/__dpkg_architecture' into 'master'
New type __dpkg_architecture See merge request ungleich-public/cdist!948
This commit is contained in:
		
				commit
				
					
						729fdb9c1a
					
				
			
		
					 7 changed files with 239 additions and 0 deletions
				
			
		
							
								
								
									
										26
									
								
								cdist/conf/type/__dpkg_architecture/explorer/architecture
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										26
									
								
								cdist/conf/type/__dpkg_architecture/explorer/architecture
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,26 @@
 | 
			
		|||
#!/bin/sh -e
 | 
			
		||||
# __dpkg_architecture/explorer/architecture
 | 
			
		||||
#
 | 
			
		||||
# 2020 Matthias Stecher <matthiasstecher at gmx.de>
 | 
			
		||||
#
 | 
			
		||||
# 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/>.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
# Get the main architecture of this machine
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# print or die in the gencode-remote
 | 
			
		||||
dpkg --print-architecture || true
 | 
			
		||||
							
								
								
									
										26
									
								
								cdist/conf/type/__dpkg_architecture/explorer/foreign-architectures
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										26
									
								
								cdist/conf/type/__dpkg_architecture/explorer/foreign-architectures
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,26 @@
 | 
			
		|||
#!/bin/sh -e
 | 
			
		||||
# __dpkg_architecture/explorer/foreign-architectures
 | 
			
		||||
#
 | 
			
		||||
# 2020 Matthias Stecher <matthiasstecher at gmx.de>
 | 
			
		||||
#
 | 
			
		||||
# 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/>.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
# Print all additional architectures
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# print or die in the gencode-remote
 | 
			
		||||
dpkg --print-foreign-architectures || true
 | 
			
		||||
							
								
								
									
										82
									
								
								cdist/conf/type/__dpkg_architecture/gencode-remote
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										82
									
								
								cdist/conf/type/__dpkg_architecture/gencode-remote
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,82 @@
 | 
			
		|||
#!/bin/sh -e
 | 
			
		||||
# __dpkg_architecture/gencode-remote
 | 
			
		||||
#
 | 
			
		||||
# 2020 Matthias Stecher <matthiasstecher at gmx.de>
 | 
			
		||||
#
 | 
			
		||||
# 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/>.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Get parameter and explorer
 | 
			
		||||
state_should="$(cat "$__object/parameter/state")"
 | 
			
		||||
arch_wanted="$__object_id"
 | 
			
		||||
main_arch="$(cat "$__object/explorer/architecture")"
 | 
			
		||||
 | 
			
		||||
# Exit here if dpkg do not work (empty explorer)
 | 
			
		||||
if [ -z "$main_arch" ]; then
 | 
			
		||||
    echo "dpkg is not available or unable to detect a architecture!" >&2
 | 
			
		||||
    exit 1
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Check if requested architecture is the main one
 | 
			
		||||
if [ "$arch_wanted" = "$main_arch" ]; then
 | 
			
		||||
    # higher than present; we can not remove it
 | 
			
		||||
    state_is="present"
 | 
			
		||||
    caution="yes"
 | 
			
		||||
 | 
			
		||||
# Check if the architecture not already used
 | 
			
		||||
elif grep -qFx "$arch_wanted" "$__object/explorer/foreign-architectures"; then
 | 
			
		||||
    state_is="present"
 | 
			
		||||
 | 
			
		||||
# arch does not exist
 | 
			
		||||
else
 | 
			
		||||
    state_is="absent"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Check what to do
 | 
			
		||||
if [ "$state_is" != "$state_should" ]; then
 | 
			
		||||
    case "$state_should" in
 | 
			
		||||
        present)
 | 
			
		||||
            # print add code
 | 
			
		||||
            printf "dpkg --add-architecture '%s'\n" "$arch_wanted"
 | 
			
		||||
            # updating the index to make the new architecture available
 | 
			
		||||
            echo "apt update"
 | 
			
		||||
 | 
			
		||||
            echo added >> "$__messages_out"
 | 
			
		||||
            ;;
 | 
			
		||||
 | 
			
		||||
        absent)
 | 
			
		||||
            if [ "$caution" ]; then
 | 
			
		||||
                printf "can not remove the main arch '%s' of the system!\n" "$main_arch" >&2
 | 
			
		||||
                exit 1
 | 
			
		||||
            fi
 | 
			
		||||
 | 
			
		||||
            # removing all existing packages for the architecture
 | 
			
		||||
            printf "apt purge '.*:%s'\n" "$arch_wanted"
 | 
			
		||||
            # print remove code
 | 
			
		||||
            printf "dpkg --remove-architecture '%s'\n" "$arch_wanted"
 | 
			
		||||
 | 
			
		||||
            echo removed >> "$__messages_out"
 | 
			
		||||
            ;;
 | 
			
		||||
 | 
			
		||||
        *)
 | 
			
		||||
            printf "state '%s' is unknown!\n" "$state_should" >&2
 | 
			
		||||
            exit 1
 | 
			
		||||
            ;;
 | 
			
		||||
    esac
 | 
			
		||||
fi
 | 
			
		||||
							
								
								
									
										103
									
								
								cdist/conf/type/__dpkg_architecture/man.rst
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								cdist/conf/type/__dpkg_architecture/man.rst
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,103 @@
 | 
			
		|||
cdist-type__dpkg_architecture(7)
 | 
			
		||||
================================
 | 
			
		||||
 | 
			
		||||
NAME
 | 
			
		||||
----
 | 
			
		||||
cdist-type__dpkg_architecture - Handles foreign architectures on debian-like
 | 
			
		||||
systems managed by `dpkg`
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
DESCRIPTION
 | 
			
		||||
-----------
 | 
			
		||||
This type handles foreign architectures on systems managed by
 | 
			
		||||
:strong:`dpkg`\ (1). The object id is the name of the architecture accepted by
 | 
			
		||||
`dpkg`, which should be added or removed.
 | 
			
		||||
 | 
			
		||||
If the architecture is not setup on the system, it adds a new architecture as a
 | 
			
		||||
new foreign architecture in `dpkg`. Then, it updates the apt package index to
 | 
			
		||||
make packages from the new architecture available.
 | 
			
		||||
 | 
			
		||||
If the architecture should be removed, it will remove it if it is not the base
 | 
			
		||||
architecture on where the system was installed on. Before it, it will purge
 | 
			
		||||
every package based on the "to be removed" architecture via `apt` to be able to
 | 
			
		||||
remove the selected architecture.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
REQUIRED PARAMETERS
 | 
			
		||||
-------------------
 | 
			
		||||
None.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
OPTIONAL PARAMETERS
 | 
			
		||||
-------------------
 | 
			
		||||
state
 | 
			
		||||
    ``present`` or ``absent``. Defaults to ``present``.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
MESSAGES
 | 
			
		||||
--------
 | 
			
		||||
added
 | 
			
		||||
   Added the specified architecture
 | 
			
		||||
 | 
			
		||||
removed
 | 
			
		||||
   Removed the specified architecture
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
ABORTS
 | 
			
		||||
------
 | 
			
		||||
Aborts in the following cases:
 | 
			
		||||
 | 
			
		||||
If :strong:`dpkg`\ (1) is not available. It will abort with a proper error
 | 
			
		||||
message.
 | 
			
		||||
 | 
			
		||||
If the architecture is the same as the base architecture the system is build
 | 
			
		||||
upon it (returned by ``dpkg --print-architecture``) and it should be removed.
 | 
			
		||||
 | 
			
		||||
It will fail if it can not execute :strong:`apt`\ (8). It is assumed that it is
 | 
			
		||||
already installed.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
EXAMPLES
 | 
			
		||||
--------
 | 
			
		||||
 | 
			
		||||
.. code-block:: sh
 | 
			
		||||
 | 
			
		||||
  # add i386 (32 bit) architecture
 | 
			
		||||
  __dpkg_architecture i386
 | 
			
		||||
 | 
			
		||||
  # remove it again :)
 | 
			
		||||
  __dpkg_architecture i386 --state absent
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
SEE ALSO
 | 
			
		||||
--------
 | 
			
		||||
`Multiarch on Debian systems <https://wiki.debian.org/Multiarch>`_
 | 
			
		||||
 | 
			
		||||
`How to setup multiarch on Debian <https://wiki.debian.org/Multiarch/HOWTO>`_
 | 
			
		||||
 | 
			
		||||
:strong:`dpkg`\ (1)
 | 
			
		||||
:strong:`cdist-type__package_dpkg`\ (7)
 | 
			
		||||
:strong:`cdist-type__package_apt`\ (7)
 | 
			
		||||
 | 
			
		||||
Useful commands:
 | 
			
		||||
 | 
			
		||||
.. code-block:: sh
 | 
			
		||||
 | 
			
		||||
   # base architecture installed on this system
 | 
			
		||||
   dpkg --print-architecture
 | 
			
		||||
 | 
			
		||||
   # extra architectures added
 | 
			
		||||
   dpkg --print-foreign-architectures
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
AUTHORS
 | 
			
		||||
-------
 | 
			
		||||
Matthias Stecher <matthiasstecher at gmx.de>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
COPYING
 | 
			
		||||
-------
 | 
			
		||||
Copyright \(C) 2020 Matthias Stecher. You can redistribute it
 | 
			
		||||
and/or modify it under the terms of the GNU General Public License as
 | 
			
		||||
ublished by the Free Software Foundation, either version 3 of the
 | 
			
		||||
License, or (at your option) any later version.
 | 
			
		||||
							
								
								
									
										0
									
								
								cdist/conf/type/__dpkg_architecture/nonparallel
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								cdist/conf/type/__dpkg_architecture/nonparallel
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
present
 | 
			
		||||
							
								
								
									
										1
									
								
								cdist/conf/type/__dpkg_architecture/parameter/optional
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								cdist/conf/type/__dpkg_architecture/parameter/optional
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
state
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue