diff --git a/img.ext2 b/img.ext2 new file mode 100644 index 00000000..53837daf Binary files /dev/null and b/img.ext2 differ diff --git a/repbuild/assets/mkfs.sh b/repbuild/assets/mkfs.sh new file mode 100644 index 00000000..e9fa36ac --- /dev/null +++ b/repbuild/assets/mkfs.sh @@ -0,0 +1,50 @@ +set -eu + +root_dir=root +img_file=img.ext2 +user="Able" + + +# Create a test directory to convert to ext2. +mkdir -p "$root_dir" +mkdir -p "$root_dir/boot" + +mkdir -p "$root_dir/system" +mkdir -p "$root_dir/system/bins" +mkdir -p "$root_dir/system/configs" + +mkdir -p "$root_dir/shared" +mkdir -p "$root_dir/shared/bins" +mkdir -p "$root_dir/shared/configs" + + +mkdir -p "$root_dir/home" + +mkdir -p "$root_dir/home/$user" +mkdir -p "$root_dir/home/$user/.trash" +mkdir -p "$root_dir/home/$user/bins" +mkdir -p "$root_dir/home/$user/configs" + + +# Build the userland here + + + + + + + + +mke2fs \ + -L '' \ + -N 0 \ + -O ^64bit \ + -d "$root_dir" \ + -m 5 \ + -r 1 \ + -I 128 \ + -t ext2 \ + "$img_file" \ + 4M \ +; + diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 0033dce7..875400df 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -1,3 +1,6 @@ +use std::io::stdin; + +use anyhow::{Error, Ok}; use clap::Parser; #[derive(clap::Parser, Debug)] @@ -27,6 +30,7 @@ enum Command { #[clap(long, short)] path: Option, }, + MakeFS {}, } #[derive(clap::ArgEnum, Debug, Clone)] @@ -110,7 +114,33 @@ fn main() -> anyhow::Result<()> { let path = path.unwrap_or_else(|| "./userland/root_fs/mnt".to_string()); xshell::cmd!("sudo umount {path}").run()?; } + Command::MakeFS {} => match make_fs() { + Result::Ok(_) => {} + Err(err) => println!("{}", err), + }, } Ok(()) } + +pub fn make_fs() -> Result<(), Error> { + xshell::cmd!("sh repbuild/assets/mkfs.sh").run()?; + + println!("Make changes in root_fs"); + + let mut input = String::new(); + println!("Press enter when ready:"); + stdin().read_line(&mut input).unwrap(); + + // build + + // xshell::cmd!("rm -rf root").run()?; + + Ok(()) +} + +pub fn make_user(user: String) -> Result<(), Error> { + xshell::mkdir_p(user)?; + + Ok(()) +}