From 123687a5aa3482b5ba9ca86179526c94422b409d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sun, 18 Jul 2021 18:49:13 +0200 Subject: Add savepatch, xpkg scripts --- Makefile | 4 ++- conv | 84 --------------------------------------------------------------- convpatch | 44 +++++++++++++++++++++++++++++++++ pkgpatch | 2 +- pkgundo | 2 +- savepatch | 35 ++++++++++++++++++++++++++ sum | 18 -------------- undopatch | 32 +++++++----------------- xpkg | 26 ++++++++++++++++++++ 9 files changed, 119 insertions(+), 128 deletions(-) delete mode 100755 conv create mode 100755 convpatch create mode 100755 savepatch delete mode 100755 sum create mode 100755 xpkg diff --git a/Makefile b/Makefile index f58e034..e6af53a 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/conv b/conv deleted file mode 100755 index 39781d7..0000000 --- a/conv +++ /dev/null @@ -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 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 - read name $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 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 diff --git a/pkgpatch b/pkgpatch index 17af25c..408edc4 100755 --- a/pkgpatch +++ b/pkgpatch @@ -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 diff --git a/pkgundo b/pkgundo index 2513bf1..9f3ad25 100755 --- a/pkgundo +++ b/pkgundo @@ -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 &2 + read ans "$root/$dir/$1" diff --git a/sum b/sum deleted file mode 100755 index 9469302..0000000 --- a/sum +++ /dev/null @@ -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" diff --git a/undopatch b/undopatch index e46bc54..82a6ae8 100755 --- a/undopatch +++ b/undopatch @@ -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 diff --git a/xpkg b/xpkg new file mode 100755 index 0000000..c63962b --- /dev/null +++ b/xpkg @@ -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" -- cgit v1.2.3