From 86a61bbcff9e8ff14fa3d38249ba97347afa4f4d Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 24 Jan 2017 00:08:55 +0100 Subject: [PATCH] need to pass a known suffix from outside Signed-off-by: Steven Armstrong --- cdist/conf/type/__chroot_mount/gencode-local | 3 +- cdist/conf/type/__chroot_mount/man.rst | 13 +++++-- .../parameter/{boolean => optional} | 0 cdist/conf/type/__chroot_umount/gencode-local | 3 +- cdist/conf/type/__chroot_umount/man.rst | 13 +++++-- cdist/conf/type/__chroot_umount/manifest | 36 +++++++++++++++++++ .../parameter/{boolean => optional} | 0 7 files changed, 60 insertions(+), 8 deletions(-) rename cdist/conf/type/__chroot_mount/parameter/{boolean => optional} (100%) create mode 100755 cdist/conf/type/__chroot_umount/manifest rename cdist/conf/type/__chroot_umount/parameter/{boolean => optional} (100%) diff --git a/cdist/conf/type/__chroot_mount/gencode-local b/cdist/conf/type/__chroot_mount/gencode-local index a2e1f423..2c3b51b8 100755 --- a/cdist/conf/type/__chroot_mount/gencode-local +++ b/cdist/conf/type/__chroot_mount/gencode-local @@ -21,8 +21,9 @@ 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}${__cdist_object_marker}" + original_resolv_conf="${resolv_conf}.${suffix}" cat << DONE $__remote_exec $__target_host << EOSSH if [ -f "${resolv_conf}" ]; then diff --git a/cdist/conf/type/__chroot_mount/man.rst b/cdist/conf/type/__chroot_mount/man.rst index a44b70ba..41fd496b 100644 --- a/cdist/conf/type/__chroot_mount/man.rst +++ b/cdist/conf/type/__chroot_mount/man.rst @@ -18,13 +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 ------------------ -manage-resolv-conf - manage /etc/resolv.conf inside the chroot +None. EXAMPLES @@ -34,6 +38,9 @@ EXAMPLES __chroot_mount /path/to/chroot + __chroot_mount /path/to/chroot \ + --manage-resolv-conf "some-known-string" + AUTHORS ------- diff --git a/cdist/conf/type/__chroot_mount/parameter/boolean b/cdist/conf/type/__chroot_mount/parameter/optional similarity index 100% rename from cdist/conf/type/__chroot_mount/parameter/boolean rename to cdist/conf/type/__chroot_mount/parameter/optional diff --git a/cdist/conf/type/__chroot_umount/gencode-local b/cdist/conf/type/__chroot_umount/gencode-local index 97f126a5..a6793534 100755 --- a/cdist/conf/type/__chroot_umount/gencode-local +++ b/cdist/conf/type/__chroot_umount/gencode-local @@ -21,8 +21,9 @@ 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}${__cdist_object_marker}" + original_resolv_conf="${resolv_conf}.${suffix}" cat << DONE $__remote_exec $__target_host << EOSSH if [ -f "${original_resolv_conf}" ]; then diff --git a/cdist/conf/type/__chroot_umount/man.rst b/cdist/conf/type/__chroot_umount/man.rst index 349cc2e0..2a15f362 100644 --- a/cdist/conf/type/__chroot_umount/man.rst +++ b/cdist/conf/type/__chroot_umount/man.rst @@ -18,13 +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 ------------------ -manage-resolv-conf - manage /etc/resolv.conf inside the chroot +None. EXAMPLES @@ -34,6 +38,9 @@ EXAMPLES __chroot_umount /path/to/chroot + __chroot_umount /path/to/chroot \ + --manage-resolv-conf "some-known-string" + SEE ALSO -------- 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/boolean b/cdist/conf/type/__chroot_umount/parameter/optional similarity index 100% rename from cdist/conf/type/__chroot_umount/parameter/boolean rename to cdist/conf/type/__chroot_umount/parameter/optional