Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
comparison files/fwireguard.in @ 471:e2555d5fc61f
Implement a fwireguard RC variable to manually determine the names of wireguard interfaces to configure to.
By default this variable is set to "AUTO" to determine the interfaces automatically.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 22 Aug 2024 14:07:27 +0200 |
| parents | f8858fc8c7f3 |
| children | 692c6357ce39 |
comparison
equal
deleted
inserted
replaced
| 470:c65a79d84e9e | 471:e2555d5fc61f |
|---|---|
| 31 load_rc_config $name | 31 load_rc_config $name |
| 32 | 32 |
| 33 : ${fwireguard_enable:="NO"} | 33 : ${fwireguard_enable:="NO"} |
| 34 : ${fwireguard_wait="2s"} | 34 : ${fwireguard_wait="2s"} |
| 35 : ${fwireguard_configdir:="%%PREFIX%%/etc/fwireguard"} | 35 : ${fwireguard_configdir:="%%PREFIX%%/etc/fwireguard"} |
| 36 : ${fwireguard_interfaces="AUTO"} | |
| 37 | |
| 38 | |
| 39 # Automatically expand to the interface names if needed | |
| 40 [ "${fwireguard_interfaces}" = "AUTO" ] && fwireguard_interfaces="$(/sbin/ifconfig -g wg)" | |
| 36 | 41 |
| 37 | 42 |
| 38 fwireguard_start() | 43 fwireguard_start() |
| 39 { | 44 { |
| 40 local _f _if | 45 local _f _if |
| 41 | 46 |
| 42 if [ ! -d "${fwireguard_configdir}" ]; then | 47 if [ ! -d "${fwireguard_configdir}" ]; then |
| 43 mkdir "${fwireguard_configdir}" | 48 mkdir "${fwireguard_configdir}" |
| 44 fi | 49 fi |
| 45 for _if in `/sbin/ifconfig -g wg`; do | 50 for _if in ${fwireguard_interfaces}; do |
| 46 | 51 |
| 47 _f="${fwireguard_configdir}/${_if}.key" | 52 _f="${fwireguard_configdir}/${_if}.key" |
| 48 if [ ! -f "${_f}" ]; then | 53 if [ ! -f "${_f}" ]; then |
| 49 echo "Generating secret key for ${_if} in ${_f}" | 54 echo "Generating secret key for ${_if} in ${_f}" |
| 50 (umask 0077; /usr/bin/wg genkey > "${_f}") | 55 (umask 0077; /usr/bin/wg genkey > "${_f}") |
| 89 | 94 |
| 90 fwireguard_stop() | 95 fwireguard_stop() |
| 91 { | 96 { |
| 92 local _if | 97 local _if |
| 93 | 98 |
| 94 for _if in `/sbin/ifconfig -g wg`; do | 99 for _if in ${fwireguard_interfaces}; do |
| 95 if [ -x "${fwireguard_configdir}/${_if}.pre-stop" ]; then | 100 if [ -x "${fwireguard_configdir}/${_if}.pre-stop" ]; then |
| 96 "${fwireguard_configdir}/${_if}.pre-stop" | 101 "${fwireguard_configdir}/${_if}.pre-stop" |
| 97 fi | 102 fi |
| 98 /sbin/ifconfig "${_if}" down | 103 /sbin/ifconfig "${_if}" down |
| 99 done | 104 done |
| 108 | 113 |
| 109 fwireguard_status() | 114 fwireguard_status() |
| 110 { | 115 { |
| 111 local _if | 116 local _if |
| 112 | 117 |
| 113 for _if in `/sbin/ifconfig -g wg`; do | 118 for _if in ${fwireguard_interfaces}; do |
| 114 /usr/bin/wg show "${_if}" | 119 /usr/bin/wg show "${_if}" |
| 115 done | 120 done |
| 116 } | 121 } |
| 117 | 122 |
| 118 | 123 |
