From aa7670cd6d2b560604f75ee93f08a37831c490ef Mon Sep 17 00:00:00 2001 From: Thorsten Glaser Date: Sat, 3 May 2014 11:07:02 +0000 Subject: require mksh for the update-patches helper script Signed-off-by: Thorsten Glaser --- scripts/update-patches | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/update-patches b/scripts/update-patches index f4303f841..8d7559a5c 100644 --- a/scripts/update-patches +++ b/scripts/update-patches @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env mksh # Copyright (c) 2006 # Thorsten Glaser # -- cgit v1.2.3 From fabbb1de0cddf2f096261e95490b8436f9ba8e7c Mon Sep 17 00:00:00 2001 From: Thorsten Glaser Date: Sat, 3 May 2014 11:18:01 +0000 Subject: lots of quoting and cleanup for files with spaces in them (ugh) Signed-off-by: Thorsten Glaser --- scripts/update-patches | 78 ++++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 35 deletions(-) (limited to 'scripts') diff --git a/scripts/update-patches b/scripts/update-patches index 8d7559a5c..7609fa34a 100644 --- a/scripts/update-patches +++ b/scripts/update-patches @@ -1,4 +1,7 @@ #!/usr/bin/env mksh +#- +# Copyright (c) 2014 +# Thorsten Glaser # Copyright (c) 2006 # Thorsten Glaser # @@ -24,15 +27,12 @@ # damage or existence of a defect, except proven that it results out # of said person's immediate fault when using the work as intended. -[[ -n $BASH_VERSION ]] && shopt -s extglob - -do_diff() -{ +do_diff() { local f1=$2/$1 local f2=$3/$1 if [[ ! -e $f1 ]]; then - [[ -d ${f1%/*}/. ]] || mkdir -p ${f1%/*} + [[ -d ${f1%/*}/. ]] || mkdir -p "${f1%/*}" if [[ ! -s $f2 ]]; then cat <> /tmp/debug + #echo "DEBUG: $file" >>/tmp/debug [[ ! -e $ORGDIST/$file && $patch_newfiles = 0 ]] && continue [[ $file = configure && $ignore_autoconf = 1 ]] && continue [[ $file = missing && $ignore_autoconf = 1 ]] && continue @@ -101,7 +104,7 @@ for file in $(cd ${WRKDIST}; find . -type f | sed 's#^\./##'); do cmp -s "$ORGDIST/$file" "$WRKDIST/$file" && continue echo "Processing ${file}..." >&2 # look in patchdir for an existing patchfile matching this - cd $PATCHDIR + cd "$PATCHDIR" for i in $PATCH_LIST; do # Ignore non-files, or old backup [[ ! -f $i || $i = *@(.orig|.rej|~) ]] && continue @@ -109,14 +112,14 @@ for file in $(cd ${WRKDIST}; find . -type f | sed 's#^\./##'); do # Patch found. Is this the one? if grep "^[+-][+-][+-] $D_CMP[^/]*/$file " "$i" >/dev/null; then # Multiple files in the diff? - if [ $(grep -c "^--- $D_CMP" "$i") -gt 1 -o \ - $(grep -c "^+++ $D_CMP" "$i") -gt 1 ]; then + if [[ $(grep -c "^--- $D_CMP" "$i") -gt 1 || \ + $(grep -c "^+++ $D_CMP" "$i") -gt 1 ]]; then echo "Cannot process, $i contains patches" >&2 echo "to multiple files! Aborting." >&2 echo FAIL [[ -n $SUBDIST ]] && mv \ - ${WRKDIR1}/${SUBDIST}.orig \ - ${WRKDIR1}.orig/${SUBDIST} + "${WRKDIR1}/${SUBDIST}.orig" \ + "${WRKDIR1}.orig/${SUBDIST}" exit 0 fi # Multiple diffs with this file? @@ -136,19 +139,19 @@ for file in $(cd ${WRKDIST}; find . -type f | sed 's#^\./##'); do echo "$pflst" >&2 echo FAIL [[ -n $SUBDIST ]] && mv \ - ${WRKDIR1}/${SUBDIST}.orig \ - ${WRKDIR1}.orig/${SUBDIST} + "${WRKDIR1}/${SUBDIST}.orig" \ + "${WRKDIR1}.orig/${SUBDIST}" exit 0 fi # No, process this patch - accounted="$accounted $i" + accounted+=("$i") # found it, copy preamble before comparision - ( sed -e "/^--- /,\$d" <$i; \ - cd $D_BASE && do_diff "$file" "$D_SUB.orig" "$D_SUB" \ + ( sed -e "/^--- /,\$d" <"$i"; \ + cd "$D_BASE" && do_diff "$file" "$D_SUB.orig" "$D_SUB" \ ) >"$i.new" # did it change ? mark it as changed - tfile="$(echo "$file" | $TRANSFORM)" + tfile=$(echo "$file" | $TRANSFORM) if eval diff "$(echo "${DIFF_FLAGS}" \ | sed "s#@@#${tfile}#g")" \ "$i" "$i.new" 1>&2; then @@ -157,30 +160,35 @@ for file in $(cd ${WRKDIST}; find . -type f | sed 's#^\./##'); do echo "Patch $i for $file updated" >&2 mv "$i" "$i.orig" mv "$i.new" "$i" - edit="$edit $i" + edit+=("$i") fi continue 2 fi done # Build a sensible name for the new patch file - patchname=patch-$(echo "$file" | sed -e 's#[/. ]#_#g') + patchname=patch-$(echo "$file" | sed -e 's#[/.- ]#_#g') echo "No patch-* found for $file, creating $patchname" >&2 - ( cd $D_BASE && do_diff "$file" "$D_SUB.orig" "$D_SUB" ) >$patchname - edit="$edit $patchname" - accounted="$accounted $patchname" + ( cd "$D_BASE" && do_diff "$file" "$D_SUB.orig" "$D_SUB" ) >"$patchname" + edit+=("$patchname") + accounted+=("$patchname") done # Verify all patches accounted for -cd $PATCHDIR +cd "$PATCHDIR" for i in *; do [[ ! -f $i || $i = *@(.orig|.rej|~) ]] && continue grep '^\\ No newline at end of file' $i >/dev/null \ && echo "*** Patch $i needs manual intervention" >&2 - [[ $accounted != *@($i)* ]] \ - && echo "*** Patch $i not accounted for" >&2 + found=0 + for j in "${accounted[@]}"; do + [[ $i = "$j" ]] || continue + found=1 + break + done + (( found )) || echo "*** Patch $i not accounted for" >&2 done -echo $edit -[[ -n $SUBDIST ]] && mv ${WRKDIR1}/${SUBDIST}.orig ${WRKDIR1}.orig/${SUBDIST} +echo "${edit[@]}" +[[ -n $SUBDIST ]] && mv "${WRKDIR1}/${SUBDIST}.orig" "${WRKDIR1}.orig/${SUBDIST}" exit 0 -- cgit v1.2.3 From fe8d93fb5856f5a60da3125b9a4c17c85d9b5edc Mon Sep 17 00:00:00 2001 From: Thorsten Glaser Date: Sat, 3 May 2014 11:21:27 +0000 Subject: =?UTF-8?q?more=20cleanup:=20echo=20=E2=86=92=20print?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thorsten Glaser --- scripts/update-patches | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'scripts') diff --git a/scripts/update-patches b/scripts/update-patches index 7609fa34a..b7e3d485d 100644 --- a/scripts/update-patches +++ b/scripts/update-patches @@ -87,11 +87,11 @@ else ignore_autoconf=0 fi -DIFF_FLAGS="-adu -I \"^--- $(echo "$D_SUBP.orig/" | $TRANSFORM)@@ .*\"" -DIFF_FLAGS="$DIFF_FLAGS -I \"^\+\+\+ $(echo "$D_SUBP/" | $TRANSFORM)@@ .*\"" +DIFF_FLAGS="-adu -I \"^--- $(print -r -- "$D_SUBP.orig/" | $TRANSFORM)@@ .*\"" +DIFF_FLAGS="$DIFF_FLAGS -I \"^\+\+\+ $(print -r -- "$D_SUBP/" | $TRANSFORM)@@ .*\"" for file in $(cd ${WRKDIST}; find . -type f | sed 's#^\./##'); do - #echo "DEBUG: $file" >>/tmp/debug + #print -r -- "DEBUG: <$file>" >>/tmp/debug [[ ! -e $ORGDIST/$file && $patch_newfiles = 0 ]] && continue [[ $file = configure && $ignore_autoconf = 1 ]] && continue [[ $file = missing && $ignore_autoconf = 1 ]] && continue @@ -102,7 +102,7 @@ for file in $(cd ${WRKDIST}; find . -type f | sed 's#^\./##'); do [[ $file = config.h.in && $ignore_autoconf = 1 ]] && continue [[ $(basename $file) = Makefile.in && $ignore_autoconf = 1 ]] && continue cmp -s "$ORGDIST/$file" "$WRKDIST/$file" && continue - echo "Processing ${file}..." >&2 + print -ru2 -- "Processing ${file}..." # look in patchdir for an existing patchfile matching this cd "$PATCHDIR" for i in $PATCH_LIST; do @@ -114,8 +114,8 @@ for file in $(cd ${WRKDIST}; find . -type f | sed 's#^\./##'); do # Multiple files in the diff? if [[ $(grep -c "^--- $D_CMP" "$i") -gt 1 || \ $(grep -c "^+++ $D_CMP" "$i") -gt 1 ]]; then - echo "Cannot process, $i contains patches" >&2 - echo "to multiple files! Aborting." >&2 + print -ru2 -- "Cannot process, $i contains patches" + print -ru2 -- "to multiple files! Aborting." echo FAIL [[ -n $SUBDIST ]] && mv \ "${WRKDIR1}/${SUBDIST}.orig" \ @@ -134,9 +134,9 @@ for file in $(cd ${WRKDIST}; find . -type f | sed 's#^\./##'); do pflst="$pflst '$j'" done if (( n != 1 )); then - echo "Cannot process, file $file" >&2 - echo "is contained in multiple patches:" >&2 - echo "$pflst" >&2 + print -ru2 -- "Cannot process, file $file" + print -ru2 -- "is contained in multiple patches:" + print -ru2 -- "$pflst" echo FAIL [[ -n $SUBDIST ]] && mv \ "${WRKDIR1}/${SUBDIST}.orig" \ @@ -151,13 +151,12 @@ for file in $(cd ${WRKDIST}; find . -type f | sed 's#^\./##'); do cd "$D_BASE" && do_diff "$file" "$D_SUB.orig" "$D_SUB" \ ) >"$i.new" # did it change ? mark it as changed - tfile=$(echo "$file" | $TRANSFORM) - if eval diff "$(echo "${DIFF_FLAGS}" \ - | sed "s#@@#${tfile}#g")" \ - "$i" "$i.new" 1>&2; then + tfile=$(print -r -- "$file" | $TRANSFORM) + if eval diff "$(print -r -- "${DIFF_FLAGS}" | sed \ + "s#@@#${tfile}#g")" "$i" "$i.new" 1>&2; then rm "$i.new" else - echo "Patch $i for $file updated" >&2 + print -ru2 -- "Patch $i for $file updated" mv "$i" "$i.orig" mv "$i.new" "$i" edit+=("$i") @@ -167,8 +166,8 @@ for file in $(cd ${WRKDIST}; find . -type f | sed 's#^\./##'); do done # Build a sensible name for the new patch file - patchname=patch-$(echo "$file" | sed -e 's#[/.- ]#_#g') - echo "No patch-* found for $file, creating $patchname" >&2 + patchname=patch-$(print -r -- "$file" | sed -e 's#[/.- ]#_#g') + print -ru2 -- "No patch-* found for $file, creating $patchname" ( cd "$D_BASE" && do_diff "$file" "$D_SUB.orig" "$D_SUB" ) >"$patchname" edit+=("$patchname") accounted+=("$patchname") @@ -178,17 +177,17 @@ done cd "$PATCHDIR" for i in *; do [[ ! -f $i || $i = *@(.orig|.rej|~) ]] && continue - grep '^\\ No newline at end of file' $i >/dev/null \ - && echo "*** Patch $i needs manual intervention" >&2 + grep '^\\ No newline at end of file' $i >/dev/null && \ + print -ru2 -- "*** Patch $i needs manual intervention" found=0 for j in "${accounted[@]}"; do [[ $i = "$j" ]] || continue found=1 break done - (( found )) || echo "*** Patch $i not accounted for" >&2 + (( found )) || print -ru2 -- "*** Patch $i not accounted for" done -echo "${edit[@]}" +print -r -- "${edit[@]}" [[ -n $SUBDIST ]] && mv "${WRKDIR1}/${SUBDIST}.orig" "${WRKDIR1}.orig/${SUBDIST}" exit 0 -- cgit v1.2.3 From 166aa788c57b5f842f89787b7d22dc47bc746602 Mon Sep 17 00:00:00 2001 From: Thorsten Glaser Date: Sat, 3 May 2014 11:29:42 +0000 Subject: move calling update-patches into a separate mksh script update-patches2 handling quoting much better Signed-off-by: Thorsten Glaser --- scripts/update-patches2 | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 scripts/update-patches2 (limited to 'scripts') diff --git a/scripts/update-patches2 b/scripts/update-patches2 new file mode 100644 index 000000000..8f8711af7 --- /dev/null +++ b/scripts/update-patches2 @@ -0,0 +1,46 @@ +#!/usr/bin/env mksh +#- +# Copyright © 2014 +# Thorsten Glaser +# +# Provided that these terms and disclaimer and all copyright notices +# are retained or reproduced in an accompanying document, permission +# is granted to deal in this work without restriction, including un‐ +# limited rights to use, publicly perform, distribute, sell, modify, +# merge, give away, or sublicence. +# +# This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to +# the utmost extent permitted by applicable law, neither express nor +# implied; without malicious intent or gross negligence. In no event +# may a licensor, author or contributor be held liable for indirect, +# direct, other damage, loss, or other issues arising in any way out +# of dealing in the work, even if advised of the possibility of such +# damage or existence of a defect, except proven that it results out +# of said person’s immediate fault when using the work as intended. + +PATCH_LIST='patch-* *.patch' +CURDIR=$PWD +export CURDIR PATCH_LIST + +mksh "${TOPDIR}"/scripts/update-patches |& +first=1 +set -A toedit +while IFS= read -p -r; do + if (( first )); then + if [[ $REPLY = FAIL ]]; then + rm -rf "${WRKDIR1}.orig" + exit 1 + fi + first=0 + fi + toedit+=("$REPLY") +done +if (( !first )); then + print -n 'edit patches: ' + read + cd patches + ${VISUAL:-${EDITOR:-vi}} "${toedit[@]}" + cd .. +fi +rm -rf "${WRKDIR1}.orig" +exit 0 -- cgit v1.2.3 From 8a0005b61300850e11fe19202ccd2118736ec661 Mon Sep 17 00:00:00 2001 From: Thorsten Glaser Date: Sat, 3 May 2014 11:36:16 +0000 Subject: pass patches NUL-terminated Signed-off-by: Thorsten Glaser --- scripts/update-patches | 11 +++++++---- scripts/update-patches2 | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/update-patches b/scripts/update-patches index b7e3d485d..1d13a3901 100644 --- a/scripts/update-patches +++ b/scripts/update-patches @@ -116,7 +116,7 @@ for file in $(cd ${WRKDIST}; find . -type f | sed 's#^\./##'); do $(grep -c "^+++ $D_CMP" "$i") -gt 1 ]]; then print -ru2 -- "Cannot process, $i contains patches" print -ru2 -- "to multiple files! Aborting." - echo FAIL + print -n 'FAIL\0' [[ -n $SUBDIST ]] && mv \ "${WRKDIR1}/${SUBDIST}.orig" \ "${WRKDIR1}.orig/${SUBDIST}" @@ -137,7 +137,7 @@ for file in $(cd ${WRKDIST}; find . -type f | sed 's#^\./##'); do print -ru2 -- "Cannot process, file $file" print -ru2 -- "is contained in multiple patches:" print -ru2 -- "$pflst" - echo FAIL + print -n 'FAIL\0' [[ -n $SUBDIST ]] && mv \ "${WRKDIR1}/${SUBDIST}.orig" \ "${WRKDIR1}.orig/${SUBDIST}" @@ -150,7 +150,7 @@ for file in $(cd ${WRKDIST}; find . -type f | sed 's#^\./##'); do ( sed -e "/^--- /,\$d" <"$i"; \ cd "$D_BASE" && do_diff "$file" "$D_SUB.orig" "$D_SUB" \ ) >"$i.new" - # did it change ? mark it as changed + # did it change? mark it as changed tfile=$(print -r -- "$file" | $TRANSFORM) if eval diff "$(print -r -- "${DIFF_FLAGS}" | sed \ "s#@@#${tfile}#g")" "$i" "$i.new" 1>&2; then @@ -188,6 +188,9 @@ for i in *; do (( found )) || print -ru2 -- "*** Patch $i not accounted for" done -print -r -- "${edit[@]}" +for i in "${edit[@]}"; do + print -nr -- "$i" + print -n '\0' +done [[ -n $SUBDIST ]] && mv "${WRKDIR1}/${SUBDIST}.orig" "${WRKDIR1}.orig/${SUBDIST}" exit 0 diff --git a/scripts/update-patches2 b/scripts/update-patches2 index 8f8711af7..2b8349bcf 100644 --- a/scripts/update-patches2 +++ b/scripts/update-patches2 @@ -25,7 +25,7 @@ export CURDIR PATCH_LIST mksh "${TOPDIR}"/scripts/update-patches |& first=1 set -A toedit -while IFS= read -p -r; do +while IFS= read -p -d '' -r; do if (( first )); then if [[ $REPLY = FAIL ]]; then rm -rf "${WRKDIR1}.orig" -- cgit v1.2.3 From 86e0e3c62349dfb43e66a78a57cf7110ef577a0f Mon Sep 17 00:00:00 2001 From: Thorsten Glaser Date: Sat, 3 May 2014 11:37:49 +0000 Subject: use find -print0 with proper shell handling Signed-off-by: Thorsten Glaser --- scripts/update-patches | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/update-patches b/scripts/update-patches index 1d13a3901..ee580c5cf 100644 --- a/scripts/update-patches +++ b/scripts/update-patches @@ -90,7 +90,9 @@ fi DIFF_FLAGS="-adu -I \"^--- $(print -r -- "$D_SUBP.orig/" | $TRANSFORM)@@ .*\"" DIFF_FLAGS="$DIFF_FLAGS -I \"^\+\+\+ $(print -r -- "$D_SUBP/" | $TRANSFORM)@@ .*\"" -for file in $(cd ${WRKDIST}; find . -type f | sed 's#^\./##'); do +(cd "${WRKDIST}"; find . -type f -print0) |& +while IFS= read -p -d '' -r file; do + file=${file#./} #print -r -- "DEBUG: <$file>" >>/tmp/debug [[ ! -e $ORGDIST/$file && $patch_newfiles = 0 ]] && continue [[ $file = configure && $ignore_autoconf = 1 ]] && continue -- cgit v1.2.3 From 15055071e180f96a4309bf93d7a6dc923fdad22f Mon Sep 17 00:00:00 2001 From: Thorsten Glaser Date: Sat, 3 May 2014 11:43:16 +0000 Subject: further optimisations Signed-off-by: Thorsten Glaser --- scripts/update-patches | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'scripts') diff --git a/scripts/update-patches b/scripts/update-patches index ee580c5cf..438cba2e1 100644 --- a/scripts/update-patches +++ b/scripts/update-patches @@ -95,14 +95,16 @@ while IFS= read -p -d '' -r file; do file=${file#./} #print -r -- "DEBUG: <$file>" >>/tmp/debug [[ ! -e $ORGDIST/$file && $patch_newfiles = 0 ]] && continue - [[ $file = configure && $ignore_autoconf = 1 ]] && continue - [[ $file = missing && $ignore_autoconf = 1 ]] && continue - [[ $file = depcomp && $ignore_autoconf = 1 ]] && continue - [[ $file = install-sh && $ignore_autoconf = 1 ]] && continue - [[ $file = aclocal.m4 && $ignore_autoconf = 1 ]] && continue - [[ $file = INSTALL && $ignore_autoconf = 1 ]] && continue - [[ $file = config.h.in && $ignore_autoconf = 1 ]] && continue - [[ $(basename $file) = Makefile.in && $ignore_autoconf = 1 ]] && continue + if (( ignore_autoconf )); then + [[ $file = configure ]] && continue + [[ $file = missing ]] && continue + [[ $file = depcomp ]] && continue + [[ $file = install-sh ]] && continue + [[ $file = aclocal.m4 ]] && continue + [[ $file = INSTALL ]] && continue + [[ $file = config.h.in ]] && continue + [[ ${file##*/} = Makefile.in ]] && continue + fi cmp -s "$ORGDIST/$file" "$WRKDIST/$file" && continue print -ru2 -- "Processing ${file}..." # look in patchdir for an existing patchfile matching this @@ -168,7 +170,7 @@ while IFS= read -p -d '' -r file; do done # Build a sensible name for the new patch file - patchname=patch-$(print -r -- "$file" | sed -e 's#[/.- ]#_#g') + patchname=patch-${file//[\/.- ]/_} print -ru2 -- "No patch-* found for $file, creating $patchname" ( cd "$D_BASE" && do_diff "$file" "$D_SUB.orig" "$D_SUB" ) >"$patchname" edit+=("$patchname") @@ -179,7 +181,7 @@ done cd "$PATCHDIR" for i in *; do [[ ! -f $i || $i = *@(.orig|.rej|~) ]] && continue - grep '^\\ No newline at end of file' $i >/dev/null && \ + grep '^\\ No newline at end of file' "$i" >/dev/null && \ print -ru2 -- "*** Patch $i needs manual intervention" found=0 for j in "${accounted[@]}"; do -- cgit v1.2.3