Add -p and -i (fix #2 fix #11)

This commit is contained in:
Roey Darwish Dror 2018-11-04 17:04:42 +02:00
parent a76b6aff0c
commit e956dc51c0
2 changed files with 22 additions and 12 deletions

View File

@ -48,6 +48,9 @@ pub enum ErrorKind {
#[fail(display = "Error calling sync")] #[fail(display = "Error calling sync")]
Sync, Sync,
#[fail(display = "Error caused by the interactive mode")]
Interactive,
} }
impl Fail for Error { impl Fail for Error {

View File

@ -43,23 +43,21 @@ SystemMaxUse=16M
enum App { enum App {
#[structopt(name = "create", about = "Create a new Arch Linux USB")] #[structopt(name = "create", about = "Create a new Arch Linux USB")]
Create { Create {
#[structopt( /// Path starting with /dev/disk/by-id for the USB drive
parse(from_os_str), #[structopt(parse(from_os_str),)]
help = "Path starting with /dev/disk/by-id for the USB drive"
)]
disk: PathBuf, disk: PathBuf,
#[structopt( /// Additional pacakges to install
short = "p", #[structopt(short = "p", long = "extra-packages", value_name = "package",)]
long = "extra-packages",
value_name = "package",
help = "Additional pacakges to install"
)]
extra_packages: Vec<String>, extra_packages: Vec<String>,
/// Enter interactive chroot before unmounting the drive
#[structopt(short = "i", long = "interactive")]
interactive: bool,
}, },
} }
fn create(disk: PathBuf, extra_packages: Vec<String>) -> Result<(), Error> { fn create(disk: PathBuf, extra_packages: Vec<String>, interactive: bool) -> Result<(), Error> {
let sgdisk = Tool::find("sgdisk")?; let sgdisk = Tool::find("sgdisk")?;
let sync = Tool::find("sync")?; let sync = Tool::find("sync")?;
let pacstrap = Tool::find("pacstrap")?; let pacstrap = Tool::find("pacstrap")?;
@ -183,6 +181,14 @@ fn create(disk: PathBuf, extra_packages: Vec<String>) -> Result<(), Error> {
.arg(format!("grub-install --target=i386-pc --boot-directory /boot {} && grub-install --target=x86_64-efi --efi-directory /boot --boot-directory /boot --removable && grub-mkconfig -o /boot/grub/grub.cfg", disk.display())) .arg(format!("grub-install --target=i386-pc --boot-directory /boot {} && grub-install --target=x86_64-efi --efi-directory /boot --boot-directory /boot --removable && grub-mkconfig -o /boot/grub/grub.cfg", disk.display()))
.run(ErrorKind::Bootloader)?; .run(ErrorKind::Bootloader)?;
if interactive {
info!("Dropping you to chroot. Do as you wish to customize the installation");
arch_chroot
.execute()
.arg(mount_point.path())
.run(ErrorKind::Interactive)?;
}
info!("Unmounting filesystems"); info!("Unmounting filesystems");
drop(mount_stack); drop(mount_stack);
sync.execute().run(ErrorKind::Sync)?; sync.execute().run(ErrorKind::Sync)?;
@ -216,7 +222,8 @@ fn main() {
App::Create { App::Create {
disk, disk,
extra_packages, extra_packages,
} => create(disk, extra_packages), interactive,
} => create(disk, extra_packages, interactive),
}; };
match result { match result {