diff options
author | John Ankarström <john@ankarstrom.se> | 2021-07-18 18:49:13 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-07-18 18:49:37 +0200 |
commit | 123687a5aa3482b5ba9ca86179526c94422b409d (patch) | |
tree | 83fa480a7727cd67eb5840e7555d984478c53afd | |
parent | 830afa08f95e2026f97b62d22484c27d42c104b1 (diff) | |
download | patches-123687a5aa3482b5ba9ca86179526c94422b409d.tar.gz |
Add savepatch, xpkg scripts
-rw-r--r-- | Makefile | 4 | ||||
-rwxr-xr-x | conv | 84 | ||||
-rwxr-xr-x | convpatch | 44 | ||||
-rwxr-xr-x | pkgpatch | 2 | ||||
-rwxr-xr-x | pkgundo | 2 | ||||
-rwxr-xr-x | savepatch | 35 | ||||
-rwxr-xr-x | sum | 18 | ||||
-rwxr-xr-x | undopatch | 32 | ||||
-rwxr-xr-x | xpkg | 26 |
9 files changed, 119 insertions, 128 deletions
@@ -1,2 +1,4 @@ +BIN != find . -type f -perm -111 -maxdepth 1 + install: - install conv pkgdiffs pkgpatch pkgundo undopatch /usr/local/bin + install $(BIN) /usr/local/bin @@ -1,84 +0,0 @@ -#!/bin/sh - -# conv -- convert git diff -p output to pkgsrc patch - -set -f -IFS=' -' - -{ - echo '$NetBSD$' - echo - - # get patch description - if [ x"$1" = x"-i" ]; then - f=`mktemp -t ${0##*/}` || exit 1 - echo 'Edit patch description...' > $f - </dev/tty >/dev/tty vi $f - c=`cat $f` - if [ x"$c" != x"Edit patch description..." ]; then - printf '%s\n\n' "$c" - fi - rm $f - fi - - sed ' - /^diff/d; - /^index/d; - s/^--- .*/&/; - ' -} | -while read -r line; do - case "$line" in - diff*) ;; - index*) ;; - '--- a/'*) - file=${line#--- a/} - echo -n "--- $file.orig " - file=$(git rev-parse --show-toplevel)/$file - echo "$(stat -x "$file")" | sed -n 's/^Access: //p' ;; - '+++ b/'*) - echo "+++ ${line#+++ b/}" ;; - *) - echo "$line" ;; - esac -done | { -if [ x"$1" = x"-i" ]; then - # read patch before proceeding - patch=`cat` - - # get patch directory - dir=$2 - if [ -z "$2" ]; then - echo -n 'Package name: ' >/dev/tty - read dir </dev/tty - fi - dir=~/patches/$dir - mkdir -p $dir - - # get patch name - name=$3 - if [ -z "$3" ]; then - echo -n 'Patch name: ' >/dev/tty - read name </dev/tty - fi - - case $name in - patch-*) ;; - *) name=patch-$name ;; - esac - - # write patch if it doesn't already exist - if [ -e $dir/$name ]; then - f=`mktemp -t ${0##*/}` || exit 1 - printf '%s\n' "$patch" > $f - echo "error: $dir/$name already exists; saving to $f" 1>&2 - exit 1 - else - printf '%s\n' "$patch" > $dir/$name - echo $dir/$name 1>&2 - fi -else - cat -fi -} diff --git a/convpatch b/convpatch new file mode 100755 index 0000000..2ebbcd8 --- /dev/null +++ b/convpatch @@ -0,0 +1,44 @@ +#!/bin/sh -f + +# convpatch -- convert git diff -p output to pkgsrc patch + +IFS=' +' + +{ + echo '$NetBSD$' + echo + + # get patch description + if [ x"$1" = x"-i" ]; then + f=`mktemp -t ${0##*/}` || exit 1 + echo 'Edit patch description...' > $f + </dev/tty >/dev/tty vi $f + c=`cat $f` + if [ x"$c" != x"Edit patch description..." ]; then + printf '%s\n\n' "$c" + fi + rm $f + fi + + sed ' + /^diff/d; + /^index/d; + s/^--- .*/&/; + ' +} | +while read -r line; do + case "$line" in + diff*) ;; + index*) ;; + '--- a/'*) + file=${line#--- a/} + echo -n "--- $file.orig " + file=$(git rev-parse --show-toplevel)/$file + echo "$(stat -x "$file")" | sed -n 's/^Access: //p' ;; + '+++ b/'*) + echo "+++ ${line#+++ b/}" ;; + *) + echo "$line" ;; + esac +done @@ -4,7 +4,7 @@ move() { - echo "${0##*/}: Renaming *.$1 to *.$2..." 1>&2 + echo "${0##*/}: renaming *.$1 to *.$2..." 1>&2 for orig in *.$1; do mv -i "$orig" "${orig%.$1}".$2 done @@ -9,4 +9,4 @@ for orig in "$@"; do : $((n++)) mv "$orig" "${orig%.orig}" done -echo "${0##*/}: Moved $n files." 2>&1 +echo "${0##*/}: moved $n files" 2>&1 diff --git a/savepatch b/savepatch new file mode 100755 index 0000000..ae0984f --- /dev/null +++ b/savepatch @@ -0,0 +1,35 @@ +#!/bin/sh + +# savepatch -- save patch on standard in to ~/patches + +root=/home/john/patches + +if [ -z "$1" ]; then + echo "usage: ${0##*/} patch-name" 1>&2 + exit 1 +fi + +case "$PWD" in +/usr/pkgsrc/*) dir=$(pwd | cut -d/ -f4,5) || dir= ;; +/usr/*src/*) dir=${PWD#/usr/} ;; +*) dir= +esac + +if [ -z "$dir" ]; then + echo "${0##*/}: could not determine package" 1>&2 + printf "package: " 1>&2 + read dir </dev/tty +fi + +mkdir -p "$root/$dir" + +if [ -e "$root/$dir/$1" ]; then + printf "%s: %s already exists; overwrite? " "${0##*/}" "$dir/$1" 1>&2 + read ans </dev/tty + case $ans in + y*) ;; + *) exit 1 ;; + esac +fi + +cat > "$root/$dir/$1" @@ -1,18 +0,0 @@ -#!/bin/sh - -# checksum -- create checksum for local patch - -# -# Note that checksums are optional for local patches. -# - -[ -z "$1" ] && { echo usage: $0 patch 1>&2; exit 1; } - -localpath=`readlink -f "$1"` -globalpath=/usr/pkgsrc/${localpath#/home/john/patches/} - -[ -e "$globalpath" ] && { echo error: "$globalpath" exists 1>&2; exit 1; } -doas cp "$localpath" "$globalpath" -cd "$(dirname "$globalpath")" -doas make makepatchsum -doas rm "$globalpath" @@ -1,26 +1,12 @@ -#!/bin/sh +#!/bin/sh -e -case "$PWD" in -/usr/pkgsrc/*/*) ;; -*) echo not in package directory 1>&2; exit 1 ;; -esac +# undopatch -- undo patches applied to pkgsrc build -w=/usr/pkgsrc/distfiles/$(sed -n '/.*(\(.*\)).*/{s//\1/;p;q}' distinfo) - -done=$(dirname $w)/.$(basename $w).done - -if [ ! -e "$done" ]; then - echo extracting archive... 1>&2 - cd $(dirname $w) - tar xf $w - touch $done - cd - -fi - -echo undoing patches... 1>&2 -cmd=echo\ cp -[ x"$1" = x"-x" ] && cmd=cp || echo '(preview, no -x)' 1>&2 -find . -name '*.orig' | while read f; do - f=${f%.orig} - $cmd $(dirname $w)/${f#./work/} $f +d=$(xpkg) +echo=echo +echo "${0##*/}: undoing patches..." 1>&2 +[ x"$1" = x"-x" ] && echo= || echo '(preview, no -x)' 1>&2 +find work -name '*.orig' | while read -r f; do + $echo cp "$d/${f#work/}" "${f%.orig}" + $echo rm "$f" done @@ -0,0 +1,26 @@ +#!/bin/sh -e + +# xpkg -- fetch and extract pkgsrc archive + +case "$PWD" in +/usr/pkgsrc/*/*) ;; +*) echo "${0##*/}: not in package directory" 1>&2; exit 1 ;; +esac + +make fetch +f=/usr/pkgsrc/distfiles/$(sed -n '/.*(\(.*\)).*/{s//\1/;p;q}' distinfo) +d=$(tar -tf "$f" | head -1) + +opt= +if [ -e "$d" ]; then + printf "%s: $d already exists; overwrite? " "${0##*/}" + read ans + case $ans in + y*) opt=-U ;; + *) exit 1 ;; + esac +fi + +echo extracting archive... 1>&2 +tar -x $opt -f "$f" +echo "$d" |