Ensure config and cookbook key are installed
This commit is contained in:
+25
-5
@@ -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
@@ -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};
|
||||
|
||||
Reference in New Issue
Block a user