mirror of
https://github.com/notwa/rc
synced 2024-11-05 02:49:02 -08:00
49 lines
1.3 KiB
Bash
Executable file
49 lines
1.3 KiB
Bash
Executable file
#!/usr/bin/env sh
|
|
# remote file access (http file-sharing shenanigans)
|
|
# YES_ZSH
|
|
# YES_BASH
|
|
# YES_DASH
|
|
|
|
ea() { ### @- **TODO:** document.
|
|
local cmd="${1:?missing subcommand}"; shift
|
|
case "$cmd" in
|
|
head)
|
|
local trg="$_REMOTE_DOMAIN/$_REMOTE_DIR/${1:?missing target}"
|
|
curl -s -I "$trg"
|
|
return;;
|
|
|
|
get)
|
|
local trg="$_REMOTE_DOMAIN/$_REMOTE_DIR/${1:?missing target}"
|
|
curl -R "$trg" -o "${2:-$1}"
|
|
return;;
|
|
|
|
put)
|
|
local src="${1:?missing source}"
|
|
local dst="$_REMOTE_DOMAIN/$_REMOTE_AUTH/"
|
|
curl -g -n -T "$src" "$dst"
|
|
return;;
|
|
|
|
move)
|
|
local src="$_REMOTE_DOMAIN/$_REMOTE_AUTH/${1:?missing source}"
|
|
local dst="$_REMOTE_DOMAIN/$_REMOTE_DIR/${2:?missing destination}"
|
|
curl -n -X MOVE -H "Destination: $dst" "$src"
|
|
return;;
|
|
|
|
copy)
|
|
local src="$_REMOTE_DOMAIN/$_REMOTE_AUTH/${1:?missing source}"
|
|
local dst="$_REMOTE_DOMAIN/$_REMOTE_DIR/${2:?missing destination}"
|
|
curl -n -X COPY -H "Destination: $dst" "$src"
|
|
return;;
|
|
|
|
delete)
|
|
local trg="$_REMOTE_DOMAIN/$_REMOTE_AUTH/${1:?missing target}"
|
|
curl -f -n -X DELETE "$trg"
|
|
return;;
|
|
|
|
*)
|
|
printf 'unknown subcommand: %s\n' "$1" >&2
|
|
return 2;;
|
|
esac
|
|
}
|
|
|
|
[ -n "${preload+-}" ] || ea "$@"
|