diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-12-19 01:39:00 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-12-19 01:39:00 +0100 |
commit | 6b53d1164c3b51999ffef9e11587285c1ac9c7c9 (patch) | |
tree | 6f72c2e74e0e259c2bf7bc593501815da1ce2d4f /fetch_version | |
parent | 29120e770a57d04219fe4087210fe959348200a1 (diff) | |
download | Nix-6b53d1164c3b51999ffef9e11587285c1ac9c7c9.tar.gz Nix-6b53d1164c3b51999ffef9e11587285c1ac9c7c9.tar.zst Nix-6b53d1164c3b51999ffef9e11587285c1ac9c7c9.zip |
multiple improvements
Add a generic fetch_git script.
New applications:
pal duplicity duply pdftk googler jrnl apg newsboat vcsh xmr-stak urlwatch pass
Diffstat (limited to 'fetch_version')
-rwxr-xr-x | fetch_version | 69 |
1 files changed, 50 insertions, 19 deletions
diff --git a/fetch_version b/fetch_version index db0af1b..cbbeb64 100755 --- a/fetch_version +++ b/fetch_version | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | usage() { | 3 | usage() { |
4 | echo "$0 file.json" | 4 | echo "$0 file.json" |
5 | echo "$0 [-n|--name name] [-b|--branch branch] [-h|--help] (-u|--url) url" | 5 | echo "$0 [-n|--name name] [-b|--branch branch] [-f|--file out_file] [-h|--help] (-u|--url) url" |
6 | exit | 6 | exit |
7 | } | 7 | } |
8 | 8 | ||
@@ -17,6 +17,7 @@ while [[ $# -gt 0 ]]; do | |||
17 | name="$(echo "$content" | jq -r ".meta.name")" | 17 | name="$(echo "$content" | jq -r ".meta.name")" |
18 | url="$(echo "$content" | jq -r ".meta.url")" | 18 | url="$(echo "$content" | jq -r ".meta.url")" |
19 | branch="$(echo "$content" | jq -r ".meta.branch")" | 19 | branch="$(echo "$content" | jq -r ".meta.branch")" |
20 | break | ||
20 | ;; | 21 | ;; |
21 | -n|--name) | 22 | -n|--name) |
22 | name=$1 | 23 | name=$1 |
@@ -30,6 +31,10 @@ while [[ $# -gt 0 ]]; do | |||
30 | branch=$1 | 31 | branch=$1 |
31 | shift | 32 | shift |
32 | ;; | 33 | ;; |
34 | -f|--file) | ||
35 | file=$1 | ||
36 | shift | ||
37 | ;; | ||
33 | -h|--help) | 38 | -h|--help) |
34 | usage | 39 | usage |
35 | ;; | 40 | ;; |
@@ -75,26 +80,52 @@ function fetch_github () { | |||
75 | tag=${rev:0:7}-$branch | 80 | tag=${rev:0:7}-$branch |
76 | } | 81 | } |
77 | 82 | ||
78 | fetch_github 2>/dev/null | 83 | function fetch_other () { |
84 | rev="$(git ls-remote --refs $url refs/heads/$branch | head -n1 | cut -f1)" | ||
85 | sha="$(nix-prefetch-git --url $url --rev refs/heads/$branch | jq -r '.sha256')" | ||
86 | tag=${rev:0:7}-$branch | ||
87 | } | ||
79 | 88 | ||
80 | owner=$(echo "$url" | cut -d"/" -f4) | 89 | case "$url" in |
81 | repo=$(echo "$url" | cut -d"/" -f5) | 90 | https://*github.com/*) |
91 | fetch_github 2>/dev/null | ||
92 | owner=$(echo "$url" | cut -d"/" -f4) | ||
93 | repo=$(echo "$url" | cut -d"/" -f5) | ||
82 | 94 | ||
83 | F='{ | 95 | F='{ |
84 | "tag": $tag, | 96 | "tag": $tag, |
85 | "meta": { | 97 | "meta": { |
86 | "name": $name, | 98 | "name": $name, |
87 | "url": $url, | 99 | "url": $url, |
88 | "branch": $branch | 100 | "branch": $branch |
89 | }, | 101 | }, |
90 | "github": { | 102 | "github": { |
91 | "owner": $owner, | 103 | "owner": $owner, |
92 | "repo": $repo, | 104 | "repo": $repo, |
93 | "rev": $rev, | 105 | "rev": $rev, |
94 | "sha256": $sha, | 106 | "sha256": $sha, |
95 | "fetchSubmodules": true | 107 | "fetchSubmodules": true |
96 | } | 108 | } |
97 | }' | 109 | }' |
110 | ;; | ||
111 | *) | ||
112 | fetch_other 2>/dev/null | ||
113 | F='{ | ||
114 | "tag": $tag, | ||
115 | "meta": { | ||
116 | "name": $name, | ||
117 | "url": $url, | ||
118 | "branch": $branch | ||
119 | }, | ||
120 | "git": { | ||
121 | "url": $url, | ||
122 | "rev": $rev, | ||
123 | "sha256": $sha, | ||
124 | "fetchSubmodules": true | ||
125 | } | ||
126 | }' | ||
127 | ;; | ||
128 | esac | ||
98 | 129 | ||
99 | jq -n \ | 130 | jq -n \ |
100 | --arg name "$name" \ | 131 | --arg name "$name" \ |