diff --git a/src/aur.rs b/src/aur.rs index 3350fc5..e165823 100644 --- a/src/aur.rs +++ b/src/aur.rs @@ -3,6 +3,7 @@ use std::str::FromStr; pub struct AurHelper { pub name: String, + pub package_name: String, pub install_command: Vec, } @@ -13,6 +14,7 @@ impl FromStr for AurHelper { match s { "yay" => Ok(AurHelper { name: String::from("yay"), + package_name: String::from("yay-bin"), install_command: vec![ String::from("yay"), String::from("-S"), diff --git a/src/constants.rs b/src/constants.rs index 997ad86..b156ba0 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -10,4 +10,4 @@ SystemMaxUse=16M pub const BASE_PACKAGES: [&str; 1] = ["base"]; // we add go so that it is cached when installing yay -pub const AUR_DEPENDENCIES: [&str; 4] = ["base-devel", "git", "sudo", "go"]; +pub const AUR_DEPENDENCIES: [&str; 3] = ["base-devel", "git", "sudo"]; diff --git a/src/main.rs b/src/main.rs index 4944850..f3be264 100644 --- a/src/main.rs +++ b/src/main.rs @@ -225,7 +225,8 @@ fn create(command: args::CreateCommand) -> anyhow::Result<()> { packages.extend(presets.packages); - if !presets.aur_packages.is_empty() { + let use_aur = !(presets.aur_packages.is_empty() && command.aur_packages.is_empty()); + if use_aur { packages.extend(constants::AUR_DEPENDENCIES.iter().map(|s| String::from(*s))); } @@ -276,7 +277,9 @@ fn create(command: args::CreateCommand) -> anyhow::Result<()> { .run() .context("locale-gen failed")?; - if !presets.aur_packages.is_empty() { + if use_aur { + info!("Installing AUR packages"); + arch_chroot .execute() .arg(mount_point.path()) @@ -284,16 +287,8 @@ fn create(command: args::CreateCommand) -> anyhow::Result<()> { .run() .context("Failed to create temporary user to install AUR packages")?; - arch_chroot - .execute() - .arg(mount_point.path()) - .args(&[ - "sed", - "-i", - "s/# %wheel ALL=(ALL) NOPASSWD: ALL/aur ALL=(ALL) NOPASSWD: ALL/g", - ]) - .arg("/etc/sudoers") - .run() + let aur_sudoers = mount_point.path().join("etc/sudoers.d/aur"); + fs::write(&aur_sudoers, "aur ALL=(ALL) NOPASSWD: ALL") .context("Failed to modify sudoers file for AUR packages")?; arch_chroot @@ -304,7 +299,7 @@ fn create(command: args::CreateCommand) -> anyhow::Result<()> { .arg("clone") .arg(format!( "https://aur.archlinux.org/{}.git", - &command.aur_helper.name + &command.aur_helper.package_name )) .arg(format!("/home/aur/{}", &command.aur_helper.name)) .run() @@ -342,17 +337,7 @@ fn create(command: args::CreateCommand) -> anyhow::Result<()> { .run() .context("Failed to delete temporary aur user")?; - arch_chroot - .execute() - .arg(mount_point.path()) - .args(&[ - "sed", - "-i", - "s/aur ALL=(ALL) NOPASSWD: ALL/# %wheel ALL=(ALL) NOPASSWD: ALL/g", - ]) - .arg("/etc/sudoers") - .run() - .context("Failed to undo sudoers changes")?; + fs::remove_file(&aur_sudoers).context("Cannot delete the AUR sudoers temporary file")?; } if !presets.scripts.is_empty() { info!("Running custom scripts");