feat: andared corporativo stuff

This commit is contained in:
2026-03-22 14:58:29 +01:00
parent cd91e41ba8
commit a0d9c6fbf7
5 changed files with 251 additions and 2 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
hardware-configuration.nix
install-local.nix
*.pdf

61
andared-connect.sh Normal file
View File

@@ -0,0 +1,61 @@
#!/usr/bin/env bash
set -euo pipefail
connection_id="Andared_Corporativo"
eap_method="${1:-auto}"
if ! command -v nmcli >/dev/null 2>&1; then
echo "nmcli no esta disponible en este sistema." >&2
exit 1
fi
ensure_profile() {
if nmcli -t -f NAME connection show | grep -Fxq "$connection_id"; then
return
fi
nmcli connection add \
type wifi \
con-name "$connection_id" \
ifname "*" \
ssid "$connection_id" \
wifi-sec.key-mgmt wpa-eap \
802-1x.phase2-auth gtc \
802-1x.password-flags 2 \
802-1x.system-ca-certs no \
ipv4.method auto \
ipv6.method auto >/dev/null
}
connect_once() {
local method="$1"
nmcli connection modify "$connection_id" \
802-1x.eap "$method" \
802-1x.phase2-auth gtc \
802-1x.password-flags 2 \
802-1x.system-ca-certs no
nmcli --ask connection up "$connection_id"
}
ensure_profile
case "$eap_method" in
auto)
if connect_once ttls; then
exit 0
fi
echo "TTLS ha fallado; probando PEAP..." >&2
connect_once peap
;;
ttls|peap)
connect_once "$eap_method"
;;
*)
echo "Uso: andared-connect [auto|ttls|peap]" >&2
exit 1
;;
esac

View File

