From 4d18c978fbfd41daea0c11f4ec16eeb7d3af9a04 Mon Sep 17 00:00:00 2001 From: hydrargyrum Date: Fri, 6 Oct 2023 11:47:40 +0200 Subject: [PATCH] dpkg-imediff: start a merge editor when dpkg needs resolving a conflict --- README.md | 1 + dpkg-imediff/dpkg-imediff | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100755 dpkg-imediff/dpkg-imediff diff --git a/README.md b/README.md index 3c0cd95..0927716 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ This repository hosts various small personal tools. - [`crc`](crc): basic CRC computation tool - [`csv2json`](csv2json): transform CSV into JSON - [`csv2table`](csv2table): pretty-print a CSV file with ASCII-art table +- [`dpkg-imediff`](dpkg-imediff): when dpkg interactively prompts for resolving a config file conflict, run this to start a merge editor - [`exiforientergui`](exiforientergui): GUI to losslessly modify EXIF orientation of an image - [`ffmcut`](ffmcut): ffmpeg wrapper to cut a video between 2 timestamps - [`firefox-relay-tools/fxrelay-add`](firefox-relay-tools/fxrelay-add): add a Firefox Relay address diff --git a/dpkg-imediff/dpkg-imediff b/dpkg-imediff/dpkg-imediff new file mode 100755 index 0000000..422fd99 --- /dev/null +++ b/dpkg-imediff/dpkg-imediff @@ -0,0 +1,26 @@ +#!/bin/sh -eu +# SPDX-License-Identifier: WTFPL + +# When installing packages, dpkg needs to preserve modifications to files in +# /etc, but sometimes a config file was also modified in the package, leading +# to a conflict. dpkg prompts what to do: +# Y: overwrite modifications to /etc, force package content +# N: don't use package content, keep /etc modifications +# Z: start a shell +# imediff is an editor for resolving conflicts. +# So, use `Z` command and just start `dpkg-imediff`. imediff must be installed. + +error () { + echo "error: $1" >&2 + exit 1 +} + +if [ $# -gt 0 ] +then + error "$0 must be called within a dpkg conflict shell, without arguments" +elif [ -z "${DPKG_CONFFILE_OLD-}" ] +then + error "$0 must be called within a dpkg conflict shell" +fi + +imediff -o "$DPKG_CONFFILE_OLD" "$DPKG_CONFFILE_OLD" "$DPKG_CONFFILE_NEW"