[PATCH] pacdiff: Add option to use sudo/sudoedit to manage files

Daniel M. Capella polyzen at archlinux.org
Thu Mar 25 04:29:21 UTC 2021


Works great, please resubmit the patch with a signoff:

https://git.archlinux.org/pacman-contrib.git/tree/doc/submitting-patches.txt#n23

On 2/20/21 3:22 PM, Daniel Parks via pacman-contrib wrote:
> This allows the user to run their diff program as their own user instead
> of root. The advantage of this approach is that they can use their own
> configuration for the editor or even use a GUI merge program such as
> meld.
> ---
>   src/pacdiff.sh.in | 20 ++++++++++++++------
>   1 file changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/src/pacdiff.sh.in b/src/pacdiff.sh.in
> index c4dbd89..aac88c8 100644
> --- a/src/pacdiff.sh.in
> +++ b/src/pacdiff.sh.in
> @@ -28,6 +28,7 @@ LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
>   diffprog=${DIFFPROG:-'vim -d'}
>   diffsearchpath=${DIFFSEARCHPATH:-/etc}
>   USE_COLOR='y'
> +SUDO=''
>   declare -a oldsaves
>   declare -i USE_FIND=0 USE_LOCATE=0 USE_PACDB=0 OUTPUTONLY=0
>   
> @@ -50,6 +51,7 @@ Search Options:     select one (default: --pacmandb)
>   General Options:
>     -o/--output       print files instead of merging them
>     --nocolor         remove colors from output
> +  -s/--sudo         use sudo to merge/remove files
>   
>   Environment Variables:
>     DIFFPROG          override the merge program: (default: 'vim -d')
> @@ -109,6 +111,8 @@ while [[ -n "$1" ]]; do
>   			OUTPUTONLY=1;;
>   		--nocolor)
>   			USE_COLOR='n';;
> +		-s|--sudo)
> +			SUDO=sudo;;
>   		-V|--version)
>   			version; exit 0;;
>   		-h|--help)
> @@ -168,25 +172,29 @@ while IFS= read -u 3 -r -d '' pacfile; do
>   	msg "%s file found for %s" "$file_type" "$file"
>   	if [ ! -f "$file" ]; then
>   		warning "$file does not exist"
> -		rm -iv "$pacfile"
> +		$SUDO rm -iv "$pacfile"
>   		continue
>   	fi
>   
>   	if cmp -s "$pacfile" "$file"; then
>   		msg2 "Files are identical, removing..."
> -		rm -v "$pacfile"
> +		$SUDO rm -v "$pacfile"
>   	else
>   		ask "(V)iew, (S)kip, (R)emove %s, (O)verwrite with %s, (Q)uit: [v/s/r/o/q] " "$file_type" "$file_type"
>   		while read c; do
>   			case $c in
>   				q|Q) exit 0;;
> -				r|R) rm -v "$pacfile"; break ;;
> -				o|O) mv -v "$pacfile" "$file"; break ;;
> +				r|R) $SUDO rm -v "$pacfile"; break ;;
> +				o|O) $SUDO mv -v "$pacfile" "$file"; break ;;
>   				v|V)
> -					$diffprog "$pacfile" "$file"
> +					if [[ -n "$SUDO" ]]; then
> +						SUDO_EDITOR="$diffprog" sudoedit "$pacfile" "$file"
> +					else
> +						$diffprog "$pacfile" "$file"
> +					fi
>   					if cmp -s "$pacfile" "$file"; then
>   						msg2 "Files are identical, removing..."
> -						rm -v "$pacfile"
> +						$SUDO rm -v "$pacfile"
>   						break
>   					fi
>   					ask "(V)iew, (S)kip, (R)emove %s, (O)verwrite with %s, (Q)uit: [v/s/r/o/q] " "$file_type" "$file_type";

-- 
Best,
Daniel <https://danielcapella.com>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0xEA4F7B321A906AD9.asc
Type: application/pgp-keys
Size: 15463 bytes
Desc: OpenPGP public key
URL: <https://lists.archlinux.org/pipermail/pacman-contrib/attachments/20210325/a784a01a/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://lists.archlinux.org/pipermail/pacman-contrib/attachments/20210325/a784a01a/attachment-0001.sig>


More information about the pacman-contrib mailing list