From c93d0ba8a3399d76e13c440ea1de1502f39b1016 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 16 Jun 2017 07:05:41 +0200 Subject: [PATCH] Backport __chroot_mount, __chroot_umount and __install variants from Steven --- cdist/conf/type/__chroot_mount/gencode-local | 36 +++++++++++++++++++ cdist/conf/type/__chroot_mount/gencode-remote | 4 --- cdist/conf/type/__chroot_mount/man.rst | 19 ++++++++-- .../type/__chroot_mount/parameter/optional | 1 + cdist/conf/type/__chroot_umount/gencode-local | 36 +++++++++++++++++++ .../conf/type/__chroot_umount/gencode-remote | 1 - cdist/conf/type/__chroot_umount/man.rst | 17 +++++++-- cdist/conf/type/__chroot_umount/manifest | 36 +++++++++++++++++++ .../type/__chroot_umount/parameter/optional | 1 + .../type/__install_chroot_mount/parameter | 1 + .../type/__install_chroot_umount/parameter | 1 + 11 files changed, 143 insertions(+), 10 deletions(-) create mode 100755 cdist/conf/type/__chroot_mount/gencode-local create mode 100644 cdist/conf/type/__chroot_mount/parameter/optional create mode 100755 cdist/conf/type/__chroot_umount/gencode-local create mode 100755 cdist/conf/type/__chroot_umount/manifest create mode 100644 cdist/conf/type/__chroot_umount/parameter/optional create mode 120000 cdist/conf/type/__install_chroot_mount/parameter create mode 120000 cdist/conf/type/__install_chroot_umount/parameter diff --git a/cdist/conf/type/__chroot_mount/gencode-local b/cdist/conf/type/__chroot_mount/gencode-local new file mode 100755 index 00000000..2c3b51b8 --- /dev/null +++ b/cdist/conf/type/__chroot_mount/gencode-local @@ -0,0 +1,36 @@ +#!/bin/sh +# +# 2016 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +chroot="/$__object_id" + +if [ -f "$__object/parameter/manage-resolv-conf" ]; then + suffix="$(cat "$__object/parameter/manage-resolv-conf")" + resolv_conf="${chroot}/etc/resolv.conf" + original_resolv_conf="${resolv_conf}.${suffix}" + cat << DONE +$__remote_exec $__target_host << EOSSH +if [ -f "${resolv_conf}" ]; then + mv "${resolv_conf}" "${original_resolv_conf}" +fi +# copy hosts resolv.conf into chroot +cp /etc/resolv.conf "${resolv_conf}" +EOSSH +DONE +fi diff --git a/cdist/conf/type/__chroot_mount/gencode-remote b/cdist/conf/type/__chroot_mount/gencode-remote index 6d855f41..a3b94b33 100755 --- a/cdist/conf/type/__chroot_mount/gencode-remote +++ b/cdist/conf/type/__chroot_mount/gencode-remote @@ -41,8 +41,4 @@ mountpoint -q "${chroot}/dev/pts" \ [ -d "${chroot}/tmp" ] || mkdir -m 1777 "${chroot}/tmp" mountpoint -q "${chroot}/tmp" \ || mount -t tmpfs -o mode=1777,strictatime,nodev,nosuid tmpfs "${chroot}/tmp" - -if [ ! -f "${chroot}/etc/resolv.conf" ]; then - cp /etc/resolv.conf "${chroot}/etc/" -fi DONE diff --git a/cdist/conf/type/__chroot_mount/man.rst b/cdist/conf/type/__chroot_mount/man.rst index 0d7cdce3..41fd496b 100644 --- a/cdist/conf/type/__chroot_mount/man.rst +++ b/cdist/conf/type/__chroot_mount/man.rst @@ -1,5 +1,5 @@ cdist-type__chroot_mount(7) -=================================== +=========================== NAME ---- @@ -18,7 +18,17 @@ None OPTIONAL PARAMETERS ------------------- -None +manage-resolv-conf + manage /etc/resolv.conf inside the chroot. + Use the value of this parameter as the suffix to save a copy + of the current /etc/resolv.conf to /etc/resolv.conf.$suffix. + This is used by the __chroot_umount type to restore the initial + file content when unmounting the chroot. + + +BOOLEAN PARAMETERS +------------------ +None. EXAMPLES @@ -28,6 +38,9 @@ EXAMPLES __chroot_mount /path/to/chroot + __chroot_mount /path/to/chroot \ + --manage-resolv-conf "some-known-string" + AUTHORS ------- @@ -36,7 +49,7 @@ Steven Armstrong COPYING ------- -Copyright \(C) 2012 Steven Armstrong. You can redistribute it +Copyright \(C) 2012-2017 Steven Armstrong. 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/cdist/conf/type/__chroot_mount/parameter/optional b/cdist/conf/type/__chroot_mount/parameter/optional new file mode 100644 index 00000000..27928f2c --- /dev/null +++ b/cdist/conf/type/__chroot_mount/parameter/optional @@ -0,0 +1 @@ +manage-resolv-conf diff --git a/cdist/conf/type/__chroot_umount/gencode-local b/cdist/conf/type/__chroot_umount/gencode-local new file mode 100755 index 00000000..a6793534 --- /dev/null +++ b/cdist/conf/type/__chroot_umount/gencode-local @@ -0,0 +1,36 @@ +#!/bin/sh +# +# 2016 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +chroot="/$__object_id" + +if [ -f "$__object/parameter/manage-resolv-conf" ]; then + suffix="$(cat "$__object/parameter/manage-resolv-conf")" + resolv_conf="${chroot}/etc/resolv.conf" + original_resolv_conf="${resolv_conf}.${suffix}" +cat << DONE +$__remote_exec $__target_host << EOSSH +if [ -f "${original_resolv_conf}" ]; then + # restore original /etc/resolv.conf that we moved out of the way + # in __chroot_mount/gencode-local + mv -f "${original_resolv_conf}" "${resolv_conf}" +fi +EOSSH +DONE +fi diff --git a/cdist/conf/type/__chroot_umount/gencode-remote b/cdist/conf/type/__chroot_umount/gencode-remote index caf2c40c..bb854efe 100755 --- a/cdist/conf/type/__chroot_umount/gencode-remote +++ b/cdist/conf/type/__chroot_umount/gencode-remote @@ -26,7 +26,6 @@ umount -l "${chroot}/dev/pts" umount -l "${chroot}/dev" umount -l "${chroot}/sys" umount -l "${chroot}/proc" -rm -f "${chroot}/etc/resolv.conf" if [ -d "${chroot}/etc/resolvconf/resolv.conf.d" ]; then # ensure /etc/resolvconf/resolv.conf.d/tail is not linked to \ # e.g. /etc/resolvconf/resolv.conf.d/original diff --git a/cdist/conf/type/__chroot_umount/man.rst b/cdist/conf/type/__chroot_umount/man.rst index ff116da5..2a15f362 100644 --- a/cdist/conf/type/__chroot_umount/man.rst +++ b/cdist/conf/type/__chroot_umount/man.rst @@ -18,7 +18,17 @@ None OPTIONAL PARAMETERS ------------------- -None +manage-resolv-conf + manage /etc/resolv.conf inside the chroot. + Use the value of this parameter as the suffix to find the backup file + that was saved by the __chroot_mount. + This is used by the to restore the initial file content when unmounting + the chroot. + + +BOOLEAN PARAMETERS +------------------ +None. EXAMPLES @@ -28,6 +38,9 @@ EXAMPLES __chroot_umount /path/to/chroot + __chroot_umount /path/to/chroot \ + --manage-resolv-conf "some-known-string" + SEE ALSO -------- @@ -41,7 +54,7 @@ Steven Armstrong COPYING ------- -Copyright \(C) 2012 Steven Armstrong. You can redistribute it +Copyright \(C) 2012-2017 Steven Armstrong. 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/cdist/conf/type/__chroot_umount/manifest b/cdist/conf/type/__chroot_umount/manifest new file mode 100755 index 00000000..a6793534 --- /dev/null +++ b/cdist/conf/type/__chroot_umount/manifest @@ -0,0 +1,36 @@ +#!/bin/sh +# +# 2016 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +chroot="/$__object_id" + +if [ -f "$__object/parameter/manage-resolv-conf" ]; then + suffix="$(cat "$__object/parameter/manage-resolv-conf")" + resolv_conf="${chroot}/etc/resolv.conf" + original_resolv_conf="${resolv_conf}.${suffix}" +cat << DONE +$__remote_exec $__target_host << EOSSH +if [ -f "${original_resolv_conf}" ]; then + # restore original /etc/resolv.conf that we moved out of the way + # in __chroot_mount/gencode-local + mv -f "${original_resolv_conf}" "${resolv_conf}" +fi +EOSSH +DONE +fi diff --git a/cdist/conf/type/__chroot_umount/parameter/optional b/cdist/conf/type/__chroot_umount/parameter/optional new file mode 100644 index 00000000..27928f2c --- /dev/null +++ b/cdist/conf/type/__chroot_umount/parameter/optional @@ -0,0 +1 @@ +manage-resolv-conf diff --git a/cdist/conf/type/__install_chroot_mount/parameter b/cdist/conf/type/__install_chroot_mount/parameter new file mode 120000 index 00000000..5b5c9e20 --- /dev/null +++ b/cdist/conf/type/__install_chroot_mount/parameter @@ -0,0 +1 @@ +../__chroot_mount/parameter \ No newline at end of file diff --git a/cdist/conf/type/__install_chroot_umount/parameter b/cdist/conf/type/__install_chroot_umount/parameter new file mode 120000 index 00000000..4148bcd0 --- /dev/null +++ b/cdist/conf/type/__install_chroot_umount/parameter @@ -0,0 +1 @@ +../__chroot_umount/parameter \ No newline at end of file