-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinviti_rotti.bash
More file actions
45 lines (34 loc) · 1.16 KB
/
inviti_rotti.bash
File metadata and controls
45 lines (34 loc) · 1.16 KB
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
#!/bin/env bash
< <( git grep -nE 'https?://t.me/(joinchat/)?[A-Za-z0-9_-]+' ':(exclude)old/*' ':(exclude)old_pn/*') mapfile -t matches
regex_parse_match='([^:]+:[0-9]+):.*"?(https?://t.me/(joinchat/)?[A-Za-z0-9_-]+)'
regex_bad_invite=$'(^|\n)[[:space:]]*<meta property="og:title" content="Join group chat on Telegram"'
(( ${#matches[@]} >= 1 )) \
|| exit 0
printf 'Checking %d URL%c...\n' "${#matches[@]}" "${matches[1]+s}"
declare -A already_checked
es=0
for match in "${matches[@]}"; do
[[ $match =~ $regex_parse_match ]] \
|| continue
file_and_linenumber=${BASH_REMATCH[1]} url=${BASH_REMATCH[2]}
case ${already_checked[$url]} in
1) echo "$file_and_linenumber: $url" ;&
2) continue ;;
esac
page=$(curl -sS "$url") || {
echo "WARN: questo URL è malformato: _${url}_"
es=1
continue
}
if [[ $page =~ $regex_bad_invite ]]; then
echo "$file_and_linenumber: $url"
already_checked[$url]=1 es=1
else
already_checked[$url]=2
fi
sleep "${1:-0.1}" 2> /dev/null || {
echo "$0: ERROR: _${1}_ non è un tempo valido." >&2
exit 2
}
done
exit "$es"