Skip to content

Commit 559aca7

Browse files
authored
Merge pull request #549 from cgwalters/minor-install
install: A few minor patches
2 parents c69e132 + 88283c5 commit 559aca7

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

lib/src/bootloader.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ pub(crate) fn install_via_bootupd(
2121
.chain(verbose)
2222
.chain(bootupd_opts.iter().copied().flatten())
2323
.chain([
24-
"--src-root",
25-
"/",
2624
"--device",
2725
device.as_str(),
2826
rootfs.as_str(),
2927
]);
30-
Task::new_and_run("Running bootupctl to install bootloader", "bootupctl", args)
28+
Task::new("Running bootupctl to install bootloader", "bootupctl")
29+
.args(args)
30+
.verbose()
31+
.run()
3132
}

lib/src/install.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,11 @@ async fn initialize_ostree_root_from_self(
650650
options.kargs = Some(kargs.as_slice());
651651
options.target_imgref = Some(&state.target_imgref);
652652
options.proxy_cfg = proxy_cfg;
653-
println!("Deploying container image");
654-
let imgstate =
655-
ostree_container::deploy::deploy(&sysroot, stateroot, &src_imageref, Some(options)).await?;
656-
println!("Deployment complete");
653+
let imgstate = crate::utils::async_task_with_spinner(
654+
"Deploying container image",
655+
ostree_container::deploy::deploy(&sysroot, stateroot, &src_imageref, Some(options)),
656+
)
657+
.await?;
657658

658659
sysroot.load(cancellable)?;
659660
let deployment = sysroot

lib/src/install/baseline.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ pub(crate) fn install_create_rootfs(
434434
let espdev = &findpart(esp_partno)?;
435435
Task::new("Creating ESP filesystem", "mkfs.fat")
436436
.args([espdev.as_str(), "-n", "EFI-SYSTEM"])
437+
.verbose()
437438
.quiet_output()
438439
.run()?;
439440
let efifs_path = bootfs.join(crate::bootloader::EFI_DIR);

lib/src/utils.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
use std::future::Future;
2+
use std::io::Write;
13
use std::process::Command;
4+
use std::time::Duration;
25

36
use anyhow::{Context, Result};
47
use ostree::glib;
@@ -87,6 +90,35 @@ pub(crate) fn medium_visibility_warning(s: &str) {
8790
std::thread::sleep(std::time::Duration::from_secs(1));
8891
}
8992

93+
/// Call an async task function, and write a message to stdout
94+
/// with an automatic spinner to show that we're not blocked.
95+
/// Note that generally the called function should not output
96+
/// anything to stdout as this will interfere with the spinner.
97+
pub(crate) async fn async_task_with_spinner<F, T>(msg: &'static str, f: F) -> T
98+
where
99+
F: Future<Output = T>,
100+
{
101+
let pb = indicatif::ProgressBar::new_spinner();
102+
let style = indicatif::ProgressStyle::default_bar();
103+
pb.set_style(style.template("{spinner} {msg}").unwrap());
104+
pb.set_message(msg);
105+
pb.enable_steady_tick(Duration::from_millis(150));
106+
// We need to handle the case where we aren't connected to
107+
// a tty, so indicatif would show nothing by default.
108+
if pb.is_hidden() {
109+
print!("{}...", msg);
110+
std::io::stdout().flush().unwrap();
111+
} else {
112+
}
113+
let r = f.await;
114+
if pb.is_hidden() {
115+
println!("done");
116+
} else {
117+
pb.finish_with_message(format!("{msg}: done"));
118+
}
119+
r
120+
}
121+
90122
/// Given a possibly tagged image like quay.io/foo/bar:latest and a digest 0ab32..., return
91123
/// the digested form quay.io/foo/bar:latest@sha256:0ab32...
92124
/// If the image already has a digest, it will be replaced.

0 commit comments

Comments
 (0)