forked from bootmortis/iran-hosted-domains
-
Notifications
You must be signed in to change notification settings - Fork 4
/
update_iran_dat.sh
executable file
·32 lines (28 loc) · 1.04 KB
/
update_iran_dat.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
url="https://github.com/MasterKia/iran-hosted-domains/releases/latest/download/iran.dat"
current_file="$1"
if [ -z "$current_file" ]; then
echo "Usage: $0 </path/to/iran.dat>"
exit 1
fi
if [ -f "$current_file" ]; then
new_checksum=$(curl -L "$url.sha256" | cut -d " " -f 1)
current_checksum=$(shasum -a 256 "$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 [ "$(shasum -a 256 "$current_file.temp" | cut -d " " -f 1)" == "$new_checksum" ]; then
mv "$current_file.temp" "$current_file"
echo "Domains file updated successfully."
else
rm "$current_file.temp"
echo "Domains file is invalid."
fi
else
echo "Domains file is already up to date."
fi
else
curl -L "$url" -o "$current_file"
echo "Domains file downloaded successfully."
fi