-
Notifications
You must be signed in to change notification settings - Fork 721
/
profile.sh
210 lines (177 loc) · 6.96 KB
/
profile.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
usage_profile() {
usage "profile" "Cluster profile operations" <<EOF
$(helpcmd profile-names) List profile names (JSON)
$(blk names ls)
$(helpcmd profile-json NAME) Get contents of either named profile, or profile JSON desc
$(blk json show pj)
$(helpcmd profile-describe NAME)
$(blk describe pdesc pd) Human-readable profile overview
$(helpcmd profile-node-specs PROFILE-NAME/JSON)
$(blk node-specs specs) Print node specs JSON for the given profile and environment
$(helpcmd allocate-time PROFILE-NAME/JSON)
Allocate time for a run of a profile
$(helpcmd describe-timing TIMING-JSON)
Explain timing allocation
EOF
}
global_profile_eras=(
shelley
allegra
mary
alonzo
babbage
conway
)
profile_default_op='profile-json'
profile() {
local op=${1:-$profile_default_op}; test $# -gt 0 && shift
case "$op" in
profile-names | names | list | lsp )
if test "${WB_CARDANO_PROFILE:-0}" != "0"
then
cardano-profile names
else
profile all-profiles | jq 'keys'
fi;;
all-profiles | all )
if test "${WB_CARDANO_PROFILE:-0}" != "0"
then
cardano-profile all
else
with_era_profiles '
map (generate_all_era_profiles(.; null; null))
| add
'
fi;;
has-profile )
local usage="USAGE: wb profile $op NAME"
local name=${1:?$usage}
if test "${WB_CARDANO_PROFILE:-0}" != "0"
then
profile profile-names | jq --exit-status --arg name "$name" 'map (. == $name) | any' >/dev/null
else
with_era_profiles '
map (generate_all_era_profiles(.; null; null)
| map (.name == $name)
| any)
| any
' --exit-status --arg name "$name" >/dev/null
fi;;
## XXX: does not respect overlays!!
compose )
local profile_names="$@"
profile all-profiles |
jq --argjson profile_names "$(to_jsonlist ${profile_names[*]})" '
. as $profiles
| $profile_names | debug
| map($profiles[.])
| add
';;
profile-json | json | show | pj )
local usage="USAGE: wb profile $op [NAME=<current-shell-profile>"
local name=${1:-${WB_SHELL_PROFILE:?variable unset, no profile name to use as a default.}}
local json=$(if test -f "$name"
then jq '.' "$name"
else profile all-profiles |
jq '.["'$name'"]'
fi)
local preset=$(jq -r '.preset // ""' <<<$json)
local preset_overlay=$global_basedir/profile/presets/$preset/overlay.json
if test -z "$preset" -o ! -f $preset_overlay
then echo "$json"
else jq '. * $overlay[0]' <<<$json --slurpfile overlay $preset_overlay
fi;;
profile-describe | describe | pdesc | pd )
local usage="USAGE: wb profile $op NAME"
local name=${1:?$usage}
profile json $name |
jq 'include "prof3-derived";
profile_pretty_describe(.)
' --raw-output -L "$global_basedir/profile" -L "$global_basedir";;
has-preset )
local usage="USAGE: wb profile $op NAME"
local profile=${1:?$usage}
profile json "$profile" | jqtest ".preset != null";;
preset )
local usage="USAGE: wb profile $op NAME"
local profile=${1:?$usage}
profile json "$profile" | jq -r '.preset // ""';;
preset-get-file )
local usage="USAGE: wb profile $op PRESET-NAME DESC FILE"
local preset=${1:?$usage}
local desc=${2:?$usage}
local file=${3:?$usage}
local preset_dir=$global_basedir/profile/presets/$preset
local path=$preset_dir/$file
if test ! -d "$preset_dir"; then fail "unknown preset: $preset"
elif test ! -f "$path"; then fail "preset $preset has no file: $file"
else echo "$path"
fi;;
profile-node-specs | node-specs | specs )
local usage="USAGE: wb profile $op PROFILE-NAME/JSON TOPO-DIR"
local profile=${1:?$usage}
local topo_dir=${2:?$usage}
local args=(
-L "$global_basedir"
--argjson env "$WB_ENV"
--slurpfile topology "$topo_dir"/topology.json
)
## WARNING: this is structured in correspondence
## with the output generated by cardano-topology
profile json "$profile" | jq '
include "profile/profile-run";
. as $prof
| profile_node_specs($env; $prof; $topology)
' "${args[@]}";;
allocate-time )
local usage="USAGE: wb profile $op PROFILE-JSON"
local profile=${1:?$usage}
if profile has-preset "$profile"
then
local preset=$(profile json "$profile" | jq '.preset' -r)
local shelley=$(profile preset-get-file "$preset" 'genesis' 'genesis/genesis-shelley.json')
local start=$(jq '.systemStart | fromdateiso8601' $shelley)
local offset="$((start - $(date +%s)))"
local start_tag=$(date --date=@$(date +%s) --utc +'%Y'-'%m'-'%d'-'%H.%M')
else
local offset=$(profile json "$profile" |
jq '.derived.genesis_future_offset' --raw-output)
local start=$(date '+%s' --date="now + $offset seconds")
local start_tag=$(date --date=@$start --utc +'%Y'-'%m'-'%d'-'%H.%M')
fi
local args=(
-L "$global_basedir"
--arg 'start' "$start"
--arg 'start_human' "$(date --date=@$start --utc +"%Y-%m-%dT%H:%M:%SZ")"
--arg 'start_tag' "$start_tag"
--arg 'systemStart' "$(date --date=@$start --utc --iso-8601=s | cut -c-19)Z"
)
profile json "$profile" | jq '
include "profile/profile-run";
. as $prof
| profile_timing($prof;
$start;
$start_human;
$start_tag;
$systemStart)
' "${args[@]}";;
describe-timing )
local usage="USAGE: wb profile $op TIMING-JSONEXPR"
local timing=${1:?$usage}
jq <<<$timing -L "$global_basedir" --raw-output '
include "profile/profile-run";
timing_pretty_describe(.)
';;
* ) set +x; usage_profile;; esac
}
with_era_profiles() {
local usage="USAGE: wb profile with-profiles JQEXP"
local jqexp=${1:?$usage}; shift
jq -L "$global_basedir" \
-L "$global_basedir"/profile \
-L "$global_basedir"/profile/pparams \
--argjson eras "$(to_jsonlist ${global_profile_eras[*]})" \
--null-input '
include "profiles";
$eras | '"$jqexp" "$@"
}