3 Commits
1.1 ... 1.3

Author SHA1 Message Date
fbt
75897a38f7 New tool: supd
supd is a very simple tool that uploads everything from a directory to zfh.
Also some refactoring on sup.
2015-04-17 00:42:06 +03:00
fbt
5e8960d376 README 2015-03-08 19:49:37 +03:00
fbt
eece601793 sup usage function 2015-03-08 19:48:26 +03:00
3 changed files with 101 additions and 10 deletions

View File

@@ -20,4 +20,18 @@ sup
--- ---
A very simple tool to upload files to the zfh.so file hosting A very simple tool to upload files to the zfh.so file hosting
Usage: sup [-RsF] [-D num] [file/url] Usage: sup [-RsF] [-D num] [file/url]"
Flags:
-R # Remove the file after uploading.
-s # Make a screenshot and upload it instead of a file.
-F # Make a fullscreen shot instead of prompting for a window/area. Implies -s.
-D <num> # Delay the shot by <num> seconds.
-p # Make the file private. Requires $secret to be set in the config.
Config options (~/.suprc):
secret # Your personal token. Get it at https://zfh.so/settings_form
cfg_screenshot_ext # Screenshot file type, used by scrot.
# Others are self-explanatory:
cfg_url_regex
cfg_tmp_dir
cfg_script_url

48
sup
View File

@@ -13,11 +13,33 @@ cfg_screenshot_ext='png'
[[ -f $HOME/.suprc ]] && { source "$HOME/.suprc"; } [[ -f $HOME/.suprc ]] && { source "$HOME/.suprc"; }
_cat() {
while read; do
printf '%s\n' "$REPLY"
done
}
sup.msg() { printf '%s\n' "[sup] $1"; } sup.msg() { printf '%s\n' "[sup] $1"; }
sup.err() { sup.msg "(error) $1" >&2; } sup.err() { sup.msg "(error) $1" >&2; }
sup.usage() { sup.usage() {
printf '%s\n' "Usage: ${_self} [-RsF] [-D num] [file/url]" _cat <<- EOF
Usage: ${_self} [-RsF] [-D num] [file/url]"
Flags:
-R # Remove the file after uploading.
-s # Make a screenshot and upload it instead of a file.
-F # Make a fullscreen shot instead of prompting for a window/area. Implies -s.
-D <num> # Delay the shot by <num> seconds.
-p # Make the file private. Requires \$secret to be set in the config.
Config options (~/.suprc):
secret # Your personal token. Get it at https://zfh.so/settings_form
cfg_screenshot_ext # Screenshot file type, used by scrot.
# Others are self-explanatory:
cfg_url_regex
cfg_tmp_dir
cfg_script_url
EOF
} }
sup.env() { sup.env() {
@@ -27,16 +49,14 @@ sup.env() {
} }
sup.upload() { sup.upload() {
curl -F file="@$file" \ curl -fsL \
-F file="@$file" \
-F upload_mode='api' \ -F upload_mode='api' \
-F flag_private="$flag_private" \ -F flag_private="$flag_private" \
-F secret="$secret" \ -F secret="$secret" \
-F submit="" \ -F submit="" \
"$cfg_script_url" -sL -A 'zerofiles.org upload script' || { return 1; } -A 'zerofiles.org upload script' \
"$cfg_script_url"
(( "$flag_rm" )) && { rm "$file"; }
return 0
} }
sup.mktemp() { sup.mktemp() {
@@ -131,8 +151,11 @@ main() {
-R|--remove-file) flag_rm='1';; -R|--remove-file) flag_rm='1';;
-s|--screenshot) flag_scrot='1';; -s|--screenshot) flag_scrot='1';;
-F|--fullscreen) flag_scrot_fullscreen='1';;
-D|--screenshot-delay) cfg_scrot_delay="$2"; shift;; -D|--screenshot-delay) cfg_scrot_delay="$2"; shift;;
-F|--fullscreen)
flag_scrot='1'
flag_scrot_fullscreen='1'
;;
-h|--help|--usage) sup.usage; return;; -h|--help|--usage) sup.usage; return;;
@@ -172,7 +195,14 @@ main() {
fi fi
fi fi
sup.upload if sup.upload; then
if (( "$flag_rm" )); then
rm "$file"
fi
else
sup.err 'Something has gone wrong with the upload.'
return 7
fi
} }
sup.set_argv "$@" sup.set_argv "$@"

47
supd Executable file
View File

@@ -0,0 +1,47 @@
#!/usr/bin/env bash
shopt -s nullglob
# Defaults
cfg_workdir="/tmp/$USER/supd"
cfg_scan_delay='30'
msg() { printf '%s\n' "$*"; }
err() { echo "$*" >&2; }
usage() { echo "No help available."; }
main() {
while (( $# )); do
case "$1" in
(--help|-h) usage; return 0;;
(--workdir|-d) cfg_workdir="$2"; shift;;
(--scan-delay|-D) cfg_scan_delay="$2"; shift;;
(--) shift; break;;
(-*)
err "Unknown key: $1"
usage
return 1
;;
(*) break;;
esac
shift
done
mkdir -p "$cfg_workdir" || {
return 1
}
cd "$cfg_workdir" || {
return 1
}
while sleep "$cfg_scan_delay"; do
for i in *; do
sup -R "$i"
done
done
}
main "$@"