diff --git a/ufw b/ufw index 77cc7e5..d627b1f 100755 --- a/ufw +++ b/ufw @@ -46,9 +46,9 @@ usage() { -c|--clipboard # Throw the result into the clipboard -i|--my-ip # Get the IP you're reaching the service with, usually it will be your public address. -l|--login # Get a login token sent to email for - -C|--xclip-selector # Set the xclip selector explicitly - --tmp-dir # Set the temp dir - --url # Set the service url + -C|--xclip-selector # Set the xclip selector explicitly + --tmp-dir # Set the temp dir + --url # Set the service url Config options (~/.config/ufw): secret # Your personal token. Get it at https://8fw.me/settings_form @@ -250,7 +250,9 @@ get_my_ip() { login() { declare api_response login=$1 - api_response=$( curl "$cfg_service_url/token_request.json?login=$login" ) + api_response=$( curl --get \ + --data-urlencode "login=$login" \ + "$cfg_service_url/token_request.json" ) if get_api_status <<< "$api_response"; then printf 'Check your email.\n' @@ -270,7 +272,14 @@ get_token() { read -sp 'Password: ' password printf '\n' - login_response=$(curl -c "$cfg_file.cookiejar" -d "login=$login" -d "password=$password" -sl "$cfg_service_url/login.json") + login_response=$(curl -f -c "$cfg_file.cookiejar" -d "login=$login" -d "password=$password" -sl "$cfg_service_url/login.json") + (( $? )) || { + err "Login failed." + return 1 + } + + chmod 600 "$cfg_file.cookiejar" + get_api_status <<< "$login_response" || { jq -r '.status.message' <<< "$login_response" return 1 @@ -379,7 +388,6 @@ main() { (--tmp-dir) cfg_tmp_dir=$2; shift;; (--url) cfg_service_url=$2; shift;; - (--max-filesize) cfg_max_filesize=$2; shift;; (-i|--my-ip) action='getmyip';; (-u|--shorten) action='url';; @@ -448,7 +456,7 @@ main() { (( ${#args[@]} )) || return 1 if [[ "$album_name" ]]; then - get_album_id "$album_name" + get_album_id "$album_name" || return 1 fi for t in "${args[@]}"; do diff --git a/ufwd b/ufwd index 861a2bc..3850ece 100755 --- a/ufwd +++ b/ufwd @@ -11,10 +11,10 @@ err() { echo "$*" >&2; } usage() { printf 'Usage: ufwd [flags]\n' - 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 ' -s # Push the file url into the clipboard.\n' + printf ' --help|-h # Show this message.\n' + printf ' --notify|-n # Enable notifications with notify-send. Must be installed.\n' + printf ' --workdir|-d [path] # Set the dir that is to be watched.\n' + printf ' --clipboard|-c # Enable clipboard.\n' printf ' --magick # Convert files of `type` into `format` with magick.\n' } @@ -75,7 +75,7 @@ main() { shift done - [[ $cfg_workdir ]] || cfg_workdir="$XDG_RUNTIME_DIR/ufwd" + [[ $cfg_workdir ]] || cfg_workdir=( "$XDG_RUNTIME_DIR/ufwd" ) if (( flag_enable_notifications )); then if type -P notify-send &>/dev/null; then @@ -87,7 +87,10 @@ main() { fi for p in "${cfg_workdir[@]}"; do - [[ -d "$p" ]] || return 1 + [[ -d "$p" ]] || { + err "No such directory: $p" + return 1 + } done printf 'Working in:\n'