diff --git a/cdist/conf/type/__install_bootloader_grub/manifest b/cdist/conf/type/__chroot_mount/gencode-local similarity index 56% rename from cdist/conf/type/__install_bootloader_grub/manifest rename to cdist/conf/type/__chroot_mount/gencode-local index 4c7c4955..2c3b51b8 100755 --- a/cdist/conf/type/__install_bootloader_grub/manifest +++ b/cdist/conf/type/__chroot_mount/gencode-local @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2016 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -18,8 +18,19 @@ # 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")" +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_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..0db6dee6 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-2015 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -18,51 +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") + +mkdir "$__object/files" +install_script="$__object/files/install_script" +# Link file descriptor #6 with stdout +exec 6>&1 +# Link stdout with $install_script +exec > $install_script + +# Generate script to install bootloader on distro +printf '#!/bin/sh -l\n' + +case "$target_os" in + ubuntu|debian) + 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) + 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) + 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 ($target_os) is currently not supported by this type (${__type##*/})." >&2 + echo "If you can, please contribute an implementation for it." >&2 + exit 1 + ;; +esac +# Restore stdout and close file descriptor #6. +exec 1>&6 6>&- + 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") -# Link file descriptor #6 with stdout -exec 6>&1 -# Link stdout with \$script -exec > \$script - -echo "#!/bin/sh -l" -echo "grub-install $device" -case \$os in - archlinux) - # bugfix/workarround: rebuild initramfs - # FIXME: doesn't belong here - echo "mkinitcpio -p linux" - echo "grub-mkconfig -o /boot/grub/grub.cfg" - ;; - ubuntu|debian) echo "update-grub" ;; -esac - -# Restore stdout and close file descriptor #6. -exec 1>&6 6>&- +script=\$(mktemp "${chroot}/tmp/${__type##*/}.XXXXXXXXXX") +cat > \$script << script_DONE +$(cat "$install_script") +script_DONE # Make script executable chmod +x "\$script" @@ -70,4 +93,5 @@ chmod +x "\$script" # Run script in chroot relative_script="\${script#$chroot}" chroot "$chroot" "\$relative_script" +rm -rf \$script DONE 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 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/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 58e6b162..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" : } @@ -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" diff --git a/cdist/conf/type/__install_config/gencode-local b/cdist/conf/type/__install_config/gencode-local index 674dec25..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 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011-2017 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -22,29 +22,15 @@ 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 -#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 \ +cdist config \ + $cdist_args \ --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 + 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 diff --git a/cdist/conf/type/__install_generate_fstab/gencode-local b/cdist/conf/type/__install_generate_fstab/gencode-local index d10e5b92..1fec9334 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")" @@ -44,6 +44,11 @@ for object in $(find "$__global/object/__install_mount" -path "*.cdist"); do tmpfs) pass=0 ;; + bind) + pass=0 + type=none + options="bind,$options" + ;; *) pass=1 ;; 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) diff --git a/cdist/conf/type/__install_mount/gencode-remote b/cdist/conf/type/__install_mount/gencode-remote index 3a35c139..b2498d41 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,18 +42,25 @@ 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\"" + 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' + device="${prefix}${device}" + 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 diff --git a/cdist/conf/type/__install_partition_msdos/man.rst b/cdist/conf/type/__install_partition_msdos/man.rst index 5ebb9218..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 @@ -49,6 +55,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 +66,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 a1547296..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 @@ -57,7 +59,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 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 /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 -# 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 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 - 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