From 407bebad05c852de2815cb1fa16501a92052cdb8 Mon Sep 17 00:00:00 2001 From: Shellgate <128194280+Shellgate@users.noreply.github.com> Date: Tue, 5 Dec 2023 04:42:13 +0330 Subject: [PATCH 1/4] Advanced Geo updater x-ui.sh --- x-ui.sh | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 127 insertions(+), 1 deletion(-) diff --git a/x-ui.sh b/x-ui.sh index 97517fc0..f24bfea5 100644 --- a/x-ui.sh +++ b/x-ui.sh @@ -612,6 +612,128 @@ ssl_cert_issue_CF() { fi } +update_geo_files() { + echo -e "${green} ------------------------- " + echo -e "${yellow} Advanced Geo System Updater Select Update Server " + echo -e "${green}\t1.${plain} Github [Default] " + echo -e "${green}\t2.${plain} jsDelivr CDN " + echo -e "${green}\t0.${plain} Back To X-UI Menu " + read -p "Select an option: " select + case "$select" in + 0) show_menu ;; + 1) +local="/usr/local/x-ui/bin" +source_mapping=( + "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat geoip.dat" + "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat geosite.dat" + "https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geoip.dat geoip_IR.dat" + "https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geosite.dat geosite_IR.dat" + "https://github.com/bootmortis/iran-hosted-domains/releases/latest/download/iran.dat iran.dat" +) + +mkdir -p "$local" && chmod 764 "$local" + +updated_files=() + +function needs_update() { + local source="$1" + local destination="$2" + + [ ! -e "$destination" ] || [ "$(wget -q --spider --no-check-certificate --timestamping "$source" && stat -c %Y "$destination")" != "$(stat -c %Y "$destination")" ] +} + +for pair in "${source_mapping[@]}"; do + output_file="${local}/$(echo "$pair" | cut -d ' ' -f 2)" + + if needs_update "$(echo "$pair" | cut -d ' ' -f 1)" "$output_file"; then + echo "Downloading $output_file..." + wget -q --no-check-certificate --timestamping --show-progress -O "$output_file" "$(echo "$pair" | cut -d ' ' -f 1)" + chmod 644 "$output_file" + updated_files+=("$output_file") + else + echo "$output_file is already up to date. No need to update." + fi +done + +echo -e "\n---------------------------" +echo -e " Summary Report " +echo -e "---------------------------" + +if [ ${#updated_files[@]} -gt 0 ]; then + echo -e "Number of Downloaded files: ${#updated_files[@]}" + echo "Downloaded files:" + for file in "${updated_files[@]}"; do + echo " - $file" + done +else + echo -e "\nNo files were updated." +fi + +echo -e "---------------------------" +sleep 2 + systemctl restart x-ui + before_show_menu + ;; + 2) +local="/usr/local/x-ui/bin" +source_mapping=( + "https://cdn.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/geoip.dat geoip.dat" + "https://cdn.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/geosite.dat geosite.dat" + "https://cdn.jsdelivr.net/gh/chocolate4u/Iran-v2ray-rules@release/geoip.dat geoip_IR.dat" + "https://cdn.jsdelivr.net/gh/chocolate4u/Iran-v2ray-rules@release/geosite.dat geosite_IR.dat" + "https://github.com/bootmortis/iran-hosted-domains/releases/latest/download/iran.dat iran.dat" +) + +mkdir -p "$local" && chmod 764 "$local" + +updated_files=() + +function needs_update() { + local source="$1" + local destination="$2" + + [ ! -e "$destination" ] || [ "$(wget -q --spider --no-check-certificate --timestamping "$source" && stat -c %Y "$destination")" != "$(stat -c %Y "$destination")" ] +} + +for pair in "${source_mapping[@]}"; do + output_file="${local}/$(echo "$pair" | cut -d ' ' -f 2)" + + if needs_update "$(echo "$pair" | cut -d ' ' -f 1)" "$output_file"; then + echo "Downloading $output_file..." + wget -q --no-check-certificate --timestamping --show-progress -O "$output_file" "$(echo "$pair" | cut -d ' ' -f 1)" + chmod 644 "$output_file" + updated_files+=("$output_file") + else + echo "$output_file is already up to date. No need to update." + fi +done + +echo -e "\n---------------------------" +echo -e " Summary Report " +echo -e "---------------------------" + +if [ ${#updated_files[@]} -gt 0 ]; then + echo -e "Number of Downloaded files: ${#updated_files[@]}" + echo "Downloaded files:" + for file in "${updated_files[@]}"; do + echo " - $file" + done +else + echo -e "\nNo files were updated." +fi + +echo -e "---------------------------" +sleep 2 + systemctl restart x-ui + before_show_menu + ;; + *) + LOGE "Please enter the correct number [0-2]" + update_geo_files + ;; + esac +} + show_usage() { echo "X-UI Control Menu Usage" echo "------------------------------------------" @@ -658,6 +780,7 @@ show_menu() { ${green}15.${plain} 一A Key Installation BBR (latest kernel) ${green}16.${plain} 一SSL Certificate Management ${green}17.${plain} 一Cloudflare SSL Certificate + ${green}18.${plain} 一Advanced Geo Updater ———————————————— " show_status @@ -718,8 +841,11 @@ show_menu() { 17) ssl_cert_issue_CF ;; + 18) + update_geo_files + ;; *) - LOGE "Please enter the correct number [0-17]" + LOGE "Please enter the correct number [0-18]" ;; esac } From bdb371367ecff2c02c664ee94a78327d98557feb Mon Sep 17 00:00:00 2001 From: Shellgate <128194280+Shellgate@users.noreply.github.com> Date: Tue, 5 Dec 2023 05:23:07 +0330 Subject: [PATCH 2/4] Add Restart request x-ui.sh Add Restart request --- x-ui.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/x-ui.sh b/x-ui.sh index f24bfea5..1774e449 100644 --- a/x-ui.sh +++ b/x-ui.sh @@ -670,8 +670,14 @@ else fi echo -e "---------------------------" -sleep 2 - systemctl restart x-ui +sleep 1 +read -p "Do you want to restart x-ui? (y/n): " restart_choice +if [[ $restart_choice == [Yy] ]]; then + systemctl restart x-ui + echo "X-UI has been restarted." +else + echo "X-UI was not restarted." +fi before_show_menu ;; 2) @@ -723,8 +729,14 @@ else fi echo -e "---------------------------" -sleep 2 - systemctl restart x-ui +sleep 1 +read -p "Do you want to restart x-ui? (y/n): " restart_choice +if [[ $restart_choice == [Yy] ]]; then + systemctl restart x-ui + echo "X-UI has been restarted." +else + echo "X-UI was not restarted." +fi before_show_menu ;; *) From 5fc7f132a10a55d481f231a116d328f042141d5a Mon Sep 17 00:00:00 2001 From: Shellgate <128194280+Shellgate@users.noreply.github.com> Date: Tue, 5 Dec 2023 06:08:29 +0330 Subject: [PATCH 3/4] Fix values x-ui.sh --- x-ui.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-ui.sh b/x-ui.sh index 1774e449..dd0ce793 100644 --- a/x-ui.sh +++ b/x-ui.sh @@ -796,7 +796,7 @@ show_menu() { ———————————————— " show_status - echo && read -p "Please enter your selection [0-17]: " num + echo && read -p "Please enter your selection [0-18]: " num case "${num}" in 0) From 5ea3333367eb9375ca3060fc462aa6ac193181c9 Mon Sep 17 00:00:00 2001 From: Shellgate <128194280+Shellgate@users.noreply.github.com> Date: Wed, 6 Dec 2023 04:48:09 +0330 Subject: [PATCH 4/4] Fix loop x-ui.sh Fix Options and loop --- x-ui.sh | 190 +++++++++++++++++++++----------------------------------- 1 file changed, 72 insertions(+), 118 deletions(-) diff --git a/x-ui.sh b/x-ui.sh index dd0ce793..95405e5f 100644 --- a/x-ui.sh +++ b/x-ui.sh @@ -613,137 +613,91 @@ ssl_cert_issue_CF() { } update_geo_files() { - echo -e "${green} ------------------------- " - echo -e "${yellow} Advanced Geo System Updater Select Update Server " - echo -e "${green}\t1.${plain} Github [Default] " - echo -e "${green}\t2.${plain} jsDelivr CDN " - echo -e "${green}\t0.${plain} Back To X-UI Menu " - read -p "Select an option: " select - case "$select" in - 0) show_menu ;; - 1) -local="/usr/local/x-ui/bin" -source_mapping=( - "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat geoip.dat" - "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat geosite.dat" - "https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geoip.dat geoip_IR.dat" - "https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geosite.dat geosite_IR.dat" - "https://github.com/bootmortis/iran-hosted-domains/releases/latest/download/iran.dat iran.dat" -) +echo -e "${green} ------------------------- " +echo -e "${yellow} Advanced Geo System Updater Select Update Server " +echo -e "${green}\t1.${plain} Github [Default] " +echo -e "${green}\t2.${plain} jsDelivr CDN " +echo -e "${green}\t0.${plain} Back To X-UI Menu " +read -p "Select an option: " select -mkdir -p "$local" && chmod 764 "$local" +case "$select" in + 0) show_menu ;; + 1|2) + local="/usr/local/x-ui/bin" + source_mapping=() -updated_files=() + if [ "$select" -eq 1 ]; then + source_mapping=( + "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat geoip.dat" + "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat geosite.dat" + "https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geoip.dat geoip_IR.dat" + "https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geosite.dat geosite_IR.dat" + "https://github.com/bootmortis/iran-hosted-domains/releases/latest/download/iran.dat iran.dat" + ) + elif [ "$select" -eq 2 ]; then + source_mapping=( + "https://cdn.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/geoip.dat geoip.dat" + "https://cdn.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/geosite.dat geosite.dat" + "https://cdn.jsdelivr.net/gh/chocolate4u/Iran-v2ray-rules@release/geoip.dat geoip_IR.dat" + "https://cdn.jsdelivr.net/gh/chocolate4u/Iran-v2ray-rules@release/geosite.dat geosite_IR.dat" + "https://github.com/bootmortis/iran-hosted-domains/releases/latest/download/iran.dat iran.dat" + ) + fi -function needs_update() { - local source="$1" - local destination="$2" + mkdir -p "$local" && chmod 764 "$local" - [ ! -e "$destination" ] || [ "$(wget -q --spider --no-check-certificate --timestamping "$source" && stat -c %Y "$destination")" != "$(stat -c %Y "$destination")" ] -} + updated_files=() -for pair in "${source_mapping[@]}"; do - output_file="${local}/$(echo "$pair" | cut -d ' ' -f 2)" + function needs_update() { + local source="$1" + local destination="$2" - if needs_update "$(echo "$pair" | cut -d ' ' -f 1)" "$output_file"; then - echo "Downloading $output_file..." - wget -q --no-check-certificate --timestamping --show-progress -O "$output_file" "$(echo "$pair" | cut -d ' ' -f 1)" - chmod 644 "$output_file" - updated_files+=("$output_file") - else - echo "$output_file is already up to date. No need to update." - fi -done + [ ! -e "$destination" ] || [ "$(wget -q --spider --no-check-certificate --timestamping "$source" && stat -c %Y "$destination")" != "$(stat -c %Y "$destination")" ] + } -echo -e "\n---------------------------" -echo -e " Summary Report " -echo -e "---------------------------" + for pair in "${source_mapping[@]}"; do + output_file="${local}/$(echo "$pair" | cut -d ' ' -f 2)" -if [ ${#updated_files[@]} -gt 0 ]; then - echo -e "Number of Downloaded files: ${#updated_files[@]}" - echo "Downloaded files:" - for file in "${updated_files[@]}"; do - echo " - $file" - done -else - echo -e "\nNo files were updated." -fi + if needs_update "$(echo "$pair" | cut -d ' ' -f 1)" "$output_file"; then + echo "Downloading $output_file..." + wget -q --no-check-certificate --timestamping --show-progress -O "$output_file" "$(echo "$pair" | cut -d ' ' -f 1)" + chmod 644 "$output_file" + updated_files+=("$output_file") + else + echo "$output_file is already up to date. No need to update." + fi + done -echo -e "---------------------------" -sleep 1 -read -p "Do you want to restart x-ui? (y/n): " restart_choice -if [[ $restart_choice == [Yy] ]]; then - systemctl restart x-ui - echo "X-UI has been restarted." -else - echo "X-UI was not restarted." -fi - before_show_menu - ;; - 2) -local="/usr/local/x-ui/bin" -source_mapping=( - "https://cdn.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/geoip.dat geoip.dat" - "https://cdn.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/geosite.dat geosite.dat" - "https://cdn.jsdelivr.net/gh/chocolate4u/Iran-v2ray-rules@release/geoip.dat geoip_IR.dat" - "https://cdn.jsdelivr.net/gh/chocolate4u/Iran-v2ray-rules@release/geosite.dat geosite_IR.dat" - "https://github.com/bootmortis/iran-hosted-domains/releases/latest/download/iran.dat iran.dat" -) + echo -e "\n---------------------------" + echo -e " Summary Report " + echo -e "---------------------------" -mkdir -p "$local" && chmod 764 "$local" + if [ ${#updated_files[@]} -gt 0 ]; then + echo -e "Number of Downloaded files: ${#updated_files[@]}" + echo "Downloaded files:" + for file in "${updated_files[@]}"; do + echo " - $file" + done + else + echo -e "\nNo files were updated." + fi -updated_files=() - -function needs_update() { - local source="$1" - local destination="$2" - - [ ! -e "$destination" ] || [ "$(wget -q --spider --no-check-certificate --timestamping "$source" && stat -c %Y "$destination")" != "$(stat -c %Y "$destination")" ] -} - -for pair in "${source_mapping[@]}"; do - output_file="${local}/$(echo "$pair" | cut -d ' ' -f 2)" - - if needs_update "$(echo "$pair" | cut -d ' ' -f 1)" "$output_file"; then - echo "Downloading $output_file..." - wget -q --no-check-certificate --timestamping --show-progress -O "$output_file" "$(echo "$pair" | cut -d ' ' -f 1)" - chmod 644 "$output_file" - updated_files+=("$output_file") - else - echo "$output_file is already up to date. No need to update." - fi -done - -echo -e "\n---------------------------" -echo -e " Summary Report " -echo -e "---------------------------" - -if [ ${#updated_files[@]} -gt 0 ]; then - echo -e "Number of Downloaded files: ${#updated_files[@]}" - echo "Downloaded files:" - for file in "${updated_files[@]}"; do - echo " - $file" - done -else - echo -e "\nNo files were updated." -fi - -echo -e "---------------------------" -sleep 1 -read -p "Do you want to restart x-ui? (y/n): " restart_choice -if [[ $restart_choice == [Yy] ]]; then - systemctl restart x-ui - echo "X-UI has been restarted." -else - echo "X-UI was not restarted." -fi - before_show_menu - ;; - *) + echo -e "---------------------------" + sleep 1 + read -p "Do you want to restart x-ui? (y/n): " restart_choice + if [[ $restart_choice == [Yy] ]]; then + systemctl restart x-ui + echo "X-UI has been restarted." + else + echo "X-UI was not restarted." + fi + before_show_menu + ;; + *) LOGE "Please enter the correct number [0-2]" update_geo_files - ;; - esac + ;; +esac } show_usage() {