Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/agama-files/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ mod tests {
)
.await;
let handler = Service::starter(progress, questions, software)
.with_scripts_workdir(tmp_dir.path())
.with_workdir(tmp_dir.path())
.with_install_dir(tmp_dir.path())
.start()
.await
Expand Down
23 changes: 16 additions & 7 deletions rust/agama-files/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,22 @@ const NM_RESOLV_CONF_PATH: &str = "run/NetworkManager/resolv.conf";
pub struct ScriptsRunner {
progress: Handler<progress::Service>,
questions: Handler<question::Service>,
root_dir: PathBuf,
install_dir: PathBuf,
workdir: PathBuf,
}

impl ScriptsRunner {
/// Creates a new runner.
///
/// * `root_dir`: root directory of the system.
/// * `install_dir`: directory where the system is being installed. It is relevant for
/// chrooted scripts.
/// * `workdir`: scripts work directory.
/// * `progress`: handler to report the progress.
/// * `questions`: handler to interact with the user.
pub fn new<P: AsRef<Path>>(
root_dir: P,
install_dir: P,
workdir: P,
progress: Handler<progress::Service>,
Expand All @@ -78,6 +81,7 @@ impl ScriptsRunner {
Self {
progress,
questions,
root_dir: root_dir.as_ref().to_path_buf(),
install_dir: install_dir.as_ref().to_path_buf(),
workdir: workdir.as_ref().to_path_buf(),
}
Expand Down Expand Up @@ -228,7 +232,7 @@ impl ScriptsRunner {
///
/// It returns false if the resolv.conf was already linked and no action was required.
fn link_resolv(&self) -> Result<bool, std::io::Error> {
let original = self.install_dir.join(NM_RESOLV_CONF_PATH);
let original = self.root_dir.join(NM_RESOLV_CONF_PATH);
let link = self.resolv_link_path();

if fs::exists(&link)? || !fs::exists(&original)? {
Expand Down Expand Up @@ -291,7 +295,7 @@ mod tests {

let (events_tx, events_rx) = broadcast::channel::<Event>(16);
let install_dir = tmp_dir.path().join("mnt");
let workdir = tmp_dir.path().join("scripts");
let workdir = tmp_dir.path().to_path_buf();
let questions = question::start(events_tx.clone()).await.unwrap();
let progress = progress::Service::starter(events_tx.clone()).start();

Expand All @@ -310,13 +314,18 @@ mod tests {
impl Context {
pub fn runner(&self) -> ScriptsRunner {
ScriptsRunner::new(
self.install_dir.clone(),
self.workdir.clone(),
self.install_dir.clone(),
self.scripts_dir(),
self.progress.clone(),
self.questions.clone(),
)
}

pub fn scripts_dir(&self) -> PathBuf {
self.workdir.join("run/agama/scripts")
}

pub fn setup_script(&self, content: &str, chroot: bool) -> Script {
let base = BaseScript {
name: "test.sh".to_string(),
Expand All @@ -329,14 +338,14 @@ mod tests {
chroot: Some(chroot),
});
script
.write(&self.workdir)
.write(&self.scripts_dir())
.expect("Could not write the script");
script
}

// Set up a fake chroot.
pub fn setup_chroot(&self) -> std::io::Result<()> {
let nm_dir = self.install_dir.join("run/NetworkManager");
let nm_dir = self.workdir.join("run/NetworkManager");
fs::create_dir_all(&nm_dir)?;
fs::create_dir_all(self.install_dir.join("etc"))?;

Expand All @@ -348,7 +357,7 @@ mod tests {

// Return the content of a script result file.
pub fn result_content(&self, script_type: &str, name: &str) -> String {
let path = &self.workdir.join(script_type).join(name);
let path = &self.scripts_dir().join(script_type).join(name);
let body: Vec<u8> = std::fs::read(path).unwrap();
String::from_utf8(body).unwrap()
}
Expand Down Expand Up @@ -448,7 +457,7 @@ mod tests {
});

// Check the generated files
let path = &ctx.workdir.join("post").join("test.stderr");
let path = &ctx.scripts_dir().join("post").join("test.stderr");
let body: Vec<u8> = std::fs::read(path).unwrap();
let body = String::from_utf8(body).unwrap();
assert!(body.contains("agama-unknown"));
Expand Down
18 changes: 11 additions & 7 deletions rust/agama-files/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ pub enum Error {
Actor(#[from] actor::Error),
}

const DEFAULT_SCRIPTS_DIR: &str = "/run/agama/scripts";
const DEFAULT_SCRIPTS_DIR: &str = "run/agama/scripts";
const DEFAULT_WORK_DIR: &str = "/";
const DEFAULT_INSTALL_DIR: &str = "/mnt";

/// Builds and spawns the files service.
///
/// This structs allows to build a files service.
pub struct Starter {
scripts_workdir: PathBuf,
workdir: PathBuf,
install_dir: PathBuf,
software: Handler<software::Service>,
progress: Handler<progress::Service>,
Expand All @@ -76,28 +77,29 @@ impl Starter {
software,
progress,
questions,
scripts_workdir: PathBuf::from(DEFAULT_SCRIPTS_DIR),
workdir: PathBuf::from(DEFAULT_WORK_DIR),
install_dir: PathBuf::from(DEFAULT_INSTALL_DIR),
}
}

/// Starts the service and returns the handler to communicate with it.
pub async fn start(self) -> Result<Handler<Service>, Error> {
let scripts = ScriptsRepository::new(self.scripts_workdir);
let scripts = ScriptsRepository::new(self.workdir.join(DEFAULT_SCRIPTS_DIR));
let service = Service {
progress: self.progress,
questions: self.questions,
software: self.software,
scripts: Arc::new(Mutex::new(scripts)),
files: vec![],
install_dir: self.install_dir,
root_dir: self.workdir,
};
let handler = actor::spawn(service);
Ok(handler)
}

pub fn with_scripts_workdir<P: AsRef<Path>>(mut self, workdir: P) -> Self {
self.scripts_workdir = PathBuf::from(workdir.as_ref());
pub fn with_workdir<P: AsRef<Path>>(mut self, workdir: P) -> Self {
self.workdir = PathBuf::from(workdir.as_ref());
self
}

Expand All @@ -114,6 +116,7 @@ pub struct Service {
scripts: Arc<Mutex<ScriptsRepository>>,
files: Vec<UserFile>,
install_dir: PathBuf,
root_dir: PathBuf,
}

impl Service {
Expand Down Expand Up @@ -198,14 +201,15 @@ impl MessageHandler<message::RunScripts> for Service {
async fn handle(&mut self, message: message::RunScripts) -> Result<(), Error> {
let scripts = self.scripts.clone();
let install_dir = self.install_dir.clone();
let root_dir = self.root_dir.clone();
let progress = self.progress.clone();
let questions = self.questions.clone();

tokio::task::spawn(async move {
let scripts = scripts.lock().await;
let workdir = scripts.workdir.clone();
let to_run = scripts.by_group(message.group).clone();
let runner = ScriptsRunner::new(install_dir, workdir, progress, questions);
let runner = ScriptsRunner::new(root_dir, install_dir, workdir, progress, questions);
runner.run(&to_run).await.unwrap();
});
Ok(())
Expand Down
6 changes: 6 additions & 0 deletions rust/package/agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Tue Feb 3 07:23:18 UTC 2026 - Knut Anderssen <kanderssen@suse.com>

- Correct the /etc/resolv.conf link in the chroot to
/run/NetworkManager/resolv.conf (bsc#257468).

-------------------------------------------------------------------
Mon Feb 2 11:56:24 UTC 2026 - Ladislav Slezák <lslezak@suse.com>

Expand Down
Loading