tar
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
JMARyA 2025-04-17 05:04:26 +02:00
parent 49e838c45a
commit 98c83c5403
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
7 changed files with 53 additions and 28 deletions

View file

@ -26,6 +26,7 @@ pub fn get_args() -> clap::ArgMatches {
.subcommand(
command!()
.name("create-tar")
.arg(arg!([dir] "root fs dir").required(true))
.about("Create a container tar image"),
)
.subcommand(

View file

@ -3,7 +3,7 @@ use crate::{config::InstallConfig, linux::install_file, pkg::install_pkgs, print
use super::navos::setup_navos;
pub fn setup_desktop(conf: &InstallConfig) {
setup_navos();
setup_navos("/mnt");
install_pkgs(&["navos_desktop"]);
print_status("Enable SDDM");
print_status("Set keyboard layout for SDDM");

View file

@ -51,7 +51,7 @@ pub mod zram;
use crate::{
config::InstallConfig,
pkg::{self, install_pkgs, pacstrap},
pkg::{self, install_pkgs, pacstrap_at},
print_status,
};
@ -129,14 +129,14 @@ pub fn install(mut conf: InstallConfig, bare: bool) {
pub fn install_mnt(conf: InstallConfig, bare: bool) {
// Base Install
pacstrap(&conf.pkg);
pacstrap_at("/mnt", conf.pkg.kernel.as_ref(), &conf.pkg.pkg);
genfstab();
// Configuration
first_boot_values(&conf.general);
if !matches!(conf.general.mode, crate::config::InstallMode::Base) {
setup_navos();
setup_navos("/mnt");
}
setup_skel(&conf.general);

View file

@ -1,19 +1,25 @@
use crate::{linux::arch_chroot, print_status};
use crate::{linux::arch_chroot_at, print_status};
pub fn setup_navos() {
pub fn setup_navos(root: &str) {
let root = std::path::PathBuf::from(root);
// pacman.conf
print_status("Copying pacman.conf");
std::fs::copy("/etc/pacman.conf", "/mnt/etc/pacman.conf").unwrap();
std::fs::copy("/etc/pacman.conf", root.join("etc").join("pacman.conf")).unwrap();
// import keys
print_status("Importing pkg keys");
std::fs::write(
"/mnt/usr/share/pacman/keyrings/navos.gpg",
root.join("usr")
.join("share")
.join("pacman")
.join("keyrings")
.join("navos.gpg"),
include_str!("../../navos.gpg"),
)
.unwrap();
arch_chroot(
arch_chroot_at(
root.display().to_string().as_str(),
&[
"pacman-key",
"--add",
@ -23,7 +29,8 @@ pub fn setup_navos() {
false,
);
arch_chroot(
arch_chroot_at(
root.display().to_string().as_str(),
&[
"pacman-key",
"--lsign-key",
@ -35,5 +42,5 @@ pub fn setup_navos() {
// remove os-release
print_status("Removing os-release");
let _ = std::fs::remove_file("/mnt/etc/os-release");
let _ = std::fs::remove_file(root.join("etc").join("os-release"));
}

View file

@ -94,6 +94,18 @@ pub fn run_command(cmd: &[&str], input: Option<&str>, inherit: bool) -> (String,
(output, stderr)
}
/// Runs a command in the chroot environment at `dir`
pub fn arch_chroot_at(
dir: &str,
cmd: &[&str],
input: Option<&str>,
inherit: bool,
) -> (String, String) {
let mut chroot_cmd = vec!["arch-chroot", dir];
chroot_cmd.extend_from_slice(cmd);
run_command(&chroot_cmd, input, inherit)
}
/// Runs a command in the chroot environment at `/mnt`
pub fn arch_chroot(cmd: &[&str], input: Option<&str>, inherit: bool) -> (String, String) {
let mut chroot_cmd = vec!["arch-chroot", "/mnt"];

View file

@ -1,12 +1,22 @@
use navinstall::config::InstallConfig;
use navinstall::install::navos::setup_navos;
use navinstall::install::{
drives::setup_disk_image, install, install_mnt, security::ensure_secure_boot,
};
use navinstall::linux::is_root;
use navinstall::pkg::pacstrap_at;
use navinstall::print::print_config;
use navinstall::print_status;
use navinstall::{create_iso::create_iso, expect_yes};
use yansi::{Color, Paint};
pub fn ensure_root() {
if !is_root() {
eprintln!("Error: You need root to install");
std::process::exit(1);
}
}
fn main() {
println!(
"{}",
@ -53,9 +63,12 @@ fn main() {
);
std::process::exit(0);
}
Some(("create-tar", _)) => {
println!("Tar creation is not yet supported");
unimplemented!()
Some(("create-tar", tar_options)) => {
ensure_root();
let dir: &String = tar_options.get_one("dir").unwrap();
print_status("Pacstrapping root fs");
pacstrap_at(&dir, None, &[]);
setup_navos(dir.as_str());
}
Some(("create-img", install_args)) => {
let config_file: &String = install_args.get_one("config").unwrap();
@ -66,10 +79,7 @@ fn main() {
install_mnt(conf, false);
}
Some(("install", install_args)) => {
if !is_root() {
eprintln!("Error: You need root to install");
std::process::exit(1);
}
ensure_root();
let config_file: &String = install_args.get_one("config").unwrap();
let force = install_args.get_flag("force");

View file

@ -1,7 +1,4 @@
use crate::{
config::PackageConfig,
linux::{arch_chroot, run_command},
};
use crate::linux::{arch_chroot, run_command};
pub const DESKTOP_PKG: [&str; 17] = [
// Desktop
@ -42,11 +39,11 @@ pub fn install_pkgs(pkg: &[&str]) {
// PACSTRAP
/// Initial system pacstrap
pub fn pacstrap(conf: &PackageConfig) {
pub fn pacstrap_at(dir: &str, kernel: Option<&String>, pkg: &[String]) {
let mut cmd: Vec<&str> = vec![
"pacstrap",
"-K",
"/mnt",
dir,
"base",
"linux-firmware",
"git",
@ -60,7 +57,7 @@ pub fn pacstrap(conf: &PackageConfig) {
];
let linux_kernel = "linux".to_string();
let kernel = conf.kernel.as_ref().unwrap_or(&linux_kernel);
let kernel = kernel.unwrap_or(&linux_kernel);
let headers = format!("{kernel}-headers");
cmd.extend(&[kernel.as_str(), headers.as_str()]);
@ -70,9 +67,7 @@ pub fn pacstrap(conf: &PackageConfig) {
}
cmd.extend(
&conf
.pkg
.iter()
pkg.iter()
.map(std::string::String::as_str)
.collect::<Vec<_>>(),
);