aboutsummaryrefslogtreecommitdiffstats
path: root/main/nftables/nftables.post-upgrade
blob: 8ab77c096d12765d1e9f92a081084e5cf26acc4b (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
#!/bin/sh

ver_new="$1"
ver_old="$2"

# Copy rules file to the new default location, to be sure that we will
# not break existing installations.
if [ "$(apk version -t "$ver_old" "0.8.3-r1")" = "<" ]; then
	old_file='/var/lib/nftables/rules-save'
	new_file='/etc/nftables.nft'

	if [ -f "$old_file" ] && [ ! -f "$new_file" ]; then
		cp -a "$old_file" "$new_file"
	fi
fi

# I made a mistake before, the new default location was /etc/firewall.nft, not
# /etc/nftables.nft. Now I changed it to /etc/nftables.nft (same as Arch Linux),
# so if /etc/firewall.nft exists and /etc/nftables.nft didn't exist, copy
# /etc/firewall.nft to /etc/nftables.nft to not break existing setup.
if [ "$(apk version -t "$ver_old" "0.9.3-r2")" = "<" ]; then
	old_file='/etc/firewall.nft'
	new_file='/etc/nftables.nft'

	cat >&2 <<-EOF
	* The default rules_file was changed to $new_file and
	* save_on_stop disabled!
	* Also note that /etc/nftables/ was moved to /usr/share/nftables/.
	EOF

	if [ -f "$old_file" ] && [ ! -f "$new_file.apk-new" ]; then
		echo "* Copying $old_file to $new_file" >&2
		cp -a "$old_file" "$new_file"
	fi
fi