-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
167 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//! Helpers related to tracing, used by main entrypoints | ||
/// Initialize tracing with the default configuration. | ||
pub fn initialize_tracing() { | ||
// Don't include timestamps and such because they're not really useful and | ||
// too verbose, and plus several log targets such as journald will already | ||
// include timestamps. | ||
let format = tracing_subscriber::fmt::format() | ||
.without_time() | ||
.with_target(false) | ||
.compact(); | ||
// Log to stderr by default | ||
tracing_subscriber::fmt() | ||
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) | ||
.event_format(format) | ||
.with_writer(std::io::stderr) | ||
.init(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[package] | ||
name = "bootc-reinstall" | ||
version = "0.1.9" | ||
edition = "2021" | ||
license = "MIT OR Apache-2.0" | ||
repository = "https://github.com/containers/bootc" | ||
readme = "README.md" | ||
publish = false | ||
# For now don't bump this above what is currently shipped in RHEL9. | ||
rust-version = "1.75.0" | ||
|
||
# See https://github.com/coreos/cargo-vendor-filterer | ||
[package.metadata.vendor-filter] | ||
# This list of platforms is not intended to be exclusive, feel free | ||
# to extend it. But missing a platform will only matter for the case where | ||
# a dependent crate is *only* built on that platform. | ||
platforms = ["x86_64-unknown-linux-gnu", "aarch64-unknown-linux-gnu", "powerpc64le-unknown-linux-gnu", "s390x-unknown-linux-gnu", "riscv64gc-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
anyhow = { workspace = true } | ||
bootc-lib = { version = "1.0", path = "../lib" } | ||
clap = { workspace = true } | ||
log = "0.4.21" | ||
tracing = { workspace = true } | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
//! The main entrypoint for bootc-reinstall | ||
use std::{io::Write, process::Command}; | ||
|
||
use anyhow::{Context, Result}; | ||
|
||
fn run() -> Result<()> { | ||
bootc_lib::cli::tracing_util::initialize_tracing(); | ||
|
||
tracing::trace!("starting bootc-reinstall"); | ||
|
||
prompt()?; | ||
|
||
let command_and_args = [ | ||
// Rootless is not supported | ||
"sudo", | ||
// We use podman to run the bootc container. This might change in the future to remove the | ||
// podman dependency. | ||
"podman", | ||
"run", | ||
// The container needs to be privileged, as it heavily modifies the host | ||
"--privileged", | ||
// The container needs to access the host's PID namespace to mount host directories | ||
"--pid=host", | ||
// Since https://github.com/containers/bootc/pull/919 this mount should not be needed, but | ||
// some reason with e.g. quay.io/fedora/fedora-bootc:41 it is still needed. | ||
"-v", | ||
"/var/lib/containers:/var/lib/containers", | ||
// TODO: Get from argv | ||
"quay.io/fedora/fedora-bootc:41", | ||
// We're replacing the current root | ||
"bootc", | ||
"install", | ||
"to-existing-root", | ||
// The user already knows they're reinstalling their machine, that's the entire purpose of | ||
// this binary. Since this is no longer an "arcane" bootc command, we can safely avoid this | ||
// timed warning prompt. TODO: Discuss in https://github.com/containers/bootc/discussions/1060 | ||
"--acknowledge-destructive", | ||
]; | ||
|
||
Command::new(command_and_args[0]) | ||
.args(&command_and_args[1..]) | ||
.status() | ||
.context(format!( | ||
"Failed to run the command \"{}\"", | ||
command_and_args.join(" ") | ||
))?; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Temporary safety mechanism to stop devs from running it on their dev machine. TODO: Discuss | ||
/// final prompting UX in https://github.com/containers/bootc/discussions/1060 | ||
fn prompt() -> Result<(), anyhow::Error> { | ||
let prompt = "This will reinstall your system. Are you sure you want to continue? (y/n) "; | ||
let mut user_input = String::new(); | ||
loop { | ||
print!("{}", prompt); | ||
std::io::stdout().flush()?; | ||
std::io::stdin().read_line(&mut user_input)?; | ||
match user_input.trim() { | ||
"y" => break, | ||
"n" => { | ||
println!("Exiting without reinstalling the system."); | ||
return Ok(()); | ||
} | ||
_ => { | ||
println!("Unrecognized input. enter 'y' or 'n'."); | ||
user_input.clear(); | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn main() { | ||
// In order to print the error in a custom format (with :#) our | ||
// main simply invokes a run() where all the work is done. | ||
// This code just captures any errors. | ||
if let Err(e) = run() { | ||
tracing::error!("{:#}", e); | ||
std::process::exit(1); | ||
} | ||
} |