#!/bin/sh # ------- # File: lliurex-grub2-default # Description: LliureX simple updater for /etc/default/grub # Author: Luis Garcia Gisbert # # This program 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. # # This program 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 this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA # -------- set -e DIVERT_FILES="grub" USR_DIR="/usr/share/grub/default" ETC_DIR="/etc/default" PNAME="lliurex-grub2" LLIUREX_DIR="/usr/share/$PNAME/default" HASH_FILE="/var/lib/ucf/hashfile" is_diverted(){ if [ "$(dpkg-divert --truename "$1")" = "$1" ] ; then return 1 fi return 0 } do_divert(){ for f in $DIVERT_FILES ; do F="$USR_DIR/${f}" if ! is_diverted "$F" ; then dpkg-divert --package "$PNAME" --rename --quiet --add --divert "$F.orig" "$F" || echo "Unable to divert file \"$F\"" >&2 fi cp "$LLIUREX_DIR/$f" "$F" do_etc_sync "$f" fix_ucf "$f" done } undo_divert(){ for f in $DIVERT_FILES ; do F="$USR_DIR/${f}" if is_diverted "$F" ; then rm -f "$F" dpkg-divert --package "$PNAME" --rename --quiet --remove "$F" || true fi do_etc_sync "$f" fix_ucf "$f" done } do_etc_sync(){ cp "$USR_DIR/$1" "$ETC_DIR/$1" } fix_ucf(){ # look in ucf if grep -q "[[:blank:]]$ETC_DIR/$1$" "$HASH_FILE" ; then TEMPFILE="$(tempfile)" cp -a "$HASH_FILE" "$TEMPFILE" sed -i -e "\%[[:blank:]]$ETC_DIR/$1$%d" "$TEMPFILE" md5sum "$ETC_DIR/$1" >> "$TEMPFILE" mv "$TEMPFILE" "$HASH_FILE" fi } do_update(){ grub-mkconfig -o /boot/grub/grub.cfg || true } # main case "$1" in divert) do_divert ;; undivert) undo_divert ;; *) echo "Usage: $0 {divert|undivert}" >&2 exit 1 ;; esac do_update exit 0