cpt

[ARCHIVED] Carbs Packaging Tools
git clone git://git.ckyln.com/~cem/cpt.git
Log | Files | Refs | README | LICENSE

commit fff1d3a77d26a4a0e60e8baad059a4887e6e7325
parent 311a07af86a4120eeba7341588f2f4ab412059e4
Author: Cem Keylan <cem@ckyln.com>
Date:   Thu, 28 May 2020 14:32:59 +0300

kiss: initial rsync support

Diffstat:
Mkiss | 105++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
1 file changed, 61 insertions(+), 44 deletions(-)

diff --git a/kiss b/kiss @@ -1219,66 +1219,83 @@ pkg_fetch() { cd "$repo" cd "$(git rev-parse --show-toplevel 2>/dev/null)" 2>/dev/null ||: - [ -d .git ] || { - log "$repo" " " - printf '%s\n' "Not a git repository, skipping." - continue - } + if [ -d .git ]; then - [ "$(git remote 2>/dev/null)" ] || { - log "$repo" " " - printf '%s\n' "No remote, skipping." - continue - } + [ "$(git remote 2>/dev/null)" ] || { + log "$repo" " " + printf '%s\n' "No remote, skipping." + continue + } - contains "$repos" "$PWD" || { - repos="$repos $PWD " + contains "$repos" "$PWD" || { + repos="$repos $PWD " - # Display a tick if signing is enabled for this - # repository. - case $(git config merge.verifySignatures) in - true) log "$PWD" "[signed ✓] " ;; - *) log "$PWD" " " ;; - esac + # Display a tick if signing is enabled for this + # repository. + case $(git config merge.verifySignatures) in + true) log "$PWD" "[signed ✓] " ;; + *) log "$PWD" " " ;; + esac - run_hook pre-pull '' "$PWD" + run_hook pre-pull '' "$PWD" - if [ -w "$PWD" ] && [ "$uid" != 0 ]; then - git fetch - git merge - git submodule update --remote --init -f + if [ -w "$PWD" ] && [ "$uid" != 0 ]; then + git fetch + git merge + git submodule update --remote --init -f + else + [ "$uid" = 0 ] || log "$PWD" "Need root to update" + + # Find out the owner of the repository and spawn + # git as this user below. + # + # 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. + ( + user=$(kiss-stat "$PWD") || user=root + id -u "$user" >/dev/null 2>&1 || user=root + + [ "$user" = root ] || + log "Dropping permissions to $user for pull" + + git_cmd="git fetch && git merge && git submodule update --remote --init -f" + 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 + + run_hook post-pull '' "$PWD" + } + elif [ -f .rsync ]; then + read -r remote < .rsync + if [ -w "$PWD" ] && [ "$uid" != 0 ]; then + rsync -avzC --delete "$remote/" "$PWD" else [ "$uid" = 0 ] || log "$PWD" "Need root to update" - # Find out the owner of the repository and spawn - # git as this user below. - # - # 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. + # Similar to the git update, we find the owner of + # the repository and spawn rsync as that user. ( - user=$(kiss-stat "$PWD") || user=root - - id -u "$user" >/dev/null 2>&1 || - user=root + user=$(kiss-stat "$PWD") || user=root + id -u "$user" >/dev/null 2>&1 || user=root [ "$user" = root ] || log "Dropping permissions to $user for pull" - git_cmd="git fetch && git merge && git submodule update --remote --init -f" - 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" + user=$user as_root rsync -avzC --delete "$remote/" "$PWD" ) fi - - run_hook post-pull '' "$PWD" - } + else + log "$repo" " " + printf '%s\n' "Not a remote repository, skipping." + fi done }