This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "IPFire 2.x development tree".
The branch, master has been updated via ff3bae7b8974808300078a7be3b46852860e4d9b (commit) from bbf2fe890270c79b494a6ccb9e5a22012585b5ba (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- commit ff3bae7b8974808300078a7be3b46852860e4d9b Author: Michael Tremer michael.tremer@ipfire.org Date: Thu Dec 18 17:27:47 2014 +0100
Add script that automatically updates/installs GRUB2
This script also handles RAID devices
-----------------------------------------------------------------------
Summary of changes: config/rootfiles/common/stage2 | 1 + config/rootfiles/core/86/filelists/files | 1 + config/rootfiles/core/86/update.sh | 12 +-- src/scripts/update-bootloader | 133 +++++++++++++++++++++++++++++++ 4 files changed, 138 insertions(+), 9 deletions(-) create mode 100644 src/scripts/update-bootloader
Difference in files: diff --git a/config/rootfiles/common/stage2 b/config/rootfiles/common/stage2 index eb97040..9a4d8ed 100644 --- a/config/rootfiles/common/stage2 +++ b/config/rootfiles/common/stage2 @@ -95,6 +95,7 @@ usr/local/bin/settime usr/local/bin/timecheck usr/local/bin/timezone-transition #usr/local/bin/uname +usr/local/bin/update-bootloader usr/local/bin/update-lang-cache #usr/local/include #usr/local/lib diff --git a/config/rootfiles/core/86/filelists/files b/config/rootfiles/core/86/filelists/files index 456f6b8..63b9c5c 100644 --- a/config/rootfiles/core/86/filelists/files +++ b/config/rootfiles/core/86/filelists/files @@ -1,6 +1,7 @@ etc/system-release etc/issue opt/pakfire/etc/pakfire.conf +usr/local/bin/update-bootloader var/ipfire/header.pl var/ipfire/langs var/ipfire/lang.pl diff --git a/config/rootfiles/core/86/update.sh b/config/rootfiles/core/86/update.sh index 6d12023..db38844 100644 --- a/config/rootfiles/core/86/update.sh +++ b/config/rootfiles/core/86/update.sh @@ -180,16 +180,10 @@ case "$(uname -m)" in echo "GRUB_TERMINAL="serial"" >> /etc/default/grub echo "GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200"" >> /etc/default/grub fi - grub-mkconfig -o /boot/grub/grub.cfg
- ROOT=$(mount | grep " / " | cut -d" " -f1) - ROOT=${ROOT::-1} - - if ! grub-install --no-floppy --recheck "${ROOT}"; then - if ! grub-install --no-floppy --recheck --force "${ROOT}"; then - logger -p syslog.emerg -t ipfire \ - "Could not update the bootloader!" - fi + if ! /usr/local/bin/update-bootloader; then + logger -p syslog.emerg -t ipfire \ + "Could not update the bootloader!" fi ;; esac diff --git a/src/scripts/update-bootloader b/src/scripts/update-bootloader new file mode 100644 index 0000000..b011b72 --- /dev/null +++ b/src/scripts/update-bootloader @@ -0,0 +1,133 @@ +#!/bin/bash +############################################################################ +# # +# This file is part of the IPFire Firewall. # +# # +# IPFire 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 2 of the License, or # +# (at your option) any later version. # +# # +# IPFire 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 IPFire; if not, write to the Free Software # +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +# # +# Copyright (C) 2014 IPFire Team info@ipfire.org. # +# # +############################################################################ + +GRUB_INSTALL_ARGS="--no-floppy --recheck" + +function find_root_device() { + # rootfs / rootfs rw 0 0 + + local root + local dev mp fs flags rest + while read -r dev mp fs flags rest; do + # Skip unwanted entries + [ "${dev}" = "rootfs" ] && continue + + if [ "${mp}" = "/" ] && [ -b "${dev}" ]; then + root="$(basename "${dev}")" + break + fi + done < /proc/mounts + + # Get the actual device from the partition that holds / + if [ -n "${root}" ]; then + while [ -n "${root}" ]; do + if [ -e "/sys/block/${root}" ]; then + echo "${root}" + return 0 + fi + + # Remove last character + root="${root::-1}" + done + fi + + return 1 +} + +function root_device_is_mdraid() { + local device="${1}" + + [ -d "/sys/block/${device}/md" ] +} + +function mdraid_get_slaves() { + local device="${1}" + + local slave + for slave in /sys/block/${device}/slaves/*; do + basename "${slave}" + done 2>/dev/null +} + +function grub_update_config() { + echo "Updating configuration..." + + if ! grub-mkconfig -o /boot/grub/grub.cfg &>/dev/null; then + echo "Could not update configuration. Aborting." >&2 + return 1 + fi + + return 0 +} + +function grub_install() { + local device="${1}" + + echo "Installing GRUB on ${device}..." + + if [ ! -b "${device}" ]; then + echo "${device} does not exist or is not a block device" >&2 + return 1 + fi + + local args + for args in "" "--force"; do + if grub-install ${GRUB_INSTALL_ARGS} ${args} "${device}" &>/dev/null; then + return 0 + fi + done + + echo "Could not install GRUB on ${device}" >&2 + return 1 +} + +function main() { + # Find the root device + local device="$(find_root_device)" + if [ -z "${device}" ]; then + echo "Could not find root device. Aborting." >&2 + exit 1 + fi + + echo "Found root device: /dev/${device}" + + # Update configuration files + grub_update_config || exit $? + + # Handle mdraid devices + if root_device_is_mdraid "${device}"; then + local slave + for slave in $(mdraid_get_slaves "${device}"); do + grub_install "/dev/${slave}" + done + + # Handle normal block devices + else + grub_install "/dev/${device}" + fi + + return 0 +} + +# Run main function +main
hooks/post-receive -- IPFire 2.x development tree