made clippy shut up and ran cargo fmt

axtloss/rework-partitioning
amy 2 years ago
parent dce3a65210
commit 09573dd0b1

@ -25,12 +25,31 @@ jade partition auto /dev/sda --efi
jade partition auto /dev/nvmen0
```
### install base packages
```sh
jade install-base
```
### install bootloader
```sh
# install as efi with esp being /boot/efi
jade bootloader grub-efi /boot/efi
# install as legacy on /dev/sda
jade bootloader grub-legacy /dev/sda
```
### configuring locale settings
```sh
# set the keyboard layout to colemak, the timezone to Europe/Berlin and set en_US.UTF-8 as the locale
jade locale colemak Europe/Berlin "en_US.UTF-8 UTF-8"
```
### create /etc/hosts
```sh
jade networking --hosts
```
### configue network settings
```sh
# set the hostname to getcryst.al with ipv6 disabled

@ -23,32 +23,42 @@ pub fn install_base_packages() {
]);
}
pub fn create_hosts() {
files::create_file("/mnt/etc/hosts");
files_eval(files::append_file("/mnt/etc/hosts", "127.0.0.1 localhost"), "create /etc/hosts");
}
pub fn install_bootloader_efi(efidir: &str) {
install::install(vec!["grub", "efibootmgr",]);
exec_eval(exec_chroot("grub-install", vec![
String::from("--target=x86_64-efi"),
format!("--efi-directory={}", efidir),
String::from("--bootloader-id=crystal"),
]), "install grub as efi");
exec_eval(exec_chroot("grub-mkconfig", vec![
String::from("-o"),
String::from("/boot/grub/grub.cfg"),
]), "create grub.cfg");
install::install(vec!["grub", "efibootmgr"]);
exec_eval(
exec_chroot(
"grub-install",
vec![
String::from("--target=x86_64-efi"),
format!("--efi-directory={}", efidir),
String::from("--bootloader-id=crystal"),
],
),
"install grub as efi",
);
exec_eval(
exec_chroot(
"grub-mkconfig",
vec![String::from("-o"), String::from("/boot/grub/grub.cfg")],
),
"create grub.cfg",
);
}
pub fn install_bootloader_legacy(device: &str) {
install::install(vec!["grub"]);
exec_eval(exec_chroot("grub-install", vec![
String::from("--target=i386-pc"),
String::from(device),
]), "install grub as legacy");
exec_eval(exec_chroot("grub-mkconfig", vec![
String::from("-o"),
String::from("/boot/grub/grub.cfg"),
]), "create grub.cfg");
exec_eval(
exec_chroot(
"grub-install",
vec![String::from("--target=i386-pc"), String::from(device)],
),
"install grub as legacy",
);
exec_eval(
exec_chroot(
"grub-mkconfig",
vec![String::from("-o"), String::from("/boot/grub/grub.cfg")],
),
"create grub.cfg",
);
}

