Message ID | 20210220202251.34660-1-danielrparks@gmail.com |
---|---|
State | Deferred |
Headers | show |
Series | pacdiff: Add option to use sudo/sudoedit to manage files | expand |
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";
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";
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";