main.rs (2838B)
1 //! patina-installer: Sector F Linux's installer (ADR-0014). The live disc's greetd runs it inside 2 //! a kiosk compositor (`cage`); it picks a whole drive, runs `patina-install` on it through 3 //! pkexec, shows the flask while it works, and restarts into the first-run setup. 4 5 mod app; 6 mod backend; 7 mod flask; 8 mod system; 9 10 use std::sync::Arc; 11 12 use backend::{Backend, Mock}; 13 14 const USAGE: &str = "usage: patina-installer 15 16 The installer on the live disc. Run by greetd inside a kiosk compositor: `cage -s -- patina-installer`. 17 18 For trying the screens without a disc, on three fake drives and a fake install: 19 PATINA_INSTALLER_MOCK=1 (=fail makes the install fail part way) 20 PATINA_INSTALLER_SIZE=1280x800 a window of that size, not full screen 21 PATINA_INSTALLER_DEMO=... choose, confirm, installing, done, failed 22 PATINA_INSTALLER_SCREENSHOT=file.png saves the screen to a file and quits 23 PATINA_SKIN=name another skin"; 24 25 fn main() -> eframe::Result { 26 match std::env::args().nth(1).as_deref() { 27 None => {} 28 Some("-h" | "--help") => { 29 println!("{USAGE}"); 30 return Ok(()); 31 } 32 Some("-V" | "--version") => { 33 println!("patina-installer {}", env!("CARGO_PKG_VERSION")); 34 return Ok(()); 35 } 36 Some(_) => { 37 eprintln!("{USAGE}"); 38 std::process::exit(2); 39 } 40 } 41 42 let backend: Arc<dyn Backend> = match std::env::var("PATINA_INSTALLER_MOCK").as_deref() { 43 Ok("fail") => Arc::new(Mock::new(true)), 44 Ok(_) => Arc::new(Mock::new(false)), 45 Err(_) => Arc::new(system::System), 46 }; 47 48 let mut viewport = egui::ViewportBuilder::default() 49 .with_title("Install Sector F Linux") 50 .with_app_id("com.sectorflabs.Installer") 51 .with_decorations(false); 52 viewport = match window_size() { 53 Some(size) => viewport.with_inner_size(size), 54 None => viewport.with_fullscreen(true), 55 }; 56 eframe::run_native( 57 "patina-installer", 58 eframe::NativeOptions { 59 viewport, 60 ..Default::default() 61 }, 62 Box::new(move |cc| { 63 let mut app = app::App::new(cc, backend); 64 if let Ok(what) = std::env::var("PATINA_INSTALLER_DEMO") { 65 app.demo(&what); 66 } 67 if let Ok(path) = std::env::var("PATINA_INSTALLER_SCREENSHOT") { 68 app.screenshot_to(path.into()); 69 } 70 Ok(Box::new(app)) 71 }), 72 ) 73 } 74 75 fn window_size() -> Option<[f32; 2]> { 76 let text = std::env::var("PATINA_INSTALLER_SIZE").ok()?; 77 let (w, h) = text.split_once('x')?; 78 Some([w.parse().ok()?, h.parse().ok()?]) 79 } 80 81 impl eframe::App for app::App { 82 fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) { 83 self.draw(ui); 84 } 85 }