mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-02 13:54:05 +02:00
Add preshared-key
This commit is contained in:
@@ -234,11 +234,14 @@ _wireguard_up() {
|
|||||||
if [[ "${config["EndpointIP"]}" == *:* ]]; then
|
if [[ "${config["EndpointIP"]}" == *:* ]]; then
|
||||||
endpoint="[${config["EndpointIP"]}]:${config["EndpointPort"]}"
|
endpoint="[${config["EndpointIP"]}]:${config["EndpointPort"]}"
|
||||||
fi
|
fi
|
||||||
if [ -v config["PersistentKeepalive"] ] && [ -n "${config["PersistentKeepalive"]}" ]; then
|
local peer_cmd="wg set ${config["Interface"]} peer ${config["PublicKey"]} endpoint ${endpoint} allowed-ips ${allowed_ips}"
|
||||||
_cmd "wg set ${config["Interface"]} peer ${config["PublicKey"]} endpoint ${endpoint} allowed-ips ${allowed_ips} persistent-keepalive ${config["PersistentKeepalive"]}" || return 1
|
if [ -n "${config["PresharedKey"]:-}" ]; then
|
||||||
else
|
peer_cmd="${peer_cmd} preshared-key ${config["PresharedKey"]}"
|
||||||
_cmd "wg set ${config["Interface"]} peer ${config["PublicKey"]} endpoint ${endpoint} allowed-ips ${allowed_ips}" || return 1
|
|
||||||
fi
|
fi
|
||||||
|
if [ -n "${config["PersistentKeepalive"]:-}" ]; then
|
||||||
|
peer_cmd="${peer_cmd} persistent-keepalive ${config["PersistentKeepalive"]}"
|
||||||
|
fi
|
||||||
|
_cmd "${peer_cmd}" || return 1
|
||||||
|
|
||||||
if [ -v config["MTU"] ] && [ -n "${config["MTU"]}" ]; then
|
if [ -v config["MTU"] ] && [ -n "${config["MTU"]}" ]; then
|
||||||
_cmd "ip link set ${config["Interface"]} mtu ${config["MTU"]}" || return 1
|
_cmd "ip link set ${config["Interface"]} mtu ${config["MTU"]}" || return 1
|
||||||
@@ -290,13 +293,20 @@ wireguard() {
|
|||||||
bashio::log.debug "${key}: ${config[$key]}"
|
bashio::log.debug "${key}: ${config[$key]}"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo ${config["PrivateKey"]} > ${WIREGUARD_STATE_DIR}/privatekey
|
printf '%s\n' "${config["PrivateKey"]}" > "${WIREGUARD_STATE_DIR}/privatekey"
|
||||||
|
chmod 600 "${WIREGUARD_STATE_DIR}/privatekey" || true
|
||||||
config["PrivateKey"]="${WIREGUARD_STATE_DIR}/privatekey"
|
config["PrivateKey"]="${WIREGUARD_STATE_DIR}/privatekey"
|
||||||
|
|
||||||
|
if [ -n "${config["PresharedKey"]:-}" ]; then
|
||||||
|
printf '%s\n' "${config["PresharedKey"]}" > "${WIREGUARD_STATE_DIR}/presharedkey"
|
||||||
|
chmod 600 "${WIREGUARD_STATE_DIR}/presharedkey" || true
|
||||||
|
config["PresharedKey"]="${WIREGUARD_STATE_DIR}/presharedkey"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "${mode}" = "up" ]; then
|
if [ "${mode}" = "up" ]; then
|
||||||
bashio::log.info "Starting WireGuard on interface ${config["Interface"]}..."
|
bashio::log.info "Starting WireGuard on interface ${config["Interface"]}..."
|
||||||
local result=0
|
local result=0
|
||||||
_check_host ${config["EndpointHost"]} || result=$?
|
_check_host "${config["EndpointHost"]}" || result=$?
|
||||||
if [ "${result}" -eq 0 ]; then
|
if [ "${result}" -eq 0 ]; then
|
||||||
bashio::log.error "WireGuard endpoint ${config["EndpointHost"]} is neither a valid IP address nor a resolvable hostname."
|
bashio::log.error "WireGuard endpoint ${config["EndpointHost"]} is neither a valid IP address nor a resolvable hostname."
|
||||||
bashio::exit.nok 'WireGuard start failed.'
|
bashio::exit.nok 'WireGuard start failed.'
|
||||||
|
|||||||
Reference in New Issue
Block a user