From 5417471dffe60932bfba50b930aac5fcc711e592 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 11 Feb 2014 10:34:22 +0100 Subject: [PATCH] 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