diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-12-13 21:25:24 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-12-13 21:26:23 +0100 |
commit | 177da38b243b59d273c0400b04a79e2b05af6bc3 (patch) | |
tree | b9e310bd5bea584b022a22d56cb94f52e9dc2a26 /fetch_version | |
download | Nix-177da38b243b59d273c0400b04a79e2b05af6bc3.tar.gz Nix-177da38b243b59d273c0400b04a79e2b05af6bc3.tar.zst Nix-177da38b243b59d273c0400b04a79e2b05af6bc3.zip |
Initial commit
Diffstat (limited to 'fetch_version')
-rwxr-xr-x | fetch_version | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/fetch_version b/fetch_version new file mode 100755 index 0000000..db0af1b --- /dev/null +++ b/fetch_version | |||
@@ -0,0 +1,108 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | usage() { | ||
4 | echo "$0 file.json" | ||
5 | echo "$0 [-n|--name name] [-b|--branch branch] [-h|--help] (-u|--url) url" | ||
6 | exit | ||
7 | } | ||
8 | |||
9 | branch="master" | ||
10 | while [[ $# -gt 0 ]]; do | ||
11 | a="$1" | ||
12 | shift | ||
13 | case "$a" in | ||
14 | *.json) | ||
15 | file=$a | ||
16 | content=$(cat $a) | ||
17 | name="$(echo "$content" | jq -r ".meta.name")" | ||
18 | url="$(echo "$content" | jq -r ".meta.url")" | ||
19 | branch="$(echo "$content" | jq -r ".meta.branch")" | ||
20 | ;; | ||
21 | -n|--name) | ||
22 | name=$1 | ||
23 | shift | ||
24 | ;; | ||
25 | -u|--url) | ||
26 | url=$1 | ||
27 | shift | ||
28 | ;; | ||
29 | -b|--branch) | ||
30 | branch=$1 | ||
31 | shift | ||
32 | ;; | ||
33 | -h|--help) | ||
34 | usage | ||
35 | ;; | ||
36 | esac | ||
37 | done | ||
38 | if [ -z "$url" ]; then | ||
39 | usage | ||
40 | fi | ||
41 | if [ -z "$name" ]; then | ||
42 | name=$(echo "$url" | cut -d"/" -f5) | ||
43 | fi | ||
44 | if [ -z "$file" ]; then | ||
45 | file=$name.json | ||
46 | fi | ||
47 | |||
48 | # function fetch_ledger () { | ||
49 | # pushd $HOME/projets/ledger >/dev/null 2>/dev/null | ||
50 | # git fetch origin | ||
51 | # tag="$(git describe origin/next | sed -e "s/^v//")" | ||
52 | # rev="$(git show-ref -s refs/remotes/origin/next)" | ||
53 | # sha="$(nix-prefetch-url --unpack file://<(git archive --format=tar.gz HEAD) 2>/dev/null)" | ||
54 | # popd >/dev/null 2>/dev/null | ||
55 | # } | ||
56 | |||
57 | # awk_describe='BEGIN { | ||
58 | # FS = "[ /^]+" | ||
59 | # while ("git ls-remote " ARGV[1] "| sort -Vk2" | getline) { | ||
60 | # if (!sha) | ||
61 | # sha = substr($0, 1, 7) | ||
62 | # tag = $3 | ||
63 | # } | ||
64 | # while ("curl -s " ARGV[1] "/releases/tag/" tag | getline) | ||
65 | # if ($3 ~ "commits") | ||
66 | # com = $2 | ||
67 | # printf com ? "%s-%s-g%s\n" : "%s\n", tag, com, sha | ||
68 | # }' | ||
69 | |||
70 | function fetch_github () { | ||
71 | rev="$(git ls-remote --refs $url refs/heads/$branch | head -n1 | cut -f1)" | ||
72 | sha="$(nix-prefetch-url --unpack $url/archive/$branch.tar.gz)" | ||
73 | # Différent du git-describe et github-spécifique | ||
74 | #tag=$(echo "$awk_describe" | awk -f - $url | sed -e "s/^v//") | ||
75 | tag=${rev:0:7}-$branch | ||
76 | } | ||
77 | |||
78 | fetch_github 2>/dev/null | ||
79 | |||
80 | owner=$(echo "$url" | cut -d"/" -f4) | ||
81 | repo=$(echo "$url" | cut -d"/" -f5) | ||
82 | |||
83 | F='{ | ||
84 | "tag": $tag, | ||
85 | "meta": { | ||
86 | "name": $name, | ||
87 | "url": $url, | ||
88 | "branch": $branch | ||
89 | }, | ||
90 | "github": { | ||
91 | "owner": $owner, | ||
92 | "repo": $repo, | ||
93 | "rev": $rev, | ||
94 | "sha256": $sha, | ||
95 | "fetchSubmodules": true | ||
96 | } | ||
97 | }' | ||
98 | |||
99 | jq -n \ | ||
100 | --arg name "$name" \ | ||
101 | --arg owner "$owner" \ | ||
102 | --arg repo "$repo" \ | ||
103 | --arg tag "$tag" \ | ||
104 | --arg rev "$rev" \ | ||
105 | --arg url "$url" \ | ||
106 | --arg branch "$branch" \ | ||
107 | --arg sha "$sha" \ | ||
108 | "$F" > $file | ||