@@ -3,6 +3,7 @@
let
username = "usuario";
learningml-desktop = pkgs.callPackage ./pkgs/learningml-desktop.nix { };
andaredConnectScript = pkgs.writeShellScriptBin "andared-connect" (builtins.readFile ./andared-connect.sh);
in
{
imports =
@@ -73,6 +74,40 @@ in
[KDE Control Module Restrictions][$i]
kcm_wallpaper=false
'';
# andared_corporativo network manager settings
"NetworkManager/system-connections/Andared_Corporativo.nmconnection" = {
mode = "0600";
text = ''
[connection]
id=Andared_Corporativo
uuid=9c4ef8e2-f9fc-4a33-b64b-cb79e5e2ca62
type=wifi
permissions=
autoconnect=false
autoconnect-priority=-1
[wifi]
mode=infrastructure
ssid=Andared_Corporativo
[wifi-security]
key-mgmt=wpa-eap
[802-1x]
eap=ttls;
phase2-auth=gtc
password-flags=2
system-ca-certs=false
[ipv4]
method=auto
[ipv6]
addr-gen-mode=default
method=auto
'';
};
};
services.logind.settings.Login = {
@@ -127,6 +162,7 @@ in
# from local repo
learningml-desktop
wireshark
andaredConnectScript
# python stuff goes here
(python314.withPackages (ps: with ps; [

View File

@@ -10,14 +10,21 @@ swap_size="4GiB"
usage() {
cat <<'EOF'
Usage: install.sh DISK [-f|--force] [--swap-size SIZE]
Usage: install.sh DISK [-f|--force] [--swap-size SIZE] [--no-andared]
[--andared-username USER] [--andared-password PASS]
Examples:
sudo ./install.sh /dev/nvme0n1
sudo ./install.sh /dev/sda --swap-size 16GiB
sudo ./install.sh /dev/sda --no-andared
sudo ./install.sh /dev/sda --andared-username usuario --andared-password clave
This script will erase the selected disk, partition it, format it,
clone this repository into /etc/nixos, and install NixOS.
By default the script will prompt for Andared Wi-Fi credentials.
Press Enter on an empty username to skip. Use --no-andared to
suppress the prompt entirely.
EOF
}
@@ -36,6 +43,24 @@ run_git() {
fi
}
prompt_secret() {
local prompt="$1"
local value=""
if [ -c /dev/tty ]; then
printf '%s' "$prompt" > /dev/tty
stty -echo < /dev/tty
IFS= read -r value < /dev/tty || value=""
stty echo < /dev/tty
printf '\n' > /dev/tty
else
echo "Cannot prompt for secrets without /dev/tty." >&2
exit 1
fi
printf '%s' "$value"
}
is_uefi() {
[ -d /sys/firmware/efi/efivars ]
}
@@ -147,11 +172,60 @@ EOF
fi
}
write_andared_connection() {
local username="$1"
local password="$2"
local profile_dir="$target_root/etc/NetworkManager/system-connections"
local profile_path="$profile_dir/Andared_Corporativo-installed.nmconnection"
local old_umask
mkdir -p "$profile_dir"
old_umask="$(umask)"
umask 077
cat > "$profile_path" <<EOF
[connection]
id=Andared_Corporativo (instalado)
uuid=dcf7cfd0-02f7-4df9-8a15-f51cbeb15566
type=wifi
permissions=
autoconnect=true
autoconnect-priority=10
[wifi]
mode=infrastructure
ssid=Andared_Corporativo
[wifi-security]
key-mgmt=wpa-eap
[802-1x]
eap=ttls;
identity=$username
password=$password
phase2-auth=gtc
system-ca-certs=false
[ipv4]
method=auto
[ipv6]
addr-gen-mode=default
method=auto
EOF
chmod 600 "$profile_path"
umask "$old_umask"
}
main() {
require_root
local disk=""
local force=0
local andared_username=""
local andared_password=""
local no_andared=0
while [ "$#" -gt 0 ]; do
case "$1" in
@@ -167,6 +241,26 @@ main() {
swap_size="$2"
shift 2
;;
--andared-username)
if [ "$#" -lt 2 ]; then
echo "Missing value for --andared-username." >&2
exit 1
fi
andared_username="$2"
shift 2
;;
--andared-password)
if [ "$#" -lt 2 ]; then
echo "Missing value for --andared-password." >&2
exit 1
fi
andared_password="$2"
shift 2
;;
--no-andared)
no_andared=1
shift
;;
-h|--help)
usage
exit 0
@@ -184,6 +278,36 @@ main() {
esac
done
if { [ -n "$andared_username" ] && [ -z "$andared_password" ]; } || { [ -z "$andared_username" ] && [ -n "$andared_password" ]; }; then
echo "Provide both --andared-username and --andared-password together." >&2
exit 1
fi
if [ "$no_andared" -eq 0 ] && [ -z "$andared_username" ]; then
if [ -c /dev/tty ]; then
printf '\n' > /dev/tty
printf '┌─────────────────────────────────────────────────────┐\n' > /dev/tty
printf '│ Andared_Corporativo — Wi-Fi del centro educativo │\n' > /dev/tty
printf '│ │\n' > /dev/tty
printf '│ Introduce tu usuario y contraseña para dejar la │\n' > /dev/tty
printf '│ conexión configurada. Pulsa Enter para omitir. │\n' > /dev/tty
printf '└─────────────────────────────────────────────────────┘\n' > /dev/tty
printf '\n' > /dev/tty
printf 'Usuario Andared: ' > /dev/tty
IFS= read -r andared_username < /dev/tty || andared_username=""
if [ -n "$andared_username" ]; then
andared_password="$(prompt_secret 'Contraseña Andared: ')"
if [ -z "$andared_password" ]; then
echo "Se ha introducido un usuario pero no una contraseña. Abortando." >&2
exit 1
fi
fi
else
echo "Nota: no se pueden pedir credenciales Andared sin /dev/tty. Omitiendo." >&2
fi
fi
if [ -z "$disk" ] || [ ! -b "$disk" ]; then
usage
exit 1
@@ -225,6 +349,11 @@ main() {
echo "Installing NixOS from flake $flake_host..."
nixos-install --no-root-passwd --flake "path:$repo_dir#$flake_host"
if [ -n "$andared_username" ] && [ -n "$andared_password" ]; then
echo "Writing Andared Wi-Fi credentials to the installed system..."
write_andared_connection "$andared_username" "$andared_password"
fi
echo
echo "Installation complete."
}

View File

@@ -2,7 +2,29 @@
## instalación
Si el equipo que usas para instalar necesita WiFi corporativa antes de clonar este repo, conecta primero la ISO a `Andared_Corporativo` de forma temporal. En la guía adjunta aparecen los parámetros esperados para Linux/NetworkManager: SSID `Andared_Corporativo`, seguridad enterprise, autenticación con túnel y autenticación interna `GTC`, sin certificado CA.
1. descarga la iso de [nixos mínima](https://nixos.org/download/#nixos-iso) y arranca el ordenador desde ella
2. busca el disco duro en `lsblk`
3. `curl -fsSL https://raw.githubusercontent.com/iesfdlr/lab/main/install.sh | bash -s -- /dev/sda` (reemplaza `/dev/sda` por el disco duro que corresponda)
4. sigue las instrucciones en pantalla
4. sigue las instrucciones en pantalla — el instalador pedirá las credenciales de Andared automáticamente. Pulsa Enter sin escribir nada para omitir este paso.
Para máquinas que no necesitan `Andared_Corporativo`, pasa `--no-andared` para omitir el mensaje directamente:
```
curl -fsSL ... | bash -s -- /dev/sda --no-andared
```
También es posible pasar las credenciales por línea de comandos para automatizar instalaciones (ojo: queda visible en el historial del shell):
```
curl -fsSL ... | bash -s -- /dev/sda --andared-username USUARIO --andared-password CLAVE
```
## andared_corporativo
El sistema instalado deja preparada una conexión de NetworkManager para `Andared_Corporativo` sin usuario ni contraseña guardados en el repositorio.
- En Plasma, basta con abrir el selector de redes, pulsar `Andared_Corporativo` e introducir las credenciales del usuario.
- Alternativamente, desde terminal se puede usar `andared-connect` para que `nmcli` pida las credenciales de forma interactiva.
- Si `TTLS` no funciona en un centro concreto, prueba `andared-connect peap`.