Skip to content

Commit 436791e

Browse files
committed
install: Factor out some options
Prep for `install-to-filesystem` which will accept an already mounted fs and not a block device. Signed-off-by: Colin Walters <[email protected]>
1 parent 6075da3 commit 436791e

File tree

1 file changed

+48
-35
lines changed

1 file changed

+48
-35
lines changed

lib/src/install.rs

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,8 @@ const PREPPN: u32 = 1;
8282
#[cfg(target_arch = "ppc64")]
8383
const RESERVEDPN: u32 = 1;
8484

85-
/// Perform an upgrade operation
86-
#[derive(Debug, Clone, clap::Parser)]
87-
pub(crate) struct InstallOpts {
88-
/// Target block device for installation. The entire device will be wiped.
89-
pub(crate) device: Utf8PathBuf,
90-
91-
/// Automatically wipe all existing data on device
92-
#[clap(long)]
93-
pub(crate) wipe: bool,
94-
95-
/// Size of the root partition (default specifier: M). Allowed specifiers: M (mebibytes), G (gibibytes), T (tebibytes).
96-
///
97-
/// By default, all remaining space on the disk will be used.
98-
#[clap(long)]
99-
pub(crate) root_size: Option<String>,
100-
85+
#[derive(clap::Args, Debug, Clone)]
86+
pub(crate) struct InstallTargetOpts {
10187
// TODO: A size specifier which allocates free space for the root in *addition* to the base container image size
10288
// pub(crate) root_additional_size: Option<String>
10389
/// The transport; e.g. oci, oci-archive. Defaults to `registry`.
@@ -115,11 +101,10 @@ pub(crate) struct InstallOpts {
115101
/// Enable verification via an ostree remote
116102
#[clap(long)]
117103
pub(crate) target_ostree_remote: Option<String>,
104+
}
118105

119-
/// Target root filesystem type.
120-
#[clap(long, value_enum, default_value_t)]
121-
pub(crate) filesystem: Filesystem,
122-
106+
#[derive(clap::Args, Debug, Clone)]
107+
pub(crate) struct InstallConfigOpts {
123108
/// Path to an Ignition config file
124109
#[clap(long, value_parser)]
125110
pub(crate) ignition_file: Option<Utf8PathBuf>,
@@ -131,13 +116,6 @@ pub(crate) struct InstallOpts {
131116
#[clap(long, value_name = "digest", value_parser)]
132117
pub(crate) ignition_hash: Option<crate::ignition::IgnitionHash>,
133118

134-
/// Target root block device setup.
135-
///
136-
/// direct: Filesystem written directly to block device
137-
/// tpm2-luks: Bind unlock of filesystem to presence of the default tpm2 device.
138-
#[clap(long, value_enum, default_value_t)]
139-
pub(crate) block_setup: BlockSetup,
140-
141119
/// Disable SELinux in the target (installed) system.
142120
///
143121
/// This is currently necessary to install *from* a system with SELinux disabled
@@ -154,6 +132,40 @@ pub(crate) struct InstallOpts {
154132
karg: Option<Vec<String>>,
155133
}
156134

135+
/// Perform an upgrade operation
136+
#[derive(Debug, Clone, clap::Parser)]
137+
pub(crate) struct InstallOpts {
138+
/// Target block device for installation. The entire device will be wiped.
139+
pub(crate) device: Utf8PathBuf,
140+
141+
/// Automatically wipe all existing data on device
142+
#[clap(long)]
143+
pub(crate) wipe: bool,
144+
145+
/// Target root block device setup.
146+
///
147+
/// direct: Filesystem written directly to block device
148+
/// tpm2-luks: Bind unlock of filesystem to presence of the default tpm2 device.
149+
#[clap(long, value_enum, default_value_t)]
150+
pub(crate) block_setup: BlockSetup,
151+
152+
/// Size of the root partition (default specifier: M). Allowed specifiers: M (mebibytes), G (gibibytes), T (tebibytes).
153+
///
154+
/// By default, all remaining space on the disk will be used.
155+
#[clap(long)]
156+
pub(crate) root_size: Option<String>,
157+
158+
/// Target root filesystem type.
159+
#[clap(long, value_enum, default_value_t)]
160+
pub(crate) filesystem: Filesystem,
161+
162+
#[clap(flatten)]
163+
pub(crate) target_opts: InstallTargetOpts,
164+
165+
#[clap(flatten)]
166+
pub(crate) config_opts: InstallConfigOpts,
167+
}
168+
157169
// Shared read-only global state
158170
struct State {
159171
opts: InstallOpts,
@@ -278,15 +290,16 @@ async fn initialize_ostree_root_from_self(
278290
};
279291

280292
// Parse the target CLI image reference options
281-
let target_sigverify = if opts.target_no_signature_verification {
293+
let target_sigverify = if opts.target_opts.target_no_signature_verification {
282294
SignatureSource::ContainerPolicyAllowInsecure
283-
} else if let Some(remote) = opts.target_ostree_remote.as_deref() {
295+
} else if let Some(remote) = opts.target_opts.target_ostree_remote.as_deref() {
284296
SignatureSource::OstreeRemote(remote.to_string())
285297
} else {
286298
SignatureSource::ContainerPolicy
287299
};
288-
let target_imgref = if let Some(imgref) = opts.target_imgref.as_ref() {
289-
let transport = ostree_container::Transport::try_from(opts.target_transport.as_str())?;
300+
let target_imgref = if let Some(imgref) = opts.target_opts.target_imgref.as_ref() {
301+
let transport =
302+
ostree_container::Transport::try_from(opts.target_opts.target_transport.as_str())?;
290303
let imgref = ostree_container::ImageReference {
291304
transport,
292305
name: imgref.to_string(),
@@ -725,7 +738,7 @@ pub(crate) async fn install(opts: InstallOpts) -> Result<()> {
725738
crate::lsm::container_setup_selinux()?;
726739
// This will re-execute the current process (once).
727740
crate::lsm::selinux_ensure_install()?;
728-
} else if opts.disable_selinux {
741+
} else if opts.config_opts.disable_selinux {
729742
override_disable_selinux = true;
730743
println!("notice: Target has SELinux enabled, overriding to disable")
731744
} else {
@@ -770,7 +783,7 @@ pub(crate) async fn install(opts: InstallOpts) -> Result<()> {
770783
kargs.push("selinux=0");
771784
}
772785
// This is interpreted by our GRUB fragment
773-
if state.opts.ignition_file.is_some() {
786+
if state.opts.config_opts.ignition_file.is_some() {
774787
kargs.push(crate::ignition::PLATFORM_METAL_KARG);
775788
kargs.push(crate::bootloader::IGNITION_VARIABLE);
776789
}
@@ -792,11 +805,11 @@ pub(crate) async fn install(opts: InstallOpts) -> Result<()> {
792805
crate::bootloader::install_via_bootupd(&rootfs.device, &rootfs.rootfs, &rootfs.boot_uuid)?;
793806

794807
// If Ignition is specified, enable it
795-
if let Some(ignition_file) = state.opts.ignition_file.as_deref() {
808+
if let Some(ignition_file) = state.opts.config_opts.ignition_file.as_deref() {
796809
let src = std::fs::File::open(ignition_file)
797810
.with_context(|| format!("Opening {ignition_file}"))?;
798811
let bootfs = rootfs.rootfs.join("boot");
799-
crate::ignition::write_ignition(&bootfs, &state.opts.ignition_hash, &src)?;
812+
crate::ignition::write_ignition(&bootfs, &state.opts.config_opts.ignition_hash, &src)?;
800813
crate::ignition::enable_firstboot(&bootfs)?;
801814
println!("Installed Ignition config from {ignition_file}");
802815
}

0 commit comments

Comments
 (0)