fix(script): report per-file geo update status and skip restart when nothing changed

Updating geo files printed raw curl progress meters showing 0 bytes when
files were already current (curl -z conditional download), claimed success
unconditionally, and restarted xray even when nothing was downloaded —
confusing enough to be reported as a bug (#5230).

Now each file reports updated / already up to date / download failed,
failures no longer print a success message, and the restart (which drops
live connections) only happens when a file actually changed. Same for the
non-interactive 'x-ui update-all-geofiles' command.
This commit is contained in:
MHSanaei
2026-06-12 22:18:42 +02:00
parent b5ef412b8d
commit c200e248f7
+42 -18
View File
@@ -1148,9 +1148,11 @@ delete_ports() {
} }
update_all_geofiles() { update_all_geofiles() {
update_geofiles "main" local failed=0
update_geofiles "IR" update_geofiles "main" || failed=1
update_geofiles "RU" update_geofiles "IR" || failed=1
update_geofiles "RU" || failed=1
return $failed
} }
update_geofiles() { update_geofiles() {
@@ -1168,12 +1170,39 @@ update_geofiles() {
dat_source="runetfreedom/russia-v2ray-rules-dat" dat_source="runetfreedom/russia-v2ray-rules-dat"
;; ;;
esac esac
local failed=0 http_code
for dat in "${dat_files[@]}"; do for dat in "${dat_files[@]}"; do
# Remove suffix for remote filename (e.g., geoip_IR -> geoip) # Remove suffix for remote filename (e.g., geoip_IR -> geoip)
remote_file="${dat%%_*}" remote_file="${dat%%_*}"
curl -fLRo ${xui_folder}/bin/${dat}.dat -z ${xui_folder}/bin/${dat}.dat \ # -z skips the download (server answers 304) when the local copy is already current
https://github.com/${dat_source}/releases/latest/download/${remote_file}.dat http_code=$(curl -sSfLRo ${xui_folder}/bin/${dat}.dat -z ${xui_folder}/bin/${dat}.dat -w '%{http_code}' \
https://github.com/${dat_source}/releases/latest/download/${remote_file}.dat)
if [[ $? -ne 0 ]]; then
echo -e "${red}${dat}.dat: download failed${plain}"
failed=1
elif [[ "$http_code" == "304" ]]; then
echo -e "${dat}.dat: already up to date"
else
echo -e "${green}${dat}.dat: updated${plain}"
geo_updated=1
fi
done done
return $failed
}
run_geo_update() {
local name="$1"
shift
geo_updated=0
"$@"
if [[ $? -ne 0 ]]; then
echo -e "${red}Some ${name} could not be updated. Check the errors above.${plain}"
elif [[ $geo_updated -eq 1 ]]; then
echo -e "${green}${name} have been updated successfully!${plain}"
restart
else
echo -e "${green}${name} are already up to date, restart is not needed.${plain}"
fi
} }
update_geo() { update_geo() {
@@ -1189,24 +1218,16 @@ update_geo() {
show_menu show_menu
;; ;;
1) 1)
update_geofiles "main" run_geo_update "Loyalsoldier datasets" update_geofiles "main"
echo -e "${green}Loyalsoldier datasets have been updated successfully!${plain}"
restart
;; ;;
2) 2)
update_geofiles "IR" run_geo_update "chocolate4u datasets" update_geofiles "IR"
echo -e "${green}chocolate4u datasets have been updated successfully!${plain}"
restart
;; ;;
3) 3)
update_geofiles "RU" run_geo_update "runetfreedom datasets" update_geofiles "RU"
echo -e "${green}runetfreedom datasets have been updated successfully!${plain}"
restart
;; ;;
4) 4)
update_all_geofiles run_geo_update "geo files" update_all_geofiles
echo -e "${green}All geo files have been updated successfully!${plain}"
restart
;; ;;
*) *)
echo -e "${red}Invalid option. Please select a valid number.${plain}\n" echo -e "${red}Invalid option. Please select a valid number.${plain}\n"
@@ -3254,7 +3275,10 @@ if [[ $# > 0 ]]; then
check_install 0 && uninstall 0 check_install 0 && uninstall 0
;; ;;
"update-all-geofiles") "update-all-geofiles")
check_install 0 && update_all_geofiles 0 && restart 0 geo_updated=0
if check_install 0 && update_all_geofiles 0; then
[[ $geo_updated -eq 0 ]] || restart 0
fi
;; ;;
"migrateDB") "migrateDB")
migrate_db "$2" "$3" migrate_db "$2" "$3"