alternate config file
Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
parent
d2529e32bd
commit
146f06e7c5
52
ufw
52
ufw
|
@ -44,6 +44,7 @@ usage() {
|
|||
-t|--tags "<tag1[, tag2,..]>" # Add tags to the file.
|
||||
-q|--quiet # Be quiet.
|
||||
-v|--void # Don't add the file to my files.
|
||||
-c|--config <file> # Use an alternate config file
|
||||
|
||||
Config options (~/.config/ufw):
|
||||
secret # Your personal token. Get it at https://zfh.so/settings_form
|
||||
|
@ -276,6 +277,7 @@ login() {
|
|||
|
||||
get_token() {
|
||||
[[ $secret ]] && return 0
|
||||
[[ -f $cfg_file ]] && return 1
|
||||
|
||||
declare api_response login password
|
||||
|
||||
|
@ -293,8 +295,8 @@ get_token() {
|
|||
api_response=$(curl -b $XDG_CONFIG_DIR/ufw.cookiejar -sl "$cfg_service_url/api_token.json")
|
||||
if get_api_status <<< "$api_response"; then
|
||||
secret=$(jq -r '.data.token' <<< "$api_response")
|
||||
printf 'export secret="%s"' "$secret" > "$XDG_CONFIG_DIR/ufw"
|
||||
chmod 600 "$XDG_CONFIG_DIR/ufw"
|
||||
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"
|
||||
|
@ -338,7 +340,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
|
||||
|
@ -350,25 +352,8 @@ 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'
|
||||
|
||||
flag_shortlink=0
|
||||
flag_directlink=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"
|
||||
return $?
|
||||
fi
|
||||
fi
|
||||
[[ $1 ]] || { usage; return 1; }
|
||||
|
||||
while [[ "$1" ]]; do
|
||||
case "$1" in
|
||||
|
@ -377,6 +362,7 @@ main() {
|
|||
-m|--max-filesize) cfg_max_filesize=$2; shift;;
|
||||
-A|--album-name) album_name=$2; shift;;
|
||||
-t|--tags) tags=$2; shift;;
|
||||
-c|--config) cfg_file=$2; shift;;
|
||||
|
||||
-i|--my-ip) action='getmyip';;
|
||||
-u|--shorten) action='url';;
|
||||
|
@ -420,14 +406,32 @@ main() {
|
|||
shift
|
||||
done
|
||||
|
||||
# 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}
|
||||
|
||||
if [[ -f "$cfg_file" ]]; then
|
||||
if ! source "$cfg_file"; then
|
||||
printf 'Failed to source configuration file: %s\n' "$cfg_file"
|
||||
return $?
|
||||
fi
|
||||
fi
|
||||
|
||||
TEMPDIR="$cfg_tmp_dir"
|
||||
|
||||
for i in "$cfg_tmp_dir"; do
|
||||
[[ -d "$i" ]] || { mkdir -p "$i"; }
|
||||
done
|
||||
|
||||
get_token || return $?
|
||||
|
||||
case "${action:-upload}" in
|
||||
upload)
|
||||
get_token || return $?
|
||||
|
||||
if (( $# )); then
|
||||
for t in "$@"; do
|
||||
upload "$t"
|
||||
|
@ -438,6 +442,8 @@ main() {
|
|||
;;
|
||||
|
||||
url)
|
||||
get_token || return $?
|
||||
|
||||
for t in "$@"; do
|
||||
get_shortlink "$1"
|
||||
done
|
||||
|
|
Loading…
Reference in New Issue
Block a user