From bc9178d2de8747278abb435e12c0335172c887cb Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Thu, 12 Dec 2024 11:56:10 +0900 Subject: [PATCH] fix: triage hotfix from testing --- dzgui.sh | 72 ++++++++++++++++++++++++++++++++++++++++----------- helpers/funcs | 8 +++--- 2 files changed, 62 insertions(+), 18 deletions(-) diff --git a/dzgui.sh b/dzgui.sh index 15dd451..3580adc 100755 --- a/dzgui.sh +++ b/dzgui.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -o pipefail -version=5.5.1 +version=5.5.2 #CONSTANTS aid=221100 @@ -54,7 +54,8 @@ km_helper="$helpers_path/latlon" sums_path="$helpers_path/sums.md5" func_helper="$helpers_path/funcs" -#URLS +#REMOTE +remote_host=gh author="aclist" repo="dztui" url_prefix="https://raw.githubusercontent.com/$author/$repo" @@ -64,6 +65,7 @@ releases_url="https://github.com/$author/$repo/releases/download/browser" km_helper_url="$releases_url/latlon" geo_file_url="$releases_url/ips.csv.gz" + set_im_module(){ #TODO: drop pending SteamOS changes pgrep -a gamescope | grep -q "generate-drm-mode" @@ -312,13 +314,14 @@ check_unmerged(){ check_version(){ local version_url=$(format_version_url) local upstream=$(curl -Ls "$version_url" | awk -F= '/^version=/ {print $2}') + #2024-12-12: do not clobber local version if unreachable + [[ -z $upstream ]] && return logger INFO "Local branch: '$branch', local version: $version" if [[ $branch == "stable" ]]; then version_url="$stable_url/dzgui.sh" elif [[ $branch == "testing" ]]; then version_url="$testing_url/dzgui.sh" fi - local upstream=$(curl -Ls "$version_url" | awk -F= '/^version=/ {print $2}') [[ ! -f "$freedesktop_path/$app_name.desktop" ]] && freedesktop_dirs if [[ $version == $upstream ]]; then logger INFO "Local version is same as upstream" @@ -371,9 +374,14 @@ prompt_dl(){ } dl_changelog(){ local mdbranch + local md [[ $branch == "stable" ]] && mdbranch="dzgui" [[ $branch == "testing" ]] && mdbranch="testing" - local md="https://raw.githubusercontent.com/$author/dztui/${mdbranch}/CHANGELOG.md" + if [[ $remote_host == "gh" ]]; then + md="https://raw.githubusercontent.com/$author/$repo/${mdbranch}/CHANGELOG.md" + else + md="https://codeberg.org/$author/$repo/raw/branch/${mdbranch}/CHANGELOG.md" + fi curl -Ls "$md" > "$state_path/CHANGELOG.md" } test_display_mode(){ @@ -535,7 +543,7 @@ fetch_dzq(){ return 0 fi local sha=3088bbfb147b77bc7b6a9425581b439889ff3f7f - local author="aclist" + local author="yepoleb" local repo="dayzquery" local url="https://raw.githubusercontent.com/$author/$repo/$sha/dayzquery.py" curl -Ls "$url" > "$file" @@ -569,14 +577,14 @@ fetch_helpers_by_sum(){ [[ -f "$config_file" ]] && source "$config_file" declare -A sums sums=( - ["ui.py"]="dd7aa34df1d374739127cca3033a3f67" + ["ui.py"]="be3da1e542d14105f4358dd38901e25a" ["query_v2.py"]="55d339ba02512ac69de288eb3be41067" ["vdf2json.py"]="2f49f6f5d3af919bebaab2e9c220f397" - ["funcs"]="ad4d7b4bf2e8ef0ac7637183876dbec6" + ["funcs"]="9c844298c5f112c0a2482dce3110ab70" ["lan"]="c62e84ddd1457b71a85ad21da662b9af" ) local author="aclist" - local repo="dztui" + local repo="dzgui" local realbranch local file local sum @@ -596,7 +604,13 @@ fetch_helpers_by_sum(){ file="$i" sum="${sums[$i]}" full_path="$helpers_path/$file" - url="https://raw.githubusercontent.com/$author/$repo/$realbranch/helpers/$file" + + if [[ $remote_host == "gh" ]]; then + url="https://raw.githubusercontent.com/$author/$repo/$realbranch/helpers/$file" + else + url="https://codeberg.org/$author/$repo/raw/branch/$realbranch/helpers/$file" + fi + if [[ -f "$full_path" ]] && [[ $(get_hash "$full_path") == $sum ]]; then logger INFO "$file is current" else @@ -845,14 +859,42 @@ is_steam_running(){ return 0 fi } +get_response_code(){ + local url="$1" + curl -Ls -I -o /dev/null -w "%{http_code}" "$url" +} test_connection(){ - ping -c1 -4 github.com 1>/dev/null 2>&1 - if [[ ! $? -eq 0 ]]; then - raise_error_and_quit "No connection could be established to the remote server (github.com)." + source "$config_file" + declare -A hr + local res1 + local res2 + local str="No connection could be established to the remote server" + hr=( + ["steampowered.com"]="https://api.steampowered.com/IGameServersService/GetServerList/v1/?key=$steam_api" + ["github.com"]="https://github.com/$author" + ["codeberg.org"]="https://codeberg.org/$author" + ) + # steam API is mandatory, except on initial setup + if [[ -n $steam_api ]]; then + res=$(get_response_code "${hr["steampowered.com"]}") + [[ $res -ne 200 ]] && raise_error_and_quit "$str ("steampowered.com")" fi - ping -c1 -4 api.steampowered.com 1>/dev/null 2>&1 - if [[ ! $? -eq 0 ]]; then - raise_error_and_quit "No connection could be established to the remote server (steampowered.com)." + + 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"]}") + [[ $res -ne 200 ]] && raise_error_and_quit "$str (${hr["codeberg.org"]})" + fi + if [[ $remote_host == "cb" ]]; then + url_prefix="https://codeberg.org/$author/$repo/raw/branch" + releases_url="https://codeberg.org/$author/$repo/releases/download/browser" + # 2024-12-12: interpolate variables again + stable_url="$url_prefix/dzgui" + testing_url="$url_prefix/testing" + km_helper_url="$releases_url/latlon" + geo_file_url="$releases_url/ips.csv.gz" fi } legacy_cols(){ diff --git a/helpers/funcs b/helpers/funcs index 69b66c8..539a6d5 100755 --- a/helpers/funcs +++ b/helpers/funcs @@ -67,12 +67,14 @@ 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://raw.githubusercontent.com/$author/$repo" +url_prefix="https://codeberg.org/$author/$repo/branch" stable_url="$url_prefix/dzgui" testing_url="$url_prefix/testing" -releases_url="$gh_prefix/$author/$repo/releases/download/browser" +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" @@ -773,7 +775,7 @@ dl_changelog(){ local file="CHANGELOG.md" [[ $branch == "stable" ]] && mdbranch="dzgui" [[ $branch == "testing" ]] && mdbranch="testing" - local md="https://raw.githubusercontent.com/$author/$repo/${mdbranch}/$file" + local md="https://codeberg.org/$author/$repo/raw/branch/${mdbranch}/$file" curl -Ls "$md" > "$state_path/$file" } toggle(){