f-1: scripts: add download scipts #1
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
b25ce92c66
commit
6ed9d8abd9
1 changed files with 31 additions and 1 deletions
|
|
@ -37,6 +37,33 @@ check_latest_script () {
|
|||
return 0
|
||||
}
|
||||
|
||||
download_binaries () {
|
||||
DRY_RUN="${1}"
|
||||
TAG="${2}"
|
||||
GIT_SERVER="${3}"
|
||||
REPO_PATH="${4}"
|
||||
|
||||
#'.[0].assets.[].browser_download_url'
|
||||
[[ "${TAG}" == "" ]] && TAG=$(curl --silent "${GIT_SERVER}api/v1/repos/${REPO_PATH}releases/?limit=1" | jq -r '.[0].tag_name')
|
||||
echo "${TAG}"
|
||||
|
||||
BIN_PATH="/opt/two/${TAG}/bin/"
|
||||
LN_PATH="/opt/two/bin/"
|
||||
|
||||
exec_with_dry_run "${DRY_RUN}" "mkdir -p \"${BIN_PATH}\""
|
||||
exec_with_dry_run "${DRY_RUN}" "mkdir -p \"${LN_PATH}\""
|
||||
|
||||
curl --silent "${GIT_SERVER}api/v1/repos/${REPO_PATH}releases/tags/${TAG}" | jq -c '.assets.[]' | while read tmp
|
||||
do
|
||||
BINARY_NAME=$(echo "${tmp}" | jq -r '.name')
|
||||
BINARY_SHORT_NAME=$(echo "${BINARY_NAME}" | cut -d_ -f 1)
|
||||
BINARY_URL=$(echo "${tmp}" | jq -r '.browser_download_url')
|
||||
exec_with_dry_run "${DRY_RUN}" "curl --silent '${BINARY_URL}' -o '${BIN_PATH}${BINARY_NAME}'"
|
||||
exec_with_dry_run "${DRY_RUN}" "rm -f '${LN_PATH}${BINARY_SHORT_NAME}'"
|
||||
exec_with_dry_run "${DRY_RUN}" "ln -s '${BIN_PATH}${BINARY_NAME}' '${LN_PATH}${BINARY_SHORT_NAME}'"
|
||||
done
|
||||
}
|
||||
|
||||
main () {
|
||||
[[ -f ./libs/shflags ]] && . ./libs/shflags || eval "$(curl --silent https://git.g3e.fr/H6N/tools/raw/branch/main/libs/shflags)"
|
||||
|
||||
|
|
@ -45,6 +72,7 @@ main () {
|
|||
DEFINE_string 'git_server' 'https://git.g3e.fr/' 'Git Server' 'g'
|
||||
DEFINE_string 'repo_path' 'syonad/two/' 'Path of repository' 'r'
|
||||
DEFINE_string 'branch' 'main/' 'Branch name' 'b'
|
||||
DEFINE_string 'tag' '' 'Tag name' 't'
|
||||
|
||||
FLAGS "$@" || exit $?
|
||||
eval set -- "${FLAGS_ARGV}"
|
||||
|
|
@ -52,9 +80,11 @@ main () {
|
|||
SCRIPT_URL="${FLAGS_git_server}${FLAGS_repo_path}raw/branch/${FLAGS_branch}${SCRIPT_PATH}"
|
||||
check_latest_script "${SCRIPT_URL}" "${0}" || (
|
||||
[[ ${FLAGS_up_script} -eq ${FLAGS_TRUE} ]] && \
|
||||
exec_with_dry_run "${FLAGS_dryrun}" "curl --silent \"${SCRIPT_URL}\" -o \"${0}\""
|
||||
exec_with_dry_run "${FLAGS_dryrun}" "curl --silent '${SCRIPT_URL}' -o '${0}'"
|
||||
exit 1
|
||||
)
|
||||
|
||||
download_binaries "${FLAGS_dryrun}" "${FLAGS_tag}" "${FLAGS_git_server}" "${FLAGS_repo_path}"
|
||||
}
|
||||
|
||||
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && (main "$@" || exit 1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue