From 05867b24908b0cbd3bb05624ad21bf34a4ccf58e Mon Sep 17 00:00:00 2001 From: "xiongdian.me" Date: Tue, 14 Mar 2023 20:07:34 +0800 Subject: [PATCH] use $DFS_CURL_OPTIONS --- .update.sh | 2 +- tools/common.sh | 1 + tools/frigg-client.sh | 14 +++++++------- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.update.sh b/.update.sh index 2ca7bba..40012b5 100644 --- a/.update.sh +++ b/.update.sh @@ -27,7 +27,7 @@ fi # get the specified commit id case $DFS_UPDATE_CHANNEL in - "main" ) DFS_COMMIT=$(curl -m 10 -fsSL https://api.beardic.cn/get-var/dfs-commit-id) ;; + "main" ) DFS_COMMIT=$(curl $DFS_CURL_OPTIONS -fsSL https://api.beardic.cn/get-var/dfs-commit-id) ;; "dev" ) DFS_COMMIT=$(git rev-parse origin/dev 2> /dev/null) || DFS_COMMIT=$(git rev-parse origin/main) ;; "latest" ) DFS_COMMIT=$(git for-each-ref --sort=-committerdate refs/heads refs/remotes --format='%(objectname)' | head -n 1) ;; * ) fmt_fatal "invalid update channel: $DFS_UPDATE_CHANNEL" ;; diff --git a/tools/common.sh b/tools/common.sh index ec2a007..a1d091b 100755 --- a/tools/common.sh +++ b/tools/common.sh @@ -4,6 +4,7 @@ THIS_DIR_COMMON_SH=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd ) export DOTFILES=$( cd "$THIS_DIR_COMMON_SH/.." && pwd ) if [[ -f ~/.config/dotfiles/env ]]; then set -a; source ~/.config/dotfiles/env; set +a; fi if [[ "$DFS_DEBUG" == "1" ]]; then set -x; fi +DFS_CURL_OPTIONS="--retry 2 --max-time 20" # parse args and set env, when it is sourced # todo: make this skipable diff --git a/tools/frigg-client.sh b/tools/frigg-client.sh index fa14b72..abefcbc 100755 --- a/tools/frigg-client.sh +++ b/tools/frigg-client.sh @@ -71,7 +71,7 @@ post_beacon() if [[ -z "$beacon_type" ]]; then fmt_fatal "beacon type is required" fi - resp=$(curl -m 10 -sSL -X POST -H "Content-Type: text/plain" -d "$meta" "https://api.beardic.cn/post-beacon?hostname=$hostname&beacon=$beacon_type") + resp=$(curl $DFS_CURL_OPTIONS -sSL -X POST -H "Content-Type: text/plain" -d "$meta" "https://api.beardic.cn/post-beacon?hostname=$hostname&beacon=$beacon_type") handle_resp "$resp" } @@ -82,7 +82,7 @@ post_log() fmt_fatal "log content is required" fi init_uuid - resp=$(curl -m 10 -sSL -X POST -H "Content-Type: text/plain" -d "$log_content" "https://api.beardic.cn/post-log?hostname=$hostname&uuid=$uuid") + resp=$(curl $DFS_CURL_OPTIONS -sSL -X POST -H "Content-Type: text/plain" -d "$log_content" "https://api.beardic.cn/post-log?hostname=$hostname&uuid=$uuid") handle_resp "$resp" } @@ -104,9 +104,9 @@ update_dns() elif [[ "$DFS_DDNS_IP4" == "auto" ]]; then ip4="auto" elif [[ "$DFS_DDNS_IP4" == "api" ]]; then - ip4=$(curl -m 10 -sSL "https://api.ipify.org") + ip4=$(curl $DFS_CURL_OPTIONS -sSL "https://api.ipify.org") elif [[ "$DFS_DDNS_IP4" == "http"* ]]; then - ip4=$(curl -m 10 -sSL "$DFS_DDNS_IP4") + ip4=$(curl $DFS_CURL_OPTIONS -sSL "$DFS_DDNS_IP4") else ip4=$(ip a show $DFS_DDNS_IP4 | grep inet | grep global | awk '/inet / {print $2}' | awk -F'[/]' '{print $1}') fi @@ -120,9 +120,9 @@ update_dns() ip6="auto" api_url="https://api6.beardic.cn" elif [[ "$DFS_DDNS_IP6" == "api" ]]; then - ip6=$(curl -m 10 -sSL "https://api6.ipify.org") + ip6=$(curl $DFS_CURL_OPTIONS -sSL "https://api6.ipify.org") elif [[ "$DFS_DDNS_IP6" == "http"* ]]; then - ip6=$(curl -m 10 -sSL "$DFS_DDNS_IP6") + ip6=$(curl $DFS_CURL_OPTIONS -sSL "$DFS_DDNS_IP6") else ip6=$(ip a show $DFS_DDNS_IP6 | grep inet6 | grep global | awk '/inet6 / {print $2}' | awk -F'[/]' '{print $1}') fi @@ -131,7 +131,7 @@ update_dns() fi # update dns fmt_note "updating dns record for $hostname with ip4=$ip4 ip6=$ip6" - resp=$(curl -m 20 -sSL "$api_url/update-dns?hostname=$hostname&uuid=$uuid&ip4=$ip4&ip6=$ip6") + resp=$(curl $DFS_CURL_OPTIONS -sSL "$api_url/update-dns?hostname=$hostname&uuid=$uuid&ip4=$ip4&ip6=$ip6") handle_resp "$resp" }