mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-09-05 01:36:19 +00:00
Advanced Geo Updater x-ui.sh
Advanced Geo Updater
This commit is contained in:
parent
ca0022754e
commit
dadf581935
1 changed files with 83 additions and 22 deletions
105
x-ui.sh
105
x-ui.sh
|
@ -508,28 +508,89 @@ open_ports() {
|
|||
}
|
||||
|
||||
update_geo() {
|
||||
local defaultBinFolder="/usr/local/x-ui/bin"
|
||||
read -p "Please enter x-ui bin folder path. Leave blank for default. (Default: '${defaultBinFolder}')" binFolder
|
||||
binFolder=${binFolder:-${defaultBinFolder}}
|
||||
if [[ ! -d ${binFolder} ]]; then
|
||||
LOGE "Folder ${binFolder} not exists!"
|
||||
LOGI "making bin folder: ${binFolder}..."
|
||||
mkdir -p ${binFolder}
|
||||
fi
|
||||
|
||||
cd ${binFolder}
|
||||
rm -f geoip.dat geosite.dat geoip_IR.dat geosite_IR.dat geoip-lite.dat geosite-lite.dat security.dat security-ip.dat iran.dat
|
||||
wget -O geoip.dat -N https://cdn.jsdelivr.net/gh/chocolate4u/Iran-v2ray-rules@release/geoip.dat
|
||||
wget -O geosite.dat -N https://cdn.jsdelivr.net/gh/chocolate4u/Iran-v2ray-rules@release/geosite.dat
|
||||
wget -O geoip-lite.dat -N https://cdn.jsdelivr.net/gh/chocolate4u/Iran-v2ray-rules@release/geoip-lite.dat
|
||||
wget -O geosite-lite.dat -N https://cdn.jsdelivr.net/gh/chocolate4u/Iran-v2ray-rules@release/geosite-lite.dat
|
||||
wget -O security-ip.dat -N https://cdn.jsdelivr.net/gh/chocolate4u/Iran-v2ray-rules@release/security-ip.dat
|
||||
wget -O security.dat -N https://cdn.jsdelivr.net/gh/chocolate4u/Iran-v2ray-rules@release/security.dat
|
||||
wget -O iran.dat -N https://github.com/bootmortis/iran-hosted-domains/releases/latest/download/iran.dat
|
||||
|
||||
systemctl restart x-ui
|
||||
echo -e "${green}Geosite.dat + Geoip.dat + security.dat + security-ip.dat + geoip-lite.dat + geosite-lite.dat + iran.dat have been updated successfully in bin folder '${binfolder}'!${plain}"
|
||||
before_show_menu
|
||||
echo -e "${green} ------------------------- "
|
||||
echo -e "${yellow} Advanced Geo Updater "
|
||||
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|2)
|
||||
local="/usr/local/x-ui/bin"
|
||||
source_mapping=()
|
||||
|
||||
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"
|
||||
)
|
||||
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"
|
||||
)
|
||||
fi
|
||||
|
||||
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 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
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
install_acme() {
|
||||
|
|
Loading…
Reference in a new issue