mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +00:00
Feature/wifi sync (#446)
* Synchronizes Wifi config during the 'embassy-init' startup sequence * Apply suggestions from code review make directories polymorphic over AsRef Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com> * make resilient to existing symlink * make this more idiomatic Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com> Co-authored-by: Aiden McClelland <me@drbonez.dev>
This commit is contained in:
committed by
Aiden McClelland
parent
c91790d1eb
commit
561e09016d
@@ -110,6 +110,7 @@ async fn init(cfg_path: Option<&str>) -> Result<(), Error> {
|
||||
.await?;
|
||||
}
|
||||
log::info!("Enabled nginx public dir");
|
||||
embassy::net::wifi::synchronize_wpa_supplicant_conf(&cfg.datadir().join("main")).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
|
||||
use clap::ArgMatches;
|
||||
@@ -517,6 +518,21 @@ pub fn country_code_parse(code: &str, _matches: &ArgMatches<'_>) -> Result<Count
|
||||
)))
|
||||
}
|
||||
|
||||
pub async fn synchronize_wpa_supplicant_conf<P: AsRef<Path>>(main_datadir: P) -> Result<(), Error> {
|
||||
let target = main_datadir.as_ref().join("wpa_supplicant.conf");
|
||||
if tokio::fs::metadata(&target).await.is_err() {
|
||||
tokio::fs::write(&target, include_str!("wpa_supplicant.conf.base")).await?;
|
||||
}
|
||||
let link = Path::new("/etc/wpa_supplicant.conf");
|
||||
if let Ok(meta) = tokio::fs::symlink_metadata(&link).await {
|
||||
if meta.file_type().is_symlink() {
|
||||
tokio::fs::remove_file(&link).await?
|
||||
}
|
||||
}
|
||||
tokio::fs::symlink(&target, link).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
pub async fn test_interface_connected() {
|
||||
println!("{}", interface_connected("wlp5s0").await.unwrap());
|
||||
|
||||
3
appmgr/src/net/wpa_supplicant.conf.base
Normal file
3
appmgr/src/net/wpa_supplicant.conf.base
Normal file
@@ -0,0 +1,3 @@
|
||||
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
|
||||
update_config=1
|
||||
country=US
|
||||
Reference in New Issue
Block a user