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
1 changed files with 57 additions and 44 deletions

31
kiss
View File

@ -1215,19 +1215,20 @@ pkg_updates() {
for repo do
# Go to the root of the repository (if it exists).
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."
continue
}
printf 'Skipping git pull, not a repository\n'
;;
*)
cd "$(git rev-parse --show-toplevel 2>/dev/null)" 2>/dev/null ||:
contains "$repos" "$PWD" || {
repos="$repos $PWD "
# Display a tick if signing is enabled for this
# repository.
# Display a tick if signing is enabled for this repository.
case $(git config merge.verifySignatures) in
true) log "$PWD" "[signed] " ;;
*) log "$PWD" " " ;;
@ -1251,14 +1252,19 @@ pkg_updates() {
# We're in a repository which is owned by a 3rd
# user. Not root or the current user.
[ "$user" = root ] || log "Dropping to $user for pull"
[ "$user" = root ] ||
log "Dropping to $user for pull"
# Nesting is deep and line is long.
git_cmd="
git pull && git submodule update --remote --init -f
"
# 'sudo' and 'doas' properly parse command-line
# 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.
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
@ -1269,6 +1275,13 @@ pkg_updates() {
)
fi
}
;;
esac
[ ! -x update ] || {
log "$PWD" "Running update hook"
./update
}
done
log "Checking for new package versions"