xref: /openbsd-src/distrib/syspatch/diff.sh (revision 5559608384574694fa52ff4765b362295ff174d2)
1a4d73c59Srobert#!/bin/ksh
2a4d73c59Srobert#
3*55596083Srobert# $OpenBSD: diff.sh,v 1.6 2019/05/12 14:57:30 robert Exp $
4a4d73c59Srobert#
5*55596083Srobert# Copyright (c) 2017, 2019 Robert Nagy <robert@openbsd.org>
6a4d73c59Srobert#
7a4d73c59Srobert# Permission to use, copy, modify, and distribute this software for any
8a4d73c59Srobert# purpose with or without fee is hereby granted, provided that the above
9a4d73c59Srobert# copyright notice and this permission notice appear in all copies.
10a4d73c59Srobert#
11a4d73c59Srobert# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12a4d73c59Srobert# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13a4d73c59Srobert# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14a4d73c59Srobert# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15a4d73c59Srobert# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16a4d73c59Srobert# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17a4d73c59Srobert# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18a4d73c59Srobert
19a4d73c59Srobertumask 0022
20a4d73c59Srobert
21a4d73c59Sroberttrap exit HUP INT TERM
22a4d73c59Srobert
23*55596083Srobert[[ "$1" != /* ]] || [[ "$2" != /* ]] &&
24*55596083Srobert	echo "paths have to be absolute" &&
25*55596083Srobert	exit 1
26*55596083Srobert
27*55596083Srobertplist=$(mktemp)
28*55596083Sroberttrap 'rm -f ${plist}' EXIT
29*55596083Srobert
30*55596083Srobertpadd() {
31*55596083Srobert	local _path=$1
32*55596083Srobert	readlink -f ${_path} >> ${plist}
33*55596083Srobert}
34*55596083Srobert
35*55596083Srobertdiff -Parq $1 $2 2>&1 | grep ' differ$' |
36a4d73c59Srobertwhile IFS= read -r _d
37a4d73c59Srobertdo
38a4d73c59Srobert	_o=$(echo $_d | cut -d ' ' -f2)
39a4d73c59Srobert	_n=$(echo $_d | cut -d ' ' -f4)
40a4d73c59Srobert	case "${_o##*.}"
41a4d73c59Srobert	in
42a4d73c59Srobert		a)
43*55596083Srobert			cmp -s ${_o} ${_n} 34 34 || padd ${_n}
44a4d73c59Srobert			;;
45a4d73c59Srobert		1|3p)
461dae96deSajacoutot			# Needed for perl(1) because Pod::Man adds the build
471dae96deSajacoutot			# date in the man page; e.g. /usr/share/man1/pod2html.1:
481dae96deSajacoutot			# .TH POD2HTML 1 "2017-07-29" "perl v5.24.1"
49a4d73c59Srobert			_onm=$(mktemp)
50a4d73c59Srobert			_nnm=$(mktemp)
51a4d73c59Srobert			trap 'rm -f ${_onm} ${_nnm}' EXIT
52a4d73c59Srobert			sed -E '/([0-9]+-[0-9]+-[0-9]+|=+)/d' ${_o} > ${_onm}
53a4d73c59Srobert			sed -E '/([0-9]+-[0-9]+-[0-9]+|=+)/d' ${_n} > ${_nnm}
54*55596083Srobert			diff -q ${_onm} ${_nnm} >/dev/null || padd ${_n}
55a4d73c59Srobert			rm -f ${_onm} ${_nnm}
56a4d73c59Srobert			;;
57a4d73c59Srobert		EFI|dat|db|tgz|*void|*dir|mk|cache-4)
58a4d73c59Srobert			;;
59a4d73c59Srobert		*)
60*55596083Srobert			padd ${_n}
61a4d73c59Srobert			;;
62a4d73c59Srobert	esac
63a4d73c59Srobertdone
64*55596083Srobert
65*55596083Srobertsort -u ${plist}
66