From cb54b59f989bd4e18eb57b51921d3d4966b1fd1c Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 24 Jul 2021 22:19:50 +0300 Subject: [PATCH] kiss: move as_root out of git --- doc/package-manager.txt | 6 +++++- kiss | 29 ++++++++++++++++------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/doc/package-manager.txt b/doc/package-manager.txt index 9a5a620..05020e5 100644 --- a/doc/package-manager.txt +++ b/doc/package-manager.txt @@ -193,7 +193,7 @@ features or conditionally do things on a per-package basis. | pre-install | Type | Package | Extracted package | | | pre-remove | Type | Package | Installed database | | | pre-source | Type | Package | Verbatim source | Resolved source | - | pre-update | Type | [7] | | | + | pre-update | Type | [8] | | | | queue-status | Type | Package | Number in queue | Total in queue | | | | | | | +---------------+--------+----------+--------------------+-----------------+ @@ -201,6 +201,10 @@ features or conditionally do things on a per-package basis. [7] The -update hooks start in the current repository. In other words, you can operate on the repository directly or grab the value from '$PWD'. + [8] The second argument of pre-update is '0' if the current user owns the + repository and '1' if they do not. In the latter case, privilege + escalation is required to preserve ownership. + [5.0] Package Manager Extensions ________________________________________________________________________________ diff --git a/kiss b/kiss index 71d1fe6..abbcc97 100755 --- a/kiss +++ b/kiss @@ -1548,9 +1548,6 @@ pkg_update() { if git -C "$repo" remote >/dev/null 2>&1; then repo_type=git - # Display whether or not signature verification is enabled. - repo_sig=$(git -C "$repo" config --get merge.verifySignatures) || : - # Get the Git repository root directory. subm=$(git -C "$repo" rev-parse --show-superproject-working-tree) repo=$(git -C "${subm:-"$repo"}" rev-parse --show-toplevel) @@ -1559,28 +1556,34 @@ pkg_update() { continue fi - pkg_update_repo "$repo" "$repo_type" "${repo_sig:-false}" + pkg_update_repo done pkg_upgrade } pkg_update_repo() { - cd "$1" || die "Repository '$1' inaccessible" + cd "$repo" || die "Repository '$repo' inaccessible" # NULL function for unsupported repository types. - pkg_update_null() { log "$PWD" "Repository has no remote"; } + pkg_update_null() { printf 'Repository has no remote\n'; } contains "$repos" "$PWD" || { repos="$repos $PWD" - log "$PWD" "[verify: $3]" + log "Updating" "$PWD" + + am_owner "$PWD" || { + printf 'Need "%s" to update\n' "$user" + set -- as_user + } # arg1: pre-update + # arg2: need su? # env: PWD is path to repository - run_hook pre-update + run_hook pre-update "$#" - "pkg_update_$2" + "pkg_update_$repo_type" "$@" # arg1: post-update # env: PWD is path to repository @@ -1589,10 +1592,10 @@ pkg_update_repo() { } pkg_update_git() { - am_owner "$PWD" || { - log "$PWD" "Need '$user' to update" - set -- as_user - } + # Display whether or not signature verification is enabled. + case $(git config --get merge.verifySignatures) in true) + printf 'Signature verification enabled.\n' + esac "$@" git pull "$@" git submodule update --remote --init -f