# HG changeset patch # User Aleksej Bobylev # Date 1546615426 -7200 # Node ID e0fb0c452bf1e9f3d3e349f2ae055bcbba7869e0 # Parent 8cf66e7d3c64a38d8ded225f26029b8c4e570fba cook: patchit(): allow external patches and patches checksum diff -r 8cf66e7d3c64 -r e0fb0c452bf1 cook --- a/cook Wed Jan 02 18:55:20 2019 +0200 +++ b/cook Fri Jan 04 17:23:46 2019 +0200 @@ -528,21 +528,59 @@ patchit() { [ -f "$stuff/patches/series" ] || return + # Empty lines and comments (started with "#") are ignored + # Up to three fields (no spaces inside allowed) separated by "|": + # 1. patch options like "-p0" (optional); + # 2. patch file name or URL (mandatory); + # 3. patch checksum in form "sha1=..." or other *sum (optional). - local done="$pkgdir/.patch.done" + local done="$pkgdir/.patch.done" var1 var2 var3 + local patchname patchopts patchfile patchsum patchsum_type patchsum_sum IFS=$'\n' while read i; do patchname=$(echo ${i%%#*} | cut -d' ' -f1) # allow comments (anything after the # or space) - case $patchname in # allow patch options in form | - *\|*) patchopts="${patchname%|*}"; patchname="${patchname#*|}";; - *) patchopts='-Np1';; + [ -n "$patchname" ] || continue # skip empty lines + + var1=$(echo "$patchname||" | cut -d'|' -f1) # options or name + var2=$(echo "$patchname||" | cut -d'|' -f2) # name or checksum or empty + var3=$(echo "$patchname||" | cut -d'|' -f3) # checksum or empty + + if [ -n "$var3" ]; then + patchopts="$var1"; patchname="$var2"; patchsum="$var3" + elif [ -n "$var2" ]; then + case $var2 in + *=*) patchopts='-Np1'; patchname="$var1"; patchsum="$var2";; + *) patchopts="$var1"; patchname="$var2"; patchsum='';; + esac + else + patchopts='-Np1'; patchname="$var1"; patchsum='' + fi + + case $patchname in + ftp://*|http://*|https://*) + patchfile="$SRC/$(basename $patchname)" + [ -e "$patchfile" ] || wget -q -T 60 -O $patchfile $patchname || + die 'ERROR: %s' "can't get $patchname" + ;; + *) + patchfile="$stuff/patches/$patchname" + ;; esac - [ -n "$patchname" ] || continue # allow empty lines + + if [ -n "$patchsum" ]; then + patchsum_type=${patchsum%=*} + patchsum_sum=${patchsum#*=} + echo "$patchsum_sum $patchfile" | ${patchsum_type}sum -cs || + die 'ERROR: %s' "wrong ${patchsum_type}sum for $patchfile" + fi + touch $done grep -q "^${patchname}$" $done && continue # already applied (useful with `cook --continue`) + newline _ 'Applying patch %s' "$patchname" - patch $patchopts -i $stuff/patches/$patchname | sed 's|^| |' + patch $patchopts -i $patchfile | sed 's|^| |' + echo $patchname >> $done done < $stuff/patches/series newline @@ -1384,7 +1422,8 @@ # cook --getsrc # cook -gs [ -n "$getsrc" -o "$2" == '-gs' ] && { - title 'Getting source for "%s"' "$1" + pkg="$1" + title 'Getting source for "%s"' "$pkg" receipt="$WOK/$pkg/receipt" check_pkg_in_wok unset_receipt