From c1141453fea8d032458c816f13804d1e821b8117 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Mon, 20 Jan 2014 12:09:55 +0100 Subject: [PATCH 01/30] fix quoting Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_reset_disk/gencode-remote | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__install_reset_disk/gencode-remote b/cdist/conf/type/__install_reset_disk/gencode-remote index e8e9cf8c..42ed00c6 100755 --- a/cdist/conf/type/__install_reset_disk/gencode-remote +++ b/cdist/conf/type/__install_reset_disk/gencode-remote @@ -33,7 +33,7 @@ fi # stop mdadm raids if any if [ -r /proc/mdstat ]; then - md_name="\$(awk "/$disk_name/ {print \$1}" /proc/mdstat)" + md_name="\$(awk '/$disk_name/ {print \$1}' /proc/mdstat)" if [ -n "\$md_name" ]; then if command -v mdadm >/dev/null; then mdadm --stop "/dev/\$md_name" From 49dfcf4885f37606af48453edb8abbc76dc80315 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Mon, 20 Jan 2014 12:13:15 +0100 Subject: [PATCH 02/30] first remove lvm, then mdadm Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_reset_disk/gencode-remote | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cdist/conf/type/__install_reset_disk/gencode-remote b/cdist/conf/type/__install_reset_disk/gencode-remote index 42ed00c6..a16ded5a 100755 --- a/cdist/conf/type/__install_reset_disk/gencode-remote +++ b/cdist/conf/type/__install_reset_disk/gencode-remote @@ -31,6 +31,12 @@ if find /sys/class/block/$disk_name*/holders/ -mindepth 1 | grep -q holders/dm; fi fi +if command -v pvremove >/dev/null; then + pvremove --force --force --yes "$disk" || true +else + echo "WARNING: pvremove command not found" >&2 +fi + # stop mdadm raids if any if [ -r /proc/mdstat ]; then md_name="\$(awk '/$disk_name/ {print \$1}' /proc/mdstat)" @@ -43,12 +49,6 @@ if [ -r /proc/mdstat ]; then fi fi fi - -if command -v pvremove >/dev/null; then - pvremove --force --force --yes "$disk" || true -else - echo "WARNING: pvremove command not found" >&2 -fi if command -v mdadm >/dev/null; then mdadm --zero-superblock --force "$disk" || true else From 2bd48f1c8d77ef2bb43478cca03972509bb45618 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Mon, 20 Jan 2014 13:45:23 +0100 Subject: [PATCH 03/30] make nuking mdadm/lvm actually work Signed-off-by: Steven Armstrong --- .../type/__install_reset_disk/gencode-remote | 64 ++++++++++--------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/cdist/conf/type/__install_reset_disk/gencode-remote b/cdist/conf/type/__install_reset_disk/gencode-remote index a16ded5a..234715ac 100755 --- a/cdist/conf/type/__install_reset_disk/gencode-remote +++ b/cdist/conf/type/__install_reset_disk/gencode-remote @@ -22,38 +22,44 @@ disk="/$__object_id" disk_name="${disk##*/}" cat << DONE -# stop lvm's if any -if find /sys/class/block/$disk_name*/holders/ -mindepth 1 | grep -q holders/dm; then - if command -v vgchange >/dev/null; then - vgchange -a n + +debug() { + echo "[DEBUG] \$@" >&2 +} + +find_md_device_names() { + local disk_name="\$1" + for slave in \$(find /sys/devices/virtual/block/*/slaves/ -name "\${disk_name}*"); do + debug "slave: \$slave" + for holder in \$slave/holders/*; do + debug "holder: \$holder" + if [ -d "\$holder/md" ]; then + debug "mdadm found at \$holder" + holder_name="\${holder##*/}" + echo "\$holder_name" + fi + done + done +} + +# disable any enabled volume group +if command -v vgchange >/dev/null; then + vgchange -a n +else + echo "WARNING: vgchange command not found" >&2 +fi + +# disable any running mdadm arrays related to $disk +for md_name in \$(find_md_device_names "$disk_name" | sort | uniq); do + echo "md_name: \$md_name" + if command -v mdadm >/dev/null; then + mdadm --stop "/dev/\$md_name" else - echo "WARNING: vgchange command not found" >&2 + echo "WARNING: mdadm command not found" >&2 + echo "WARNING: could not stop active mdadm raid for disk $disk" >&2 fi -fi +done -if command -v pvremove >/dev/null; then - pvremove --force --force --yes "$disk" || true -else - echo "WARNING: pvremove command not found" >&2 -fi - -# stop mdadm raids if any -if [ -r /proc/mdstat ]; then - md_name="\$(awk '/$disk_name/ {print \$1}' /proc/mdstat)" - if [ -n "\$md_name" ]; then - if command -v mdadm >/dev/null; then - mdadm --stop "/dev/\$md_name" - else - echo "WARNING: mdadm command not found" >&2 - echo "WARNING: could not stop active mdadm raid for disk $disk" >&2 - fi - fi -fi -if command -v mdadm >/dev/null; then - mdadm --zero-superblock --force "$disk" || true -else - echo "WARNING: mdadm command not found" >&2 -fi # clean disks from any legacy signatures if command -v wipefs >/dev/null; then wipefs -a "$disk" || true From 5417471dffe60932bfba50b930aac5fcc711e592 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 11 Feb 2014 10:34:22 +0100 Subject: [PATCH 04/30] add support for centos Signed-off-by: Steven Armstrong --- .../explorer/target_os | 100 ++++++++++++++++++ .../__install_bootloader_grub/gencode-remote | 88 +++++++++------ .../parameter/default/chroot | 1 + 3 files changed, 156 insertions(+), 33 deletions(-) create mode 100755 cdist/conf/type/__install_bootloader_grub/explorer/target_os create mode 100644 cdist/conf/type/__install_bootloader_grub/parameter/default/chroot diff --git a/cdist/conf/type/__install_bootloader_grub/explorer/target_os b/cdist/conf/type/__install_bootloader_grub/explorer/target_os new file mode 100755 index 00000000..f235710a --- /dev/null +++ b/cdist/conf/type/__install_bootloader_grub/explorer/target_os @@ -0,0 +1,100 @@ +#!/bin/sh +# +# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2014 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 . +# +# +# All os variables are lower case. Keep this file in alphabetical +# order by os variable except in cases where order otherwise matters, +# in which case keep the primary os and its derivatives together in +# a block (see Debian and Redhat examples below). +# + +chroot="$(cat "$__object/parameter/chroot")" + +if grep -q ^Amazon "$chroot/etc/system-release" 2>/dev/null; then + echo amazon + exit 0 +fi + +if [ -f "$chroot/etc/arch-release" ]; then + echo archlinux + exit 0 +fi + +if [ -f "$chroot/etc/cdist-preos" ]; then + echo cdist-preos + exit 0 +fi + +### Debian and derivatives +if grep -q ^DISTRIB_ID=Ubuntu "$chroot/etc/lsb-release" 2>/dev/null; then + echo ubuntu + exit 0 +fi + +if [ -f "$chroot/etc/debian_version" ]; then + echo debian + exit 0 +fi +### + +if [ -f "$chroot/etc/gentoo-release" ]; then + echo gentoo + exit 0 +fi + +if [ -f "$chroot/etc/openwrt_version" ]; then + echo openwrt + exit 0 +fi + +if [ -f "$chroot/etc/owl-release" ]; then + echo owl + exit 0 +fi + +### Redhat and derivatives +if grep -q ^CentOS "$chroot/etc/redhat-release" 2>/dev/null; then + echo centos + exit 0 +fi + +if grep -q ^Fedora "$chroot/etc/redhat-release" 2>/dev/null; then + echo fedora + exit 0 +fi + +if [ -f "$chroot/etc/redhat-release" ]; then + echo redhat + exit 0 +fi +### + +if [ -f "$chroot/etc/SuSE-release" ]; then + echo suse + exit 0 +fi + +if [ -f "$chroot/etc/slackware-version" ]; then + echo slackware + exit 0 +fi + +echo "Unknown OS" >&2 +exit 1 diff --git a/cdist/conf/type/__install_bootloader_grub/gencode-remote b/cdist/conf/type/__install_bootloader_grub/gencode-remote index ed57331a..24a132ea 100755 --- a/cdist/conf/type/__install_bootloader_grub/gencode-remote +++ b/cdist/conf/type/__install_bootloader_grub/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011-2014 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -18,52 +18,74 @@ # along with cdist. If not, see . # -device="$(cat "$__object/parameter/device")" +device="$(cat "$__object/parameter/device" 2>/dev/null || echo "/$__object_id")" chroot="$(cat "$__object/parameter/chroot")" +target_os=$(cat "$__object/explorer/target_os") -cat << DONE -os=\$( -if grep -q ^DISTRIB_ID=Ubuntu ${chroot}/etc/lsb-release 2>/dev/null; then - echo ubuntu - exit 0 -fi - -if [ -f ${chroot}/etc/arch-release ]; then - echo archlinux - exit 0 -fi - -if [ -f ${chroot}/etc/debian_version ]; then - echo debian - exit 0 -fi -) - -# Ensure /tmp exists -[ -d "${chroot}/tmp" ] || mkdir -m 1777 "${chroot}/tmp" -# Generate script to run in chroot -script=\$(mktemp "${chroot}/tmp/__install_bootloader_grub.XXXXXXXXXX") +mkdir "$__object/files" +install_script="$__object/files/install_script" # Link file descriptor #6 with stdout exec 6>&1 -# Link stdout with \$script -exec > \$script +# Link stdout with $install_script +exec > $install_script -echo "#!/bin/sh -l" -echo "grub-install $device" -case \$os in +# Generate script to install bootloader on distro +printf '#!/bin/sh -l\n' +printf 'grub-install "%s"\n' "$device" + +case "$target_os" in + ubuntu|debian) + printf 'update-grub\n' + ;; archlinux) # bugfix/workarround: rebuild initramfs # FIXME: doesn't belong here - echo "mkinitcpio -p linux" - echo "grub-mkconfig -o /boot/grub/grub.cfg" + printf 'mkinitcpio -p linux\n' + printf 'grub-mkconfig -o /boot/grub/grub.cfg\n' + ;; + centos) + cat << centos_DONE +( +printf '# Generated by cdist ${__type##*/}' +printf 'default=0' +printf 'timeout=3' +for kernel in \$(find /boot -mindepth 1 -maxdepth 2 -name "vmlinuz-*"); do + kernel_version="\${kernel#*-}" + initramfs="\$(echo "\$kernel" | sed 's|/boot/vmlinuz-|/boot/initramfs-|').img" + root_device="\$(awk '\$2 == "/" {print \$1}' /etc/fstab)" + cat << centos_entry_DONE +title \$(cat /etc/redhat-release) (\$kernel_version) + # root is assumed to be on the first partition + root (hd0,0) + kernel \$kernel ro root=\$root_device norhgb noquiet + initrd \$initramfs +centos_entry_DONE +done +) > /boot/grub/grub.conf +cd /boot/grub +ln -sf grub.conf menu.lst +centos_DONE + ;; + *) + echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 + echo "If you can, please contribute an implementation for it." >&2 + exit 1 ;; - ubuntu|debian) echo "update-grub" ;; esac - # Restore stdout and close file descriptor #6. exec 1>&6 6>&- + +cat << DONE +# Ensure /tmp exists +[ -d "${chroot}/tmp" ] || mkdir -m 1777 "${chroot}/tmp" +# Generate script to run in chroot +script=\$(mktemp "${chroot}/tmp/${__type##*/}.XXXXXXXXXX") +cat > \$script << script_DONE +$(cat "$install_script") +script_DONE + # Make script executable chmod +x "\$script" diff --git a/cdist/conf/type/__install_bootloader_grub/parameter/default/chroot b/cdist/conf/type/__install_bootloader_grub/parameter/default/chroot new file mode 100644 index 00000000..ea8c4bf7 --- /dev/null +++ b/cdist/conf/type/__install_bootloader_grub/parameter/default/chroot @@ -0,0 +1 @@ +/target From f97e6c42c79f8d6a2059f5fc845ce9f9658fc952 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 11 Feb 2014 22:29:09 +0100 Subject: [PATCH 05/30] no point generating grub.conf at this time, there is no kernel installed yet Signed-off-by: Steven Armstrong --- .../__install_bootloader_grub/gencode-remote | 22 +--------------- .../type/__install_bootloader_grub/manifest | 25 ------------------- 2 files changed, 1 insertion(+), 46 deletions(-) delete mode 100755 cdist/conf/type/__install_bootloader_grub/manifest diff --git a/cdist/conf/type/__install_bootloader_grub/gencode-remote b/cdist/conf/type/__install_bootloader_grub/gencode-remote index 24a132ea..ccc38912 100755 --- a/cdist/conf/type/__install_bootloader_grub/gencode-remote +++ b/cdist/conf/type/__install_bootloader_grub/gencode-remote @@ -45,27 +45,7 @@ case "$target_os" in printf 'grub-mkconfig -o /boot/grub/grub.cfg\n' ;; centos) - cat << centos_DONE -( -printf '# Generated by cdist ${__type##*/}' -printf 'default=0' -printf 'timeout=3' -for kernel in \$(find /boot -mindepth 1 -maxdepth 2 -name "vmlinuz-*"); do - kernel_version="\${kernel#*-}" - initramfs="\$(echo "\$kernel" | sed 's|/boot/vmlinuz-|/boot/initramfs-|').img" - root_device="\$(awk '\$2 == "/" {print \$1}' /etc/fstab)" - cat << centos_entry_DONE -title \$(cat /etc/redhat-release) (\$kernel_version) - # root is assumed to be on the first partition - root (hd0,0) - kernel \$kernel ro root=\$root_device norhgb noquiet - initrd \$initramfs -centos_entry_DONE -done -) > /boot/grub/grub.conf -cd /boot/grub -ln -sf grub.conf menu.lst -centos_DONE + : ;; *) echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 diff --git a/cdist/conf/type/__install_bootloader_grub/manifest b/cdist/conf/type/__install_bootloader_grub/manifest deleted file mode 100755 index 4c7c4955..00000000 --- a/cdist/conf/type/__install_bootloader_grub/manifest +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh -# -# 2011 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 . -# - -# set defaults -device="$(cat "$__object/parameter/device" 2>/dev/null \ - || echo "/$__object_id" | tee "$__object/parameter/device")" -chroot="$(cat "$__object/parameter/chroot" 2>/dev/null \ - || echo "/target" | tee "$__object/parameter/chroot")" From bb62787c7c0ca695c14693aa0cfba4e8b365c4a3 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 10 Jul 2015 16:28:15 +0200 Subject: [PATCH 06/30] deal with that stinkin cdist marker thinggy Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_generate_fstab/gencode-local | 2 +- cdist/conf/type/__install_partition_msdos_apply/gencode-remote | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__install_generate_fstab/gencode-local b/cdist/conf/type/__install_generate_fstab/gencode-local index d10e5b92..4c9a87b9 100755 --- a/cdist/conf/type/__install_generate_fstab/gencode-local +++ b/cdist/conf/type/__install_generate_fstab/gencode-local @@ -25,7 +25,7 @@ mkdir "$__object/files" # get current UUID's from target_host $__remote_exec $__target_host blkid > "$__object/files/blkid" -for object in $(find "$__global/object/__install_mount" -path "*.cdist"); do +for object in $(find "$__global/object/__install_mount" -path "*.cdist-*"); do device="$(cat "$object/parameter/device")" dir="$(cat "$object/parameter/dir")" prefix="$(cat "$object/parameter/prefix")" diff --git a/cdist/conf/type/__install_partition_msdos_apply/gencode-remote b/cdist/conf/type/__install_partition_msdos_apply/gencode-remote index a1547296..00cff3d3 100755 --- a/cdist/conf/type/__install_partition_msdos_apply/gencode-remote +++ b/cdist/conf/type/__install_partition_msdos_apply/gencode-remote @@ -57,7 +57,7 @@ size_to_mb() { get_objects() { objects_file=$(mktemp) - for object in $(find "$__global/object/__install_partition_msdos" -path "*.cdist"); do + for object in $(find "$__global/object/__install_partition_msdos" -path "*.cdist-*"); do object_device="$(cat "$object/parameter/device")" object_minor="$(cat "$object/parameter/minor")" echo "$object_device $object_minor $object" >> $objects_file From 9ad203c7448d4fdfef8b2d39eb63a16893d9c881 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 10 Jul 2015 16:36:02 +0200 Subject: [PATCH 07/30] deal with that stinkin cdist marker thinggy Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_generate_fstab/gencode-local | 2 +- cdist/conf/type/__install_partition_msdos_apply/gencode-remote | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__install_generate_fstab/gencode-local b/cdist/conf/type/__install_generate_fstab/gencode-local index 4c9a87b9..5dfc0249 100755 --- a/cdist/conf/type/__install_generate_fstab/gencode-local +++ b/cdist/conf/type/__install_generate_fstab/gencode-local @@ -25,7 +25,7 @@ mkdir "$__object/files" # get current UUID's from target_host $__remote_exec $__target_host blkid > "$__object/files/blkid" -for object in $(find "$__global/object/__install_mount" -path "*.cdist-*"); do +for object in $(find "$__global/object/__install_mount" -type d -name "$__cdist_object_marker"); do device="$(cat "$object/parameter/device")" dir="$(cat "$object/parameter/dir")" prefix="$(cat "$object/parameter/prefix")" diff --git a/cdist/conf/type/__install_partition_msdos_apply/gencode-remote b/cdist/conf/type/__install_partition_msdos_apply/gencode-remote index 00cff3d3..e9ec588b 100755 --- a/cdist/conf/type/__install_partition_msdos_apply/gencode-remote +++ b/cdist/conf/type/__install_partition_msdos_apply/gencode-remote @@ -57,7 +57,7 @@ size_to_mb() { get_objects() { objects_file=$(mktemp) - for object in $(find "$__global/object/__install_partition_msdos" -path "*.cdist-*"); do + for object in $(find "$__global/object/__install_partition_msdos" -type d -name "$__cdist_object_marker"); do object_device="$(cat "$object/parameter/device")" object_minor="$(cat "$object/parameter/minor")" echo "$object_device $object_minor $object" >> $objects_file From d05f11b0b8636fe4eb1e658dbb4380553ca48808 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 10 Jul 2015 16:39:27 +0200 Subject: [PATCH 08/30] deal with that stinkin cdist marker thinggy Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_mount/gencode-remote | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__install_mount/gencode-remote b/cdist/conf/type/__install_mount/gencode-remote index 3a35c139..ea5d260b 100755 --- a/cdist/conf/type/__install_mount/gencode-remote +++ b/cdist/conf/type/__install_mount/gencode-remote @@ -20,7 +20,7 @@ get_type_from_mkfs() { _device="$1" - for mkfs_object in $(find "$__global/object/__install_mkfs" -path "*.cdist"); do + for mkfs_object in $(find "$__global/object/__install_mkfs" -type d -name "$__cdist_object_marker"); do mkfs_device="$(cat "$mkfs_object/parameter/device")" if [ "$_device" = "$mkfs_device" ]; then cat "$mkfs_object/parameter/type" @@ -42,7 +42,10 @@ else # store for later use by others echo "$type" > "$__object/parameter/type" fi -[ -n "$type" ] || die "Can't determine type for $__object" +[ -n "$type" ] || { + echo "Can't determine type for $__object" >&2 + exit 1 +} if [ "$type" = "swap" ]; then echo "swapon \"$device\"" else From fd6258c90e1c3b1090279c862eee24e0374f077a Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 27 Oct 2015 15:54:30 +0100 Subject: [PATCH 09/30] unsure apt index is up2date Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_config/gencode-local | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/cdist/conf/type/__install_config/gencode-local b/cdist/conf/type/__install_config/gencode-local index 674dec25..6f9bb3c7 100755 --- a/cdist/conf/type/__install_config/gencode-local +++ b/cdist/conf/type/__install_config/gencode-local @@ -26,25 +26,9 @@ cdist_args="-v" [ "$__debug" = "yes" ] && cdist_args="$cdist_args -d" cat << DONE -#echo "__apt_noautostart --state present" \ -# | cdist $cdist_args \ -# config \ -# --initial-manifest - \ -# --remote-exec="$remote_exec $chroot" \ -# --remote-copy="$remote_copy $chroot" \ -# $__target_host - cdist $cdist_args \ config \ --remote-exec="$remote_exec $chroot" \ --remote-copy="$remote_copy $chroot" \ $__target_host - -#echo "__apt_noautostart --state absent" \ -# | cdist $cdist_args \ -# config \ -# --initial-manifest - \ -# --remote-exec="$remote_exec $chroot" \ -# --remote-copy="$remote_copy $chroot" \ -# $__target_host DONE From c6e4888c842ef8ce5f18640cfdb2fac2675bff09 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 27 Oct 2015 15:54:50 +0100 Subject: [PATCH 10/30] support for centos7 Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_bootloader_grub/gencode-remote | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cdist/conf/type/__install_bootloader_grub/gencode-remote b/cdist/conf/type/__install_bootloader_grub/gencode-remote index ccc38912..0ca94b90 100755 --- a/cdist/conf/type/__install_bootloader_grub/gencode-remote +++ b/cdist/conf/type/__install_bootloader_grub/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011-2014 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011-2015 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -32,20 +32,22 @@ exec > $install_script # Generate script to install bootloader on distro printf '#!/bin/sh -l\n' -printf 'grub-install "%s"\n' "$device" case "$target_os" in ubuntu|debian) + printf 'grub-install "%s"\n' "$device" printf 'update-grub\n' ;; archlinux) # bugfix/workarround: rebuild initramfs # FIXME: doesn't belong here + printf 'grub-install "%s"\n' "$device" printf 'mkinitcpio -p linux\n' printf 'grub-mkconfig -o /boot/grub/grub.cfg\n' ;; centos) - : + printf 'grub2-install "%s"\n' "$device" + printf 'grub2-mkconfig --output=/boot/grub2/grub.cfg\n' ;; *) echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 From 1d42e4afcba38b1da14de40b6230e6901d62d863 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Mon, 4 Apr 2016 21:58:43 +0200 Subject: [PATCH 11/30] bind mount /etc/resolv.conf instead of overwriting/removing Signed-off-by: Steven Armstrong --- cdist/conf/type/__chroot_mount/gencode-remote | 5 ++--- cdist/conf/type/__chroot_umount/gencode-remote | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cdist/conf/type/__chroot_mount/gencode-remote b/cdist/conf/type/__chroot_mount/gencode-remote index 6d855f41..14da81ee 100755 --- a/cdist/conf/type/__chroot_mount/gencode-remote +++ b/cdist/conf/type/__chroot_mount/gencode-remote @@ -42,7 +42,6 @@ mountpoint -q "${chroot}/dev/pts" \ 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 +mountpoint -q "${chroot}/etc/resolv.conf" \ + || mount --bind -o ro /etc/resolv.conf "${chroot}/etc/resolv.conf" DONE diff --git a/cdist/conf/type/__chroot_umount/gencode-remote b/cdist/conf/type/__chroot_umount/gencode-remote index caf2c40c..ad06a0a2 100755 --- a/cdist/conf/type/__chroot_umount/gencode-remote +++ b/cdist/conf/type/__chroot_umount/gencode-remote @@ -26,7 +26,9 @@ umount -l "${chroot}/dev/pts" umount -l "${chroot}/dev" umount -l "${chroot}/sys" umount -l "${chroot}/proc" -rm -f "${chroot}/etc/resolv.conf" +if mountpoint -q "${chroot}/etc/resolv.conf"; then + umount "${chroot}/etc/resolv.conf" +fi 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 From 73cad9dee2c7c361d2dcacf5daa94b6bf7c74d42 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Mon, 4 Apr 2016 23:31:38 +0200 Subject: [PATCH 12/30] backcompat Signed-off-by: Steven Armstrong --- cdist/conf/type/__chroot_mount/gencode-remote | 10 ++++++++-- cdist/conf/type/__chroot_umount/gencode-remote | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__chroot_mount/gencode-remote b/cdist/conf/type/__chroot_mount/gencode-remote index 14da81ee..7ec41f28 100755 --- a/cdist/conf/type/__chroot_mount/gencode-remote +++ b/cdist/conf/type/__chroot_mount/gencode-remote @@ -42,6 +42,12 @@ mountpoint -q "${chroot}/dev/pts" \ mountpoint -q "${chroot}/tmp" \ || mount -t tmpfs -o mode=1777,strictatime,nodev,nosuid tmpfs "${chroot}/tmp" -mountpoint -q "${chroot}/etc/resolv.conf" \ - || mount --bind -o ro /etc/resolv.conf "${chroot}/etc/resolv.conf" +if [ -f "${chroot}/etc/resolv.conf" ]; then + # if file exists, bind mount over it + mountpoint -q "${chroot}/etc/resolv.conf" \ + || mount --bind -o ro /etc/resolv.conf "${chroot}/etc/resolv.conf" +else + # otherwise copy + cp /etc/resolv.conf "${chroot}/etc/resolv.conf" +fi DONE diff --git a/cdist/conf/type/__chroot_umount/gencode-remote b/cdist/conf/type/__chroot_umount/gencode-remote index ad06a0a2..cbcdeff2 100755 --- a/cdist/conf/type/__chroot_umount/gencode-remote +++ b/cdist/conf/type/__chroot_umount/gencode-remote @@ -28,6 +28,8 @@ umount -l "${chroot}/sys" umount -l "${chroot}/proc" if mountpoint -q "${chroot}/etc/resolv.conf"; then umount "${chroot}/etc/resolv.conf" +else + rm -rf "${chroot}/etc/resolv.conf" fi if [ -d "${chroot}/etc/resolvconf/resolv.conf.d" ]; then # ensure /etc/resolvconf/resolv.conf.d/tail is not linked to \ From aea9747918daa1b597d88b78ff2f47e93c43f6e1 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 26 Apr 2016 22:39:36 +0200 Subject: [PATCH 13/30] mount/umounting a chroot should not mess with resolv.conf at all Signed-off-by: Steven Armstrong --- cdist/conf/type/__chroot_mount/gencode-remote | 9 --------- cdist/conf/type/__chroot_umount/gencode-remote | 5 ----- 2 files changed, 14 deletions(-) diff --git a/cdist/conf/type/__chroot_mount/gencode-remote b/cdist/conf/type/__chroot_mount/gencode-remote index 7ec41f28..a3b94b33 100755 --- a/cdist/conf/type/__chroot_mount/gencode-remote +++ b/cdist/conf/type/__chroot_mount/gencode-remote @@ -41,13 +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 - # if file exists, bind mount over it - mountpoint -q "${chroot}/etc/resolv.conf" \ - || mount --bind -o ro /etc/resolv.conf "${chroot}/etc/resolv.conf" -else - # otherwise copy - cp /etc/resolv.conf "${chroot}/etc/resolv.conf" -fi DONE diff --git a/cdist/conf/type/__chroot_umount/gencode-remote b/cdist/conf/type/__chroot_umount/gencode-remote index cbcdeff2..bb854efe 100755 --- a/cdist/conf/type/__chroot_umount/gencode-remote +++ b/cdist/conf/type/__chroot_umount/gencode-remote @@ -26,11 +26,6 @@ umount -l "${chroot}/dev/pts" umount -l "${chroot}/dev" umount -l "${chroot}/sys" umount -l "${chroot}/proc" -if mountpoint -q "${chroot}/etc/resolv.conf"; then - umount "${chroot}/etc/resolv.conf" -else - rm -rf "${chroot}/etc/resolv.conf" -fi 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 From 4547d2efa1fd735b4c36be0c06df54c1794972d0 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 25 May 2016 12:39:11 +0200 Subject: [PATCH 14/30] properly escape single quotes Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_config/files/remote/exec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__install_config/files/remote/exec b/cdist/conf/type/__install_config/files/remote/exec index 58e6b162..fc217e3e 100755 --- a/cdist/conf/type/__install_config/files/remote/exec +++ b/cdist/conf/type/__install_config/files/remote/exec @@ -35,7 +35,10 @@ target_host="$__target_host" shift ssh="ssh -o User=root -q $target_host" -code="$ssh chroot $chroot sh -c '$@'" + +# escape ' with '"'"' +code="$(echo "$@" | sed -e "s/'/'\"'\"'/g")" +code="$ssh chroot $chroot sh -c '$code'" log "target_host: $target_host" log "chroot: $chroot" From ce82e32c5962af7ad473fa83d63f29c39e7d1feb Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 16 Jun 2016 16:02:29 +0200 Subject: [PATCH 15/30] handle resolv.conf Signed-off-by: Steven Armstrong --- .../conf/type/__install_config/gencode-local | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__install_config/gencode-local b/cdist/conf/type/__install_config/gencode-local index 6f9bb3c7..4f1dcc23 100755 --- a/cdist/conf/type/__install_config/gencode-local +++ b/cdist/conf/type/__install_config/gencode-local @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011-2016 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -25,6 +25,16 @@ remote_copy="$__type/files/remote/copy" cdist_args="-v" [ "$__debug" = "yes" ] && cdist_args="$cdist_args -d" + +cat << DONE +$__remote_exec $__target_host << EOSSH +if [ ! -f "${chroot}/etc/resolv.conf" ]; then + touch "${chroot}/etc/resolv.conf" +fi +mount --bind -o ro /etc/resolv.conf "${chroot}/etc/resolv.conf" +EOSSH +DONE + cat << DONE cdist $cdist_args \ config \ @@ -32,3 +42,16 @@ cdist $cdist_args \ --remote-copy="$remote_copy $chroot" \ $__target_host DONE + +cat << DONE +$__remote_exec $__target_host << EOSSH +if mountpoint -q "${chroot}/etc/resolv.conf"; + umount "${chroot}/etc/resolv.conf" +fi +if [ -f "${chroot}/etc/resolv.conf" -a ! -s "${chroot}/etc/resolv.conf" ]; then + # file exists but is empty which means we created it or it's useless anyway + rm "${chroot}/etc/resolv.conf" +fi + +EOSSH +DONE From 8305477e01d0e07a9ab166c2b95cee19ca68b11d Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 22 Jun 2016 23:54:14 +0200 Subject: [PATCH 16/30] fix typo Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_config/gencode-local | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__install_config/gencode-local b/cdist/conf/type/__install_config/gencode-local index 4f1dcc23..cbf916da 100755 --- a/cdist/conf/type/__install_config/gencode-local +++ b/cdist/conf/type/__install_config/gencode-local @@ -45,7 +45,7 @@ DONE cat << DONE $__remote_exec $__target_host << EOSSH -if mountpoint -q "${chroot}/etc/resolv.conf"; +if mountpoint -q "${chroot}/etc/resolv.conf"; then umount "${chroot}/etc/resolv.conf" fi if [ -f "${chroot}/etc/resolv.conf" -a ! -s "${chroot}/etc/resolv.conf" ]; then From 2ce00f3357df1188c39556e90371497b1ad6a8a7 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 23 Sep 2016 15:33:17 +0200 Subject: [PATCH 17/30] fix syntax error Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_config/gencode-local | 1 + 1 file changed, 1 insertion(+) diff --git a/cdist/conf/type/__install_config/gencode-local b/cdist/conf/type/__install_config/gencode-local index cbf916da..980eb996 100755 --- a/cdist/conf/type/__install_config/gencode-local +++ b/cdist/conf/type/__install_config/gencode-local @@ -27,6 +27,7 @@ cdist_args="-v" cat << DONE + $__remote_exec $__target_host << EOSSH if [ ! -f "${chroot}/etc/resolv.conf" ]; then touch "${chroot}/etc/resolv.conf" From 9ee0de7c8bbcef8daa2f167d953ea2cf958bca77 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 7 Dec 2016 23:41:02 +0100 Subject: [PATCH 18/30] make uefi boot work Signed-off-by: Steven Armstrong --- cdist/conf/type/__chroot_mount/gencode-local | 35 +++++++++++++++++++ cdist/conf/type/__chroot_mount/man.rst | 10 ++++-- .../type/__chroot_mount/parameter/boolean | 1 + cdist/conf/type/__chroot_umount/gencode-local | 35 +++++++++++++++++++ cdist/conf/type/__chroot_umount/man.rst | 8 ++++- .../type/__chroot_umount/parameter/boolean | 1 + .../type/__install_chroot_mount/parameter | 1 + .../type/__install_chroot_umount/parameter | 1 + .../conf/type/__install_config/gencode-local | 23 ------------ .../type/__install_partition_msdos/man.rst | 4 ++- .../type/__install_partition_msdos/manifest | 13 ++++--- .../parameter/optional | 2 ++ .../gencode-remote | 2 ++ 13 files changed, 105 insertions(+), 31 deletions(-) create mode 100755 cdist/conf/type/__chroot_mount/gencode-local create mode 100644 cdist/conf/type/__chroot_mount/parameter/boolean create mode 100755 cdist/conf/type/__chroot_umount/gencode-local create mode 100644 cdist/conf/type/__chroot_umount/parameter/boolean 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..a2e1f423 --- /dev/null +++ b/cdist/conf/type/__chroot_mount/gencode-local @@ -0,0 +1,35 @@ +#!/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 + resolv_conf="${chroot}/etc/resolv.conf" + original_resolv_conf="${resolv_conf}${__cdist_object_marker}" + 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/man.rst b/cdist/conf/type/__chroot_mount/man.rst index 0d7cdce3..a44b70ba 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 ---- @@ -21,6 +21,12 @@ OPTIONAL PARAMETERS None +BOOLEAN PARAMETERS +------------------ +manage-resolv-conf + manage /etc/resolv.conf inside the chroot + + EXAMPLES -------- @@ -36,7 +42,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/boolean b/cdist/conf/type/__chroot_mount/parameter/boolean new file mode 100644 index 00000000..27928f2c --- /dev/null +++ b/cdist/conf/type/__chroot_mount/parameter/boolean @@ -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..97f126a5 --- /dev/null +++ b/cdist/conf/type/__chroot_umount/gencode-local @@ -0,0 +1,35 @@ +#!/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 + resolv_conf="${chroot}/etc/resolv.conf" + original_resolv_conf="${resolv_conf}${__cdist_object_marker}" +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/man.rst b/cdist/conf/type/__chroot_umount/man.rst index ff116da5..349cc2e0 100644 --- a/cdist/conf/type/__chroot_umount/man.rst +++ b/cdist/conf/type/__chroot_umount/man.rst @@ -21,6 +21,12 @@ OPTIONAL PARAMETERS None +BOOLEAN PARAMETERS +------------------ +manage-resolv-conf + manage /etc/resolv.conf inside the chroot + + EXAMPLES -------- @@ -41,7 +47,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/parameter/boolean b/cdist/conf/type/__chroot_umount/parameter/boolean new file mode 100644 index 00000000..27928f2c --- /dev/null +++ b/cdist/conf/type/__chroot_umount/parameter/boolean @@ -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 diff --git a/cdist/conf/type/__install_config/gencode-local b/cdist/conf/type/__install_config/gencode-local index 980eb996..30434d1b 100755 --- a/cdist/conf/type/__install_config/gencode-local +++ b/cdist/conf/type/__install_config/gencode-local @@ -25,17 +25,6 @@ remote_copy="$__type/files/remote/copy" cdist_args="-v" [ "$__debug" = "yes" ] && cdist_args="$cdist_args -d" - -cat << DONE - -$__remote_exec $__target_host << EOSSH -if [ ! -f "${chroot}/etc/resolv.conf" ]; then - touch "${chroot}/etc/resolv.conf" -fi -mount --bind -o ro /etc/resolv.conf "${chroot}/etc/resolv.conf" -EOSSH -DONE - cat << DONE cdist $cdist_args \ config \ @@ -44,15 +33,3 @@ cdist $cdist_args \ $__target_host DONE -cat << DONE -$__remote_exec $__target_host << EOSSH -if mountpoint -q "${chroot}/etc/resolv.conf"; then - umount "${chroot}/etc/resolv.conf" -fi -if [ -f "${chroot}/etc/resolv.conf" -a ! -s "${chroot}/etc/resolv.conf" ]; then - # file exists but is empty which means we created it or it's useless anyway - rm "${chroot}/etc/resolv.conf" -fi - -EOSSH -DONE diff --git a/cdist/conf/type/__install_partition_msdos/man.rst b/cdist/conf/type/__install_partition_msdos/man.rst index 5ebb9218..aa194110 100644 --- a/cdist/conf/type/__install_partition_msdos/man.rst +++ b/cdist/conf/type/__install_partition_msdos/man.rst @@ -49,6 +49,8 @@ EXAMPLES __install_partition_msdos /dev/sda6 --type 83 --size 50% # rest of the extended partition, linux __install_partition_msdos /dev/sda7 --type 83 --size + + # nvm device partition 2 + __install_partition_msdos /dev/nvme0n1p2 --device /dev/nvme0n1 --minor 2 --type 83 --size 128M --bootable true AUTHORS @@ -58,7 +60,7 @@ Steven Armstrong COPYING ------- -Copyright \(C) 2011 Steven Armstrong. You can redistribute it +Copyright \(C) 2011-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/__install_partition_msdos/manifest b/cdist/conf/type/__install_partition_msdos/manifest index e55d3f24..636fbd6a 100755 --- a/cdist/conf/type/__install_partition_msdos/manifest +++ b/cdist/conf/type/__install_partition_msdos/manifest @@ -25,10 +25,15 @@ else partition="/$__object_id" echo "$partition" > "$__object/parameter/partition" fi -device="$(echo "$partition" | sed 's/[0-9]//g')" -echo "$device" > "$__object/parameter/device" -minor="$(echo "$partition" | sed 's/[^0-9]//g')" -echo "$minor" > "$__object/parameter/minor" + +if [ ! -f "$__object/parameter/device" ]; then + device="$(echo "$partition" | sed 's/[0-9]//g')" + echo "$device" > "$__object/parameter/device" +fi +if [ ! -f "$__object/parameter/minor" ]; then + minor="$(echo "$partition" | sed 's/[^0-9]//g')" + echo "$minor" > "$__object/parameter/minor" +fi if [ ! -f "$__object/parameter/bootable" ]; then echo "false" > "$__object/parameter/bootable" diff --git a/cdist/conf/type/__install_partition_msdos/parameter/optional b/cdist/conf/type/__install_partition_msdos/parameter/optional index b2b0a4c2..3b3f2083 100644 --- a/cdist/conf/type/__install_partition_msdos/parameter/optional +++ b/cdist/conf/type/__install_partition_msdos/parameter/optional @@ -1,3 +1,5 @@ +device +minor partition bootable size diff --git a/cdist/conf/type/__install_partition_msdos_apply/gencode-remote b/cdist/conf/type/__install_partition_msdos_apply/gencode-remote index e9ec588b..60f2fd1e 100755 --- a/cdist/conf/type/__install_partition_msdos_apply/gencode-remote +++ b/cdist/conf/type/__install_partition_msdos_apply/gencode-remote @@ -18,6 +18,8 @@ # along with cdist. If not, see . # +#set -x + die() { echo "[__install_partition_msdos_apply] $@" >&2 exit 1 From 42e197a5bae4f3eb8f876528dbf683d8fdd923d9 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 9 Dec 2016 14:20:23 +0100 Subject: [PATCH 19/30] use the force when creating swap Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_mkfs/gencode-remote | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__install_mkfs/gencode-remote b/cdist/conf/type/__install_mkfs/gencode-remote index da643cce..63a4b96d 100755 --- a/cdist/conf/type/__install_mkfs/gencode-remote +++ b/cdist/conf/type/__install_mkfs/gencode-remote @@ -24,7 +24,7 @@ type="$(cat "$__object/parameter/type")" case "$type" in swap) - echo "mkswap $device" + echo "mkswap -f $device" exit 0 ;; xfs) From f9d371c6e3740c1e0244443771453be888b32a07 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 14 Dec 2016 08:12:02 +0100 Subject: [PATCH 20/30] use sysrq to reboot Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_reboot/gencode-remote | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__install_reboot/gencode-remote b/cdist/conf/type/__install_reboot/gencode-remote index 4358347d..c4307de8 100755 --- a/cdist/conf/type/__install_reboot/gencode-remote +++ b/cdist/conf/type/__install_reboot/gencode-remote @@ -20,4 +20,13 @@ options="$(cat "$__object/parameter/options")" -echo "reboot $options" +#echo "reboot $options" +cat << DONE +echo 1 > /proc/sys/kernel/sysrq +echo s > /proc/sysrq-trigger + +# close file descriptors to detach from ssh +sh -c 'sleep 3; echo b > /proc/sysrq-trigger' > /dev/null 2>&1 Date: Thu, 15 Dec 2016 14:08:08 +0100 Subject: [PATCH 21/30] add __install_directory type Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_directory/explorer | 1 + cdist/conf/type/__install_directory/gencode-remote | 1 + cdist/conf/type/__install_directory/install | 0 cdist/conf/type/__install_directory/man.rst | 1 + cdist/conf/type/__install_directory/parameter | 1 + 5 files changed, 4 insertions(+) create mode 120000 cdist/conf/type/__install_directory/explorer create mode 120000 cdist/conf/type/__install_directory/gencode-remote create mode 100644 cdist/conf/type/__install_directory/install create mode 120000 cdist/conf/type/__install_directory/man.rst create mode 120000 cdist/conf/type/__install_directory/parameter diff --git a/cdist/conf/type/__install_directory/explorer b/cdist/conf/type/__install_directory/explorer new file mode 120000 index 00000000..ba2591e1 --- /dev/null +++ b/cdist/conf/type/__install_directory/explorer @@ -0,0 +1 @@ +../__directory/explorer \ No newline at end of file diff --git a/cdist/conf/type/__install_directory/gencode-remote b/cdist/conf/type/__install_directory/gencode-remote new file mode 120000 index 00000000..c86d61c9 --- /dev/null +++ b/cdist/conf/type/__install_directory/gencode-remote @@ -0,0 +1 @@ +../__directory/gencode-remote \ No newline at end of file diff --git a/cdist/conf/type/__install_directory/install b/cdist/conf/type/__install_directory/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_directory/man.rst b/cdist/conf/type/__install_directory/man.rst new file mode 120000 index 00000000..1ad7fa84 --- /dev/null +++ b/cdist/conf/type/__install_directory/man.rst @@ -0,0 +1 @@ +../__directory/man.rst \ No newline at end of file diff --git a/cdist/conf/type/__install_directory/parameter b/cdist/conf/type/__install_directory/parameter new file mode 120000 index 00000000..e23d9672 --- /dev/null +++ b/cdist/conf/type/__install_directory/parameter @@ -0,0 +1 @@ +../__directory/parameter \ No newline at end of file From a495a20d9577d9111b8764a71bdaf5f6b47d0553 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 20 Dec 2016 11:08:24 +0100 Subject: [PATCH 22/30] uefi support Signed-off-by: Steven Armstrong --- .../__install_bootloader_grub/gencode-remote | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/cdist/conf/type/__install_bootloader_grub/gencode-remote b/cdist/conf/type/__install_bootloader_grub/gencode-remote index 0ca94b90..0db6dee6 100755 --- a/cdist/conf/type/__install_bootloader_grub/gencode-remote +++ b/cdist/conf/type/__install_bootloader_grub/gencode-remote @@ -35,22 +35,41 @@ printf '#!/bin/sh -l\n' case "$target_os" in ubuntu|debian) - printf 'grub-install "%s"\n' "$device" - printf 'update-grub\n' + if [ -s "$__global/explorer/efi" ]; then + # FIXME: untested. maybe also just run update-grub for EFI system? + printf 'grub-mkconfig --output=/boot/efi/EFI/%s/grub.cfg\n' "$target_os" + printf 'mkdir -p /boot/efi/EFI/BOOT\n' + printf 'cp /boot/efi/EFI/%s/grubx64.efi /boot/efi/EFI/BOOT/bootx64.efi' "$target_os" + else + printf 'grub-install "%s"\n' "$device" + printf 'update-grub\n' + fi ;; archlinux) - # bugfix/workarround: rebuild initramfs - # FIXME: doesn't belong here - printf 'grub-install "%s"\n' "$device" - printf 'mkinitcpio -p linux\n' - printf 'grub-mkconfig -o /boot/grub/grub.cfg\n' + if [ -s "$__global/explorer/efi" ]; then + echo "EFI boot loader installation is on your operating system ($target_os) is currently not supported by this type (${__type##*/})." >&2 + echo "Please contribute an implementation for it if you can." >&2 + exit 1 + else + printf 'grub-install "%s"\n' "$device" + # bugfix/workarround: rebuild initramfs + # FIXME: doesn't belong here + printf 'mkinitcpio -p linux\n' + printf 'grub-mkconfig -o /boot/grub/grub.cfg\n' + fi ;; centos) - printf 'grub2-install "%s"\n' "$device" - printf 'grub2-mkconfig --output=/boot/grub2/grub.cfg\n' + if [ -s "$__global/explorer/efi" ]; then + printf 'grub2-mkconfig --output=/boot/efi/EFI/%s/grub.cfg\n' "$target_os" + printf 'mkdir -p /boot/efi/EFI/BOOT\n' + printf 'cp /boot/efi/EFI/%s/grubx64.efi /boot/efi/EFI/BOOT/bootx64.efi' "$target_os" + else + printf 'grub2-install "%s"\n' "$device" + printf 'grub2-mkconfig --output=/boot/grub2/grub.cfg\n' + fi ;; *) - echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 + echo "Your operating system ($target_os) is currently not supported by this type (${__type##*/})." >&2 echo "If you can, please contribute an implementation for it." >&2 exit 1 ;; @@ -74,4 +93,5 @@ chmod +x "\$script" # Run script in chroot relative_script="\${script#$chroot}" chroot "$chroot" "\$relative_script" +rm -rf \$script DONE From 058e4d757bf43266b9d6001c367518a01e962b1c Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 18 Jan 2017 21:14:17 +0100 Subject: [PATCH 23/30] disabel debug log Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_config/files/remote/copy | 2 +- cdist/conf/type/__install_config/files/remote/exec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__install_config/files/remote/copy b/cdist/conf/type/__install_config/files/remote/copy index 5b6f555c..df6a3f06 100755 --- a/cdist/conf/type/__install_config/files/remote/copy +++ b/cdist/conf/type/__install_config/files/remote/copy @@ -25,7 +25,7 @@ # log() { - echo "$@" | logger -t "__install_config copy" + #echo "$@" | logger -t "__install_config copy" : } diff --git a/cdist/conf/type/__install_config/files/remote/exec b/cdist/conf/type/__install_config/files/remote/exec index fc217e3e..17375693 100755 --- a/cdist/conf/type/__install_config/files/remote/exec +++ b/cdist/conf/type/__install_config/files/remote/exec @@ -25,7 +25,7 @@ # log() { - echo "$@" | logger -t "__install_config exec" + #echo "$@" | logger -t "__install_config exec" : } From 86a61bbcff9e8ff14fa3d38249ba97347afa4f4d Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 24 Jan 2017 00:08:55 +0100 Subject: [PATCH 24/30] 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 From efd935150093be4a7e94bd13361fd038f4436644 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 1 Feb 2017 06:53:13 +0100 Subject: [PATCH 25/30] document new parameters: device, minor Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_partition_msdos/man.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cdist/conf/type/__install_partition_msdos/man.rst b/cdist/conf/type/__install_partition_msdos/man.rst index aa194110..c408a614 100644 --- a/cdist/conf/type/__install_partition_msdos/man.rst +++ b/cdist/conf/type/__install_partition_msdos/man.rst @@ -19,6 +19,12 @@ type OPTIONAL PARAMETERS ------------------- +device + the device we're working on. Defaults to the string prefix of --partition + +minor + the partition number we're working on. Defaults to the numeric suffix of --partition + partition defaults to object_id From e74d2be2d47ddfd9468d75721177cb29c6591651 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 1 Feb 2017 07:16:19 +0100 Subject: [PATCH 26/30] add support for bind mounting Signed-off-by: Steven Armstrong --- .../conf/type/__install_mount/gencode-remote | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/cdist/conf/type/__install_mount/gencode-remote b/cdist/conf/type/__install_mount/gencode-remote index ea5d260b..35f08e57 100755 --- a/cdist/conf/type/__install_mount/gencode-remote +++ b/cdist/conf/type/__install_mount/gencode-remote @@ -47,16 +47,19 @@ fi exit 1 } if [ "$type" = "swap" ]; then - echo "swapon \"$device\"" + printf 'swapon "%s"\n' "$device" else - if [ -f "$__object/parameter/options" ]; then - options="$(cat "$__object/parameter/options")" - else - options="" - fi - [ -n "$options" ] && options="-o $options" mount_point="${prefix}${dir}" - - echo "[ -d \"$mount_point\" ] || mkdir -p \"$mount_point\"" - echo "mount -t \"$type\" $options \"$device\" \"$mount_point\"" + printf '[ -d "%s" ] || mkdir -p "%s"\n' "$mount_point" "$mount_point" + printf 'mount' + if [ "$type" = "bind" ]; then + printf ' --bind' + else + printf ' -t "%s"' "$type" + fi + if [ -f "$__object/parameter/options" ]; then + printf ' -o %s' "$(cat "$__object/parameter/options")" + fi + printf ' "%s"' "$device" + printf ' "%s"\n' "$mount_point" fi From 1627b58cfc0623ff1193ab94ae61138a8cb7effa Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 1 Feb 2017 07:42:06 +0100 Subject: [PATCH 27/30] for bind mount also have to prefix device Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_mount/gencode-remote | 1 + 1 file changed, 1 insertion(+) diff --git a/cdist/conf/type/__install_mount/gencode-remote b/cdist/conf/type/__install_mount/gencode-remote index 35f08e57..b2498d41 100755 --- a/cdist/conf/type/__install_mount/gencode-remote +++ b/cdist/conf/type/__install_mount/gencode-remote @@ -54,6 +54,7 @@ else printf 'mount' if [ "$type" = "bind" ]; then printf ' --bind' + device="${prefix}${device}" else printf ' -t "%s"' "$type" fi From c740c968903b93695aee84bc7e7a6de0785789d6 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 2 Feb 2017 22:52:39 +0100 Subject: [PATCH 28/30] set log level for cdist config based on env vars Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_config/gencode-local | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__install_config/gencode-local b/cdist/conf/type/__install_config/gencode-local index 30434d1b..a1caea69 100755 --- a/cdist/conf/type/__install_config/gencode-local +++ b/cdist/conf/type/__install_config/gencode-local @@ -22,8 +22,9 @@ chroot="$(cat "$__object/parameter/chroot")" remote_exec="$__type/files/remote/exec" remote_copy="$__type/files/remote/copy" -cdist_args="-v" -[ "$__debug" = "yes" ] && cdist_args="$cdist_args -d" +cdist_args="" +[ "$__verbose" = "yes" ] && cdist_args="-vv" +[ "$__debug" = "yes" ] && cdist_args="-d" cat << DONE cdist $cdist_args \ From b8fcd30a37d6a18e3d1d7e199e6e289f8cff69bf Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 2 Feb 2017 23:46:57 +0100 Subject: [PATCH 29/30] support for bind mounts Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_generate_fstab/gencode-local | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cdist/conf/type/__install_generate_fstab/gencode-local b/cdist/conf/type/__install_generate_fstab/gencode-local index 5dfc0249..1fec9334 100755 --- a/cdist/conf/type/__install_generate_fstab/gencode-local +++ b/cdist/conf/type/__install_generate_fstab/gencode-local @@ -44,6 +44,11 @@ for object in $(find "$__global/object/__install_mount" -type d -name "$__cdist_ tmpfs) pass=0 ;; + bind) + pass=0 + type=none + options="bind,$options" + ;; *) pass=1 ;; From 574f36f59398d005929a9f84f1a87d297a0157af Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 15 Jun 2017 22:42:46 +0200 Subject: [PATCH 30/30] fix order of arguments Signed-off-by: Steven Armstrong --- cdist/conf/type/__install_config/gencode-local | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cdist/conf/type/__install_config/gencode-local b/cdist/conf/type/__install_config/gencode-local index a1caea69..3767253e 100755 --- a/cdist/conf/type/__install_config/gencode-local +++ b/cdist/conf/type/__install_config/gencode-local @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011-2016 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011-2017 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -27,8 +27,8 @@ cdist_args="" [ "$__debug" = "yes" ] && cdist_args="-d" cat << DONE -cdist $cdist_args \ - config \ +cdist config \ + $cdist_args \ --remote-exec="$remote_exec $chroot" \ --remote-copy="$remote_copy $chroot" \ $__target_host