7 Commits

Author SHA1 Message Date
fbt
bfbd899554 Forgot to change this
Signed-off-by: fbt <fbt@fleshless.org>
2019-11-25 04:39:24 +03:00
fbt
4e1d3a7bcd A better way
Signed-off-by: fbt <fbt@fleshless.org>
2019-11-24 14:00:32 +03:00
fbt
03e0fda896 A better way
Signed-off-by: fbt <fbt@fleshless.org>
2019-11-24 13:59:08 +03:00
fbt
146f06e7c5 alternate config file
Signed-off-by: fbt <fbt@fleshless.org>
2019-11-24 13:50:24 +03:00
fbt
d2529e32bd Let the script get its own damn token
Signed-off-by: fbt <fbt@fleshless.org>
2019-11-24 13:18:22 +03:00
fbt
bb704f4856 fix the doc
Signed-off-by: fbt <fbt@fleshless.org>
2019-11-24 08:46:22 +03:00
fbt
fadba21791 void
Signed-off-by: fbt <fbt@fleshless.org>
2019-11-24 08:41:53 +03:00

78
ufw
View File

@@ -42,6 +42,8 @@ usage() {
-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.
-q|--quiet # Be quiet.
-v|--void # Don't add the file to my files.
Config options (~/.config/ufw):
secret # Your personal token. Get it at https://zfh.so/settings_form
@@ -51,6 +53,9 @@ usage() {
cfg_url_regex
cfg_tmp_dir
cfg_service_url
Environment variables:
UFW_CFG_FILE # Config file to read, defaults to \$XDG_CONFIG_DIR/ufw
EOF
}
@@ -144,6 +149,7 @@ upload() {
-F secret="$secret" \
-F tags="$tags" \
-F notify="$flag_notify" \
-F void="${flag_void:-0}" \
-F submit="" \
"${misc_curl_args[@]}" \
-A 'zerofiles.org upload script' \
@@ -207,7 +213,7 @@ take_screenshot() {
}
(( "$flag_scn_fullscreen" )) || { scn_args+=( '-s' ); }
[[ "$cfg_scn_delay" ]] && { scn_args+=( "-d $cfg_scn_delay" ); }
[[ "$cfg_scn_delay" ]] && { scn_args+=( "-d" "$cfg_scn_delay" ); }
tmp_file="$(_mktemp "${cfg_tmp_dir}" ".${cfg_screenshot_ext}")"
@@ -224,7 +230,7 @@ get_api_status() {
jq -r '.status.code, .status.message'
)
if ! (( api_status == 200 )); then
if (( api_status >= 400 )); then
return 1
fi
}
@@ -271,6 +277,37 @@ login() {
fi
}
get_token() {
[[ $secret ]] && return 0
[[ -f $cfg_file ]] && return 1
declare api_response login password
printf "First-time setup...\n"
read -p 'Username: ' login
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")
get_api_status <<< "$login_response" || {
jq -r '.status.message' <<< "$login_response"
return 1
}
api_response=$(curl -b "$cfg_file.cookiejar" -sl "$cfg_service_url/api_token.json")
rm -f "$cfg_file.cookiejar"
if get_api_status <<< "$api_response"; then
secret=$(jq -r '.data.token' <<< "$api_response")
printf 'export secret="%s"' "$secret" >> "$cfg_file"
chmod 600 "$cfg_file"
printf 'Done\n'
else
printf 'Error: %s %s\n' "$api_status" "$api_status_message"
return 1
fi
}
set_argv() {
declare arg opt c
declare -g argv
@@ -308,7 +345,7 @@ set_argv() {
main() {
declare args file target flag_private flag_rm flag_scn flag_scn_fullscreen cfg_scn_delay flag_notify
declare flag_shortlink=0
declare flag_shortlink
# Defaults for XDG
if ! [[ "$XDG_RUNTIME_DIR" ]]; then
@@ -320,26 +357,26 @@ main() {
fi
cfg_url_regex='^[A-Za-z]([A-Za-z0-9+.-]+)?://.+'
cfg_tmp_dir="$XDG_RUNTIME_DIR/ufw"; TEMPDIR="$cfg_tmp_dir"
cfg_service_url='https://8fw.me'
cfg_screenshot_ext='png'
cfg_max_filesize='200M'
cfg_file=${UFW_CFG_FILE:-"$XDG_CONFIG_DIR/ufw"}
flag_shortlink=0
flag_directlink=1
[[ $1 ]] || { usage; return 1; }
if [[ -f "$HOME/.suprc" ]]; then
printf 'Found legacy configfile, moving...\n' >&2
mv "$HOME/.suprc" "$XDG_CONFIG_DIR/ufw"
fi
if [[ -f "$XDG_CONFIG_DIR/ufw" ]]; then
if ! source "$XDG_CONFIG_DIR/ufw"; then
printf 'Failed to source configuration file: %s\n' "$XDG_CONFIG_DIR/ufw"
if [[ -f "$cfg_file" ]]; then
if ! source "$cfg_file"; then
printf 'Failed to source configuration file: %s\n' "$cfg_file"
return $?
fi
fi
# Defaults
: ${cfg_file:="$XDG_CONFIG_DIR/ufw"}
: ${cfg_tmp_dir:="$XDG_RUNTIME_DIR/ufw"}
: ${cfg_service_url:='https://8fw.me'}
: ${cfg_screenshot_ext:='png'}
: ${cfg_max_filesize:='200M'}
: ${flag_shortlink:=0}
: ${flag_directlink:=1}
while [[ "$1" ]]; do
case "$1" in
-h|--help|--usage) usage; return;;
@@ -357,6 +394,7 @@ main() {
-S|--short-url) flag_shortlink=1;;
-P|--page-url) flag_directlink=0;;
-q|--quiet) flag_quiet=1;;
-v|--void) flag_void=1;;
--notify) flag_notify=1;;
--no-notify|-n) flag_notify=0;;
@@ -389,12 +427,16 @@ main() {
shift
done
TEMPDIR="$cfg_tmp_dir"
for i in "$cfg_tmp_dir"; do
[[ -d "$i" ]] || { mkdir -p "$i"; }
done
case "${action:-upload}" in
upload)
get_token || return $?
if (( $# )); then
for t in "$@"; do
upload "$t"
@@ -405,6 +447,8 @@ main() {
;;
url)
get_token || return $?
for t in "$@"; do
get_shortlink "$1"
done