summarylogtreecommitdiffstats
path: root/piavpn-bin.install
blob: c9693320237c1da2c474e581eaba0447a6a6e953 (plain)
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
# copy-pasted from install.sh in .run file
function addRoutingTable() {
    local highestIndex=$(awk '/^[0-9]/{print $1}' /etc/iproute2/rt_tables | sort -n | tail -1)
    local newIndex=$(($highestIndex + 1))
    local routingTable="$1"

    if ! grep -q "$routingTable" /etc/iproute2/rt_tables; then
        echo -e "$newIndex\t$routingTable" >> /etc/iproute2/rt_tables
    fi
}

pre_install() {
	groupadd piavpn
	groupadd piahnsd

	addRoutingTable piavpnrt
	addRoutingTable piavpnOnlyrt
	addRoutingTable piavpnWgrt
	addRoutingTable piavpnFwdrt
}

pre_remove() {
	systemctl stop piavpn
	systemctl disable piavpn
}

post_remove() {
	sed -i '/.*piavpnrt$/d' /etc/iproute2/rt_tables
	sed -i '/.*piavpnOnlyrt$/d' /etc/iproute2/rt_tables
	sed -i '/.*piavpnWgrt$/d' /etc/iproute2/rt_tables
	groupdel piavpn
	groupdel piahnsd
}

post_upgrade() {
	systemctl daemon-reload
	if systemctl is-active piavpn >/dev/null; then
		systemctl restart piavpn
		echo ":: Don't forget to reconnect to your vpn if needed"
	fi
}