From 6b53d1164c3b51999ffef9e11587285c1ac9c7c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Wed, 19 Dec 2018 01:39:00 +0100 Subject: multiple improvements Add a generic fetch_git script. New applications: pal duplicity duply pdftk googler jrnl apg newsboat vcsh xmr-stak urlwatch pass --- fetch_version | 69 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 19 deletions(-) (limited to 'fetch_version') diff --git a/fetch_version b/fetch_version index db0af1b..cbbeb64 100755 --- a/fetch_version +++ b/fetch_version @@ -2,7 +2,7 @@ usage() { echo "$0 file.json" - echo "$0 [-n|--name name] [-b|--branch branch] [-h|--help] (-u|--url) url" + echo "$0 [-n|--name name] [-b|--branch branch] [-f|--file out_file] [-h|--help] (-u|--url) url" exit } @@ -17,6 +17,7 @@ while [[ $# -gt 0 ]]; do name="$(echo "$content" | jq -r ".meta.name")" url="$(echo "$content" | jq -r ".meta.url")" branch="$(echo "$content" | jq -r ".meta.branch")" + break ;; -n|--name) name=$1 @@ -30,6 +31,10 @@ while [[ $# -gt 0 ]]; do branch=$1 shift ;; + -f|--file) + file=$1 + shift + ;; -h|--help) usage ;; @@ -75,26 +80,52 @@ function fetch_github () { tag=${rev:0:7}-$branch } -fetch_github 2>/dev/null +function fetch_other () { + rev="$(git ls-remote --refs $url refs/heads/$branch | head -n1 | cut -f1)" + sha="$(nix-prefetch-git --url $url --rev refs/heads/$branch | jq -r '.sha256')" + tag=${rev:0:7}-$branch +} -owner=$(echo "$url" | cut -d"/" -f4) -repo=$(echo "$url" | cut -d"/" -f5) +case "$url" in + https://*github.com/*) + fetch_github 2>/dev/null + owner=$(echo "$url" | cut -d"/" -f4) + repo=$(echo "$url" | cut -d"/" -f5) -F='{ - "tag": $tag, - "meta": { - "name": $name, - "url": $url, - "branch": $branch - }, - "github": { - "owner": $owner, - "repo": $repo, - "rev": $rev, - "sha256": $sha, - "fetchSubmodules": true - } -}' + F='{ + "tag": $tag, + "meta": { + "name": $name, + "url": $url, + "branch": $branch + }, + "github": { + "owner": $owner, + "repo": $repo, + "rev": $rev, + "sha256": $sha, + "fetchSubmodules": true + } + }' + ;; + *) + fetch_other 2>/dev/null + F='{ + "tag": $tag, + "meta": { + "name": $name, + "url": $url, + "branch": $branch + }, + "git": { + "url": $url, + "rev": $rev, + "sha256": $sha, + "fetchSubmodules": true + } + }' + ;; +esac jq -n \ --arg name "$name" \ -- cgit v1.2.3