mirror of
https://github.com/hassio-addons/addon-wireguard.git
synced 2025-05-05 19:31:25 +00:00
✨ Allow customize of WireGuard interface name
This commit is contained in:
parent
13b6047511
commit
b0562090f0
3 changed files with 24 additions and 7 deletions
|
@ -56,6 +56,7 @@
|
||||||
"log_level": "match(^(trace|debug|info|notice|warning|error|fatal)$)?",
|
"log_level": "match(^(trace|debug|info|notice|warning|error|fatal)$)?",
|
||||||
"server": {
|
"server": {
|
||||||
"host": "str",
|
"host": "str",
|
||||||
|
"interface": "match(^wg([0-9])+$)?",
|
||||||
"addresses": ["str"],
|
"addresses": ["str"],
|
||||||
"dns": ["str"],
|
"dns": ["str"],
|
||||||
"private_key": "str?",
|
"private_key": "str?",
|
||||||
|
|
|
@ -13,6 +13,7 @@ declare endpoint
|
||||||
declare filename
|
declare filename
|
||||||
declare fwmark
|
declare fwmark
|
||||||
declare host
|
declare host
|
||||||
|
declare interface
|
||||||
declare keep_alive
|
declare keep_alive
|
||||||
declare mtu
|
declare mtu
|
||||||
declare name
|
declare name
|
||||||
|
@ -33,8 +34,15 @@ if ! bashio::fs.directory_exists '/ssl/wireguard'; then
|
||||||
bashio::exit.nok "Could create wireguard storage folder!"
|
bashio::exit.nok "Could create wireguard storage folder!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Get interface and config file location
|
||||||
|
interface="wg0"
|
||||||
|
if bashio::config.has_value "server.interface"; then
|
||||||
|
interface=$(bashio::config "server.interface")
|
||||||
|
fi
|
||||||
|
config="/etc/wireguard/${interface}.conf"
|
||||||
|
|
||||||
# Start creation of configuration
|
# Start creation of configuration
|
||||||
echo "[Interface]" > "${CONFIG}"
|
echo "[Interface]" > "${config}"
|
||||||
|
|
||||||
# Check if at least 1 address is specified
|
# Check if at least 1 address is specified
|
||||||
if ! bashio::config.has_value 'server.addresses'; then
|
if ! bashio::config.has_value 'server.addresses'; then
|
||||||
|
@ -44,17 +52,17 @@ fi
|
||||||
# Add all server addresses to the configuration
|
# Add all server addresses to the configuration
|
||||||
for address in $(bashio::config 'server.addresses'); do
|
for address in $(bashio::config 'server.addresses'); do
|
||||||
[[ "${address}" == *"/"* ]] || address="${address}/24"
|
[[ "${address}" == *"/"* ]] || address="${address}/24"
|
||||||
echo "Address = ${address}" >> "${CONFIG}"
|
echo "Address = ${address}" >> "${config}"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Add all server DNS addresses to the configuration
|
# Add all server DNS addresses to the configuration
|
||||||
if bashio::config.has_value 'server.dns'; then
|
if bashio::config.has_value 'server.dns'; then
|
||||||
for dns in $(bashio::config 'server.dns'); do
|
for dns in $(bashio::config 'server.dns'); do
|
||||||
echo "DNS = ${dns}" >> "${CONFIG}"
|
echo "DNS = ${dns}" >> "${config}"
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
dns=$(bashio::dns.host)
|
dns=$(bashio::dns.host)
|
||||||
echo "DNS = ${dns}" >> ${CONFIG}
|
echo "DNS = ${dns}" >> ${config}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get the server's private key
|
# Get the server's private key
|
||||||
|
@ -137,7 +145,7 @@ fi
|
||||||
|
|
||||||
# End configuration file with an empty line
|
# End configuration file with an empty line
|
||||||
echo ""
|
echo ""
|
||||||
} >> "${CONFIG}"
|
} >> "${config}"
|
||||||
|
|
||||||
# Get DNS for client configurations
|
# Get DNS for client configurations
|
||||||
if bashio::config.has_value 'server.dns'; then
|
if bashio::config.has_value 'server.dns'; then
|
||||||
|
@ -226,7 +234,7 @@ for peer in $(bashio::config 'peers|keys'); do
|
||||||
bashio::config.has_value "peers[${peer}].endpoint" \
|
bashio::config.has_value "peers[${peer}].endpoint" \
|
||||||
&& echo "Endpoint = ${endpoint}"
|
&& echo "Endpoint = ${endpoint}"
|
||||||
echo ""
|
echo ""
|
||||||
} >> "${CONFIG}"
|
} >> "${config}"
|
||||||
|
|
||||||
# Generate client configuration
|
# Generate client configuration
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
# Community Hass.io Add-ons: WireGuard
|
# Community Hass.io Add-ons: WireGuard
|
||||||
# Runs WireGuard
|
# Runs WireGuard
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
|
declare interface
|
||||||
|
|
||||||
s6-svc -O /var/run/s6/services/wireguard
|
s6-svc -O /var/run/s6/services/wireguard
|
||||||
|
|
||||||
bashio::log.info "Starting WireGuard..."
|
bashio::log.info "Starting WireGuard..."
|
||||||
|
@ -11,5 +13,11 @@ bashio::log.info "Starting WireGuard..."
|
||||||
# WireGuard we are OK to go.
|
# WireGuard we are OK to go.
|
||||||
export WG_I_PREFER_BUGGY_USERSPACE_TO_POLISHED_KMOD=1
|
export WG_I_PREFER_BUGGY_USERSPACE_TO_POLISHED_KMOD=1
|
||||||
|
|
||||||
|
# Get the interface
|
||||||
|
interface="wg0"
|
||||||
|
if bashio::config.has_value "server.interface"; then
|
||||||
|
interface=$(bashio::config "server.interface")
|
||||||
|
fi
|
||||||
|
|
||||||
# Run the WireGuard
|
# Run the WireGuard
|
||||||
exec wg-quick up wg0
|
exec wg-quick up "${interface}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue