-
Notifications
You must be signed in to change notification settings - Fork 0
/
wb_prep.sh
71 lines (59 loc) · 1.49 KB
/
wb_prep.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
67
68
69
70
71
#!/bin/bash
### USAGE:
# wb_prep - add lines of text to file if they are not there
# wb_prep DELETE - undo
# RUN PORT COMMAND ON LOGIN NODE
# if ! pgrep -f "$(hostname)" > /dev/null ; then
# ssh -fNt -D 41080 tarch@login04.rc.byu.edu;
# fi;
#
### ADD SOCKS5 TO SOCKET
TEXT="# BEGIN ADDITION"
FILE="../env/internn/lib/python3.8/socket.py"
remove_additions() {
sed -i '/# BEGIN ADDITION/,/# END ADDITION/d' $FILE
}
add_to_file_if_missing() {
# Example ./add_to_file_if_missing.sh "this" "this_file.txt"
TEXT=${1:-$TEXT}
FILE=${2:-$FILE}
echo $FILE
echo "Looking for $TEXT"
cat "$FILE" | grep -F "$TEXT"
# If grep doesn't find it
if [ $? -ne 0 ]; then
if [ -f "$FILE" ]; then
echo "$FILE exists, appending"
cat << 'EOF' >> $FILE
# BEGIN ADDITION
import socks
def internet(host="8.8.8.8", port=53, timeout=3):
"""
Host: 8.8.8.8 (google-public-dns-a.google.com)
OpenPort: 53/tcp
Service: domain (DNS/TCP)
"""
try:
setdefaulttimeout(timeout)
socket(AF_INET, SOCK_STREAM).connect((host, port))
return True
except error as ex:
print(ex)
return False
if not internet():
socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 41080)
socket = socks.socksocket
# END ADDITION
EOF
else
echo "$FILE does not exists"
fi
else
echo "$FILE contains $TEXT, not adding"
fi
}
if [[ $1 == "DELETE" ]]; then
remove_additions
else
add_to_file_if_missing
fi