2017-06-28 11:19:32 +00:00
|
|
|
#!/bin/sh -e
|
2013-08-29 20:33:43 +00:00
|
|
|
#
|
2015-10-27 14:54:50 +00:00
|
|
|
# 2011-2015 Steven Armstrong (steven-cdist at armstrong.cc)
|
2013-08-29 20:33:43 +00:00
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
#
|
|
|
|
|
2014-02-11 09:34:22 +00:00
|
|
|
device="$(cat "$__object/parameter/device" 2>/dev/null || echo "/$__object_id")"
|
2013-08-29 20:33:43 +00:00
|
|
|
chroot="$(cat "$__object/parameter/chroot")"
|
|
|
|
|
2014-02-11 09:34:22 +00:00
|
|
|
target_os=$(cat "$__object/explorer/target_os")
|
2013-08-29 20:33:43 +00:00
|
|
|
|
2014-02-11 09:34:22 +00:00
|
|
|
mkdir "$__object/files"
|
|
|
|
install_script="$__object/files/install_script"
|
2013-08-29 20:33:43 +00:00
|
|
|
# Link file descriptor #6 with stdout
|
|
|
|
exec 6>&1
|
2014-02-11 09:34:22 +00:00
|
|
|
# Link stdout with $install_script
|
2018-10-02 19:44:27 +00:00
|
|
|
exec > "$install_script"
|
2013-08-29 20:33:43 +00:00
|
|
|
|
2014-02-11 09:34:22 +00:00
|
|
|
# Generate script to install bootloader on distro
|
|
|
|
printf '#!/bin/sh -l\n'
|
|
|
|
|
|
|
|
case "$target_os" in
|
|
|
|
ubuntu|debian)
|
2016-12-20 10:08:24 +00:00
|
|
|
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
|
2014-02-11 09:34:22 +00:00
|
|
|
;;
|
2013-08-29 20:33:43 +00:00
|
|
|
archlinux)
|
2016-12-20 10:08:24 +00:00
|
|
|
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
|
2014-02-11 09:34:22 +00:00
|
|
|
;;
|
|
|
|
centos)
|
2016-12-20 10:08:24 +00:00
|
|
|
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
|
2014-02-11 09:34:22 +00:00
|
|
|
;;
|
|
|
|
*)
|
2016-12-20 10:08:24 +00:00
|
|
|
echo "Your operating system ($target_os) is currently not supported by this type (${__type##*/})." >&2
|
2014-02-11 09:34:22 +00:00
|
|
|
echo "If you can, please contribute an implementation for it." >&2
|
|
|
|
exit 1
|
2013-08-29 20:33:43 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
# Restore stdout and close file descriptor #6.
|
|
|
|
exec 1>&6 6>&-
|
|
|
|
|
2014-02-11 09:34:22 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2013-08-29 20:33:43 +00:00
|
|
|
# Make script executable
|
|
|
|
chmod +x "\$script"
|
|
|
|
|
|
|
|
# Run script in chroot
|
|
|
|
relative_script="\${script#$chroot}"
|
|
|
|
chroot "$chroot" "\$relative_script"
|
2016-12-20 10:08:24 +00:00
|
|
|
rm -rf \$script
|
2013-08-29 20:33:43 +00:00
|
|
|
DONE
|