@ -2,29 +2,50 @@ use crate::internal::exec::*;
use crate::internal::*;
pub fn set_timezone(timezone: &str) {
exec_eval(exec(
"ln",
vec![
"-sf".to_string(),
format!("/usr/share/zoneinfo/{}", timezone),
"/etc/localtime".to_string(),
],
), "Set timezone");
exec_eval(exec_chroot("hwclock", vec!["--systohc".to_string()]), "Set system clock");
exec_eval(
exec(
"ln",
vec![
"-sf".to_string(),
format!("/usr/share/zoneinfo/{}", timezone),
"/etc/localtime".to_string(),
],
),
"Set timezone",
);
exec_eval(
exec_chroot("hwclock", vec!["--systohc".to_string()]),
"Set system clock",
);
}
pub fn set_locale(locale: String) {
files_eval(files::append_file("/etc/locale.gen", "en_US.UTF-8 UTF-8"), "add en_US.UTF-8 UTF-8 to locale.gen");
files_eval(files::append_file("/etc/locale.gen", locale.as_str()), "add locales to locale.gen");
exec_eval(exec_chroot("locale-gen", vec!["".to_string()]), "generate locales");
files_eval(
files::append_file("/etc/locale.gen", "en_US.UTF-8 UTF-8"),
"add en_US.UTF-8 UTF-8 to locale.gen",
);
files_eval(
files::append_file("/etc/locale.gen", locale.as_str()),
"add locales to locale.gen",
);
exec_eval(
exec_chroot("locale-gen", vec!["".to_string()]),
"generate locales",
);
files::create_file("/etc/locale.conf");
files_eval(files::append_file("/etc/locale.conf", "LANG=en_US.UTF-8"), "edit locale.conf");
files_eval(
files::append_file("/etc/locale.conf", "LANG=en_US.UTF-8"),
"edit locale.conf",
);
}
pub fn set_keyboard(keyboard: &str) {
files::create_file("/etc/vconsole.conf");
files_eval(files::append_file(
"/etc/vconsole.conf",
format!("KEYMAP={}", keyboard).as_str(),
), "set keyboard layout");
files_eval(
files::append_file(
"/etc/vconsole.conf",
format!("KEYMAP={}", keyboard).as_str(),
),
"set keyboard layout",
);
}

@ -1,6 +1,6 @@
pub mod base;
pub mod desktops;
pub mod locale;
pub mod network;
pub mod partition;
pub mod users;
pub mod base;

@ -3,14 +3,23 @@ use crate::internal::*;
pub fn set_hostname(hostname: &str) {
println!("Setting hostname to {}", hostname);
files::create_file("/mnt/etc/hostname");
files_eval(files::append_file("/mnt/etc/hostname", hostname), "set hostname");
files_eval(
files::append_file("/mnt/etc/hostname", hostname),
"set hostname",
);
}
pub fn create_hosts() {
files::create_file("/mnt/etc/hosts");
files_eval(files::append_file("/mnt/etc/hosts", "127.0.0.1 localhost"), "create /etc/hosts");
files_eval(
files::append_file("/mnt/etc/hosts", "127.0.0.1 localhost"),
"create /etc/hosts",
);
}
pub fn enable_ipv6() {
files_eval(files::append_file("/mnt/etc/hosts", "::1 localhost"), "add ipv6 localhost");
files_eval(
files::append_file("/mnt/etc/hosts", "::1 localhost"),
"add ipv6 localhost",
);
}

