2021-08-01 10:29:38 -07:00
|
|
|
#!/usr/bin/env sh
|
2017-03-02 23:24:01 -08:00
|
|
|
# remote file access (http file-sharing shenanigans)
|
2024-07-22 05:28:58 -07:00
|
|
|
# compat: +ash +bash +dash +zsh
|
2017-03-02 23:24:01 -08:00
|
|
|
|
2024-03-04 20:40:03 -08:00
|
|
|
__ea_curl() {
|
2024-07-12 02:03:58 -07:00
|
|
|
curl -q --no-progress-meter 127.255.255.255 >/dev/null 2>&1
|
2024-03-04 20:40:03 -08:00
|
|
|
if [ $? = 2 ]
|
|
|
|
then __ea_curl() { curl -sS "$@"; }
|
|
|
|
else __ea_curl() { curl --no-progress-meter "$@"; }
|
|
|
|
fi
|
|
|
|
__ea_curl "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
__ea_urlencode() {
|
|
|
|
while test "$1"; do
|
|
|
|
case "$1" in
|
|
|
|
([a-zA-Z0-9~_.-]*) printf '%.1s' "$1";; # RFC 3986
|
|
|
|
(*) printf '%%%02X' "'$1";; # bash complains but works
|
|
|
|
esac
|
|
|
|
set -- "${1#?}"
|
|
|
|
done
|
|
|
|
} 2>&- # send bash's complaints to the abyss
|
|
|
|
|
2024-03-04 20:42:48 -08:00
|
|
|
__ea() { ### @ ea - **TODO:** document.
|
2024-03-04 21:22:39 -08:00
|
|
|
unset LC_ALL cmd dst src trg
|
|
|
|
export LC_ALL=C
|
2024-03-04 20:40:46 -08:00
|
|
|
cmd="${1:?missing subcommand}"; shift
|
2021-08-01 10:29:38 -07:00
|
|
|
case "$cmd" in
|
2024-03-04 20:42:04 -08:00
|
|
|
(head)
|
2024-03-04 20:40:46 -08:00
|
|
|
trg="$(__ea_urlencode "$EA_DIR/${1:?missing target}")"
|
2024-03-04 20:40:03 -08:00
|
|
|
__ea_curl -I "$EA_DOMAIN/$trg"
|
2021-08-01 10:29:38 -07:00
|
|
|
return;;
|
|
|
|
|
2024-03-04 20:42:04 -08:00
|
|
|
(get)
|
2024-03-04 20:40:46 -08:00
|
|
|
trg="$(__ea_urlencode "$EA_DIR/${1:?missing target}")"
|
2024-03-04 20:40:03 -08:00
|
|
|
__ea_curl -f -R "$EA_DOMAIN/$trg" -o "${2:-$1}"
|
2021-08-01 10:29:38 -07:00
|
|
|
return;;
|
|
|
|
|
2024-03-04 20:42:04 -08:00
|
|
|
(put)
|
2024-03-04 20:40:46 -08:00
|
|
|
src="${1:?missing source}"
|
|
|
|
dst="$EA_DOMAIN/$EA_AUTH/"
|
2024-03-04 20:40:03 -08:00
|
|
|
__ea_curl -g -n -T "$src" "$dst"
|
2021-08-01 10:29:38 -07:00
|
|
|
return;;
|
|
|
|
|
2024-03-04 20:42:04 -08:00
|
|
|
(puts)
|
2024-03-04 20:40:03 -08:00
|
|
|
for src; do
|
2024-03-04 20:40:46 -08:00
|
|
|
dst="$EA_DOMAIN/$EA_AUTH/"
|
2024-03-04 20:40:03 -08:00
|
|
|
minisign -QSm "$src" || return
|
|
|
|
__ea_curl -g -n -T "$src" "$dst" || return
|
|
|
|
__ea_curl -g -n -T "$src.minisig" "$dst" || return
|
|
|
|
rm "$src.minisig"
|
|
|
|
done
|
2024-02-23 22:33:17 -08:00
|
|
|
return;;
|
|
|
|
|
2024-03-04 20:42:04 -08:00
|
|
|
(move)
|
2024-03-04 20:40:46 -08:00
|
|
|
src="$EA_DOMAIN/$EA_AUTH/${1:?missing source}"
|
|
|
|
dst="$EA_DOMAIN/$EA_DIR/${2:?missing destination}"
|
2024-03-04 20:40:03 -08:00
|
|
|
__ea_curl -n -X MOVE -H "Destination: $dst" "$src"
|
2021-08-01 10:29:38 -07:00
|
|
|
return;;
|
|
|
|
|
2024-03-04 20:42:04 -08:00
|
|
|
(copy)
|
2024-03-04 20:40:46 -08:00
|
|
|
src="$EA_DOMAIN/$EA_AUTH/${1:?missing source}"
|
|
|
|
dst="$EA_DOMAIN/$EA_DIR/${2:?missing destination}"
|
2024-03-04 20:40:03 -08:00
|
|
|
__ea_curl -n -X COPY -H "Destination: $dst" "$src"
|
2021-08-01 10:29:38 -07:00
|
|
|
return;;
|
|
|
|
|
2024-03-04 20:42:04 -08:00
|
|
|
(delete)
|
2024-03-04 20:40:46 -08:00
|
|
|
trg="$EA_DOMAIN/$EA_AUTH/${1:?missing target}"
|
2024-03-04 20:40:03 -08:00
|
|
|
__ea_curl -f -n -X DELETE "$trg"
|
2021-08-01 10:29:38 -07:00
|
|
|
return;;
|
|
|
|
|
2024-03-04 20:42:04 -08:00
|
|
|
(*)
|
2024-02-23 22:32:25 -08:00
|
|
|
printf 'unknown subcommand: %s\n' "$cmd" >&2
|
2021-08-01 10:29:38 -07:00
|
|
|
return 2;;
|
|
|
|
esac
|
2024-03-04 20:42:48 -08:00
|
|
|
}
|
2017-03-02 23:24:01 -08:00
|
|
|
|
2024-03-04 20:42:48 -08:00
|
|
|
ea()(__ea "$@")
|
|
|
|
[ -n "${preload+-}" ] || __ea "$@"
|