repbuild r uses udisks
This commit is contained in:
parent
78a52f7102
commit
403e410797
|
@ -11,7 +11,10 @@ use std::{
|
||||||
os::fd::AsRawFd,
|
os::fd::AsRawFd,
|
||||||
process::Command,
|
process::Command,
|
||||||
};
|
};
|
||||||
use udisks::{filesystem::UnMountOptions, manager::LoopSetupOptions};
|
use udisks::{
|
||||||
|
filesystem::{MountOptions, UnMountOptions},
|
||||||
|
manager::LoopSetupOptions,
|
||||||
|
};
|
||||||
|
|
||||||
struct Options {
|
struct Options {
|
||||||
pub subcommand: Subcommand,
|
pub subcommand: Subcommand,
|
||||||
|
@ -257,40 +260,52 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
// Setup loopback device for disk.img, with partitions
|
// Setup loopback device for disk.img, with partitions
|
||||||
// FIXME: don't do ths if running without changes
|
// FIXME: don't do ths if running without changes
|
||||||
Command::new("sudo")
|
// Setup loop device
|
||||||
.arg("losetup")
|
let disk_img = File::options().read(true).write(true).open("disk.img")?;
|
||||||
.args(["-P", "/dev/loop0", "disk.img"])
|
let dbus_conn = zbus::blocking::Connection::system()?;
|
||||||
.status()
|
let loopdev = udisks::manager::UDisks2ManagerProxyBlocking::new(&dbus_conn)?
|
||||||
.unwrap();
|
.loop_setup(
|
||||||
|
disk_img.as_raw_fd().into(),
|
||||||
|
LoopSetupOptions {
|
||||||
|
no_user_interaction: true,
|
||||||
|
offset: 0,
|
||||||
|
size: 0,
|
||||||
|
readonly: false,
|
||||||
|
no_part_scan: false,
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
|
||||||
// mount the root fs to ./disk
|
let parts = udisks::partition::PartitionTableProxyBlocking::builder(&dbus_conn)
|
||||||
Command::new("sudo")
|
.destination("org.freedesktop.UDisks2")?
|
||||||
.arg("mount")
|
.path(loopdev)?
|
||||||
.args(["/dev/loop0p1", "./disk"])
|
.build()?
|
||||||
.status()
|
.partitions()?;
|
||||||
.unwrap();
|
|
||||||
|
let fsobjpath = parts.get(0).ok_or("missing boot partition")?;
|
||||||
|
let mountpoint =
|
||||||
|
udisks::filesystem::FilesystemProxyBlocking::builder(&dbus_conn)
|
||||||
|
.path(fsobjpath)?
|
||||||
|
.build()?
|
||||||
|
.mount(MountOptions {
|
||||||
|
no_user_interaction: true,
|
||||||
|
fs_type: String::new(),
|
||||||
|
mount_options: String::new(),
|
||||||
|
})?;
|
||||||
|
|
||||||
// copy the kernel over to ./disk/boot/kernel
|
// copy the kernel over to ./disk/boot/kernel
|
||||||
Command::new("sudo")
|
Command::new("cp")
|
||||||
.arg("cp")
|
|
||||||
.arg("./target/x86_64-ableos/debug/ableos")
|
.arg("./target/x86_64-ableos/debug/ableos")
|
||||||
.arg("./disk/boot/kernel")
|
.arg(format!("{mountpoint}/boot/kernel"))
|
||||||
.status()
|
.status()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// unmount the root fs
|
udisks::filesystem::FilesystemProxyBlocking::builder(&dbus_conn)
|
||||||
Command::new("sudo")
|
.path(fsobjpath)?
|
||||||
.arg("umount")
|
.build()?
|
||||||
.arg("./disk")
|
.unmount(UnMountOptions {
|
||||||
.status()
|
no_user_interaction: true,
|
||||||
.unwrap();
|
force: false,
|
||||||
|
})?;
|
||||||
// remove loopback device
|
|
||||||
Command::new("sudo")
|
|
||||||
.arg("losetup")
|
|
||||||
.args(["-d", "/dev/loop0"])
|
|
||||||
.status()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// run qemu with "-S", "-gdb", "tcp:9000"
|
// run qemu with "-S", "-gdb", "tcp:9000"
|
||||||
Command::new("qemu-system-x86_64")
|
Command::new("qemu-system-x86_64")
|
||||||
|
@ -324,40 +339,48 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
// Setup loopback device for disk.img, with partitions
|
// Setup loopback device for disk.img, with partitions
|
||||||
// FIXME: don't do ths if running without changes
|
// FIXME: don't do ths if running without changes
|
||||||
Command::new("sudo")
|
let disk_img = File::options().read(true).write(true).open("disk.img")?;
|
||||||
.arg("losetup")
|
let dbus_conn = zbus::blocking::Connection::system()?;
|
||||||
.args(["-P", "/dev/loop0", "disk.img"])
|
let loopdev = udisks::manager::UDisks2ManagerProxyBlocking::new(&dbus_conn)?
|
||||||
.status()
|
.loop_setup(
|
||||||
.unwrap();
|
disk_img.as_raw_fd().into(),
|
||||||
|
LoopSetupOptions {
|
||||||
|
no_user_interaction: true,
|
||||||
|
offset: 0,
|
||||||
|
size: 0,
|
||||||
|
readonly: false,
|
||||||
|
no_part_scan: false,
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
|
||||||
// mount the root fs to ./disk
|
let parts = udisks::partition::PartitionTableProxyBlocking::builder(&dbus_conn)
|
||||||
Command::new("sudo")
|
.destination("org.freedesktop.UDisks2")?
|
||||||
.arg("mount")
|
.path(loopdev)?
|
||||||
.args(["/dev/loop0p1", "./disk"])
|
.build()?
|
||||||
.status()
|
.partitions()?;
|
||||||
.unwrap();
|
|
||||||
|
let fsproxy = udisks::filesystem::FilesystemProxyBlocking::builder(&dbus_conn)
|
||||||
|
.path(&parts[0])?
|
||||||
|
.build()?;
|
||||||
|
|
||||||
|
// Obtain mountpoint
|
||||||
|
let mountpoint = loop {
|
||||||
|
if let Some(m) = fsproxy.mount_points()?.get(0) {
|
||||||
|
break m.to_string();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// copy the kernel over to ./disk/boot/kernel
|
// copy the kernel over to ./disk/boot/kernel
|
||||||
Command::new("sudo")
|
Command::new("cp")
|
||||||
.arg("cp")
|
|
||||||
.arg("./target/x86_64-ableos/release/ableos")
|
.arg("./target/x86_64-ableos/release/ableos")
|
||||||
.arg("./disk/boot/kernel")
|
.arg(format!("{mountpoint}/boot/kernel"))
|
||||||
.status()
|
.status()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// unmount the root fs
|
fsproxy.unmount(UnMountOptions {
|
||||||
Command::new("sudo")
|
no_user_interaction: true,
|
||||||
.arg("umount")
|
force: false,
|
||||||
.arg("./disk")
|
})?;
|
||||||
.status()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// remove loopback device
|
|
||||||
Command::new("sudo")
|
|
||||||
.arg("losetup")
|
|
||||||
.args(["-d", "/dev/loop0"])
|
|
||||||
.status()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// run qemu
|
// run qemu
|
||||||
Command::new("qemu-system-x86_64")
|
Command::new("qemu-system-x86_64")
|
||||||
|
|
Loading…
Reference in a new issue