Ensure config and cookbook key are installed

This commit is contained in:
Jeremy Soller
2022-09-05 09:55:15 -06:00
parent e8e4687c05
commit ad11b2adb2
2 changed files with 27 additions and 7 deletions
+25 -5
View File
@@ -3,8 +3,7 @@ extern crate redox_installer;
extern crate serde;
extern crate toml;
use std::{env, io, process};
use std::fs::File;
use std::{env, fs, io, process};
use std::io::{Read, Write};
use std::path::Path;
@@ -21,10 +20,10 @@ fn main() {
.add_flag(&["live"]);
parser.parse(env::args());
let config = if let Some(path) = parser.get_opt("config") {
match File::open(&path) {
let mut config_data = String::new();
let mut config = if let Some(path) = parser.get_opt("config") {
match fs::File::open(&path) {
Ok(mut config_file) => {
let mut config_data = String::new();
match config_file.read_to_string(&mut config_data) {
Ok(_) => {
match toml::from_str(&config_data) {
@@ -52,12 +51,33 @@ fn main() {
redox_installer::Config::default()
};
// Add filesystem.toml to config
config.files.push(redox_installer::FileConfig {
path: "filesystem.toml".to_string(),
data: config_data,
..Default::default()
});
let cookbook = if let Some(path) = parser.get_opt("cookbook") {
if ! Path::new(&path).is_dir() {
writeln!(stderr, "installer: {}: cookbook not found", path).unwrap();
process::exit(1);
}
// Add cookbook key to config
let key_path = Path::new(&path).join("build/id_ed25519.pub.toml");
match fs::read_to_string(&key_path) {
Ok(data) => config.files.push(redox_installer::FileConfig {
path: "pkg/id_ed25519.pub.toml".to_string(),
data: data,
..Default::default()
}),
Err(err) => {
writeln!(stderr, "installer: {}: failed to read cookbook key: {}", key_path.display(), err).unwrap();
process::exit(1);
}
}
Some(path)
} else {
None
+2 -2
View File
@@ -14,8 +14,8 @@ extern crate termion;
mod config;
pub use config::Config;
use config::file::FileConfig;
use config::package::PackageConfig;
pub use config::file::FileConfig;
pub use config::package::PackageConfig;
use failure::{Error, err_msg};
use rand::{RngCore, rngs::OsRng};