Add passwd launch option

This commit is contained in:
Raphaël Thériault 2020-03-09 15:35:18 -04:00
parent 93b211f743
commit fa02a9adb5
2 changed files with 13 additions and 6 deletions

View File

@ -19,7 +19,13 @@ lazy_static! {
#[cfg(not(feature = "dev"))]
lazy_static! {
pub static ref CONFIG: crate::setup::Config =
crate::setup::init(std::env::args().any(|a| &a == "init"));
crate::setup::init(std::env::args().fold(0, |mode, a| if &a == "init" {
2
} else if &a == "passwd" {
1
} else {
mode
}));
pub static ref PASSWORD_HASH: Vec<u8> = {
let password_path = crate::setup::get_password_path();
std::fs::read(&password_path).unwrap_or_else(|e| {

View File

@ -251,15 +251,16 @@ pub fn logger_middleware() -> Logger {
}
/// Performs the initial setup
// mode: 0 = normal, 1 = reset password, 2 = reset everything
#[cfg(not(feature = "dev"))]
pub fn init(init: bool) -> Config {
pub fn init(mode: u8) -> Config {
fs::create_dir_all(get_config_dir()).unwrap_or_else(|e| {
eprintln!("Can't create config directory: {}.", e);
process::exit(1);
});
let password_path = get_password_path();
if init {
if mode > 0 {
let mut password;
loop {
password = PasswordInput::new()
@ -295,12 +296,12 @@ pub fn init(init: bool) -> Config {
process::exit(1);
});
} else if !get_password_path().exists() {
eprintln!("No password file found. Try running `filite init`.");
eprintln!("No password file found. Try running `filite init` or `filite passwd`.");
process::exit(1);
}
let config_path = get_config_path();
if init {
if mode > 1 {
println!("Generating config file at {}", config_path.display());
let config = Config::default();
config.write_file().unwrap_or_else(|e| {
@ -312,7 +313,7 @@ pub fn init(init: bool) -> Config {
process::exit(1);
}
if init {
if mode > 0 {
process::exit(0);
}
Config::read_file().unwrap_or_else(|e| {