Prepare packaging

This commit is contained in:
Iurii Egorov 2023-12-09 18:02:43 +03:00
parent 6cca06e846
commit 761c2d5fb5

View file

@ -99,7 +99,7 @@ del_if() {
local table local table
[[ $HAVE_SET_DNS -eq 0 ]] || unset_dns [[ $HAVE_SET_DNS -eq 0 ]] || unset_dns
[[ $HAVE_SET_FIREWALL -eq 0 ]] || remove_firewall [[ $HAVE_SET_FIREWALL -eq 0 ]] || remove_firewall
if [[ -z $TABLE || $TABLE == auto ]] && get_fwmark table && [[ $(wg show "$INTERFACE" allowed-ips) =~ /0(\ |$'\n'|$) ]]; then if [[ -z $TABLE || $TABLE == auto ]] && get_fwmark table && [[ $(awg show "$INTERFACE" allowed-ips) =~ /0(\ |$'\n'|$) ]]; then
while [[ $(ip -4 rule show 2>/dev/null) == *"lookup $table"* ]]; do while [[ $(ip -4 rule show 2>/dev/null) == *"lookup $table"* ]]; do
cmd ip -4 rule delete table $table cmd ip -4 rule delete table $table
done done
@ -132,7 +132,7 @@ set_mtu_up() {
[[ $endpoint =~ ^\[?([a-z0-9:.]+)\]?:[0-9]+$ ]] || continue [[ $endpoint =~ ^\[?([a-z0-9:.]+)\]?:[0-9]+$ ]] || continue
output="$(ip route get "${BASH_REMATCH[1]}" || true)" output="$(ip route get "${BASH_REMATCH[1]}" || true)"
[[ ( $output =~ mtu\ ([0-9]+) || ( $output =~ dev\ ([^ ]+) && $(ip link show dev "${BASH_REMATCH[1]}") =~ mtu\ ([0-9]+) ) ) && ${BASH_REMATCH[1]} -gt $mtu ]] && mtu="${BASH_REMATCH[1]}" [[ ( $output =~ mtu\ ([0-9]+) || ( $output =~ dev\ ([^ ]+) && $(ip link show dev "${BASH_REMATCH[1]}") =~ mtu\ ([0-9]+) ) ) && ${BASH_REMATCH[1]} -gt $mtu ]] && mtu="${BASH_REMATCH[1]}"
done < <(wg show "$INTERFACE" endpoints) done < <(awg show "$INTERFACE" endpoints)
if [[ $mtu -eq 0 ]]; then if [[ $mtu -eq 0 ]]; then
read -r output < <(ip route show default || true) || true read -r output < <(ip route show default || true) || true
[[ ( $output =~ mtu\ ([0-9]+) || ( $output =~ dev\ ([^ ]+) && $(ip link show dev "${BASH_REMATCH[1]}") =~ mtu\ ([0-9]+) ) ) && ${BASH_REMATCH[1]} -gt $mtu ]] && mtu="${BASH_REMATCH[1]}" [[ ( $output =~ mtu\ ([0-9]+) || ( $output =~ dev\ ([^ ]+) && $(ip link show dev "${BASH_REMATCH[1]}") =~ mtu\ ([0-9]+) ) ) && ${BASH_REMATCH[1]} -gt $mtu ]] && mtu="${BASH_REMATCH[1]}"
@ -180,7 +180,7 @@ add_route() {
get_fwmark() { get_fwmark() {
local fwmark local fwmark
fwmark="$(wg show "$INTERFACE" fwmark)" || return 1 fwmark="$(awg show "$INTERFACE" fwmark)" || return 1
[[ -n $fwmark && $fwmark != off ]] || return 1 [[ -n $fwmark && $fwmark != off ]] || return 1
printf -v "$1" "%d" "$fwmark" printf -v "$1" "%d" "$fwmark"
return 0 return 0
@ -216,7 +216,7 @@ add_default() {
while [[ -n $(ip -4 route show table $table 2>/dev/null) || -n $(ip -6 route show table $table 2>/dev/null) ]]; do while [[ -n $(ip -4 route show table $table 2>/dev/null) || -n $(ip -6 route show table $table 2>/dev/null) ]]; do
((table++)) ((table++))
done done
cmd wg set "$INTERFACE" fwmark $table cmd awg set "$INTERFACE" fwmark $table
fi fi
local proto=-4 iptables=iptables pf=ip local proto=-4 iptables=iptables pf=ip
[[ $1 == *:* ]] && proto=-6 iptables=ip6tables pf=ip6 [[ $1 == *:* ]] && proto=-6 iptables=ip6tables pf=ip6
@ -278,7 +278,7 @@ save_config() {
done done
old_umask="$(umask)" old_umask="$(umask)"
umask 077 umask 077
current_config="$(cmd wg showconf "$INTERFACE")" current_config="$(cmd awg showconf "$INTERFACE")"
trap 'rm -f "$CONFIG_FILE.tmp"; exit' INT TERM EXIT trap 'rm -f "$CONFIG_FILE.tmp"; exit' INT TERM EXIT
echo "${current_config/\[Interface\]$'\n'/$new_config}" > "$CONFIG_FILE.tmp" || die "Could not write configuration file" echo "${current_config/\[Interface\]$'\n'/$new_config}" > "$CONFIG_FILE.tmp" || die "Could not write configuration file"
sync "$CONFIG_FILE.tmp" sync "$CONFIG_FILE.tmp"
@ -303,7 +303,7 @@ cmd_usage() {
CONFIG_FILE is a configuration file, whose filename is the interface name CONFIG_FILE is a configuration file, whose filename is the interface name
followed by \`.conf'. Otherwise, INTERFACE is an interface name, with followed by \`.conf'. Otherwise, INTERFACE is an interface name, with
configuration found at /etc/amnezia/INTERFACE.conf. It is to be readable configuration found at /etc/amnezia/INTERFACE.conf. It is to be readable
by wg(8)'s \`setconf' sub-command, with the exception of the following additions by awg(8)'s \`setconf' sub-command, with the exception of the following additions
to the [Interface] section, which are handled by $PROGRAM: to the [Interface] section, which are handled by $PROGRAM:
- Address: may be specified one or more times and contains one or more - Address: may be specified one or more times and contains one or more
@ -319,7 +319,7 @@ cmd_usage() {
- SaveConfig: if set to \`true', the configuration is saved from the current - SaveConfig: if set to \`true', the configuration is saved from the current
state of the interface upon shutdown. state of the interface upon shutdown.
See wg-quick(8) for more info and examples. See awg-quick(8) for more info and examples.
_EOF _EOF
} }
@ -335,7 +335,7 @@ cmd_up() {
done done
set_mtu_up set_mtu_up
set_dns set_dns
for i in $(while read -r _ i; do for i in $i; do [[ $i =~ ^[0-9a-z:.]+/[0-9]+$ ]] && echo "$i"; done; done < <(wg show "$INTERFACE" allowed-ips) | sort -nr -k 2 -t /); do for i in $(while read -r _ i; do for i in $i; do [[ $i =~ ^[0-9a-z:.]+/[0-9]+$ ]] && echo "$i"; done; done < <(awg show "$INTERFACE" allowed-ips) | sort -nr -k 2 -t /); do
add_route "$i" add_route "$i"
done done
execute_hooks "${POST_UP[@]}" execute_hooks "${POST_UP[@]}"