save default peachcloud config if file does not exist

This commit is contained in:
glyph 2022-03-07 11:26:52 +02:00
parent 84656ff251
commit 824cbdbc0c
1 changed files with 13 additions and 0 deletions

View File

@ -34,6 +34,7 @@ use std::{process, sync::RwLock};
use lazy_static::lazy_static;
use log::{debug, error, info};
use peach_lib::{config_manager, config_manager::YAML_PATH as PEACH_CONFIG};
use rocket::{fairing::AdHoc, serde::Deserialize, Build, Rocket};
use utils::Theme;
@ -90,6 +91,18 @@ async fn main() {
// initialize logger
env_logger::init();
// check if /var/lib/peachcloud/config.yml exists
if !std::path::Path::new(PEACH_CONFIG).exists() {
info!("PeachCloud configuration file not found; loading default values");
// since we're in the intialisation phase, panic if the loading fails
let config =
config_manager::load_peach_config().expect("peachcloud configuration loading failed");
info!("Saving default PeachCloud configuration values to file");
// this ensures a config file is created if it does not already exist
config_manager::save_peach_config(config).expect("peachcloud configuration saving failed");
}
// initialize rocket
let rocket = init_rocket();