forked from MortezaBashsiz/Sudoer_VPN_bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync.sh
68 lines (59 loc) · 1.72 KB
/
sync.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash -
#===============================================================================
#
# FILE: sync.sh
#
# USAGE: ./sync.sh [arv|cf]
#
# DESCRIPTION:
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Morteza Bashsiz (mb), [email protected]
# ORGANIZATION: Linux
# CREATED: 01/17/2023 10:00:23 PM
# REVISION: ---
#===============================================================================
set -o nounset # Treat unset variables as an error
arv_hosts=( ip1.ip1.ip1.ip1 ip2.ip2.ip2.ip2 )
arv_regex="gheychi"
cf_hosts=( ip3.ip3.ip3.ip3 ip4.ip4.ip4.ip4 )
cf_regex="schere"
hosts=()
regex="null"
base_dir="null"
if [[ "$1" == "arv" ]]
then
base_dir="./$1"
hosts=("${arv_hosts[@]}")
regex="$arv_regex"
elif [[ "$1" == "cf" ]]
then
base_dir="./$1"
hosts=("${cf_hosts[@]}")
regex="$cf_regex"
else
echo "invalid input"
exit 0
fi
local_urls_dir="$base_dir/urls"
host_urls_dir="/opt/v2ray_urls"
db_file="/opt/bot/bot-dev.db"
for host in "${hosts[@]}"
do
host_local_urls_dir="$local_urls_dir/$host"
rm -fr "$host_local_urls_dir"
mkdir -p "$host_local_urls_dir"
rsync -avh "$host:$host_urls_dir" "$host_local_urls_dir"
done
sqlite3 "$db_file" -cmd "delete from user_url where url in (select user_url.url from user_url left join urls on user_url.url=urls.url where hostname like \"%$regex%\");" ".exit"
sqlite3 "$db_file" -cmd "delete from urls where hostname like \"%$regex%\";" ".exit"
for file in $(find "$local_urls_dir" -type f -iname "*.url")
do
echo "$file"
host="$(awk -F '://' '{print $2}' "$file" | base64 -d | jq -r .host )"
sed -i "s/$/;$host/" "$file"
python3 /opt/bot/insert_urls.py "$file"
done