Skip to content

Commit

Permalink
fix regex to parse endpoint for wireguard
Browse files Browse the repository at this point in the history
  • Loading branch information
binhex committed Jan 2, 2025
1 parent 0c490b2 commit 3b0cce8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions build/root/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ if [[ "${VPN_ENABLED}" == "yes" ]]; then
/usr/local/bin/dos2unix.sh "${VPN_CONFIG}"
# get endpoint line from wireguard config file
export VPN_REMOTE_SERVER=$(cat "${VPN_CONFIG}" | grep -P -o '(?<=^Endpoint\s=\s)[^:]+' || true)
export VPN_REMOTE_SERVER=$(cat "${VPN_CONFIG}" | grep -P -o '(?<=^Endpoint(\s+)?=(\s+)?)[^:]+' || true)
if [[ -z "${VPN_REMOTE_SERVER}" ]]; then
echo "[crit] VPN configuration file ${VPN_CONFIG} does not contain 'Endpoint' line, showing contents of file before exit..." | ts '%Y-%m-%d %H:%M:%.S'
cat "${VPN_CONFIG}" && exit 1
Expand All @@ -179,15 +179,15 @@ if [[ "${VPN_ENABLED}" == "yes" ]]; then
if [[ "${VPN_PROV}" == "pia" ]]; then
export VPN_REMOTE_PORT=$(cat "${VPN_CONFIG}" | grep -P -o '(?<=^Endpoint\s=\s).*' | grep -P -o '[\d]+$' || true)
export VPN_REMOTE_PORT=$(cat "${VPN_CONFIG}" | grep -P -o '(?<=^Endpoint(\s+)?=(\s+)?).*' | grep -P -o '[\d]+$' || true)
if [[ -z "${VPN_REMOTE_PORT}" ]]; then
echo "[warn] VPN configuration file ${VPN_CONFIG} does not contain port on 'Endpoint' line, defaulting to '1337'" | ts '%Y-%m-%d %H:%M:%.S'
export VPN_REMOTE_PORT="1337"
fi
else
export VPN_REMOTE_PORT=$(cat "${VPN_CONFIG}" | grep -P -o '(?<=^Endpoint\s=\s).*' | grep -P -o '[\d]+$' || true)
export VPN_REMOTE_PORT=$(cat "${VPN_CONFIG}" | grep -P -o '(?<=^Endpoint(\s+)?=(\s+)?).*' | grep -P -o '[\d]+$' || true)
if [[ -z "${VPN_REMOTE_PORT}" ]]; then
echo "[crit] VPN configuration file ${VPN_CONFIG} does not contain port on 'Endpoint' line, showing contents of file before exit..." | ts '%Y-%m-%d %H:%M:%.S'
cat "${VPN_CONFIG}" && exit 1
Expand Down

0 comments on commit 3b0cce8

Please sign in to comment.