mirror of
https://github.com/notwa/rc
synced 2024-11-12 15:49:03 -08:00
79 lines
2.1 KiB
Bash
Executable file
79 lines
2.1 KiB
Bash
Executable file
#!/usr/bin/env sh
|
|
# remote file access (http file-sharing shenanigans)
|
|
# YES_ZSH YES_BASH YES_DASH YES_ASH
|
|
|
|
__ea_curl() {
|
|
curl -q --no-progress-meter 127.255.255.255 >/dev/null 2>&1
|
|
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
|
|
|
|
__ea() { ### @ ea - **TODO:** document.
|
|
unset LC_ALL cmd dst src trg
|
|
export LC_ALL=C
|
|
cmd="${1:?missing subcommand}"; shift
|
|
case "$cmd" in
|
|
(head)
|
|
trg="$(__ea_urlencode "$EA_DIR/${1:?missing target}")"
|
|
__ea_curl -I "$EA_DOMAIN/$trg"
|
|
return;;
|
|
|
|
(get)
|
|
trg="$(__ea_urlencode "$EA_DIR/${1:?missing target}")"
|
|
__ea_curl -f -R "$EA_DOMAIN/$trg" -o "${2:-$1}"
|
|
return;;
|
|
|
|
(put)
|
|
src="${1:?missing source}"
|
|
dst="$EA_DOMAIN/$EA_AUTH/"
|
|
__ea_curl -g -n -T "$src" "$dst"
|
|
return;;
|
|
|
|
(puts)
|
|
for src; do
|
|
dst="$EA_DOMAIN/$EA_AUTH/"
|
|
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
|
|
return;;
|
|
|
|
(move)
|
|
src="$EA_DOMAIN/$EA_AUTH/${1:?missing source}"
|
|
dst="$EA_DOMAIN/$EA_DIR/${2:?missing destination}"
|
|
__ea_curl -n -X MOVE -H "Destination: $dst" "$src"
|
|
return;;
|
|
|
|
(copy)
|
|
src="$EA_DOMAIN/$EA_AUTH/${1:?missing source}"
|
|
dst="$EA_DOMAIN/$EA_DIR/${2:?missing destination}"
|
|
__ea_curl -n -X COPY -H "Destination: $dst" "$src"
|
|
return;;
|
|
|
|
(delete)
|
|
trg="$EA_DOMAIN/$EA_AUTH/${1:?missing target}"
|
|
__ea_curl -f -n -X DELETE "$trg"
|
|
return;;
|
|
|
|
(*)
|
|
printf 'unknown subcommand: %s\n' "$cmd" >&2
|
|
return 2;;
|
|
esac
|
|
}
|
|
|
|
ea()(__ea "$@")
|
|
[ -n "${preload+-}" ] || __ea "$@"
|