2021-09-28 18:54:37 -04:00
|
|
|
/*##############################################################################
|
|
|
|
## Author: Shaun Reed ##
|
|
|
|
## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
|
|
|
|
## About: Main entry point for Linux configuration manager kot ##
|
|
|
|
## ##
|
|
|
|
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
|
|
|
##############################################################################*/
|
|
|
|
|
2021-12-29 13:31:09 -05:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2021-09-28 18:54:37 -04:00
|
|
|
mod kot;
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
// MAIN ENTRY-POINT
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2021-12-29 13:31:09 -05:00
|
|
|
fn main() -> kot::Result<()> {
|
2021-12-26 19:08:58 -05:00
|
|
|
// Call augmented kot::cli::from_args() to parse CLI arguments
|
2021-12-29 13:31:09 -05:00
|
|
|
let args = kot::cli::from_args()?;
|
2021-12-26 19:08:58 -05:00
|
|
|
// At this point all paths exist and have been converted to absolute paths
|
2021-09-28 18:54:37 -04:00
|
|
|
println!("args: {:?}\n", args);
|
|
|
|
|
2021-12-26 19:08:58 -05:00
|
|
|
// Attempt to install the configurations, checking for collisions
|
2021-09-28 18:54:37 -04:00
|
|
|
match kot::install_configs(&args) {
|
2021-12-26 19:08:58 -05:00
|
|
|
Err(e) => {
|
|
|
|
// If there was an error, show the error type and run settings
|
|
|
|
println!(
|
|
|
|
"Error: {:?}\n+ Configs used: {:?}\n+ Install directory: {:?}\n",
|
2021-12-29 13:31:09 -05:00
|
|
|
e, args.dotfiles_dir, args.install_dir
|
|
|
|
);
|
|
|
|
|
|
|
|
// If we were forcing a backup and met some error, revert backups to last good state
|
|
|
|
// TODO: Isolate this to limit error scope to backup related functions
|
|
|
|
if args.force {
|
|
|
|
let mut temp_path : PathBuf = kot::fs::Path::new("/tmp/").to_path_buf();
|
|
|
|
temp_path.push(args.backup_dir.file_name().unwrap());
|
|
|
|
kot::fs::move_dir(&temp_path, &args.backup_dir, None)?;
|
|
|
|
}
|
2021-12-26 19:08:58 -05:00
|
|
|
},
|
2021-12-29 13:31:09 -05:00
|
|
|
_ => ()
|
2021-09-28 18:54:37 -04:00
|
|
|
}
|
2021-12-29 13:31:09 -05:00
|
|
|
// Configurations installed successfully
|
|
|
|
Ok(())
|
2021-09-25 13:39:37 -04:00
|
|
|
}
|