-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwireguard-transmission.bash
98 lines (83 loc) · 2.87 KB
/
wireguard-transmission.bash
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
start() {
if [ ! -f /usr/bin/whois ] || [ ! -f /usr/bin/transmission-daemon ] || [ ! -f /usr/bin/wg-quick ]; then
clear
echo && echo -e '\e[91m' "************* MISSING DEPENDENCIES *************" && echo
echo && echo && echo -e '\e[95m'"Starting install dependencies..." && echo && echo -e '\e[0m' && sleep 1
sudo apt update && sudo apt upgrade -y && sudo apt install whois wireguard-tools transmission-daemon transmission-common -y
systemctl disable wg-quick@wg0 && systemctl disable transmission-daemon
fi
[ -x openvpn ] || systemctl stop wg-quick@wg0
[ -x transmission-daemon ] || systemctl stop transmission-daemon
killall wg-quick@wg0 >> /dev/null 2>&1
sleep 2
killall -9 wg-quick@wg0 >> /dev/null 2>&1
CLIENT=`cat /etc/wireguard/wg0.conf | grep Endpoint | awk '{print $3}'`
systemctl start wg-quick@wg0 >> /dev/null 2>&1
clear
echo && echo -e '\e[91m'"Starting Wireguard and transmission-daemon"
echo -e '\e[33m'"Connecting with $CLIENT"
echo -e '\e[0m'"Please wait 30 seconds..." && echo
sleep 26
systemctl start transmission-daemon
sleep 3
CHECKWG=`ip -o -f inet addr show | awk '/scope global/' | grep wg0 | awk '{print $2}'`
$0 status &
while [[ $CHECKWG = wg0 ]]; do
sleep 7
CHECKWG=`ip -o -f inet addr show | awk '/scope global/' | grep wg0 | awk '{print $2}'`
sleep 8
done
systemctl stop transmission-daemon
}
stop() {
[ -x wg-quick ] || systemctl stop wg-quick@wg0
[ -x transmission-daemon ] || systemctl stop transmission-daemon
killall wg-quick@wg0 >> /dev/null 2>&1
sleep 2
killall -9 wg-quick@wg0 >> /dev/null 2>&1
}
status() {
clear
PRESS=" ***** Press ENTER to continue *****"
EXTIP=$(curl -s icanhazip.com)
COUNTRY=$(whois $EXTIP | grep -m 1 country: | awk '{print $2}')
CHECKWG=`ip -o -f inet addr show | awk '/scope global/' | grep wg0 | awk '{print $2}'`
if [[ $CHECKWG = wg0 ]]; then
echo && echo -e '\e[32m'"You are connected with Wireguard: your IP is $EXTIP $COUNTRY"
echo "$PRESS" && echo -e '\e[0m'
else
echo && echo -e '\e[91m'"You are NOT connected with Wireguard: your IP is $EXTIP $COUNTRY"
[ -x transmission-daemon ] || systemctl stop transmission-daemon
echo "$PRESS" && echo -e '\e[0m'
fi
}
help() {
clear
echo && echo "Welcome to the OpenVPN and transmission-daemon initialization script."
echo && echo
echo "To ensure optimal performance, please follow these steps:"
echo "1) Place the WireGuard configuration file (.conf) in /etc/wireguard"
echo "2) Make the script executable: chmod +x wireguard-transmission"
echo "3) Run the script with: $0 start"
echo && echo "If WireGuard crashes or the server becomes unavailable, the script will stop the transmission-daemon service."
echo && echo "Usage: $0 {start|stop|status|help}"
echo && echo
}
case "$1" in
start)
start &
;;
stop)
stop
;;
status)
status &
;;
help)
help
;;
*)
echo "Usage: $0 {start|stop|status|help}"
esac
exit 0