@ -7,69 +7,87 @@ pub fn partition(device: &str, mode: &str, efi: bool) {
} else {
log(format!("automatically partitioning {}", device));
if efi {
exec_eval(exec(
"parted",
vec![
String::from("-s"),
String::from(device),
String::from("mklabel"),
String::from("gpt"),
],
), format!("create gpt label on {}", device).as_str());
exec_eval(exec(
"parted",
vec![
String::from("-s"),
String::from(device),
String::from("mkpart"),
String::from("fat32"),
String::from("0"),
String::from("300"),
],
), "create EFI partition");
exec_eval(exec(
"parted",
vec![
String::from("-s"),
String::from(device),
String::from("mkpart"),
String::from("btrfs"),
String::from("300"),
String::from("100%"),
],
), "Create btrfs root partition");
exec_eval(
exec(
"parted",
vec![
String::from("-s"),
String::from(device),
String::from("mklabel"),
String::from("gpt"),
],
),
format!("create gpt label on {}", device).as_str(),
);
exec_eval(
exec(
"parted",
vec![
String::from("-s"),
String::from(device),
String::from("mkpart"),
String::from("fat32"),
String::from("0"),
String::from("300"),
],
),
"create EFI partition",
);
exec_eval(
exec(
"parted",
vec![
String::from("-s"),
String::from(device),
String::from("mkpart"),
String::from("btrfs"),
String::from("300"),
String::from("100%"),
],
),
"Create btrfs root partition",
);
} else {
exec_eval(exec(
"parted",
vec![
String::from("-s"),
String::from(device),
String::from("mklabel"),
String::from("msdos"),
],
), format!("Create msdos label on {}", device).as_str());
exec_eval(exec(
"parted",
vec![
String::from("-s"),
String::from(device),
String::from("mkpart"),
String::from("btrfs"),
String::from("512MIB"),
String::from("100&"),
],
), "create btrfs root partition");
exec_eval(exec(
"parted",
vec![
String::from("-s"),
String::from(device),
String::from("mkpart"),
String::from("ext4"),
String::from("1MIB"),
String::from("512MIB"),
],
), "create bios boot partition");
exec_eval(
exec(
"parted",
vec![
String::from("-s"),
String::from(device),
String::from("mklabel"),
String::from("msdos"),
],
),
format!("Create msdos label on {}", device).as_str(),
);
exec_eval(
exec(
"parted",
vec![
String::from("-s"),
String::from(device),
String::from("mkpart"),
String::from("btrfs"),
String::from("512MIB"),
String::from("100&"),
],
),
"create btrfs root partition",
);
exec_eval(
exec(
"parted",
vec![
String::from("-s"),
String::from(device),
String::from("mkpart"),
String::from("ext4"),
String::from("1MIB"),
String::from("512MIB"),
],
),
"create bios boot partition",
);
}
}
if device.contains("nvme") {
@ -81,121 +99,189 @@ pub fn partition(device: &str, mode: &str, efi: bool) {
fn part_nvme(device: &str, efi: bool) {
if efi {
exec_eval(exec("mkfs.vfat", vec![format!("{}p1", device)]), format!("format {}p1 as fat32", device).as_str());
exec_eval(exec("mkfs.btrfs", vec![format!("{}p2", device)]), format!("format {}p2 as btrfs", device).as_str());
exec_eval(
exec("mkfs.vfat", vec![format!("{}p1", device)]),
format!("format {}p1 as fat32", device).as_str(),
);
exec_eval(
exec("mkfs.btrfs", vec![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");
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/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!("{}p2", device).as_str(),
"/mnt/home",
"subvol=@home",
);
mount(format!("{}p1", device).as_str(), "/mnt/boot/efi", "");
} else {
exec_eval(exec("mkfs.ext4", vec![format!("{}p1", device)]), format!("format {}p1 as ext4", device).as_str());
exec_eval(exec("mkfs.btrfs", vec![format!("{}p2", device)]), format!("format {}p2 as btrfs", device).as_str());
exec_eval(
exec("mkfs.ext4", vec![format!("{}p1", device)]),
format!("format {}p1 as ext4", device).as_str(),
);
exec_eval(
exec("mkfs.btrfs", vec![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");
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!("{}p2", device).as_str(),
"/mnt/home",
"subvol=@home",
);
mount(format!("{}p1", device).as_str(), "/mnt/boot", "");
}
}
fn part_disk(device: &str, efi: bool) {
if efi {
exec_eval(exec("mkfs.vfat", vec![format!("{}1", device)]), format!("format {}1 as fat32", device).as_str());
exec_eval(exec("mkfs.btrfs", vec![format!("{}2", device)]), format!("format {}2 as btrfs", device).as_str());
exec_eval(
exec("mkfs.vfat", vec![format!("{}1", device)]),
format!("format {}1 as fat32", device).as_str(),
);
exec_eval(
exec("mkfs.btrfs", vec![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");
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 /mnt/boot");
files_eval(files::create_directory("/mnt/boot/efi"), "create /mnt/boot/efi");
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 {
exec_eval(exec("mkfs.ext4", vec![format!("{}1", device)]), format!("format {}1 as ext4", device).as_str());
exec_eval(exec("mkfs.btrfs", vec![format!("{}2", device)]), format!("format {}2 as btrfs", device).as_str());
exec_eval(
exec("mkfs.ext4", vec![format!("{}1", device)]),
format!("format {}1 as ext4", device).as_str(),
);
exec_eval(
exec("mkfs.btrfs", vec![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");
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");
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", "");
}
@ -203,17 +289,27 @@ fn part_disk(device: &str, efi: bool) {
fn mount(partition: &str, mountpoint: &str, options: &str) {
let options = if options.is_empty() { "\"\"" } else { options };
exec_eval(exec(
"mount",
vec![
String::from(partition),
String::from(mountpoint),
String::from("-o"),
String::from(options),
],
), format!("mount {} with options {} at {}", partition, options, mountpoint).as_str());
exec_eval(
exec(
"mount",
vec![
String::from(partition),
String::from(mountpoint),
String::from("-o"),
String::from(options),
],
),
format!(
"mount {} with options {} at {}",
partition, options, mountpoint
)
.as_str(),
);
}
fn umount(mountpoint: &str) {
exec_eval(exec("umount", vec![String::from(mountpoint)]), format!("unmount {}", mountpoint).as_str());
exec_eval(
exec("umount", vec![String::from(mountpoint)]),
format!("unmount {}", mountpoint).as_str(),
);
}

@ -2,56 +2,68 @@ use crate::internal::exec::*;
use crate::internal::*;
pub fn new_user(username: &str, hasroot: bool, password: &str) {
exec_eval(exec_chroot(
"useradd",
vec![
String::from("-m"),
String::from("-s"),
String::from("/bin/bash"),
String::from(username),
],
), format!("Create user {}", username).as_str());
exec_eval(
exec_chroot(
"useradd",
vec![
String::from("-m"),
String::from("-s"),
String::from("/bin/bash"),
String::from(username),
],
),
format!("Create user {}", username).as_str(),
);
if hasroot {
exec_eval(exec_chroot(
exec_eval(
exec_chroot(
"usermod",
vec![
String::from("-a"),
String::from("-G"),
String::from("wheel"),
String::from(username),
],
),
format!("Add user {} to wheel group", username).as_str(),
);
}
exec_eval(
exec_chroot(
"usermod",
vec![
String::from("-a"),
String::from("-G"),
String::from("wheel"),
String::from("--password"),
String::from("$(echo"),
format!("${}", password),
String::from("|"),
String::from("openssl"),
String::from("passwd"),
String::from("-1"),
String::from("-stdin)"),
String::from(username),
],
), format!("Add user {} to wheel group", username).as_str());
}
exec_eval(exec_chroot(
"usermod",
vec![
String::from("--password"),
String::from("$(echo"),
format!("${}", password),
String::from("|"),
String::from("openssl"),
String::from("passwd"),
String::from("-1"),
String::from("-stdin)"),
String::from(username),
],
), format!("Set password for user {}", username).as_str());
),
format!("Set password for user {}", username).as_str(),
);
}
pub fn root_pass(root_pass: &str) {
println!("Setting root password to '{}'", root_pass);
exec_eval(exec_chroot(
"usermod",
vec![
String::from("--password"),
String::from("$(echo"),
format!("${{{}}}", root_pass),
String::from("|"),
String::from("openssl"),
String::from("passwd"),
String::from("-1"),
String::from("-stdin)"),
String::from("root"),
],
), "set root password");
exec_eval(
exec_chroot(
"usermod",
vec![
String::from("--password"),
String::from("$(echo"),
format!("${{{}}}", root_pass),
String::from("|"),
String::from("openssl"),
String::from("passwd"),
String::from("-1"),
String::from("-stdin)"),
String::from("root"),
],
),
"set root password",
);
}

@ -7,7 +7,7 @@ pub fn exec(command: &str, args: Vec<String>) -> Result<std::process::ExitStatus
pub fn exec_chroot(
command: &str,
args: Vec<String>
args: Vec<String>,
) -> Result<std::process::ExitStatus, std::io::Error> {
let returncode = Command::new("arch-chroot")
.args(&["/mnt", command])

@ -1,8 +1,8 @@
pub mod exec;
pub mod files;
pub mod install;
pub mod strings;
pub mod returncode_eval;
pub mod strings;
pub fn install(pkgs: Vec<&str>) {
install::install(pkgs);
@ -20,7 +20,10 @@ pub fn files_eval(returncode: std::result::Result<(), std::io::Error>, logmsg: &
returncode_eval::files_eval(returncode, logmsg);
}
pub fn exec_eval(returncode: std::result::Result<std::process::ExitStatus, std::io::Error>, logmsg: &str) {
pub fn exec_eval(
returncode: std::result::Result<std::process::ExitStatus, std::io::Error>,
logmsg: &str,
) {
returncode_eval::exec_eval(returncode, logmsg);
}

@ -1,23 +1,32 @@
use crate::internal::*;
pub fn exec_eval(return_code: std::result::Result<std::process::ExitStatus, std::io::Error>, logmsg: &str) {
match &return_code {
Ok(_) => {
log(format!("{}: Success", logmsg));
}
Err(e) => {
crash(format!("{}: Failed with error: {}", logmsg, e), return_code.unwrap_err().raw_os_error().unwrap());
}
}
}
pub fn files_eval(return_code: std::result::Result<(), std::io::Error>, logmsg: &str) {
match &return_code {
Ok(_) => {
log(format!("[ \x1b[2;1;32mOK\x1b[0m ] {}", logmsg));
}
Err(e) => {
crash(format!("[ \x1b[2;1;31mFAILED\x1b[0m ] {} ERROR: {}", logmsg, e), return_code.unwrap_err().raw_os_error().unwrap());
}
}
}
use crate::internal::*;
pub fn exec_eval(
return_code: std::result::Result<std::process::ExitStatus, std::io::Error>,
logmsg: &str,
) {
match &return_code {
Ok(_) => {
log(format!("{}: Success", logmsg));
}
Err(e) => {
crash(
format!("{}: Failed with error: {}", logmsg, e),
return_code.unwrap_err().raw_os_error().unwrap(),
);
}
}
}
pub fn files_eval(return_code: std::result::Result<(), std::io::Error>, logmsg: &str) {
match &return_code {
Ok(_) => {
log(format!("[ \x1b[2;1;32mOK\x1b[0m ] {}", logmsg));
}
Err(e) => {
crash(
format!("[ \x1b[2;1;31mFAILED\x1b[0m ] {} ERROR: {}", logmsg, e),
return_code.unwrap_err().raw_os_error().unwrap(),
);
}
}
}

@ -44,7 +44,7 @@ fn main() {
Arg::with_name("efidir")
.help("The directory to install the EFI bootloader to")
.required(true),
),
),
)
.subcommand(
SubCommand::with_name("grub-legacy")
@ -96,7 +96,6 @@ fn main() {
.help("Wether ipv6 should be enabled")
.short("i6")
.long("ipv6")
.required(true)
.takes_value(false),
),
)
@ -161,8 +160,12 @@ fn main() {
locale::set_keyboard(kbrlayout);
locale::set_timezone(timezn);
} else if let Some(app) = app.subcommand_matches("networking") {
if app.is_present("ipv6") { network::enable_ipv6() }
if app.is_present("create-hosts") { network::create_hosts() }
if app.is_present("ipv6") {
network::enable_ipv6()
}
if app.is_present("create-hosts") {
network::create_hosts()
}
network::set_hostname(app.value_of("hostname").unwrap())
} else if let Some(app) = app.subcommand_matches("users") {
if let Some(app) = app.subcommand_matches("newUser") {
@ -184,7 +187,7 @@ fn main() {
} else if let Some(app) = app.subcommand_matches("grub-legacy") {
base::install_bootloader_legacy(app.value_of("device").unwrap());
}
} else if let Some(_) = app.subcommand_matches("install-base") {
} else if app.subcommand_matches("install-base").is_some() {
base::install_base_packages();
} else {
println!("Running TUI installer");

Loading…
Cancel
Save