complete unakite

axtloss/rework-partitioning
axtlos 3 years ago
parent 96aaa78850
commit dc8219831a

@ -95,6 +95,9 @@ pub struct PartitionArgs {
#[clap(long)]
pub efi: bool,
#[clap(long)]
pub unakite: bool,
/// The partitions to use for manual partitioning
#[clap(required_if_eq("mode", "Partition::Manual"), parse(try_from_str = parse_partitions))]
pub partitions: Vec<Partition>,

@ -159,7 +159,7 @@ pub fn fmt_mount(mountpoint: &str, filesystem: &str, blockdevice: &str) {
mount(blockdevice, mountpoint, "");
}
pub fn partition(device: PathBuf, mode: PartitionMode, efi: bool, partitions: &mut Vec<args::Partition>) {
pub fn partition(device: PathBuf, mode: PartitionMode, efi: bool, partitions: &mut Vec<args::Partition>, unakite: bool) {
println!("{:?}", mode);
match mode {
@ -169,14 +169,14 @@ pub fn partition(device: PathBuf, mode: PartitionMode, efi: bool, partitions: &m
}
log::debug!("automatically partitioning {device:?}");
if efi {
partition_with_efi(&device);
partition_with_efi(&device, unakite);
} else {
partition_no_efi(&device);
partition_no_efi(&device, unakite);
}
if device.to_string_lossy().contains("nvme") {
part_nvme(&device, efi);
part_nvme(&device, efi, unakite);
} else {
part_disk(&device, efi);
part_disk(&device, efi, unakite);
}
}
PartitionMode::Manual => {
@ -198,7 +198,7 @@ pub fn partition(device: PathBuf, mode: PartitionMode, efi: bool, partitions: &m
}
}
fn partition_no_efi(device: &Path) {
fn partition_no_efi(device: &Path, unakite: bool) {
let device = device.to_string_lossy().to_string();
exec_eval(
exec(
@ -227,24 +227,57 @@ fn partition_no_efi(device: &Path) {
),
"create bios boot partition",
);
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",
);
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 partition_with_efi(device: &Path) {
fn partition_with_efi(device: &Path, unakite: bool) {
let device = device.to_string_lossy().to_string();
exec_eval(
exec(
@ -272,25 +305,59 @@ fn partition_with_efi(device: &Path) {
),
"create EFI partition",
);
exec_eval(
exec(
"parted",
vec![
String::from("-s"),
device,
String::from("mkpart"),
String::from("btrfs"),
String::from("300"),
String::from("100%"),
],
),
"Create btrfs root partition",
);
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) {
fn part_nvme(device: &Path, efi: bool, unakite: bool) {
let device = device.to_string_lossy().to_string();
if efi {
if efi && !unakite {
exec_eval(
exec("mkfs.vfat", vec![format!("{}p1", device)]),
format!("format {}p1 as fat32", device).as_str(),
@ -341,7 +408,112 @@ fn part_nvme(device: &Path, efi: bool) {
"subvol=@home",
);
mount(format!("{}p1", device).as_str(), "/mnt/boot/efi", "");
} else {
} 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![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(),
@ -391,9 +563,9 @@ fn part_nvme(device: &Path, efi: bool) {
}
}
fn part_disk(device: &Path, efi: bool) {
fn part_disk(device: &Path, efi: bool, unakite: bool) {
let device = device.to_string_lossy().to_string();
if efi {
if efi && !unakite {
exec_eval(
exec("mkfs.vfat", vec![format!("{}1", device)]),
format!("format {}1 as fat32", device).as_str(),
@ -437,7 +609,7 @@ fn part_disk(device: &Path, efi: bool) {
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 {
} else if !efi && !unakite {
exec_eval(
exec("mkfs.ext4", vec![format!("{}1", device)]),
format!("format {}1 as ext4", device).as_str(),
@ -483,6 +655,104 @@ fn part_disk(device: &Path, efi: bool) {
);
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![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::create_directory("/mnt/home"),
"create directory /mnt/home",
);
mount(format!("{}3", device).as_str(), "/mnt/home", "subvol=@home");
mount(format!("{}1", device).as_str(), "/mnt/boot", "");
}
}

@ -146,9 +146,6 @@ pub fn setup_unakite(root: &str, oldroot: &str, efi: bool, efidir: &str, bootdev
remount(root, oldroot, efi, efidir, bootdev, true);
base::install_base_packages();
base::genfstab();
if efi {
install_bootloader_efi(PathBuf::from(efidir.replace("/mnt", "")));
}
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");
@ -158,8 +155,42 @@ pub fn setup_unakite(root: &str, oldroot: &str, efi: bool, efidir: &str, bootdev
true,
"Cp7oN04ZY0PsA", // unakite
);
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"]);
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"
);
}

@ -17,6 +17,7 @@ struct Config {
timeshift: bool,
flatpak: bool,
extra_packages: Vec<String>,
unakite: Unakite,
}
#[derive(Serialize, Deserialize)]
@ -53,6 +54,15 @@ struct Users {
hasroot: bool,
}
#[derive(Serialize, Deserialize)]
struct Unakite {
enable: bool,
root: String,
oldroot: String,
efidir: String,
bootdev: String,
}
pub fn read_config(configpath: PathBuf) {
let data = std::fs::read_to_string(&configpath);
match &data {
@ -88,11 +98,13 @@ pub fn read_config(configpath: PathBuf) {
partition.split(':').collect::<Vec<&str>>()[2].to_string(),
));
}
let device = PathBuf::from("/dev/").join(config.partition.device.as_str());
partition::partition(
PathBuf::from("/dev/").join(config.partition.device),
device,
config.partition.mode,
config.partition.efi,
&mut partitions,
config.unakite.enable
);
base::install_base_packages();
base::genfstab();
@ -168,5 +180,23 @@ pub fn read_config(configpath: PathBuf) {
extra_packages.push(config.extra_packages[i].as_str());
}
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!")
}

@ -14,7 +14,7 @@ fn main() {
match opt.command {
Command::Partition(args) => {
let mut partitions = args.partitions;
partition::partition(args.device, args.mode, args.efi, &mut partitions);
partition::partition(args.device, args.mode, args.efi, &mut partitions, args.unakite);
}
Command::InstallBase => {
base::install_base_packages();

Loading…
Cancel
Save