From 0ae83ee81b9f34216accaec39165255883bf89ca Mon Sep 17 00:00:00 2001 From: Konstantin Demin Date: Fri, 5 Jul 2024 17:51:22 +0300 Subject: [PATCH] dotfiles: improve forge selection --- .config/dotfiles/install.sh | 36 ++++++++++++++++++++++++--------- .config/zsh/lib/selfservice.zsh | 4 ++-- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/.config/dotfiles/install.sh b/.config/dotfiles/install.sh index 6841256..19254cc 100755 --- a/.config/dotfiles/install.sh +++ b/.config/dotfiles/install.sh @@ -47,25 +47,41 @@ fetch() { return 1 } +test_forge() { + fetch "$1" "$2" || return 1 + [ "$(head -n 1 "$2")" = '*' ] || return 1 + return 0 +} + select_forge() { unset uri_gitignore uri_repo uri_tarball + __t=$(mktemp) ## try with git.krd.sh - t_gitignore="${uri_krdsh}/raw/branch/${git_branch}/${f_gitignore}" - if fetch "${t_gitignore}" >/dev/null ; then + while [ -z "${uri_repo}" ] ; do + t_gitignore="${uri_krdsh}/raw/branch/${git_branch}/${f_gitignore}" + test_forge "${t_gitignore}" "${__t}" || break + uri_repo="${uri_krdsh}.git" uri_gitignore="${t_gitignore}" uri_tarball="${uri_krdsh}/archive/${git_branch}.tar.gz" - unset t_gitignore - return - fi + + break + done ## try with github.com - t_gitignore="${uri_github}/raw/${git_branch}/${f_gitignore}" - if fetch "${t_gitignore}" >/dev/null ; then + while [ -z "${uri_repo}" ] ; do + t_gitignore="${uri_github}/raw/${git_branch}/${f_gitignore}" + test_forge "${t_gitignore}" "${__t}" || break + uri_repo="${uri_github}.git" uri_gitignore="${t_gitignore}" uri_tarball="${uri_github}/archive/refs/heads/${git_branch}.tar.gz" - unset t_gitignore - return + + break + done + rm -f "${__t}" ; unset __t + unset t_gitignore + if [ -n "${uri_repo}" ] ; then + return 0 fi echo 'no forge is available to fetch URLs' >&2 return 1 @@ -181,7 +197,9 @@ git_config() { git config --unset pull.ff || : ## size optimization git config core.compression 9 + git config core.looseCompression 6 git config pack.compression 9 + git config pack.threads 2 ## generic git config receive.denyNonFastForwards true } diff --git a/.config/zsh/lib/selfservice.zsh b/.config/zsh/lib/selfservice.zsh index 79c7220..ac4a822 100644 --- a/.config/zsh/lib/selfservice.zsh +++ b/.config/zsh/lib/selfservice.zsh @@ -1,7 +1,7 @@ #!/bin/zsh dotfiles-update() { - "${ZSHU[d_dotfiles]}/install.sh" "$@" + "${ZSHU[d_dotfiles]}/install.sh" "$@" || return $? } dotfiles-git() { ( @@ -49,7 +49,7 @@ z-zwc-flush() { } z-update() { - dotfiles-update + dotfiles-update || return $? z-cache-flush }