621e8895c9
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
4.3 KiB
4.3 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | params | output | tested | tests | test_file_path | file_path | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| wg_client_install | function | bash | infra | 1.0.0 | impure | wg_client_install(config_path_or_stdin, [interface_name]) -> json | Device-side: instala wg0.conf en /etc/wireguard/, habilita systemd wg-quick@wg0, verifica handshake con hub. Idempotente. Acepta config por path o stdin (para pipes desde wg_client_config). |
|
|
false | error_go_core |
|
JSON {status, interface, hub_endpoint, handshake_seen}. status: installed | already-configured | installed-no-handshake | installed-no-systemd | false | bash/functions/infra/wg_client_install.sh |
Ejemplo
source bash/functions/infra/wg_client_install.sh
# Desde pipe (caso más común en flow 0009):
wg_client_config_go_infra | jq -r '.INI' | wg_client_install -
# {"status":"installed","interface":"wg0","hub_endpoint":"203.0.113.1:51820","handshake_seen":true}
# Desde archivo .conf generado previamente:
wg_client_install /tmp/peer_laptop.conf
# {"status":"installed","interface":"wg0","hub_endpoint":"203.0.113.1:51820","handshake_seen":true}
# Con interfaz personalizada:
wg_client_install /tmp/peer_laptop.conf wg1
# {"status":"installed","interface":"wg1","hub_endpoint":"203.0.113.1:51820","handshake_seen":true}
# Segunda ejecución con misma config (idempotente):
wg_client_install /tmp/peer_laptop.conf
# {"status":"already-configured","interface":"wg0","hub_endpoint":"203.0.113.1:51820","handshake_seen":false}
Cuando usarla
Cuando necesites conectar un nuevo peer al mesh WireGuard en el flow 0009. Úsala justo después de wg_client_config (que genera el .conf) para instalarlo en el device peer. Es el paso final del onboarding de un nodo: config generada → instalada → verificada con handshake.
Gotchas
- Requiere root/sudo para escribir en
/etc/wireguard/, hacerchmod 600, y ejecutarsystemctl. El operador debe tenersudosin password para estos comandos, o ejecutar la función como root. - Idempotente por contenido: si
/etc/wireguard/<iface>.confya existe con el mismo contenido, retornastatus=already-configuredsin tocar nada. Si el contenido difiere, hace backup automático con timestamp antes de sobreescribir. - NetworkManager: si NM gestiona la interfaz wg0,
wg-quickpuede fallar con conflicto. Solución: crear/etc/NetworkManager/conf.d/99-wg.confcon[keyfile]\nunmanaged-devices=interface-name:wg0y reiniciar NM antes de ejecutar esta función. - WSL2 sin systemd (variantes antiguas o sin
/etc/wsl.confcon[boot] systemd=true):systemctlno está disponible. La función detecta esto, emitestatus=installed-no-systemdcon instrucciones en stderr para levantar la interfaz manualmente consudo wg-quick up wg0. Para autostart en WSL2 sin systemd: añadirsudo wg-quick up wg0al final de~/.bashrc. - WSL2 con systemd: kernel WSL2 >= 5.6 (default en distros recientes) incluye WireGuard built-in. Habilitar systemd en WSL2 con
[boot]\nsystemd=trueen/etc/wsl.confy reiniciar WSL. Luego esta función funciona igual que en Linux nativo. - Android / Termux: NO usar esta función. Termux no tiene systemd ni
/etc/wireguard/. En Android usar la app WireGuard oficial (F-Droid / Play Store) e importar el .conf generado porwg_client_configdirectamente desde la app. - handshake_seen=false con status=installed-no-handshake: la interfaz está activa pero el hub no ha respondido en 10s. No es un error fatal — puede tardar más si el hub está ocupado o hay NAT traversal pendiente. Verificar: endpoint accesible por UDP, hub corriendo con
wg show, claves public/preshared coincidentes. - Los logs van siempre a stderr con prefijo
[wg_client_install]; stdout es exclusivamente el JSON de resultado.