2 Commits
Author SHA256 Message Date
kira 25a706d6ea Change uki image location to EFI/boot 2026-10-05 16:57:42 +02:00
kira 2fedcd0805 Pre Post transaction hooks for snapshots and such. 2026-09-14 22:48:05 +02:00
8 changed files with 125 additions and 63 deletions
Generated
+21 -21
View File
@@ -60,9 +60,9 @@ checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
[[package]]
name = "cfg-if"
version = "1.0.4"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
[[package]]
name = "cfg_aliases"
@@ -72,9 +72,9 @@ checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527"
[[package]]
name = "clap"
version = "4.6.6"
version = "4.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "473c7e07f409a8d772161724aa8db6a765a2532a70f9667eeb7b49d3d02fbdca"
checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946"
dependencies = [
"clap_builder",
"clap_derive",
@@ -82,9 +82,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.6.6"
version = "4.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b48fea5a88e9ae728a2dcbedbfc0e730f7d60da42e1cb049a83c9fb8b789889"
checksum = "ec0797fb7aeb1406c84efac526901f7ec3ead2124f946b494e72879d4b54704d"
dependencies = [
"anstream",
"anstyle",
@@ -94,9 +94,9 @@ dependencies = [
[[package]]
name = "clap_derive"
version = "4.6.4"
version = "4.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d012d2b9d65aca7f18f4d9878a045bc17899bba951561ba5ec3c2ba1eed9a061"
checksum = "f9c751b79415d4e559e3d1fcf128e09e720eb673a06d26cf6f392d37d75b66e0"
dependencies = [
"heck",
"proc-macro2",
@@ -106,9 +106,9 @@ dependencies = [
[[package]]
name = "clap_lex"
version = "1.1.0"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9"
checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486"
[[package]]
name = "colorchoice"
@@ -146,7 +146,7 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "hive-up"
version = "0.2.0"
version = "0.2.2"
dependencies = [
"clap",
"nix",
@@ -175,9 +175,9 @@ checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
[[package]]
name = "libc"
version = "0.2.189"
version = "0.2.190"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
checksum = "ce5d3ddc6d3fa000eb1536d85e147bfe31aacaba692ed6a876f95cb7c855be78"
[[package]]
name = "nix"
@@ -262,9 +262,9 @@ dependencies = [
[[package]]
name = "signal-hook"
version = "0.4.4"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2a0c28ca5908dbdbcd52e6fdaa00358ab88637f8ab33e1f188dd510eb44b53d"
checksum = "b29ffa27d3d59a049bb328258de100f8012848d1b08d444e08bbc02ac468435e"
dependencies = [
"libc",
"signal-hook-registry",
@@ -288,9 +288,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "syn"
version = "3.0.5"
version = "3.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12df2e0110f65b775f769bb17ef989067a1d931b2eb822bd4346631eeada89f9"
checksum = "8593e8e72159ed2257d083c7a454a85cbf854f37a0966d8d483aff8c8a3ebcee"
dependencies = [
"proc-macro2",
"quote",
@@ -299,9 +299,9 @@ dependencies = [
[[package]]
name = "time-format"
version = "1.2.3"
version = "1.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb54c799611991d3d4a66fee3ff17b9f600c2a0f8c0d34e8209dbd153ff0a87b"
checksum = "c21b401b09485cb2403a336b3c6f9d53bd8a7273463f71b71d4f6325f7f74f6c"
[[package]]
name = "toml"
@@ -344,9 +344,9 @@ checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2"
[[package]]
name = "unicode-ident"
version = "1.0.24"
version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954"
[[package]]
name = "utf8parse"
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "hive-up"
version = "0.2.0"
version = "0.2.2"
edition = "2024"
[dependencies]
+27 -30
View File
@@ -4,57 +4,54 @@ Program to manage update process of Kira Linux. Creating snapshots. Dealing with
There should be some documantation here.
hive-up uses `/var/lib/hive-up/hyve-db.json` file as database for stuff
And `/etc/hive-up.toml` as config file.
As an daemon hive-up righ now doing only periodical checks for updates.
hive-up uses `/etc/hive-up.toml` as config file.
```text
Update program fot Kira Linux :3
Usage: hive-up <COMMAND>
Commands:
cli Perform local operations
remote Ask hive-up daemon something
daemon Run hive-up in daemon mode
help Print this message or the help of the given subcommand(s)
boot Manage system boot
pac Intended to be used by pacman hooks
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
```
For cli mode:
Pac mode:
```text
Usage: hive-up cli <--upgrade|--update-boot|--init-boot-menu|--init-boot>
Usage: hive-up pac <COMMAND>
Commands:
snapshot-system Creates snapshoots of /usr and /var subvolumea
start This supposed to be called by pacman hook before transaction hive-up will check for /var/lib/hive-up/pac-lock and will not create snapshots in case it present Its safe lock mesure to prevent multiple snapshots on system fixing or some corner cases Lock file can be deleted by `pac finish` that should be called by pacman after transaction
finis This supposed to be called by pacman hook before transaction. Right now only thing it does is removes /var/lib/hive-up/pac-lock file
help Print this message or the help of the given subcommand(s)
Options:
--upgrade Perform system upgrade
--update-boot Install new kernel into boot partition
--init-boot-menu Cleans up and recreates UFI boot menu
--init-boot Cleans up and recreates UFI boot menu and /EFI dir content
-h, --help Print help
-h, --help Print help
Print help
```
For remote mode:
Boot mode:
```text
Usage: hive-up remote <--check-updates|--updates-avail|--schedule-update>
Usage: hive-up boot <COMMAND>
Commands:
update Install new kernel into boot partition
efi-menu-init Cleans up and recreates UFI boot menu
init Cleans up and recreates UFI boot menu and /EFI dir content
help Print this message or the help of the given subcommand(s)
Options:
--check-updates Ask daemon to check for updates
--updates-avail Ask daemon if there is any updates available
--schedule-update Ask daemon to perform system update on next reboot
-h, --help Print help
-h, --help Print help
```
`hive-up daemon` - do not have any flags for now.
`hive-up cli --upgrade` - generally not supposed to be called by user. It get called by system service manager (dinit) after hive-up service stop (on reboot or system shutdown)
When `hive-up cli --upgrade` is called, it checks if `update_on_reboot` flag is set in **DB** or `auto_update` flag checked in **config**, and if `updates_available` in **DB** is non zero. Update routine continue only if this conditios are met.
1. It creates snapshots of `/usr` and `/var` subvolumes
2. It sets `update_status` to **false** in **DB**
3. Performs update, and if everything was fine sets `update_status` to **true** in **DB**
After this, system reboots, and on system boot Nyanit figures up what to do with failed updates if any
+12
View File
@@ -0,0 +1,12 @@
[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = Package
Target = *
[Action]
Description = Release lock and do stuff
When = PostTransaction
Exec = /usr/bin/hive-up pac finish
+12
View File
@@ -0,0 +1,12 @@
[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = Package
Target = *
[Action]
Description = Snapshot system before any changes
When = PreTransaction
Exec = /usr/bin/hive-up pac start
+40 -8
View File
@@ -25,14 +25,17 @@ use time_format;
const SNAPS_DIR: &str = "/bzz-snaps";
const EFI_BOOT_MOUNT_POINT: &str = "/beefi";
const UKI_IMAGE_NAME: &str = "/beefi/EFI/linux-kira-lts.efi";
const UKI_IMAGE_BACK_NAME: &str = "/beefi/EFI/linux-kira-lts-back.efi";
const EFI_BOOT_DIR: &str = "/beefi/EFI/boot";
const UKI_IMAGE_NAME: &str = "/beefi/EFI/boot/linux-kira-lts.efi";
const UKI_IMAGE_BACK_NAME: &str = "/beefi/EFI/boot/linux-kira-lts-back.efi";
const EFI_PARTLABEL: &str = "bee-efi";
const BOOT_MENU_LABEL: &str = "Kira OS";
const BOOT_MENU_LABEL_BACK: &str = "Kira OS Fallback";
const BOOT_UKI_IMAGE_NAME: &str = "\\EFI\\linux-kira-lts.efi";
const BOOT_UKI_IMAGE_NAME_BACK: &str = "\\EFI\\linux-kira-lts-back.efi";
const BOOT_UKI_IMAGE_NAME: &str = "\\EFI\\boot\\linux-kira-lts.efi";
const BOOT_UKI_IMAGE_NAME_BACK: &str = "\\EFI\\boot\\linux-kira-lts-back.efi";
const PAC_LOCK_FILE: &str = "/var/lib/hive-up/pac-lock";
#[derive(Debug)]
pub struct CommandFailed {
@@ -184,7 +187,6 @@ pub fn exec_command_out(cmd: &str, args: &Vec<&str>) -> Result<String, ExecComma
// exec_command("pacman", &vec!["-Su", "--noconfirm", "--noprogressbar"])
// }
///
/// creates read only snapshoy of "subvolume" and places it into "target"]
/// bcachefs subvolume snapshot -r /subvolume /target
@@ -192,7 +194,6 @@ pub fn exec_command_out(cmd: &str, args: &Vec<&str>) -> Result<String, ExecComma
/// returns snapshot time on sucess
///
pub fn snapshot(subvolume: &str, target: &str) -> Result<(), ExecCommandError> {
exec_command(
"bcachefs",
&vec!["subvolume", "snapshot", "-r", subvolume, target],
@@ -227,6 +228,36 @@ pub fn snapshot_system() -> Result<String, ExecCommandError> {
Ok(local_time)
}
/// Function for pacman preTransaction hook
///
pub fn pac_start() -> Result<(), ExecCommandError> {
use std::path::Path;
// Check if lock file exist
let pack_lock_path = Path::new(PAC_LOCK_FILE);
if pack_lock_path.exists() {
println!("Warning! Pac Lock file exist, skipping system snapshot...");
return Ok(());
}
println!("Creating system snapshot...");
let snap_time = snapshot_system()?;
println!("Ok.");
fs::write(PAC_LOCK_FILE, snap_time)?;
Ok(())
}
pub fn pac_finish() -> Result<(), ExecCommandError> {
use std::path::Path;
// Check if lock file exist
let pack_lock_path = Path::new(PAC_LOCK_FILE);
if pack_lock_path.exists() {
println!("Remowing pac-lock...");
fs::remove_file(pack_lock_path)?;
} else {
println!("Warning! Pac Lock file does not exist - something is wrong...");
}
Ok(())
}
//const TMP_ROOT: &str = "/mnt/bee-root";
// pub fn list_bzzpss_snaps() -> Result<Vec<String>, ExecCommandError> {
// use regex::Regex;
@@ -492,8 +523,9 @@ pub fn init_efi_boot_partition_content() -> Result<(), ExecCommandError> {
let efi_dir = format!("{}/EFI", EFI_BOOT_MOUNT_POINT);
println!("Romoving efi dir {}", efi_dir);
fs::remove_dir_all(&efi_dir)?;
println!("Creating efi dir {}", efi_dir);
fs::create_dir(efi_dir)?;
println!("Creating efi dir {}", EFI_BOOT_DIR);
fs::create_dir_all(EFI_BOOT_DIR)?;
println!("Copy {} to {}", kernel_img_path, UKI_IMAGE_NAME);
fs::copy(&kernel_img_path, UKI_IMAGE_NAME)?;
println!("Copy {} to {}", kernel_img_path, UKI_IMAGE_BACK_NAME);
+11 -2
View File
@@ -21,7 +21,6 @@ use std::sync::Arc;
use std::sync::atomic::AtomicBool;
mod hive_system;
mod hive_config;
#[derive(Debug)]
@@ -92,6 +91,14 @@ enum BootCommand {
enum Pac {
/// Creates snapshoots of /usr and /var subvolumea
SnapshotSystem,
/// This supposed to be called by pacman hook before transaction
/// hive-up will check for /var/lib/hive-up/pac-lock and will not create snapshots in case it present
/// Its safe lock mesure to prevent multiple snapshots on system fixing or some corner cases
/// Lock file can be deleted by `pac finish` that should be called by pacman after transaction
Start,
/// This supposed to be called by pacman hook before transaction.
/// Right now only thing it does is removes /var/lib/hive-up/pac-lock file
Finis,
}
#[derive(Subcommand, Debug)]
@@ -158,7 +165,9 @@ fn main() -> Result<(), HiveUpError> {
println!("Creating system snapshot...");
let _ = hive_system::snapshot_system()?;
println!("Ok.");
}
},
Pac::Start => hive_system::pac_start()?,
Pac::Finis => hive_system::pac_finish()?
}
}