Commit 66b24d11 authored by SamwiseFilmore's avatar SamwiseFilmore

Support Directories

parent e58815f8
......@@ -171,3 +171,10 @@ Welcome to Redox OS!
path = "/usr"
data = "/"
symlink = true
[[files]]
path = "/tmp"
data = ""
directory = true
# 0o1777
mode = 1023
......@@ -17,12 +17,14 @@ pub struct FileConfig {
pub data: String,
#[serde(default)]
pub symlink: bool,
#[serde(default)]
pub directory: bool,
pub mode: Option<u32>,
pub uid: Option<u32>,
pub gid: Option<u32>
}
// TODO: Rewrite
// TODO: Rewrite impls
impl FileConfig {
pub(crate) fn create<P: AsRef<Path>>(self, prefix: P) -> Result<()> {
......@@ -30,9 +32,12 @@ impl FileConfig {
let target_file = prefix.as_ref()
.join(path);
println!("target file: {:?}", target_file);
if let Some(parent) = target_file.parent() {
if self.directory {
println!("Create directory {}", target_file.display());
fs::create_dir_all(&target_file)?;
self.apply_perms(&target_file)?;
return Ok(());
} else if let Some(parent) = target_file.parent() {
println!("Create file parent {}", parent.display());
fs::create_dir_all(parent)?;
}
......@@ -52,7 +57,11 @@ impl FileConfig {
fn apply_perms<P: AsRef<Path>>(&self, target: P) -> Result<()> {
let path = target.as_ref();
let mode = self.mode.unwrap_or(0o0755);
let mode = self.mode.unwrap_or_else(|| if self.directory {
0o0755
} else {
0o0644
});
let uid = self.uid.unwrap_or(0);
let gid = self.gid.unwrap_or(0);
......
......@@ -22,7 +22,7 @@ use rand::{OsRng, Rng};
use termion::input::TermRead;
use pkgutils::{Repo, Package};
use std::{env, fs};
use std::env;
use std::io::{self, stderr, Write};
use std::path::Path;
use std::process::{self, Command};
......@@ -32,7 +32,6 @@ pub(crate) type Result<T> = std::result::Result<T, Error>;
const REMOTE: &'static str = "https://static.redox-os.org/pkg";
const TARGET: &'static str = "x86_64-unknown-redox";
const SYSROOT: &'static str = "SYSROOT";
/// Converts a password to a serialized argon2rs hash, understandable
/// by redox_users. If the password is blank, the hash is blank.
......@@ -121,17 +120,6 @@ fn install_packages<S: AsRef<str>>(config: &Config, dest: &str, cookbook: Option
}
pub fn install<P: AsRef<Path>, S: AsRef<str>>(config: Config, output_dir: P, cookbook: Option<S>) -> Result<()> {
/// Creates a directory relative to the output directory
fn create_dir_relative<P: AsRef<Path>>(path: P) -> Result<()> {
let root = env::var(SYSROOT)?;
let target_dir = Path::new(&root)
.join(path.as_ref());
println!("Create directory {}", target_dir.display());
fs::create_dir_all(&target_dir)?;
Ok(())
}
let mut context = liner::Context::new();
macro_rules! prompt {
......@@ -151,10 +139,6 @@ pub fn install<P: AsRef<Path>, S: AsRef<str>>(config: Config, output_dir: P, coo
let output_dir = output_dir.as_ref();
// Using an env var here to communicate the root dir to the functions
// instead of passing it as a param
env::set_var(SYSROOT, output_dir.as_os_str());
println!("Install {:#?} to {}", config, output_dir.display());
// TODO: Mount disk if output is a file
......@@ -201,7 +185,15 @@ pub fn install<P: AsRef<Path>, S: AsRef<str>>(config: Config, output_dir: P, coo
println!("\tHome: {}", home);
println!("\tShell: {}", shell);
create_dir_relative(home.trim_matches('/'))?;
FileConfig {
path: home.clone(),
data: String::new(),
symlink: false,
directory: true,
mode: Some(0o0700),
uid: Some(uid),
gid: Some(gid)
}.create(&output_dir)?;
let password = hash_password(&password)?;
......@@ -213,10 +205,12 @@ pub fn install<P: AsRef<Path>, S: AsRef<str>>(config: Config, output_dir: P, coo
path: "/etc/passwd".to_string(),
data: passwd,
symlink: false,
mode: Some(0o755),
uid: Some(0),
gid: Some(0)
}.create(output_dir)?;
directory: false,
// Take defaults
mode: None,
uid: None,
gid: None
}.create(&output_dir)?;
}
Ok(())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment