Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
d73f41e2de | |||
52f5ea9028 | |||
83bbe70c80 | |||
47fe62a7c8 | |||
639a97f43e | |||
784ad95215 | |||
58e1b63fb7 | |||
65fdd688bf | |||
488fdc0a5a | |||
14af6b720f | |||
c22e34afb2 |
23
ufw
23
ufw
@@ -39,6 +39,7 @@ usage() {
|
||||
-m|--max-filesize <num>[suf] # Maximum filesize (takes K, M and G suffixes).
|
||||
-a|--album-id # Add the file to an album.
|
||||
-A|--album-name # Add the file to an album by name. The album will be created, if necessary.
|
||||
-t|--tags "<tag1[, tag2,..]>" # Add tags to the file.
|
||||
|
||||
Config options (~/.config/ufw):
|
||||
secret # Your personal token. Get it at https://zfh.so/settings_form
|
||||
@@ -140,6 +141,7 @@ upload() {
|
||||
-F api_format='json' \
|
||||
-F flag_private="$flag_private" \
|
||||
-F secret="$secret" \
|
||||
-F tags="$tags" \
|
||||
-F submit="" \
|
||||
"${misc_curl_args[@]}" \
|
||||
-A 'zerofiles.org upload script' \
|
||||
@@ -244,7 +246,7 @@ _mktemp() {
|
||||
get_my_ip() {
|
||||
declare api_response api_status api_status_message my_ip
|
||||
|
||||
api_response=$( curl -sl "$cfg_service_url/$cfg_api_path/ip?format=json" )
|
||||
api_response=$( curl -sl "$cfg_service_url/ip.json" )
|
||||
|
||||
get_api_status <<< "$api_response"
|
||||
|
||||
@@ -344,6 +346,7 @@ main() {
|
||||
-D|--screenshot-delay) cfg_scn_delay="$2"; shift;;
|
||||
-m|--max-filesize) cfg_max_filesize=$2; shift;;
|
||||
-A|--album-name) album_name=$2; shift;;
|
||||
-t|--tags) tags=$2; shift;;
|
||||
|
||||
-i|--my-ip) action='getmyip';;
|
||||
-u|--shorten) action='url';;
|
||||
@@ -388,8 +391,22 @@ main() {
|
||||
done
|
||||
|
||||
case "${action:-upload}" in
|
||||
upload) upload "$1";;
|
||||
url) get_shortlink "$1";;
|
||||
upload)
|
||||
if (( $# )); then
|
||||
for t in "$@"; do
|
||||
upload "$t"
|
||||
done
|
||||
else
|
||||
upload
|
||||
fi
|
||||
;;
|
||||
|
||||
url)
|
||||
for t in "$@"; do
|
||||
get_shortlink "$1"
|
||||
done
|
||||
;;
|
||||
|
||||
getmyip) get_my_ip;;
|
||||
login) login;;
|
||||
esac
|
||||
|
85
ufwd
85
ufwd
@@ -6,10 +6,6 @@ if ! [[ "$XDG_RUNTIME_DIR" ]]; then
|
||||
XDG_RUNTIME_DIR="/run/user/$UID"
|
||||
fi
|
||||
|
||||
# Defaults
|
||||
cfg_workdir="$XDG_RUNTIME_DIR/ufwd"
|
||||
cfg_scan_delay='30'
|
||||
|
||||
msg() { printf '%s\n' "$*"; }
|
||||
err() { echo "$*" >&2; }
|
||||
|
||||
@@ -18,47 +14,12 @@ usage() {
|
||||
printf ' -h # Show this message.\n'
|
||||
printf ' -n # Enable notifications with notify-send. Must be installed.\n'
|
||||
printf ' -d [path] # Set the dir that is to be watched.\n'
|
||||
printf ' -D [sec] # Set the check interval.\n'
|
||||
}
|
||||
|
||||
main() {
|
||||
while (( $# )); do
|
||||
case "$1" in
|
||||
(--help|-h) usage; return 0;;
|
||||
upload() {
|
||||
declare file=$1; shift
|
||||
|
||||
(--workdir|-d) cfg_workdir="$2"; shift;;
|
||||
(--scan-delay|-D) cfg_scan_delay="$2"; shift;;
|
||||
|
||||
(--notify|-n) flag_enable_notifications=1;;
|
||||
|
||||
(--clipboard|-c) flag_enable_clipboard=1;;
|
||||
|
||||
(--) shift; break;;
|
||||
(-*)
|
||||
err "Unknown key: $1"
|
||||
usage
|
||||
return 1
|
||||
;;
|
||||
|
||||
(*) break;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if (( flag_enable_notifications )); then
|
||||
if type -P notify-send &>/dev/null; then
|
||||
msg "Found notify-send."
|
||||
else
|
||||
err "notify-send not found in PATH, disabling notifications."
|
||||
flag_enable_notifications=0
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p "$cfg_workdir" || return 1
|
||||
cd "$cfg_workdir" || return 1
|
||||
|
||||
while read -r dir action path; do
|
||||
upload_output=$( ufw "$@" -R "$dir$path" )
|
||||
upload_output=$( ufw -R "$@" "$file" )
|
||||
upload_return=$?
|
||||
|
||||
if (( flag_enable_notifications )); then
|
||||
@@ -75,7 +36,45 @@ main() {
|
||||
fi
|
||||
|
||||
printf '%s\n' "$upload_output"
|
||||
done < <( inotifywait -m -e create "$cfg_workdir" )
|
||||
}
|
||||
|
||||
main() {
|
||||
while (( $# )); do
|
||||
case "$1" in
|
||||
(--help|-h) usage; return 0;;
|
||||
(--notify|-n) flag_enable_notifications=1;;
|
||||
(--clipboard|-c) flag_enable_clipboard=1;;
|
||||
|
||||
(--workdir|-d) cfg_workdir+=( "$2" ); shift;;
|
||||
|
||||
(--) shift; break;;
|
||||
(-*) err "Unknown key: $1"; usage; return 1;;
|
||||
(*) break;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
[[ $cfg_workdir ]] || cfg_workdir="$XDG_RUNTIME_DIR/ufwd"
|
||||
|
||||
if (( flag_enable_notifications )); then
|
||||
if type -P notify-send &>/dev/null; then
|
||||
msg "Found notify-send."
|
||||
else
|
||||
err "notify-send not found in PATH, disabling notifications."
|
||||
flag_enable_notifications=0
|
||||
fi
|
||||
fi
|
||||
|
||||
for p in "${cfg_workdir[@]}"; do
|
||||
[[ -d "$p" ]] || return 1
|
||||
done
|
||||
|
||||
printf 'Working in:\n'
|
||||
printf ' - %s\n' "${cfg_workdir[@]}"
|
||||
|
||||
while read -r d e f; do
|
||||
upload "$d$f" "$@" &
|
||||
done < <( inotifywait -m -e close_write "${cfg_workdir[@]}" )
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
Reference in New Issue
Block a user