From: lxoliva Date: Mon, 21 Sep 2009 07:15:46 +0000 (+0000) Subject: Make --force better: idempotent, less confusing messages, no empty X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=85571a08e396ad15d2ddfa38eeddab8acf1d8b5c;p=releases.git Make --force better: idempotent, less confusing messages, no empty files. From Rubén Rodríguez Pérez. Reformat for consistet indentation. Report at the end when errors were ignored. git-svn-id: http://www.fsfla.org/svn/fsfla/software/linux-libre/scripts@5540 559672b5-ba27-0410-b829-e8f1faed8b1b --- diff --git a/deblob-2.6.31 b/deblob-2.6.31 index 3426ac11eec..d553bd384c3 100755 --- a/deblob-2.6.31 +++ b/deblob-2.6.31 @@ -2,6 +2,7 @@ # Copyright (C) 2008, 2009 Alexandre Oliva # Copyright (C) 2008 Jeff Moe +# Copyright (C) 2009 Rubén Rodríguez # # 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 @@ -46,14 +47,24 @@ # from 1 if changes are needed that require rebuilding the tarball. kver=2.6.31 extra=1 -fatal () { - echo "$@" - exit 1 -} - case $1 in ---force) die () { echo ERROR: "$@": ignored >&2; }; forced=:; shift;; -*) die () { fatal "$@"; }; forced=false;; +--force) + echo "WARNING: Using the force, ignored errors will be" >&2 + die () { + echo ERROR: "$@" >&2 + errors=: + } + forced=: errors=false + shift + ;; +*) + die () { + echo ERROR: "$@" >&2 + echo Use --force to ignore + exit 1 + } + forced=false errors=false + ;; esac check=`echo "$0" | sed 's,[^/]*$,,;s,^$,.,;s,/*$,,'`/deblob-check @@ -68,129 +79,129 @@ else have_check=: fi +filetest () { + [ -f $1 ] +} + announce () { - echo - echo "$@" + echo + echo "$@" } clean_file () { - #$1 = filename - if test ! -f $1; then - die $1 does not exist, something is wrong - fi - rm $1 - echo $1: removed + #$1 = filename + filetest $1 || return + rm $1 + echo $1: removed } check_changed () { - if test ! -f $1; then - die $1 does not exist, something is wrong - elif cmp $1.deblob $1 > /dev/null; then - die $1 did not change, something is wrong - fi - mv $1.deblob $1 + #$1 = filename + if cmp $1.deblob $1 > /dev/null; then + rm $1.deblob + die $1 did not change, something is wrong && return 1 + fi + mv $1.deblob $1 } clean_blob () { - #$1 = filename - if $have_check; then - if test ! -f $1; then - die $1 does not exist, something is wrong - fi - name=$1 - set fnord "$@" -d - shift 2 - $check "$@" -i linux-$kver $name > $name.deblob - echo $name: removed blobs - check_changed $name - else - clean_file $1 - fi + #$1 = filename + filetest $1 || return + if $have_check; then + name=$1 + set fnord "$@" -d + shift 2 + $check "$@" -i linux-$kver $name > $name.deblob + check_changed $name && echo $name: removed blobs + else + clean_file $1 + fi } dummy_blob () { - #$1 = filename - if test -f $1; then - die $1 exists, something is wrong - elif test ! -f firmware/Makefile; then - die firmware/Makefile does not exist, something is wrong - fi - - clean_sed "s,`echo $1 | sed s,^firmware/,,`,\$(DEBLOBBED),g" \ - firmware/Makefile "dropped $1" + #$1 = filename + if test -f $1; then + die $1 exists, something is wrong && return + elif test ! -f firmware/Makefile; then + die firmware/Makefile does not exist, something is wrong && return + fi + + clean_sed "s,`echo $1 | sed s,^firmware/,,`,\$(DEBLOBBED),g" \ + firmware/Makefile "dropped $1" } clean_fw () { - #$1 = firmware text input, $2 = firmware output - if test ! -f $1; then - die $1 does not exist, something is wrong - elif test -f $2; then - die $2 exists, something is wrong - fi - clean_blob $1 -s 4 - dummy_blob $2 + #$1 = firmware text input, $2 = firmware output + filetest $1 || return + if test -f $2; then + die $2 exists, something is wrong && return + fi + clean_blob $1 -s 4 + dummy_blob $2 } drop_fw_file () { - #$1 = firmware text input, $2 = firmware output - if test ! -f $1; then - die $1 does not exist, something is wrong - elif test -f $2; then - die $2 exists, something is wrong - fi - clean_file $1 - dummy_blob $2 + #$1 = firmware text input, $2 = firmware output + filetest $1 || return + if test -f $2; then + die $2 exists, something is wrong && return + fi + clean_file $1 + dummy_blob $2 } clean_kconfig () { - #$1 = filename $2 = things to remove - case $1 in - -f) - shift - ;; - *) - if $have_check; then - return - fi - ;; - esac - sed "/^config \\($2\\)\$/{p;i\ + #$1 = filename $2 = things to remove + case $1 in + -f) + shift + ;; + *) + if $have_check; then + return + fi + ;; + esac + filetest $1 || return + sed "/^config \\($2\\)\$/{p;i\ depends on NONFREE d;}" $1 > $1.deblob - echo $1: marked config $2 as depending on NONFREE - check_changed $1 + check_changed $1 && echo $1: marked config $2 as depending on NONFREE } clean_mk () { - #$1 = config $2 = Makefile name - # We don't clean up Makefiles any more --lxoliva - # sed -i "/\\($1\\)/d" $2 - # echo $2: removed $1 support - # check_changed $2 - if sed -n "/\\($1\\)/p" $2 | grep . > /dev/null; then - : - else - die $2 does not contain matches for $1 - fi + #$1 = config $2 = Makefile name + # We don't clean up Makefiles any more --lxoliva + # sed -i "/\\($1\\)/d" $2 + # echo $2: removed $1 support + # check_changed $2 + filetest $2 || return + if sed -n "/\\($1\\)/p" $2 | grep . > /dev/null; then + : + else + die $2 does not contain matches for $1 + fi } clean_sed () { - #$1 = sed-script $2 = file $3 = comment - sed -e "$1" "$2" > "$2".deblob - echo $2: ${3-applied sed script $1} - check_changed "$2" + #$1 = sed-script $2 = file $3 = comment + filetest $2 || return + sed -e "$1" "$2" > "$2".deblob + check_changed $2 && echo $2: ${3-applied sed script $1} } reject_firmware () { - #$1 = file - clean_sed ' + #$1 = file + filetest $1 || return + clean_sed ' s,request\(_ihex\)\?_firmware\(_nowait\)\?,reject_firmware\2,g ' "$1" 'disabled non-Free firmware-loading machinery' } maybe_reject_firmware () { - #$1 = file - clean_sed ' + #$1 = file + filetest $1 || return + clean_sed ' s,request_firmware\(_nowait\)\?,maybe_reject_firmware\1,g ' "$1" 'retain Free firmware-loading machinery, disabling non-Free one' } @@ -203,8 +214,8 @@ undefine_macro () { macro=$1 repl=$2 msg=$3; shift 3 for f in "$@"; do clean_sed " - s,^#define $macro .*\$,/*(DEBLOBBED)*/,; - s,$macro,$repl,g; +s,^#define $macro .*\$,/*(DEBLOBBED)*/,; +s,$macro,$repl,g; " "$f" "$msg" done } @@ -255,18 +266,18 @@ for f in \ sound/pci/cs46xx/imgs/cwcdma.asp \ ; do if test ! $f; then - die $f is not present, something is amiss + die $f is not present, something is amiss && return fi done # Identify the tarball. -clean_sed " -s,^EXTRAVERSION.*,&-libre$extra, +grep -q 'EXTRAVERSION.*-libre' Makefile || +clean_sed "s,^EXTRAVERSION.*,&-libre$extra, " Makefile 'added -libre to EXTRAVERSION' # Add reject_firmware and maybe_reject_firmware -clean_sed ' -$i\ +grep -q _LINUX_LIBRE_FIRMWARE_H include/linux/firmware.h || +clean_sed '$i\ #ifndef _LINUX_LIBRE_FIRMWARE_H\ #define _LINUX_LIBRE_FIRMWARE_H\ \ @@ -1976,4 +1987,8 @@ clean_sed s,usb8388,whatever,g drivers/base/Kconfig 'removed blob name' clean_blob firmware/README.AddingFirmware clean_blob firmware/WHENCE +if $errors; then + echo errors above were ignored because of --force >&2 +fi + exit 0