forked from ungleich-public/cdist
		
	add support for centos
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
		
					parent
					
						
							
								2bd48f1c8d
							
						
					
				
			
			
				commit
				
					
						5417471dff
					
				
			
		
					 3 changed files with 156 additions and 33 deletions
				
			
		
							
								
								
									
										100
									
								
								cdist/conf/type/__install_bootloader_grub/explorer/target_os
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										100
									
								
								cdist/conf/type/__install_bootloader_grub/explorer/target_os
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
					@ -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 <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# 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
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
#!/bin/sh
 | 
					#!/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.
 | 
					# This file is part of cdist.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
| 
						 | 
					@ -18,52 +18,74 @@
 | 
				
			||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
 | 
					# along with cdist. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
device="$(cat "$__object/parameter/device")"
 | 
					device="$(cat "$__object/parameter/device" 2>/dev/null || echo "/$__object_id")"
 | 
				
			||||||
chroot="$(cat "$__object/parameter/chroot")"
 | 
					chroot="$(cat "$__object/parameter/chroot")"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					target_os=$(cat "$__object/explorer/target_os")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cat << DONE
 | 
					mkdir "$__object/files"
 | 
				
			||||||
os=\$(
 | 
					install_script="$__object/files/install_script"
 | 
				
			||||||
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
 | 
					# Link file descriptor #6 with stdout
 | 
				
			||||||
exec 6>&1
 | 
					exec 6>&1
 | 
				
			||||||
# Link stdout with \$script
 | 
					# Link stdout with $install_script
 | 
				
			||||||
exec > \$script
 | 
					exec > $install_script
 | 
				
			||||||
 | 
					
 | 
				
			||||||
echo "#!/bin/sh -l"
 | 
					# Generate script to install bootloader on distro
 | 
				
			||||||
echo "grub-install $device"
 | 
					printf '#!/bin/sh -l\n'
 | 
				
			||||||
case \$os in
 | 
					printf 'grub-install "%s"\n' "$device"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					case "$target_os" in
 | 
				
			||||||
 | 
					   ubuntu|debian)
 | 
				
			||||||
 | 
					      printf 'update-grub\n'
 | 
				
			||||||
 | 
					   ;;
 | 
				
			||||||
   archlinux)
 | 
					   archlinux)
 | 
				
			||||||
      # bugfix/workarround: rebuild initramfs
 | 
					      # bugfix/workarround: rebuild initramfs
 | 
				
			||||||
      # FIXME: doesn't belong here
 | 
					      # FIXME: doesn't belong here
 | 
				
			||||||
      echo "mkinitcpio -p linux"
 | 
					      printf 'mkinitcpio -p linux\n'
 | 
				
			||||||
      echo "grub-mkconfig -o /boot/grub/grub.cfg"
 | 
					      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
 | 
					esac
 | 
				
			||||||
 | 
					 | 
				
			||||||
# Restore stdout and close file descriptor #6.
 | 
					# Restore stdout and close file descriptor #6.
 | 
				
			||||||
exec 1>&6 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
 | 
					# Make script executable
 | 
				
			||||||
chmod +x "\$script"
 | 
					chmod +x "\$script"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					/target
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue