Rework partitioning functions

axtloss/rework-partitioning
axtloss 2 years ago
parent b7b1d38cc8
commit 8cd714f537
No known key found for this signature in database
GPG Key ID: DD6D66939396C90E

@ -64,10 +64,6 @@ pub enum Command {
#[clap(name = "flatpak")] #[clap(name = "flatpak")]
Flatpak, Flatpak,
/// Setup Unakite
#[clap(name = "unakite")]
Unakite(UnakiteArgs),
/// Read Jade installation config /// Read Jade installation config
#[clap(name = "config")] #[clap(name = "config")]
Config { Config {
@ -99,9 +95,6 @@ pub struct PartitionArgs {
#[clap(long)] #[clap(long)]
pub efi: bool, pub efi: bool,
#[clap(long)]
pub unakite: bool,
/// The partitions to use for manual partitioning /// The partitions to use for manual partitioning
#[clap(required_if_eq("mode", "Partition::Manual"), parse(try_from_str = parse_partitions))] #[clap(required_if_eq("mode", "Partition::Manual"), parse(try_from_str = parse_partitions))]
pub partitions: Vec<Partition>, pub partitions: Vec<Partition>,
@ -113,25 +106,6 @@ pub struct InstallBaseArgs {
pub kernel: String, pub kernel: String,
} }
#[derive(Debug, Args)]
pub struct UnakiteArgs {
/// Root device of Unakite
#[clap(long)]
pub root: String,
/// Root device of Crystal
#[clap(long)]
pub oldroot: String,
/// Whether the system is an EFI system
#[clap(long)]
pub efi: bool,
/// Boot directory (if not EFI), or EFI directory
#[clap(long)]
pub efidir: String,
/// Blockdev of boot device
#[clap(long)]
pub bootdev: String,
}
#[derive(Debug)] #[derive(Debug)]
pub struct Partition { pub struct Partition {
pub mountpoint: String, pub mountpoint: String,

@ -3,5 +3,4 @@ pub mod desktops;
pub mod locale; pub mod locale;
pub mod network; pub mod network;
pub mod partition; pub mod partition;
pub mod unakite;
pub mod users; pub mod users;

@ -1,6 +1,7 @@
use crate::args; use crate::args;
use crate::args::PartitionMode; use crate::args::PartitionMode;
use crate::internal::exec::*; use crate::internal::exec::*;
use crate::internal::files::create_directory;
use crate::internal::*; use crate::internal::*;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -88,7 +89,6 @@ pub fn partition(
mode: PartitionMode, mode: PartitionMode,
efi: bool, efi: bool,
partitions: &mut Vec<args::Partition>, partitions: &mut Vec<args::Partition>,
unakite: bool,
) { ) {
println!("{:?}", mode); println!("{:?}", mode);
match mode { match mode {
@ -97,18 +97,23 @@ pub fn partition(
crash(format!("The device {device:?} doesn't exist"), 1); crash(format!("The device {device:?} doesn't exist"), 1);
} }
log::debug!("automatically partitioning {device:?}"); log::debug!("automatically partitioning {device:?}");
if efi { create_partitions(&device, efi);
partition_with_efi(&device, unakite);
} else { let part1: String; // This is probably a horrible way of doing this, but the borrow checker is annoying
partition_no_efi(&device, unakite); let part2: String;
} let partitions: Vec<&str> = if device.to_string_lossy().contains("nvme")
if device.to_string_lossy().contains("nvme")
|| device.to_string_lossy().contains("mmcblk") || device.to_string_lossy().contains("mmcblk")
{ {
part_nvme(&device, efi, unakite); part1 = format!("{}p1", device.to_string_lossy());
part2 = format!("{}p2", device.to_string_lossy());
vec![part1.as_str(), part2.as_str()]
} else { } else {
part_disk(&device, efi, unakite); part1 = format!("{}1", device.to_string_lossy());
} part2 = format!("{}2", device.to_string_lossy());
vec![part1.as_str(), part2.as_str()]
};
auto_format(partitions);
mount_disks(efi);
} }
PartitionMode::Manual => { PartitionMode::Manual => {
log::debug!("Manual partitioning"); log::debug!("Manual partitioning");
@ -129,7 +134,7 @@ pub fn partition(
} }
} }
fn partition_no_efi(device: &Path, unakite: bool) { fn create_partitions(device: &Path, efi: bool) {
let device = device.to_string_lossy().to_string(); let device = device.to_string_lossy().to_string();
exec_eval( exec_eval(
exec( exec(
@ -138,27 +143,17 @@ fn partition_no_efi(device: &Path, unakite: bool) {
String::from("-s"), String::from("-s"),
String::from(&device), String::from(&device),
String::from("mklabel"), String::from("mklabel"),
String::from("msdos"), String::from(if efi { "gpt" } else { "msdos" }),
], ],
), ),
format!("Create msdos label on {}", device).as_str(), format!(
"Create {} label on {}",
if efi { "gpt" } else { "msdos" },
device
)
.as_str(),
); );
exec_eval( if efi {
exec(
"parted",
vec![
String::from("-s"),
String::from(&device),
String::from("mkpart"),
String::from("primary"),
String::from("ext4"),
String::from("1MIB"),
String::from("512MIB"),
],
),
"create bios boot partition",
);
if unakite {
exec_eval( exec_eval(
exec( exec(
"parted", "parted",
@ -166,28 +161,12 @@ fn partition_no_efi(device: &Path, unakite: bool) {
String::from("-s"), String::from("-s"),
String::from(&device), String::from(&device),
String::from("mkpart"), String::from("mkpart"),
String::from("primary"), String::from("fat32"),
String::from("btrfs"), String::from("0"),
String::from("512MIB"), String::from("300"),
String::from("10048MIB"),
],
),
"create btrfs Unakite root partition",
);
exec_eval(
exec(
"parted",
vec![
String::from("-s"),
device,
String::from("mkpart"),
String::from("primary"),
String::from("btrfs"),
String::from("10048MIB"),
String::from("100%"),
], ],
), ),
"create btrfs Crystal root partition", "create EFI partition",
); );
} else { } else {
exec_eval( exec_eval(
@ -195,507 +174,104 @@ fn partition_no_efi(device: &Path, unakite: bool) {
"parted", "parted",
vec![ vec![
String::from("-s"), String::from("-s"),
device, String::from(&device),
String::from("mkpart"), String::from("mkpart"),
String::from("primary"), String::from("primary"),
String::from("btrfs"), String::from("ext4"),
String::from("1MIB"),
String::from("512MIB"), String::from("512MIB"),
String::from("100%"),
], ],
), ),
"create btrfs root partition", "create bios boot partition",
); );
} }
}
fn partition_with_efi(device: &Path, unakite: bool) {
let device = device.to_string_lossy().to_string();
exec_eval( exec_eval(
exec( exec(
"parted", "parted",
vec![ vec![
String::from("-s"), String::from("-s"),
String::from(&device), device,
String::from("mklabel"), String::from("mkpart"),
String::from("gpt"), String::from("primary"),
String::from("btrfs"),
String::from("512MIB"),
String::from("100%"),
], ],
), ),
format!("create gpt label on {}", &device).as_str(), "create btrfs root partition",
); );
}
fn auto_format(partitions: Vec<&str>) {
exec_eval( exec_eval(
exec( exec(
"parted", "mkfs.vfat",
vec![ vec![
String::from("-s"), "-F32".to_string(),
String::from(&device), "-n".to_string(),
String::from("mkpart"), "CYRSTAL_EFI".to_string(),
String::from("fat32"), partitions[0].to_string(),
String::from("0"),
String::from("300"),
], ],
), ),
"create EFI partition", format!("format {} as fat32 with label CRYSTAL_EFI", partitions[0]).as_str(),
);
exec_eval(
exec(
"mkfs.btfrs",
vec![
"-f".to_string(),
"-L".to_string(),
"CRYSTAL_ROOT".to_string(),
partitions[1].to_string(),
],
),
format!("format {} as btrfs with label CRYSTAL_ROOT", partitions[1]).as_str(),
); );
if unakite {
exec_eval(
exec(
"parted",
vec![
String::from("-s"),
String::from(&device),
String::from("mkpart"),
String::from("primary"),
String::from("btrfs"),
String::from("512MIB"),
String::from("10048MIB"),
],
),
"create btrfs Unakite root partition",
);
exec_eval(
exec(
"parted",
vec![
String::from("-s"),
device,
String::from("mkpart"),
String::from("primary"),
String::from("btrfs"),
String::from("10048MIB"),
String::from("100%"),
],
),
"create btrfs Crystal root partition",
);
} else {
exec_eval(
exec(
"parted",
vec![
String::from("-s"),
device,
String::from("mkpart"),
String::from("primary"),
String::from("btrfs"),
String::from("512MIB"),
String::from("100%"),
],
),
"create btrfs root partition",
);
}
}
fn part_nvme(device: &Path, efi: bool, unakite: bool) {
let device = device.to_string_lossy().to_string();
if efi && !unakite {
exec_eval(
exec(
"mkfs.vfat",
vec![String::from("-F32"), format!("{}p1", device)],
),
format!("format {}p1 as fat32", device).as_str(),
);
exec_eval(
exec(
"mkfs.btrfs",
vec!["-f".to_string(), format!("{}p2", device)],
),
format!("format {}p2 as btrfs", device).as_str(),
);
mount(format!("{}p2", device).as_str(), "/mnt", "");
exec_eval(
exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@"),
],
),
"Create btrfs subvolume @",
);
exec_eval(
exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@home"),
],
),
"Create btrfs subvolume @home",
);
umount("/mnt");
mount(format!("{}p2", device).as_str(), "/mnt/", "subvol=@");
files_eval(files::create_directory("/mnt/boot"), "create /mnt/boot");
files_eval(
files::create_directory("/mnt/boot/efi"),
"create /mnt/boot/efi",
);
files_eval(files::create_directory("/mnt/home"), "create /mnt/home");
mount(
format!("{}p2", device).as_str(),
"/mnt/home",
"subvol=@home",
);
mount(format!("{}p1", device).as_str(), "/mnt/boot/efi", "");
} else if !efi && !unakite {
exec_eval(
exec("mkfs.ext4", vec![format!("{}p1", device)]),
format!("format {}p1 as ext4", device).as_str(),
);
exec_eval(
exec(
"mkfs.btrfs",
vec!["-f".to_string(), format!("{}p2", device)],
),
format!("format {}p2 as btrfs", device).as_str(),
);
mount(format!("{}p2", device).as_str(), "/mnt/", "");
exec_eval(
exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@"),
],
),
"Create btrfs subvolume @",
);
exec_eval(
exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@home"),
],
),
"Create btrfs subvolume @home",
);
umount("/mnt");
mount(format!("{}p2", device).as_str(), "/mnt/", "subvol=@");
files_eval(files::create_directory("/mnt/boot"), "create /mnt/boot");
files_eval(files::create_directory("/mnt/home"), "create /mnt/home");
mount(
format!("{}p2", device).as_str(),
"/mnt/home",
"subvol=@home",
);
mount(format!("{}p1", device).as_str(), "/mnt/boot", "");
} else if efi && unakite {
exec_eval(
exec(
"mkfs.vfat",
vec![String::from("-F32"), format!("{}p1", device)],
),
format!("format {}p1 as fat32", device).as_str(),
);
exec_eval(
exec(
"mkfs.btrfs",
vec!["-f".to_string(), format!("{}p2", device)],
),
format!("format {}p2 as btrfs", device).as_str(),
);
exec_eval(
exec(
"mkfs.btrfs",
vec!["-f".to_string(), format!("{}p3", device)],
),
format!("format {}p3 as btrfs", device).as_str(),
);
mount(format!("{}p3", device).as_str(), "/mnt", "");
exec_eval(
exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@"),
],
),
"Create btrfs subvolume @",
);
exec_eval(
exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@home"),
],
),
"Create btrfs subvolume @home",
);
umount("/mnt");
mount(format!("{}p3", device).as_str(), "/mnt/", "subvol=@");
files_eval(files::create_directory("/mnt/boot"), "create /mnt/boot");
files_eval(
files::create_directory("/mnt/boot/efi"),
"create /mnt/boot/efi",
);
files_eval(files::create_directory("/mnt/home"), "create /mnt/home");
mount(
format!("{}p3", device).as_str(),
"/mnt/home",
"subvol=@home",
);
mount(format!("{}p1", device).as_str(), "/mnt/boot/efi", "");
} else if !efi && unakite {
exec_eval(
exec("mkfs.ext4", vec![format!("{}p1", device)]),
format!("format {}p1 as ext4", device).as_str(),
);
exec_eval(
exec(
"mkfs.btrfs",
vec!["-f".to_string(), format!("{}p2", device)],
),
format!("format {}p2 as btrfs", device).as_str(),
);
mount(format!("{}p2", device).as_str(), "/mnt/", "");
exec_eval(
exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@"),
],
),
"Create btrfs subvolume @",
);
exec_eval(
exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@home"),
],
),
"Create btrfs subvolume @home",
);
umount("/mnt");
mount(format!("{}p2", device).as_str(), "/mnt/", "subvol=@");
files_eval(files::create_directory("/mnt/boot"), "create /mnt/boot");
files_eval(files::create_directory("/mnt/home"), "create /mnt/home");
mount(
format!("{}p2", device).as_str(),
"/mnt/home",
"subvol=@home",
);
mount(format!("{}p1", device).as_str(), "/mnt/boot", "");
}
} }
fn part_disk(device: &Path, efi: bool, unakite: bool) { fn mount_disks(efi: bool) {
let device = device.to_string_lossy().to_string(); mount("/dev/disk/by-label/CRYSTAL_ROOT", "/mnt", "");
if efi && !unakite { exec_eval(
exec_eval( exec_workdir(
exec( "btrfs",
"mkfs.vfat", "/mnt",
vec![String::from("-F32"), format!("{}1", device)], vec![
), String::from("subvolume"),
format!("format {}1 as fat32", device).as_str(), String::from("create"),
); String::from("@"),
exec_eval( ],
exec("mkfs.btrfs", vec!["-f".to_string(), format!("{}2", device)]), ),
format!("format {}2 as btrfs", device).as_str(), "create btrfs subvolume @",
); );
mount(format!("{}2", device).as_str(), "/mnt", ""); exec_eval(
exec_eval( exec_workdir(
exec_workdir( "btrfs",
"btrfs", "/mnt",
"/mnt", vec![
vec![ String::from("subvolume"),
String::from("subvolume"), String::from("create"),
String::from("create"), String::from("@home"),
String::from("@"), ],
], ),
), "create btrfs subvolume @home",
"Create btrfs subvolume @", );
); umount("/mnt");
exec_eval( mount("/dev/disk/by-label/CRYSTAL_ROOT", "/mnt", "subvol=@");
exec_workdir( files_eval(create_directory("/mnt/home"), "create directory /mnt/home");
"btrfs", mount(
"/mnt", "/dev/disk/by-label/CRYSTAL_ROOT",
vec![ "/mnt/home",
String::from("subvolume"), "subvol=@home",
String::from("create"), );
String::from("@home"), files_eval(create_directory("/mnt/boot"), "create directory /mnt/boot");
], if efi {
),
"Create btrfs subvolume @home",
);
umount("/mnt");
mount(format!("{}2", device).as_str(), "/mnt/", "subvol=@");
files_eval(files::create_directory("/mnt/boot"), "create /mnt/boot");
files_eval(
files::create_directory("/mnt/boot/efi"),
"create /mnt/boot/efi",
);
files_eval(files::create_directory("/mnt/home"), "create /mnt/home");
mount(format!("{}2", device).as_str(), "/mnt/home", "subvol=@home");
mount(format!("{}1", device).as_str(), "/mnt/boot/efi", "");
} else if !efi && !unakite {
exec_eval(
exec("mkfs.ext4", vec![format!("{}1", device)]),
format!("format {}1 as ext4", device).as_str(),
);
exec_eval(
exec("mkfs.btrfs", vec!["-f".to_string(), format!("{}2", device)]),
format!("format {}2 as btrfs", device).as_str(),
);
mount(format!("{}2", device).as_str(), "/mnt/", "");
exec_eval(
exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@"),
],
),
"Create btrfs subvolume @",
);
exec_eval(
exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@home"),
],
),
"create btrfs subvolume @home",
);
umount("/mnt");
mount(format!("{}2", device).as_str(), "/mnt/", "subvol=@");
files_eval(
files::create_directory("/mnt/boot"),
"create directory /mnt/boot",
);
files_eval(
files::create_directory("/mnt/home"),
"create directory /mnt/home",
);
mount(format!("{}2", device).as_str(), "/mnt/home", "subvol=@home");
mount(format!("{}1", device).as_str(), "/mnt/boot", "");
} else if efi && unakite {
exec_eval(
exec(
"mkfs.vfat",
vec![String::from("-F32"), format!("{}1", device)],
),
format!("format {}1 as fat32", device).as_str(),
);
exec_eval(
exec("mkfs.btrfs", vec!["-f".to_string(), format!("{}2", device)]),
format!("format {}2 as btrfs", device).as_str(),
);
exec_eval(
exec("mkfs.btrfs", vec!["-f".to_string(), format!("{}3", device)]),
format!("format {}3 as btrfs", device).as_str(),
);
mount(format!("{}3", device).as_str(), "/mnt", "");
exec_eval(
exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@"),
],
),
"Create btrfs subvolume @",
);
exec_eval(
exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@home"),
],
),
"Create btrfs subvolume @home",
);
umount("/mnt");
mount(format!("{}3", device).as_str(), "/mnt/", "subvol=@");
files_eval(files::create_directory("/mnt/boot"), "create /mnt/boot");
files_eval(
files::create_directory("/mnt/boot/efi"),
"create /mnt/boot/efi",
);
files_eval(files::create_directory("/mnt/home"), "create /mnt/home");
mount(format!("{}3", device).as_str(), "/mnt/home", "subvol=@home");
mount(format!("{}1", device).as_str(), "/mnt/boot/efi", "");
} else if !efi && unakite {
exec_eval(
exec("mkfs.ext4", vec![format!("{}1", device)]),
format!("format {}1 as ext4", device).as_str(),
);
exec_eval(
exec("mkfs.btrfs", vec!["-f".to_string(), format!("{}2", device)]),
format!("format {}2 as btrfs", device).as_str(),
);
exec_eval(
exec("mkfs.btrfs", vec!["-f".to_string(), format!("{}3", device)]),
format!("format {}3 as btrfs", device).as_str(),
);
mount(format!("{}3", device).as_str(), "/mnt/", "");
exec_eval(
exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@"),
],
),
"Create btrfs subvolume @",
);
exec_eval(
exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@home"),
],
),
"create btrfs subvolume @home",
);
umount("/mnt");
mount(format!("{}3", device).as_str(), "/mnt/", "subvol=@");
files_eval(
files::create_directory("/mnt/boot"),
"create directory /mnt/boot",
);
files_eval( files_eval(
files::create_directory("/mnt/home"), create_directory("/mnt/boot/efi"),
"create directory /mnt/home", "create directory /mnt/boot/efi",
); );
mount(format!("{}3", device).as_str(), "/mnt/home", "subvol=@home"); mount("/dev/disk/by-label/CRYSTAL_EFI", "/mnt/boot/efi", "");
mount(format!("{}1", device).as_str(), "/mnt/boot", ""); } else {
mount("/dev/disk/by-label/CRYSTAL_BOOT", "/mnt/boot", "");
} }
} }

@ -1,180 +0,0 @@
use crate::args::DesktopSetup;
use crate::functions::partition::mount;
use crate::functions::*;
use crate::internal::exec::*;
use crate::internal::*;
use std::path::PathBuf;
pub fn install_bootloader_efi(efidir: PathBuf) {
install::install(vec![
"grub",
"efibootmgr",
"grub-btrfs",
"crystal-grub-theme",
]);
let efidir = std::path::Path::new("/mnt").join(efidir);
let efi_str = efidir.to_str().unwrap();
if !std::path::Path::new(&format!("/mnt{efi_str}")).exists() {
crash(format!("The efidir {efidir:?} doesn't exist"), 1);
}
exec_eval(
exec_chroot(
"grub-install",
vec![
String::from("--target=x86_64-efi"),
format!("--efi-directory={}", efi_str),
String::from("--bootloader-id=unakite"),
String::from("--removable"),
],
),
"install unakite grub as efi with --removable",
);
exec_eval(
exec_chroot(
"grub-install",
vec![
String::from("--target=x86_64-efi"),
format!("--efi-directory={}", efi_str),
String::from("--bootloader-id=unakite"),
],
),
"install unakite grub as efi without --removable",
);
files_eval(
files::append_file(
"/mnt/etc/default/grub",
"GRUB_THEME=\"/usr/share/grub/themes/crystal/theme.txt\"",
),
"enable crystal grub theme",
);
exec_eval(
exec_chroot(
"grub-mkconfig",
vec![String::from("-o"), String::from("/boot/grub/grub.cfg")],
),
"create grub.cfg",
);
}
pub fn remount(root: &str, oldroot: &str, efi: bool, efidir: &str, bootdev: &str, firstrun: bool) {
if efi && firstrun {
exec_eval(
exec("umount", vec![String::from(bootdev)]),
&format!("Unmount {}", bootdev),
);
exec_eval(
exec("umount", vec![String::from(oldroot)]),
"Unmount old root",
);
mount(root, "/mnt", "");
exec_eval(
exec("mkdir", vec![String::from("-p"), String::from(efidir)]),
format!("Creating mountpoint {efidir} for {bootdev}").as_str(),
);
mount(bootdev, efidir, "");
} else if efi && !firstrun {
exec_eval(
exec("umount", vec![String::from(bootdev)]),
&format!("Unmount {}", bootdev),
);
exec_eval(
exec("umount", vec![String::from(root)]),
"Unmount unakite root",
);
mount(oldroot, "/mnt", "");
mount(bootdev, efidir, "");
} else if !efi && firstrun {
exec_eval(
exec("umount", vec![String::from(bootdev)]),
&format!("Unmount {}", bootdev),
);
exec_eval(
exec("umount", vec![String::from(oldroot)]),
"Unmount old root",
);
mount(root, "/mnt", "");
exec_eval(
exec("mkdir", vec![String::from("-p"), String::from("/mnt/boot")]),
format!("Creating mountpoint /boot for {bootdev}").as_str(),
);
mount(bootdev, "/mnt/boot", "");
} else if !efi && !firstrun {
exec_eval(
exec("umount", vec![String::from(bootdev)]),
&format!("Unmount {}", bootdev),
);
exec_eval(
exec("umount", vec![String::from(root)]),
"Unmount unakite root",
);
mount(oldroot, "/mnt", "");
mount(bootdev, "/mnt/boot", "");
} else {
panic!("Unknown state");
}
}
pub fn setup_unakite(root: &str, oldroot: &str, efi: bool, efidir: &str, bootdev: &str) {
log::debug!("Setting up Unakite");
remount(root, oldroot, efi, efidir, bootdev, true);
base::install_base_packages("linux".to_string());
base::genfstab();
locale::set_locale("en_US.UTF-8 UTF-8".to_string());
locale::set_timezone("Europe/Berlin"); // TODO: get the proper timezone
network::set_hostname("unakite");
network::create_hosts();
users::new_user(
"unakite",
true,
"Cp7oN04ZY0PsA", // unakite
false,
"/bin/bash",
);
exec_eval(
exec(
"sed",
vec![
String::from("-i"),
String::from("-e"),
String::from("s/crystal/unakite/g"),
String::from("/mnt/etc/os-release"),
],
),
"Change os-release",
);
exec_eval(
exec(
"sed",
vec![
String::from("-i"),
String::from("-e"),
String::from("s/Crystal/Unakite/g"),
String::from("/mnt/etc/os-release"),
],
),
"Change os-release",
);
if efi {
install_bootloader_efi(PathBuf::from(efidir.replace("/mnt", "")));
}
users::root_pass("Cp7oN04ZY0PsA"); // unakite
desktops::install_desktop_setup(DesktopSetup::Xfce);
install(vec!["gparted", "firefox"]);
exec_eval(
exec(
"cp",
vec![
String::from("/tmp/jade.json"),
String::from("/mnt/etc/installSettings.json"),
],
),
"Copy jade.json to /etc/installSettings.json in unakite",
);
remount(root, oldroot, efi, efidir, bootdev, false);
exec_eval(
exec_chroot(
"grub-mkconfig",
vec![String::from("-o"), String::from("/boot/grub/grub.cfg")],
),
"Recreate grub.cfg in crystal",
);
}

@ -18,7 +18,6 @@ struct Config {
flatpak: bool, flatpak: bool,
zramd: bool, zramd: bool,
extra_packages: Vec<String>, extra_packages: Vec<String>,
unakite: Unakite,
kernel: String, kernel: String,
} }
@ -57,15 +56,6 @@ struct Users {
shell: String, shell: String,
} }
#[derive(Serialize, Deserialize)]
struct Unakite {
enable: bool,
root: String,
oldroot: String,
efidir: String,
bootdev: String,
}
pub fn read_config(configpath: PathBuf) { pub fn read_config(configpath: PathBuf) {
let data = std::fs::read_to_string(&configpath); let data = std::fs::read_to_string(&configpath);
match &data { match &data {
@ -107,7 +97,6 @@ pub fn read_config(configpath: PathBuf) {
config.partition.mode, config.partition.mode,
config.partition.efi, config.partition.efi,
&mut partitions, &mut partitions,
config.unakite.enable,
); );
base::install_base_packages(config.kernel); base::install_base_packages(config.kernel);
base::genfstab(); base::genfstab();
@ -199,69 +188,5 @@ pub fn read_config(configpath: PathBuf) {
extra_packages.push(config.extra_packages[i].as_str()); extra_packages.push(config.extra_packages[i].as_str());
} }
install(extra_packages); install(extra_packages);
log::info!("Setup unakite");
if config.partition.mode == PartitionMode::Auto
&& !config.partition.efi
&& config.unakite.enable
&& !config.partition.device.to_string().contains("nvme")
{
let root = PathBuf::from("/dev/").join(config.partition.device.as_str());
unakite::setup_unakite(
format!("{}2", root.to_str().unwrap()).as_str(),
format!("{}3", root.to_str().unwrap()).as_str(),
config.partition.efi,
"/boot",
format!("{}1", root.to_str().unwrap()).as_str(),
)
} else if config.partition.mode == PartitionMode::Auto
&& config.partition.efi
&& config.unakite.enable
&& !config.partition.device.to_string().contains("nvme")
{
let root = PathBuf::from("/dev/").join(config.partition.device.as_str());
unakite::setup_unakite(
format!("{}2", root.to_str().unwrap()).as_str(),
format!("{}3", root.to_str().unwrap()).as_str(),
config.partition.efi,
"/boot/efi",
format!("{}1", root.to_str().unwrap()).as_str(),
)
} else if config.unakite.enable {
unakite::setup_unakite(
&config.unakite.root,
&config.unakite.oldroot,
config.partition.efi,
&config.unakite.efidir,
&config.unakite.bootdev,
);
} else if config.partition.mode == PartitionMode::Auto
&& config.partition.efi
&& config.unakite.enable
&& config.partition.device.to_string().contains("nvme")
{
let root = PathBuf::from("/dev/").join(config.partition.device.as_str());
unakite::setup_unakite(
format!("{}p2", root.to_str().unwrap()).as_str(),
format!("{}p3", root.to_str().unwrap()).as_str(),
config.partition.efi,
"/boot/efi",
format!("{}p1", root.to_str().unwrap()).as_str(),
)
} else if config.partition.mode == PartitionMode::Auto
&& !config.partition.efi
&& config.unakite.enable
&& config.partition.device.to_string().contains("nvme")
{
let root = PathBuf::from("/dev/").join(config.partition.device.as_str());
unakite::setup_unakite(
format!("{}p2", root.to_str().unwrap()).as_str(),
format!("{}p3", root.to_str().unwrap()).as_str(),
config.partition.efi,
"/boot",
format!("{}p1", root.to_str().unwrap()).as_str(),
)
} else {
log::info!("Unakite disabled");
}
println!("Installation finished! You may reboot now!") println!("Installation finished! You may reboot now!")
} }

@ -14,13 +14,7 @@ fn main() {
match opt.command { match opt.command {
Command::Partition(args) => { Command::Partition(args) => {
let mut partitions = args.partitions; let mut partitions = args.partitions;
partition::partition( partition::partition(args.device, args.mode, args.efi, &mut partitions);
args.device,
args.mode,
args.efi,
&mut partitions,
args.unakite,
);
} }
Command::InstallBase(args) => { Command::InstallBase(args) => {
base::install_base_packages(args.kernel); base::install_base_packages(args.kernel);
@ -74,15 +68,6 @@ fn main() {
Command::Flatpak => { Command::Flatpak => {
base::install_flatpak(); base::install_flatpak();
} }
Command::Unakite(args) => {
unakite::setup_unakite(
&args.root,
&args.oldroot,
args.efi,
&args.efidir,
&args.bootdev,
);
}
Command::Config { config } => { Command::Config { config } => {
crate::internal::config::read_config(config); crate::internal::config::read_config(config);
} }

Loading…
Cancel
Save