From 047f8eccceaf864373be17c7ba434988841da6dc Mon Sep 17 00:00:00 2001 From: JMARyA Date: Sun, 27 Apr 2025 22:38:44 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20auto=20wlan?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PKGBUILD | 2 +- installs/full.toml | 5 +++++ src/config.rs | 8 ++++++++ src/install/mod.rs | 35 ++++++++++++++++++++++++++++++++++- src/root/wlan.nmconnection | 18 ++++++++++++++++++ 5 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 src/root/wlan.nmconnection diff --git a/PKGBUILD b/PKGBUILD index 8890964..d49c797 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -6,7 +6,7 @@ pkgdesc="navOS Installer" arch=('x86_64' 'aarch64') url="https://git.hydrar.de/navos/navinstall" license=("MIT") -depends=("arch-install-scripts" "git") +depends=("arch-install-scripts" "git" "wpa_supplicant") optdepends=('sbctl' 'sbsigntools' 'archiso') makedepends=("rustup" "git") source=("${pkgname}::git+https://git.hydrar.de/navos/navinstall.git") diff --git a/installs/full.toml b/installs/full.toml index 04c5c4c..d0a45a7 100644 --- a/installs/full.toml +++ b/installs/full.toml @@ -125,3 +125,8 @@ gpu = true models = [ "llama3.1:8b" ] + +# Setup predefined WLAN +[wlan] +ssid = "SSID" +passphrase = "pass" diff --git a/src/config.rs b/src/config.rs index 065ddab..5e83aec 100644 --- a/src/config.rs +++ b/src/config.rs @@ -19,6 +19,14 @@ pub struct InstallConfig { pub ssh: Option, /// Ollama AI Config pub ai: Option, + // WLAN + pub wlan: Option, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct WlanConfig { + pub ssid: String, + pub passphrase: String, } #[derive(Debug, Clone, Deserialize)] diff --git a/src/install/mod.rs b/src/install/mod.rs index 8e365b4..63d37ea 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -50,7 +50,8 @@ pub mod zram; // TODO : Make zsh default + completions use crate::{ - config::InstallConfig, + config::{InstallConfig, WlanConfig}, + linux::run_command, pkg::{self, install_pkgs, pacstrap_at, setup_kernel}, print_status, }; @@ -134,6 +135,33 @@ pub fn setup_pacman(dir: &str, conf: &str) { std::fs::write(dir.join("etc").join("pacman.conf"), content).unwrap(); } +pub fn setup_wlan(wlan: &WlanConfig) { + print_status("Setting base wlan"); + install_pkgs(&["networkmanager"]); + let res = run_command( + &[ + "wpa_passphrase", + wlan.ssid.as_str(), + wlan.passphrase.as_str(), + ], + None, + false, + ) + .0; + let psk = res + .lines() + .find(|x| x.trim().starts_with("psk")) + .map(|x| x.trim_start_matches("psk=").to_string()) + .unwrap(); + std::fs::write( + "/mnt/etc/NetworkManager/system-connections/base.nmconnection", + include_str!("../root/wlan.nmconnection") + .replace("", &psk) + .replace("", &wlan.ssid), + ) + .unwrap(); +} + pub fn install_mnt(conf: InstallConfig, bare: bool) { // Base Install pacstrap_at("/mnt", &conf.pkg.pkg); @@ -151,6 +179,11 @@ pub fn install_mnt(conf: InstallConfig, bare: bool) { // Configuration first_boot_values(&conf.general); + // Setup network + if let Some(wlan) = &conf.wlan { + setup_wlan(wlan); + } + if !matches!(conf.general.mode, crate::config::InstallMode::Base) { setup_navos("/mnt"); } diff --git a/src/root/wlan.nmconnection b/src/root/wlan.nmconnection new file mode 100644 index 0000000..716438e --- /dev/null +++ b/src/root/wlan.nmconnection @@ -0,0 +1,18 @@ +[connection] +id=BaseWiFi +type=wifi +autoconnect=true + +[wifi] +ssid= +mode=infrastructure + +[wifi-security] +key-mgmt=wpa-psk +psk= + +[ipv4] +method=auto + +[ipv6] +method=auto