Created
July 5, 2024 10:51
-
-
Save ahbanavi/cccf067de8586311f63dadd63aded507 to your computer and use it in GitHub Desktop.
update v2ray geofiles on openwrt passwall
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/ash | |
ASSETS_DIR="/usr/share/v2ray" | |
GEOIP_FILE_NAME="geoip.dat" | |
GEOSITE_FILE_NAME="geosite.dat" | |
RELEASE_BASE_URL="https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/" | |
update_file() { | |
url="$RELEASE_BASE_URL$1" | |
current_file="$ASSETS_DIR/$1" | |
if [ -f "$current_file" ]; then | |
new_checksum=$(curl -L "$url.sha256sum" | cut -d " " -f 1) | |
current_checksum=$(sha256sum "$current_file" | cut -d " " -f 1) | |
# Compare the two checksums | |
if [ "$new_checksum" != "$current_checksum" ]; then | |
curl -L "$url" -o "$current_file.temp" | |
# Replace the current file with the new file only if the new one is valid | |
if [ "$(sha256sum "$current_file.temp" | cut -d " " -f 1)" == "$new_checksum" ]; then | |
mv "$current_file.temp" "$current_file" | |
echo "$1 file updated successfully." | |
return 0 | |
else | |
rm "$current_file.temp" | |
echo "$1 file is invalid." | |
return 1 | |
fi | |
else | |
echo "$1 file is already up to date." | |
return 2 | |
fi | |
else | |
curl -L "$url" -o "$current_file" | |
echo "$1 file downloaded successfully." | |
return 0 | |
fi | |
return 3 | |
} | |
update_file "$GEOIP_FILE_NAME" | |
geoip_updated=$? | |
update_file "$GEOSITE_FILE_NAME" | |
geosite_updated=$? | |
if [ $geoip_updated -eq 0 ] || [ $geosite_updated -eq 0 ]; then | |
# Update nftset table | |
logger -p info -t passwall "geofiles updated, reloading nftset" | |
sh /usr/share/passwall2/nftables.sh flush_nftset_reload > /dev/null 2>&1 & | |
echo "passwall nftset reloaded" | |
else | |
echo "No file updated." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment