use proxmox_auto_installer::{
log::AutoInstLogger,
- utils::{AutoInstSettings, FetchAnswerFrom},
+ utils::{AutoInstSettings, FetchAnswerFrom, HttpOptions},
};
use fetch_plugins::{http::FetchFromHTTP, partition::FetchFromPartition};
bail!("Could not find any answer file!");
}
+fn settings_from_cli_args(args: &[String]) -> Result<AutoInstSettings> {
+ // TODO: this was done in a bit of a hurry, needs tidying up
+ let mode = match args[1].to_lowercase().as_str() {
+ "iso" => FetchAnswerFrom::Iso,
+ "http" => FetchAnswerFrom::Http,
+ "partition" => FetchAnswerFrom::Partition,
+ "-h" | "--help" => bail!(
+ "usage: {} <http|iso|partition> [<http-url>] [<tls-cert-fingerprint>]",
+ args[0]
+ ),
+ _ => bail!("failed to parse fetch-from argument, not one of 'http', 'iso', or 'partition'"),
+ };
+ if args.len() > 4 {
+ } else if args.len() > 2 && mode != FetchAnswerFrom::Http {
+ bail!("only 'http' fetch-from mode supports additional url and cert-fingerprint mode");
+ }
+ Ok(AutoInstSettings {
+ mode,
+ http: HttpOptions {
+ url: args.get(2).cloned(),
+ cert_fingerprint: args.get(3).cloned(),
+ },
+ })
+}
+
fn do_main() -> Result<()> {
if let Err(err) = init_log() {
bail!("could not initialize logging: {err}");
}
- let raw_install_settings = fs::read_to_string(AUTOINST_MODE_FILE).map_err(|err| {
- format_err!("Could not find needed file '{AUTOINST_MODE_FILE}' in live environment: {err}")
- })?;
- let install_settings: AutoInstSettings = toml::from_str(raw_install_settings.as_str())
- .map_err(|err| format_err!("Failed to parse '{AUTOINST_MODE_FILE}': {err}"))?;
+ let args: Vec<String> = std::env::args().collect();
+
+ let install_settings: AutoInstSettings = if args.len() > 1 {
+ settings_from_cli_args(&args)?
+ } else {
+ let raw_install_settings = fs::read_to_string(AUTOINST_MODE_FILE).map_err(|err| {
+ format_err!(
+ "Could not find needed file '{AUTOINST_MODE_FILE}' in live environment: {err}"
+ )
+ })?;
+ toml::from_str(raw_install_settings.as_str())
+ .map_err(|err| format_err!("Failed to parse '{AUTOINST_MODE_FILE}': {err}"))?
+ };
let answer = fetch_answer(&install_settings).map_err(|err| format_err!("Aborting: {err}"))?;
info!("queried answer file for automatic installation successfully");