1
0
mirror of https://codeberg.org/kiss-community/kiss synced 2024-12-24 16:10:05 -07:00

kiss: add repository update hook

The package manager will look for an executable called 'update' in the
repository's root directory. If a KISS repository is one of many
children in a git repository, the hook will only be called once.

This hook is run /after/ a repository has been updated by the package
manager. If your repository is not using git, the hook is run immediately.

If the hook fails (exits non-zero), the package manager will also fail.
Hooks can be written in any language. No arguments are given to the executable.

Closes #174
This commit is contained in:
Dylan Araps 2020-08-11 21:24:43 +03:00
parent a15c6b74fb
commit 64e77c91e5
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E

101
kiss
View File

@ -1215,59 +1215,72 @@ pkg_updates() {
for repo do for repo do
# Go to the root of the repository (if it exists). # Go to the root of the repository (if it exists).
cd "$repo" cd "$repo"
cd "$(git rev-parse --show-toplevel 2>/dev/null)" 2>/dev/null ||:
[ "$(git remote 2>/dev/null)" ] || { case $(git remote 2>/dev/null) in
log "$repo" " " "")
printf '%s\n' "No remote or not git repository, skipping." log "$repo" " "
continue printf 'Skipping git pull, not a repository\n'
} ;;
contains "$repos" "$PWD" || { *)
repos="$repos $PWD " cd "$(git rev-parse --show-toplevel 2>/dev/null)" 2>/dev/null ||:
# Display a tick if signing is enabled for this contains "$repos" "$PWD" || {
# repository. repos="$repos $PWD "
case $(git config merge.verifySignatures) in
true) log "$PWD" "[signed] " ;;
*) log "$PWD" " " ;;
esac
if [ -w "$PWD" ] && [ "$uid" != 0 ]; then # Display a tick if signing is enabled for this repository.
git pull case $(git config merge.verifySignatures) in
git submodule update --remote --init -f true) log "$PWD" "[signed] " ;;
*) log "$PWD" " " ;;
esac
else if [ -w "$PWD" ] && [ "$uid" != 0 ]; then
[ "$uid" = 0 ] || log "$PWD" "Need root to update" git pull
git submodule update --remote --init -f
# Find out the owner of the repository and spawn else
# git as this user below. [ "$uid" = 0 ] || log "$PWD" "Need root to update"
#
# This prevents 'git' from changing the original
# ownership of files and directories in the rare
# case that the repository is owned by a 3rd user.
(
file_owner "$PWD"
# We're in a repository which is owned by a 3rd # Find out the owner of the repository and spawn
# user. Not root or the current user. # git as this user below.
[ "$user" = root ] || log "Dropping to $user for pull" #
# This prevents 'git' from changing the original
# ownership of files and directories in the rare
# case that the repository is owned by a 3rd user.
(
file_owner "$PWD"
# 'sudo' and 'doas' properly parse command-line # We're in a repository which is owned by a 3rd
# arguments and split them in the common way. 'su' # user. Not root or the current user.
# on the other hand requires that each argument be [ "$user" = root ] ||
# properly quoted as the command passed to it must log "Dropping to $user for pull"
# be a string... This sets quotes where needed.
git_cmd="git pull && git submodule update --remote --init -f"
case $su in *su) git_cmd="'$git_cmd'"; esac
# Spawn a subshell to run multiple commands as # Nesting is deep and line is long.
# root at once. This makes things easier on users git_cmd="
# who aren't using persist/timestamps for auth git pull && git submodule update --remote --init -f
# caching. "
user=$user as_root sh -c "$git_cmd"
) # 'sudo' and 'doas' properly parse command-line
fi # arguments and split them in the common way. 'su'
# on the other hand requires that each argument be
# properly quoted as the command passed to it must
# be a string... This sets quotes where needed.
case $su in *su) git_cmd="'$git_cmd'"; esac
# Spawn a subshell to run multiple commands as
# root at once. This makes things easier on users
# who aren't using persist/timestamps for auth
# caching.
user=$user as_root sh -c "$git_cmd"
)
fi
}
;;
esac
[ ! -x update ] || {
log "$PWD" "Running update hook"
./update
} }
done done