-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare_AirVPN_wg.sh
executable file
·119 lines (107 loc) · 2.3 KB
/
prepare_AirVPN_wg.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh
# Prepare files made by the AirVPN generator
# WireGuard version
# 28.08.2024
basedir=/etc/wireguard
steps=5
dir_wg=$basedir/AirVPN_wg
sed_disable_ipv6_wg="s/^(Address = .*)(, .*)$/\1/g ; s/^(DNS = .*)(, .*)$/\1/g ; s/^(AllowedIPs = .*)(, .*)$/\1/g"
ask_continue () {
read -p "Continue = Enter; Skip = s; Quit = q " ans
if [ "$ans" = "q" ]; then
ret=1
elif [ "$ans" = "s" ]; then
ret=2
else
ret=0
fi
}
purgecreate () {
if [ -d "$dir" ]; then
echo "Purging $dir"
rm "$dir"/* 2> /dev/null
else
if [ ! -d "$dir" ]; then
echo "Creating $dir"
mkdir "$dir"
fi
fi
}
if [ $# -lt 1 ]; then
echo "Usage: prepare_AirVPN.sh <path_to_AirVPN_wg.tar.gz>"
exit
fi
gzfile=$1
if [ ! -f "$gzfile" ]; then
echo "File $gzfile not found"
echo "Exiting..."
exit
fi
if ! file -b -L "$gzfile" | grep "gzip compressed data" > /dev/null; then
echo "File $gzfile is not a gzip file"
echo "Exiting..."
fi
step=1
echo
echo "Step $step/$steps: purge/create the target directories"
ask_continue
if [ $ret -eq 0 ]; then
dir="$dir_wg"
purgecreate
elif [ $ret -eq 1 ]; then
echo "Exiting..."
exit 1
fi
step=$(expr $step + 1)
echo
echo "Step $step/$steps: move $gzfile to $basedir"
ask_continue
if [ $ret -eq 0 ]; then
mv "$gzfile" "$basedir"
echo "Done"
elif [ $ret -eq 1 ]; then
echo "Exiting..."
exit 1
fi
gzbasename=$(basename "$gzfile")
gzfile="$basedir"/"$gzbasename"
if [ ! -f "$gzfile" ]; then
echo "File $gzfile does not exist"
echo "Exiting..."
fi
step=$(expr $step + 1)
echo
echo "Step $step/$steps: unpack $gzfile"
ask_continue
if [ $ret -eq 0 ]; then
echo "$gzfile"
echo "Unpacking WireGuard files to $dir_wg..."
tar xv -C "$dir_wg" -f "$gzfile" --wildcards "*.conf"
elif [ $ret -eq 1 ]; then
echo "Exiting..."
exit 1
fi
step=$(expr $step + 1)
echo
echo "Step $step/$steps: fix permissions"
ask_continue
if [ $ret -eq 0 ]; then
echo "Setting to 600 for files in $dir_wg"
chmod 600 "$dir_wg"/*
elif [ $ret -eq 1 ]; then
echo "Exiting..."
exit 1
fi
step=$(expr $step + 1)
echo
echo "Step $step/$steps: disable IPv6 everywhere"
ask_continue
if [ $ret -eq 0 ]; then
echo "Disabling for WireGuard"
find "$dir_wg" -print -type f -exec sed -i -E "$sed_disable_ipv6_wg" {} \;
elif [ $ret -eq 1 ]; then
echo "Exiting..."
exit 1;
fi
echo
echo "Done!"