1
0
Fork 0
mirror of https://github.com/aclist/dztui.git synced 2025-09-07 14:12:26 +02:00

fix: add fallbacks and remote resource checks

This commit is contained in:
aclist 2024-12-13 09:40:46 +09:00
parent c5785d1857
commit cbecf569ad
3 changed files with 60 additions and 21 deletions

View file

@ -70,18 +70,12 @@ game_dir="$steam_path/steamapps/common/DayZ"
#URLS
author="aclist"
repo="dztui"
#TODO: this is hardcoded
#2024-12-12
gh_prefix="https://github.com"
issues_url="$gh_prefix/$author/$repo/issues"
url_prefix="https://codeberg.org/$author/$repo/raw/branch"
url_prefix="https://raw.githubusercontent.com/$author/$repo"
stable_url="$url_prefix/dzgui"
testing_url="$url_prefix/testing"
releases_url="https://codeberg.org/$author/$repo/releases/download/browser"
km_helper_url="$releases_url/latlon"
db_file="$releases_url/ips.csv.gz"
sums_url="$stable_url/helpers/sums.md5"
#TODO: move adoc to index
releases_url="$gh_prefix/$author/$repo/releases/download/browser"
help_url="https://$author.github.io/dzgui/dzgui"
forum_url="$gh_prefix/$author/$repo/discussions"
sponsor_url="$gh_prefix/sponsors/$author"
@ -829,7 +823,40 @@ format_version_url(){
esac
echo "$version_url"
}
get_response_code(){
local url="$1"
curl -Ls -I -o /dev/null -w "%{http_code}" "$url"
}
test_connection(){
source "$config_file"
declare -A hr
local res1
local res2
local str="No connection could be established to the remote server"
hr=(
["github.com"]="https://github.com/$author"
["codeberg.org"]="https://codeberg.org/$author"
)
res=$(get_response_code "${hr["github.com"]}")
if [[ $res -ne 200 ]]; then
logger WARN "Remote host '${hr["github.com"]}' unreachable', trying fallback"
remote_host=cb
res=$(get_response_code "${hr["codeberg.org"]}")
if [[ $res -ne 200 ]]; then
printf "Failed to fetch new version. Rolling back"
return 1
fi
fi
logger INFO "Set remote host to '${hr["codeberg.org"]}'"
if [[ $remote_host == "cb" ]]; then
url_prefix="https://codeberg.org/$author/$repo/raw/branch"
releases_url="https://codeberg.org/$author/$repo/releases/download/browser"
stable_url="$url_prefix/dzgui"
testing_url="$url_prefix/testing"
fi
}
download_new_version(){
test_connection
local version_url="$(format_version_url)"
mv "$src_path" "$src_path.old"
curl -Ls "$version_url" > "$src_path"
@ -854,9 +881,7 @@ dl_changelog(){
local file="CHANGELOG.md"
[[ $branch == "stable" ]] && mdbranch="dzgui"
[[ $branch == "testing" ]] && mdbranch="testing"
#TODO: this is hardcoded
#2024-12-12
local md="https://codeberg.org/$author/$repo/raw/branch/${mdbranch}/$file"
local md="$url_prefix/${mdbranch}/$file"
curl -Ls "$md" > "$state_path/$file"
}
toggle(){