: 'Volcano' : 'IGNORED_LABEL_IN_CMD_and_SH_COMMENT_INTRODUCER @goto cmd_part ***** Volcano: one polyglot client, run by sh and by cmd. ***** LF only: a carriage return breaks the sh side (how_it_parses.md). ***** Every cmd label is written twice (LF files, serverfault.com/a/1077433). ***** No sh line may start with a colon: cmd would read it as a label. ***** ***** Usage: e.cmd [] sh e.cmd [] ***** curl -fsS | sh -s -- [] ***** Without an id it shows the menu of its home; with one it walks ***** the menu tree to that eruption, checks its SHA-256 and asks ***** before running it. ' v_main() { LC_ALL=C export LC_ALL v_release=0.1.0 v_home=https://beacon.azimutzero.ca v_host=${v_home#https://} v_dot=$(printf '\302\267') v_user= v_tok_server= v_tok_user= v_has_login= command -v curl >/dev/null 2>&1 || v_die 'curl is needed' v_tmp=$(mktemp -d 2>/dev/null) || v_die 'cannot create a temp folder' trap 'rm -rf "$v_tmp"' EXIT trap 'exit 130' INT HUP TERM if [ $# -gt 0 ]; then v_walk "$1" else v_browse fi } v_die() { printf 'volcano: %s\n' "$*" >&2; exit 1; } v_ask() { # : one answer from the terminal into v_ans printf '%s' "$1" v_ans= read -r v_ans v_ok_path "$1" || v_die "bad path: $1" v_tok= case $1 in shared/private/*) v_tok=$v_tok_server ;; esac if [ -n "$v_user" ]; then case $1 in "$v_user"/private/*) v_tok=$v_tok_user ;; esac fi if [ -n "$v_tok" ]; then printf 'Authorization: Bearer %s\n' "$v_tok" | curl -fsS -H @- -o "$2" "$v_home/$1" else curl -fsS -o "$2" "$v_home/$1" fi } v_menu() { # : fetched and checked v_fetch "$1" "$v_tmp/menu.raw" || return 1 v_first= IFS= read -r v_first <"$v_tmp/menu.raw" || true [ "$v_first" = '# volcano-menu 2' ] || v_die "$1: not in menu format 2" while IFS='|' read -r v_a v_b v_c v_d v_e v_f v_g; do case $v_a in ''|\#*) continue ;; esac v_ok_line "$v_a" "$v_b" "$v_c" "$v_d" "$v_e" "$v_f" "$v_g" || v_die "$1: bad line: $v_a|$v_b|$v_c|$v_d|$v_e|$v_f|$v_g" printf '%s|%s|%s|%s|%s|%s|%s\n' "$v_a" "$v_b" "$v_c" "$v_d" "$v_e" "$v_f" "$v_g" done <"$v_tmp/menu.raw" >"$2" } v_add() { # : append its entries while IFS='|' read -r v_a v_b v_c v_d v_e v_f v_g; do case " $2 " in *" $v_a "*) ;; *) continue ;; esac [ "$v_a" = u ] && [ "$v_b" = "$v_user" ] && continue printf '%s|%s|%s|%s|%s|%s|%s|%s|%s%s\n' "$v_a" "$v_b" "$v_c" "$v_d" "$v_e" "$v_f" "$v_g" "$3" "$4" "$v_b" done <"$1" >>"$v_tmp/entries" } v_build_top() { : >"$v_tmp/entries" v_menu menu "$v_tmp/root" || v_die "cannot fetch the menu of $v_home" v_has_login= grep -q '^l|' "$v_tmp/root" && v_has_login=1 if [ -n "$v_tok_server" ] && v_menu shared/private/menu "$v_tmp/shared"; then v_add "$v_tmp/shared" e Shared '' else v_add "$v_tmp/root" e Shared '' fi if [ -n "$v_user" ]; then if [ -n "$v_tok_user" ] && v_menu "$v_user/private/menu" "$v_tmp/mine"; then v_add "$v_tmp/mine" 'p r' 'Personal repository' "$v_user/" else v_uf=$(grep "^u|$v_user|" "$v_tmp/root" | cut -d'|' -f3) if [ -n "$v_uf" ] && v_menu "$v_uf/menu" "$v_tmp/mine"; then v_add "$v_tmp/mine" 'p r' 'Personal repository' "$v_user/" fi fi fi v_add "$v_tmp/root" u 'Publishing user' '' } v_build_level() { # : >"$v_tmp/entries" v_menu "$1/menu" "$v_tmp/level" || v_die "cannot fetch $1/menu" v_add "$v_tmp/level" e Eruption '' v_add "$v_tmp/level" 'p r' Repository '' } v_line() { #