2018-08-03 11:52:31 +00:00
|
|
|
//! main.rs
|
|
|
|
//!
|
|
|
|
//! The main entrypoint for the application. Orchestrates the building of the installation
|
|
|
|
//! framework, and opens necessary HTTP servers/frontends.
|
|
|
|
|
2018-08-03 15:12:03 +00:00
|
|
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
2018-08-04 07:15:27 +00:00
|
|
|
#![deny(unsafe_code)]
|
2018-08-04 08:35:00 +00:00
|
|
|
#![deny(missing_docs)]
|
2018-01-26 12:29:28 +00:00
|
|
|
|
|
|
|
extern crate web_view;
|
2018-01-27 11:56:36 +00:00
|
|
|
|
2018-07-28 05:33:06 +00:00
|
|
|
extern crate futures;
|
2018-08-03 07:50:17 +00:00
|
|
|
extern crate hyper;
|
2018-08-03 11:52:31 +00:00
|
|
|
extern crate url;
|
2018-01-29 10:27:54 +00:00
|
|
|
|
2018-01-30 04:53:28 +00:00
|
|
|
extern crate number_prefix;
|
2018-01-30 04:54:44 +00:00
|
|
|
extern crate reqwest;
|
2018-01-30 04:53:28 +00:00
|
|
|
|
2018-01-27 03:27:41 +00:00
|
|
|
extern crate serde;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
|
|
|
extern crate serde_json;
|
|
|
|
extern crate toml;
|
|
|
|
|
2018-01-29 12:28:14 +00:00
|
|
|
extern crate regex;
|
2018-01-29 12:37:17 +00:00
|
|
|
extern crate semver;
|
2018-01-29 07:21:37 +00:00
|
|
|
|
2018-08-04 08:35:00 +00:00
|
|
|
extern crate dirs;
|
2018-08-08 02:47:32 +00:00
|
|
|
extern crate tar;
|
2019-07-05 01:23:16 +00:00
|
|
|
extern crate xz2;
|
2018-01-30 07:29:34 +00:00
|
|
|
extern crate zip;
|
|
|
|
|
2018-08-04 06:28:13 +00:00
|
|
|
extern crate fern;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
|
|
|
|
|
|
|
extern crate chrono;
|
|
|
|
|
2018-08-04 13:35:56 +00:00
|
|
|
extern crate clap;
|
2019-07-05 01:23:16 +00:00
|
|
|
#[cfg(windows)]
|
|
|
|
extern crate widestring;
|
2019-11-16 05:43:11 +00:00
|
|
|
#[cfg(windows)]
|
|
|
|
extern crate winapi;
|
2019-07-05 01:23:16 +00:00
|
|
|
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
extern crate slug;
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
extern crate sysinfo;
|
2018-12-15 08:14:25 +00:00
|
|
|
|
2019-10-02 07:13:53 +00:00
|
|
|
extern crate jsonwebtoken as jwt;
|
|
|
|
|
2019-10-21 07:09:16 +00:00
|
|
|
extern crate base64;
|
|
|
|
|
2018-08-08 02:47:32 +00:00
|
|
|
mod archives;
|
2018-01-27 03:27:41 +00:00
|
|
|
mod config;
|
2019-07-05 01:23:16 +00:00
|
|
|
mod frontend;
|
2018-05-03 11:50:44 +00:00
|
|
|
mod http;
|
2018-01-27 03:27:41 +00:00
|
|
|
mod installer;
|
2018-08-04 07:03:32 +00:00
|
|
|
mod logging;
|
2018-08-06 10:51:59 +00:00
|
|
|
mod native;
|
2019-07-05 01:23:16 +00:00
|
|
|
mod self_update;
|
2018-01-29 07:21:37 +00:00
|
|
|
mod sources;
|
2018-08-03 07:50:17 +00:00
|
|
|
mod tasks;
|
2018-01-26 12:29:28 +00:00
|
|
|
|
2018-01-27 03:27:41 +00:00
|
|
|
use installer::InstallerFramework;
|
2018-01-26 12:29:28 +00:00
|
|
|
|
2018-08-04 07:03:32 +00:00
|
|
|
use logging::LoggingErrors;
|
|
|
|
|
2018-08-04 13:35:56 +00:00
|
|
|
use clap::App;
|
|
|
|
use clap::Arg;
|
|
|
|
|
2018-08-07 05:34:57 +00:00
|
|
|
use config::BaseAttributes;
|
|
|
|
|
2018-09-20 03:37:44 +00:00
|
|
|
static RAW_CONFIG: &'static str = include_str!(concat!(env!("OUT_DIR"), "/bootstrap.toml"));
|
2018-01-26 12:29:28 +00:00
|
|
|
|
|
|
|
fn main() {
|
2018-10-01 03:17:59 +00:00
|
|
|
let config = BaseAttributes::from_toml_str(RAW_CONFIG).expect("Config file could not be read");
|
2018-10-01 01:27:31 +00:00
|
|
|
|
2018-10-01 03:17:59 +00:00
|
|
|
logging::setup_logger(format!("{}_installer.log", config.name))
|
|
|
|
.expect("Unable to setup logging!");
|
2018-01-27 03:27:41 +00:00
|
|
|
|
2019-07-05 01:23:16 +00:00
|
|
|
// Parse CLI arguments
|
2018-08-07 05:34:57 +00:00
|
|
|
let app_name = config.name.clone();
|
2018-01-27 04:33:15 +00:00
|
|
|
|
2018-08-09 05:21:50 +00:00
|
|
|
let app_about = format!("An interactive installer for {}", app_name);
|
|
|
|
let app = App::new(format!("{} installer", app_name))
|
2018-08-04 13:35:56 +00:00
|
|
|
.version(env!("CARGO_PKG_VERSION"))
|
2018-08-09 05:21:50 +00:00
|
|
|
.about(app_about.as_ref())
|
2018-08-04 13:35:56 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("launcher")
|
|
|
|
.long("launcher")
|
|
|
|
.value_name("TARGET")
|
|
|
|
.help("Launches the specified executable after checking for updates")
|
|
|
|
.takes_value(true),
|
2019-07-05 01:23:16 +00:00
|
|
|
)
|
|
|
|
.arg(
|
2018-08-09 05:21:50 +00:00
|
|
|
Arg::with_name("swap")
|
|
|
|
.long("swap")
|
|
|
|
.value_name("TARGET")
|
|
|
|
.help("Internal usage - swaps around a new installer executable")
|
|
|
|
.takes_value(true),
|
|
|
|
);
|
|
|
|
|
|
|
|
let reinterpret_app = app.clone(); // In case a reparse is needed
|
|
|
|
let mut matches = app.get_matches();
|
2018-08-04 13:35:56 +00:00
|
|
|
|
2018-08-04 06:28:13 +00:00
|
|
|
info!("{} installer", app_name);
|
2018-08-03 10:59:43 +00:00
|
|
|
|
2019-07-05 01:23:16 +00:00
|
|
|
// Handle self-updating if needed
|
2018-08-04 07:03:32 +00:00
|
|
|
let current_exe = std::env::current_exe().log_expect("Current executable could not be found");
|
|
|
|
let current_path = current_exe
|
|
|
|
.parent()
|
|
|
|
.log_expect("Parent directory of executable could not be found");
|
2018-08-09 05:21:50 +00:00
|
|
|
|
2019-07-05 01:23:16 +00:00
|
|
|
self_update::perform_swap(¤t_exe, matches.value_of("swap"));
|
|
|
|
if let Some(new_matches) = self_update::check_args(reinterpret_app, current_path) {
|
|
|
|
matches = new_matches;
|
2018-08-09 05:21:50 +00:00
|
|
|
}
|
2019-07-05 01:23:16 +00:00
|
|
|
self_update::cleanup(current_path);
|
2018-08-09 05:21:50 +00:00
|
|
|
|
2019-07-05 01:23:16 +00:00
|
|
|
// Load in metadata + setup the installer framework
|
2018-05-03 04:14:44 +00:00
|
|
|
let metadata_file = current_path.join("metadata.json");
|
2018-08-04 13:35:56 +00:00
|
|
|
let mut framework = if metadata_file.exists() {
|
2018-08-04 06:28:13 +00:00
|
|
|
info!("Using pre-existing metadata file: {:?}", metadata_file);
|
2018-08-04 07:03:32 +00:00
|
|
|
InstallerFramework::new_with_db(config, current_path).log_expect("Unable to parse metadata")
|
2018-05-03 03:30:58 +00:00
|
|
|
} else {
|
2018-08-04 06:28:13 +00:00
|
|
|
info!("Starting fresh install");
|
2018-05-03 03:30:58 +00:00
|
|
|
InstallerFramework::new(config)
|
|
|
|
};
|
2018-01-27 03:27:41 +00:00
|
|
|
|
2018-08-04 13:35:56 +00:00
|
|
|
let is_launcher = if let Some(string) = matches.value_of("launcher") {
|
|
|
|
framework.is_launcher = true;
|
|
|
|
framework.launcher_path = Some(string.to_string());
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
};
|
|
|
|
|
2019-07-05 01:23:16 +00:00
|
|
|
// Start up the UI
|
|
|
|
frontend::launch(&app_name, is_launcher, framework);
|
2018-01-26 12:29:28 +00:00
|
|
|
}
|