summarylogtreecommitdiffstats
path: root/surfshark-yac.install
blob: af0469606ffb67e4aa96f66623d2c8dc815a7996 (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
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
120
121
122
123
post_install() {
	gtk-update-icon-cache -q -t -f usr/share/icons/hicolor
	PATH="/sbin:/usr/sbin:/bin:/usr/bin"

	ln -sf '/opt/Surfshark/surfshark' '/usr/bin/surfshark'

	chmod 4755 '/opt/Surfshark/chrome-sandbox' || true

	update-mime-database /usr/share/mime || true
	update-desktop-database /usr/share/applications || true

	mkdir -p /usr/lib/systemd/user || true
	echo "
	[Unit]
	Description=Surfshark Daemon

	[Service]
	ExecStart=/opt/Surfshark/resources/dist/resources/surfsharkd.js
	Restart=on-failure
	RestartSec=5
	IPAddressDeny=any
	RestrictRealtime=true
	ProtectKernelTunables=true
	ProtectSystem=full
	RestrictSUIDSGID=true

	[Install]
	WantedBy=default.target
	" > /usr/lib/systemd/user/surfsharkd.service || true

	mkdir -p /usr/lib/systemd/system || true
	echo "
	[Unit]
	Description=Surfshark Daemon2

	[Service]
	ExecStart=/opt/Surfshark/resources/dist/resources/surfsharkd2.js
	Restart=on-failure
	RestartSec=5
	IPAddressDeny=any
	RestrictRealtime=true
	ProtectKernelTunables=true
	ProtectSystem=full
	RestrictSUIDSGID=true

	[Install]
	WantedBy=default.target
	" > /usr/lib/systemd/system/surfsharkd2.service || true

	chmod 644 /usr/lib/systemd/user/surfsharkd.service || true
	chmod 644 /usr/lib/systemd/system/surfsharkd2.service || true

	chmod 755 '/opt/Surfshark/resources/dist/resources/surfsharkd.js' || true

	chmod 755 '/opt/Surfshark/resources/dist/resources/surfsharkd2.js' || true

	chmod 755 '/opt/Surfshark/resources/dist/resources/update' || true
	chmod 755 '/opt/Surfshark/resources/dist/resources/diagnostics' || true

	chmod 755 '/etc/init.d/surfshark' || true
	chmod 755 '/etc/init.d/surfshark2' || true

	case "$(ps -p 1 --no-headers -o '%c' | tr -d '\n')" in
	    systemd)
	        systemctl daemon-reload || true
	        systemctl enable --global surfsharkd.service || true
	    ;;
	    init)
	        update-rc.d surfshark defaults || true
	        update-rc.d surfshark2 defaults || true
	        /etc/init.d/surfshark restart || true
	        /etc/init.d/surfshark2 restart || true
	    ;;
	    *)
	        echo "Unsupported service manager"
	    ;;
	esac
	update-desktop-database -q
}

post_upgrade() {
	post_install
}

post_remove() {
	gtk-update-icon-cache -q -t -f usr/share/icons/hicolor
	PATH="/sbin:/usr/sbin:/bin:/usr/bin"

	systemctl disable --global surfsharkd.service || true
	systemctl disable surfsharkd2.service || true

	systemctl stop surfsharkd2.service || true

	/etc/init.d/surfshark stop || true
	/etc/init.d/surfshark2 stop || true

	kill -15 $(pidof surfshark) || :
	kill -15 $(pgrep surfsharkd) || :

	rm -rf /run/surfshark || :
	rm -f /tmp/surfsharkd.sock || :
	rm -f /tmp/surfshark-electron.sock || :
	rm -f $XDG_RUNTIME_DIR/surfsharkd.sock || :
	rm -f $XDG_RUNTIME_DIR/surfshark-electron.sock || :

	rm -f '/usr/bin/surfshark' || :

	# Surfshark post-remove
	nmcli connection delete surfshark_ipv6 || true
	nmcli connection delete surfshark_wg || true
	nmcli connection delete surfshark_openvpn || true

	shopt -s globstar
	if [ "$1" = purge ]; then
	    rm -rf /home/**/.config/Surfshark || true
	fi

	rm -rf /home/**/.cache/Surfshark || true

	iptables -S | grep surfshark_ks | sed -r '/.*comment.*surfshark_ks*/s/-A/iptables -D/e' || true
	ip6tables -S | grep surfshark_ks | sed -r '/.*comment.*surfshark_ks*/s/-A/ip6tables -D/e' || true
	update-desktop-database -q
}