From f3ebd5566ef46d408ce1014702088cd523fba671 Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 9 Oct 2024 15:31:25 +0300 Subject: [PATCH] [eos-bash-shared] added option --pacdiff and setting EOS_UPDATE_PACDIFFER --- eos-script-lib-yad.conf | 8 ++++++ eos-update | 63 ++++++++++++++++++++++++++++++++++------- 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/eos-script-lib-yad.conf b/eos-script-lib-yad.conf index b24bc30..888e0f1 100644 --- a/eos-script-lib-yad.conf +++ b/eos-script-lib-yad.conf @@ -90,6 +90,13 @@ EOS_WELCOME_PACDIFFERS=(meld kdiff3 kompare diffuse diff vim) # EOS_PACDIFF_WARNING=yes +## EOS_UPDATE_PACDIFFER contains the command to run in the end of 'eos-update'. +## If it is not empty, the string is used as-is. +## Example: EOS_UPDATE_PACDIFFER="eos-pacdiff --quiet" +## Default is empty because incorrect usage of pacdiff can break the system in various ways. +# +EOS_UPDATE_PACDIFFER="" + ## EOS_SUDO_EDITORS is an array of editor names that are suitable for ## editing files with root permissions. ## Currently they are used only in eos-update-notifier-configure. @@ -220,3 +227,4 @@ EOS_REBOOT_RECOMMENDING=yes ## EOS_YAD_MISSING_NOTIFICATION specifies whether some EndeavourOS apps show a notification ## when 'yad' might be needed but is not installed. EOS_YAD_MISSING_NOTIFICATION=yes + diff --git a/eos-update b/eos-update index 78dbfb3..0566e86 100755 --- a/eos-update +++ b/eos-update @@ -172,7 +172,7 @@ OptionCheck() { Options() { local opts local lopts="aur,clear-databases,dump-options,keyrings-reset,nvidia,nvidia-auto,no-keyring,no-sync,helper:" - lopts+=",min-free-bytes:,paru,yay,pacman,help" + lopts+=",min-free-bytes:,pacdiff,paru,yay,pacman,help" lopts+=",show-only-fixed,show-upstream-news,check-mirrors-arch,check-mirrors-eos,check-mirrors,edit-mirrorlist:" local sopts="h" @@ -205,6 +205,7 @@ Options() { --helper) SetHelper "$2" ; shift ;; --aur) SetHelper ;; --paru | --yay | --pacman) SetHelper "${1/--/}" ;; + --pacdiff) pacdiffer="$pacdiffer_cmd_default" ;; --show-only-fixed) which arch-audit >/dev/null && arch-audit -u exit @@ -270,6 +271,8 @@ Options: --no-sync Do not run 'sync' after update. --show-only-fixed Show only packages that have already been fixed (runs: arch-audit -u) and exit. --show-upstream-news Show the news page of the upstream site and exit. + --pacdiff Run eos-pacdiff in the end of $progname. See also EOS_UPDATE_PACDIFFER + in file /etc/eos-script-lib-yad.conf. --helper AUR helper name. Supported: yay, paru, pacman. Default: pacman Other AUR helpers supporting option -Sua like yay should work as well. @@ -281,10 +284,10 @@ Options: before updating. Otherwise a warning message will be displayed. Default: $min_free_bytes -Tip: create an alias in file ~/.bashrc for eos-update to have the options you need, for example: +Tip: create an alias in file ~/.bashrc for $progname to have the options you need, for example: # Enable Nvidia update check, disable sync execution, use paru for AUR updates. - alias eos-update='eos-update --nvidia --no-sync --paru' + alias $progname='$progname --nvidia --no-sync --paru' EOF } @@ -329,6 +332,8 @@ Main() { local lock=/var/lib/pacman/db.lck local rmopt=f + local pacdiffer="" # default = "" because pacdiff can change critical files + local -r pacdiffer_cmd_default="eos-pacdiff --quiet" local subopts=() local afteropts=() local keyring=yes # user may disable keyring check with --no-keyring @@ -346,6 +351,8 @@ Main() { Options "$@" + [ "$EOS_UPDATE_PACDIFFER" ] && pacdiffer="$EOS_UPDATE_PACDIFFER" + [ $nvidia = yes ] && subopts+=(--nvidia) [ $keyring = yes ] && subopts+=(--keyrings) @@ -356,14 +363,50 @@ Main() { if [ -e $lock ] && fuser $lock &>/dev/null ; then rmopt=i fi - if [ "$helper" = "pacman" ] ; then - echo2green "Updating native apps..." - sudo bash -c "rm -$rmopt $lock; [ -e $lock ] || { pacman -Sy && eos-update-extras ${subopts[*]} && pacman -Su && $sync ; }" - else - echo2green "Updating native and AUR apps..." - local helper2="/usr/bin/sudo -u $LOGNAME $helper -Sua" - sudo bash -c "rm -$rmopt $lock; [ -e $lock ] || { pacman -Sy && eos-update-extras ${subopts[*]} && pacman -Su && $helper2 ; $sync ; }" + local cmdfile=$(mktemp "$HOME/.$progname.helper.XXX") + case "$helper" in + pacman) + echo2green "Updating native apps..." + cat < "$cmdfile" +#!/bin/bash + +eos_update_sudofunc() { + rm -$rmopt $lock + if [ ! -e $lock ] ; then + pacman -Sy || return + ${progname}-extras "${subopts[@]}" || return + pacman -Su || return + $pacdiffer + $sync + fi +} +eos_update_sudofunc +EOF + ;; + *) + echo2green "Updating native and AUR apps..." + local helper2="/usr/bin/sudo -u $LOGNAME $helper -Sua" + cat < "$cmdfile" +#!/bin/bash + +eos_update_sudofunc() { + rm -$rmopt $lock + if [ ! -e $lock ] ; then + pacman -Sy || return + ${progname}-extras "${subopts[@]}" || return + pacman -Su || return + $helper2 || return # Note: 'paru' returns 1 on error, but 'yay' does not! + $pacdiffer + $sync fi } +eos_update_sudofunc +EOF + ;; + esac + chmod u+x,go-rwx "$cmdfile" + sudo "$cmdfile" + rm -f "$cmdfile" +} Main "$@"