mirror of
https://github.com/amnezia-vpn/amneziawg-tools.git
synced 2025-08-02 09:32:51 +02:00
wg-quick for linux and openbsd
This commit is contained in:
parent
18901ddeaf
commit
837235f51f
2 changed files with 36 additions and 2 deletions
|
@ -28,6 +28,8 @@ CONFIG_FILE=""
|
||||||
PROGRAM="${0##*/}"
|
PROGRAM="${0##*/}"
|
||||||
ARGS=( "$@" )
|
ARGS=( "$@" )
|
||||||
|
|
||||||
|
IS_ASESCURITY_ON=0
|
||||||
|
|
||||||
cmd() {
|
cmd() {
|
||||||
echo "[#] $*" >&3
|
echo "[#] $*" >&3
|
||||||
"$@"
|
"$@"
|
||||||
|
@ -96,6 +98,17 @@ parse_options() {
|
||||||
PostDown) POST_DOWN+=( "$value" ); continue ;;
|
PostDown) POST_DOWN+=( "$value" ); continue ;;
|
||||||
SaveConfig) read_bool SAVE_CONFIG "$value"; continue ;;
|
SaveConfig) read_bool SAVE_CONFIG "$value"; continue ;;
|
||||||
esac
|
esac
|
||||||
|
case "$key" in
|
||||||
|
Jc);&
|
||||||
|
Jmin);&
|
||||||
|
Jmax);&
|
||||||
|
S1);&
|
||||||
|
S2);&
|
||||||
|
H1);&
|
||||||
|
H2);&
|
||||||
|
H3);&
|
||||||
|
H4) IS_ASESCURITY_ON=1;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
WG_CONFIG+="$line"$'\n'
|
WG_CONFIG+="$line"$'\n'
|
||||||
done < "$CONFIG_FILE"
|
done < "$CONFIG_FILE"
|
||||||
|
@ -116,7 +129,11 @@ auto_su() {
|
||||||
|
|
||||||
add_if() {
|
add_if() {
|
||||||
local ret rc
|
local ret rc
|
||||||
if ret="$(cmd ifconfig wg create name "$INTERFACE" 2>&1 >/dev/null)"; then
|
local cmd="ifconfig wg create name "$INTERFACE""
|
||||||
|
if [[ $IS_ASESCURITY_ON == 1 ]]; then
|
||||||
|
cmd="wireguard-go "$INTERFACE"";
|
||||||
|
fi
|
||||||
|
if ret="$(cmd $cmd 2>&1 >/dev/null)"; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
rc=$?
|
rc=$?
|
||||||
|
|
|
@ -26,6 +26,7 @@ SAVE_CONFIG=0
|
||||||
CONFIG_FILE=""
|
CONFIG_FILE=""
|
||||||
PROGRAM="${0##*/}"
|
PROGRAM="${0##*/}"
|
||||||
ARGS=( "$@" )
|
ARGS=( "$@" )
|
||||||
|
IS_ASESCURITY_ON=0
|
||||||
|
|
||||||
cmd() {
|
cmd() {
|
||||||
echo "[#] $*" >&2
|
echo "[#] $*" >&2
|
||||||
|
@ -37,6 +38,7 @@ die() {
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
parse_options() {
|
parse_options() {
|
||||||
local interface_section=0 line key value stripped v
|
local interface_section=0 line key value stripped v
|
||||||
CONFIG_FILE="$1"
|
CONFIG_FILE="$1"
|
||||||
|
@ -67,6 +69,17 @@ parse_options() {
|
||||||
PostDown) POST_DOWN+=( "$value" ); continue ;;
|
PostDown) POST_DOWN+=( "$value" ); continue ;;
|
||||||
SaveConfig) read_bool SAVE_CONFIG "$value"; continue ;;
|
SaveConfig) read_bool SAVE_CONFIG "$value"; continue ;;
|
||||||
esac
|
esac
|
||||||
|
case "$key" in
|
||||||
|
Jc);&
|
||||||
|
Jmin);&
|
||||||
|
Jmax);&
|
||||||
|
S1);&
|
||||||
|
S2);&
|
||||||
|
H1);&
|
||||||
|
H2);&
|
||||||
|
H3);&
|
||||||
|
H4) IS_ASESCURITY_ON=1;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
WG_CONFIG+="$line"$'\n'
|
WG_CONFIG+="$line"$'\n'
|
||||||
done < "$CONFIG_FILE"
|
done < "$CONFIG_FILE"
|
||||||
|
@ -87,7 +100,11 @@ auto_su() {
|
||||||
|
|
||||||
add_if() {
|
add_if() {
|
||||||
local ret
|
local ret
|
||||||
if ! cmd ip link add "$INTERFACE" type wireguard; then
|
local cmd="ip link add "$INTERFACE" type wireguard"
|
||||||
|
if [[ $IS_ASESCURITY_ON == 1 ]]; then
|
||||||
|
cmd="wireguard-go "$INTERFACE"";
|
||||||
|
fi
|
||||||
|
if ! cmd $cmd; then
|
||||||
ret=$?
|
ret=$?
|
||||||
[[ -e /sys/module/wireguard ]] || ! command -v "${WG_QUICK_USERSPACE_IMPLEMENTATION:-wireguard-go}" >/dev/null && exit $ret
|
[[ -e /sys/module/wireguard ]] || ! command -v "${WG_QUICK_USERSPACE_IMPLEMENTATION:-wireguard-go}" >/dev/null && exit $ret
|
||||||
echo "[!] Missing WireGuard kernel module. Falling back to slow userspace implementation." >&2
|
echo "[!] Missing WireGuard kernel module. Falling back to slow userspace implementation." >&2
|
||||||
|
|
Loading…
Add table
Reference in a new issue