SHA256
Compare commits
6
Commits
4a4e6927bd
...
v0.2.6
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
aec7de0cc4 | ||
|
|
e13806ce05 | ||
|
|
37c4d64bee | ||
|
|
01b66cf589 | ||
|
|
25a706d6ea | ||
|
|
2fedcd0805 |
No files matched your search
Generated
+81
-32
@@ -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"
|
||||
@@ -116,6 +116,12 @@ version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
|
||||
|
||||
[[package]]
|
||||
name = "deranged"
|
||||
version = "0.5.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c"
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.2"
|
||||
@@ -146,13 +152,14 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "hive-up"
|
||||
version = "0.2.0"
|
||||
version = "0.2.6"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"nix",
|
||||
"regex-lite",
|
||||
"serde",
|
||||
"signal-hook",
|
||||
"time",
|
||||
"time-format",
|
||||
"toml",
|
||||
]
|
||||
@@ -175,9 +182,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"
|
||||
@@ -191,12 +198,24 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-conv"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell_polyfill"
|
||||
version = "1.70.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
|
||||
|
||||
[[package]]
|
||||
name = "powerfmt"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a6394b9e965e73d0a289ee54f589087e2c676aedf60885baf52c76b771e4958"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.107"
|
||||
@@ -253,18 +272,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_spanned"
|
||||
version = "1.1.1"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26"
|
||||
checksum = "4e7523beb55eece201a2356bee0bbca0d1ab466c14c07703b2e0ee6d42cb0c2c"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[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 +307,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "3.0.5"
|
||||
version = "3.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12df2e0110f65b775f769bb17ef989067a1d931b2eb822bd4346631eeada89f9"
|
||||
checksum = "d62a2e0561533f2ca2561d0cf27fd9fedb640a1bf2616ff5d5c80d99017faadc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -298,16 +317,46 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time-format"
|
||||
version = "1.2.3"
|
||||
name = "time"
|
||||
version = "0.3.55"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fb54c799611991d3d4a66fee3ff17b9f600c2a0f8c0d34e8209dbd153ff0a87b"
|
||||
checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"num-conv",
|
||||
"powerfmt",
|
||||
"serde_core",
|
||||
"time-core",
|
||||
"time-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time-core"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109"
|
||||
|
||||
[[package]]
|
||||
name = "time-format"
|
||||
version = "1.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c21b401b09485cb2403a336b3c6f9d53bd8a7273463f71b71d4f6325f7f74f6c"
|
||||
|
||||
[[package]]
|
||||
name = "time-macros"
|
||||
version = "0.2.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7e689342a48d2ea927c87ea50cabf8594854bf940e9310208848d680d668ed85"
|
||||
dependencies = [
|
||||
"num-conv",
|
||||
"time-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "1.1.6+spec-1.1.0"
|
||||
version = "1.1.8+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "920602543f0911ab71da12c50d59701da54c196d1a2bf5cb4b75667f137a406a"
|
||||
checksum = "20489e00e4d8741d6be680764cc12e270655e375a20d1011e844a9c3379e678d"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"serde_core",
|
||||
@@ -320,33 +369,33 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "1.1.1+spec-1.1.0"
|
||||
version = "1.1.2+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7"
|
||||
checksum = "2b86d767906c6c42421dcba507eb9d203e779497710a47782a224bb871653053"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_parser"
|
||||
version = "1.1.3+spec-1.1.0"
|
||||
version = "1.1.5+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d38ac1cf9b95face32296c0a3ede1fdc270627c9d9c02a7274dd6d960dc4d56"
|
||||
checksum = "baa693a8032d7e1cada7d0041e96126df243179ff061456783ac7f12bda4744c"
|
||||
dependencies = [
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_writer"
|
||||
version = "1.1.2+spec-1.1.0"
|
||||
version = "1.1.3+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2"
|
||||
checksum = "06bdbd8cfc056b8d2e2e85f29b56a3bdbecb527cef81eb39e3e7b98af4652770"
|
||||
|
||||
[[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"
|
||||
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "hive-up"
|
||||
version = "0.2.0"
|
||||
version = "0.2.6"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
@@ -9,6 +9,7 @@ nix = { version = "0", features = ["user"] }
|
||||
regex-lite = "0.1"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
signal-hook = "0.4"
|
||||
time = { version = "0.3", features = ["parsing", "macros"] }
|
||||
time-format = "1.2"
|
||||
toml = "1.1"
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
File renamed without changes.
@@ -3,3 +3,15 @@
|
||||
# In [kernel] section user may specify kernel cmd
|
||||
# [kernel]
|
||||
# cmd = ""
|
||||
|
||||
# [snapshots] section
|
||||
[snapshots]
|
||||
# enable shapshots
|
||||
enable = true
|
||||
# keep at max this number of snapshots, 0 - keep all
|
||||
keep_max = 1
|
||||
# keep shapshots not older than specified days. 0 - indefinatly.
|
||||
keep_days = 0
|
||||
# Keep atleast that much snapshots
|
||||
keep_min = 1
|
||||
|
||||
+15
-1
@@ -26,8 +26,10 @@ const CONFIG_PATH: &str = "/etc/hive-up.toml";
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct HiveConfig {
|
||||
// Matches [kernel] in TOML
|
||||
/// Matches [kernel] in TOML
|
||||
pub kernel: Option<KernelConfig>,
|
||||
/// Matches [snapshots] in TOML
|
||||
pub snapshots: Option<SnapshotsConfig>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
@@ -36,6 +38,18 @@ pub struct KernelConfig {
|
||||
pub cmd: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct SnapshotsConfig {
|
||||
/// enable shapshots
|
||||
pub enable: Option<bool>,
|
||||
/// keep at max this number of snapshots, 0 - keep all
|
||||
pub keep_max: Option<u32>,
|
||||
/// keep shapshots not older than specified days. 0 - indefinatly.
|
||||
pub keep_days: Option<u32>,
|
||||
/// keep atleast that much snapshots
|
||||
pub keep_min: Option<u32>
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ConfigError {
|
||||
|
||||
+191
-40
@@ -23,16 +23,22 @@ use std::process::Command;
|
||||
use std::vec;
|
||||
use time_format;
|
||||
|
||||
use crate::hive_config::{HiveConfig, SnapshotsConfig};
|
||||
|
||||
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";
|
||||
const PAC_LOCK_DIR: &str = "/var/lib/hive-up";
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CommandFailed {
|
||||
@@ -184,7 +190,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 +197,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],
|
||||
@@ -209,15 +213,8 @@ pub fn snapshot(subvolume: &str, target: &str) -> Result<(), ExecCommandError> {
|
||||
/// returns snapshot time on sucess
|
||||
///
|
||||
pub fn snapshot_system() -> Result<String, ExecCommandError> {
|
||||
use std::path::Path;
|
||||
// if snaps dir path do not exist - create it
|
||||
let snaps_path = Path::new(SNAPS_DIR);
|
||||
if !snaps_path.exists() {
|
||||
fs::create_dir(snaps_path)?;
|
||||
}
|
||||
|
||||
let ts = time_format::now().unwrap();
|
||||
let local_time = time_format::strftime_local("%Y-%m-%dT%H:%M:%S", ts).unwrap();
|
||||
let local_time = time_format::strftime_local("%Y-%m-%dT%H-%M-%S", ts).unwrap();
|
||||
let usr_snapshot_name = format!("{}/bzz-usr-{}", SNAPS_DIR, local_time);
|
||||
let var_snapshot_name = format!("{}/bzz-var-{}", SNAPS_DIR, local_time);
|
||||
|
||||
@@ -227,33 +224,186 @@ pub fn snapshot_system() -> Result<String, ExecCommandError> {
|
||||
Ok(local_time)
|
||||
}
|
||||
|
||||
//const TMP_ROOT: &str = "/mnt/bee-root";
|
||||
// pub fn list_bzzpss_snaps() -> Result<Vec<String>, ExecCommandError> {
|
||||
// use regex::Regex;
|
||||
// use std::path::Path;
|
||||
///
|
||||
/// bcachefs subvolume delete shortcut
|
||||
///
|
||||
fn subvolume_delete(subvolume: &str) -> Result<(), ExecCommandError> {
|
||||
exec_command("bcachefs", &vec!["subvolume", "delete", subvolume])?;
|
||||
|
||||
// // root snapshoot in a form of bzz-yyyy-mm-ddTHH-MM-SS
|
||||
// let re = Regex::new(r"^bzz-[a-z]+-[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}-[0-9]{2}-[0-9]{2}$").unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// let mut res: Vec<String> = Vec::new();
|
||||
// // if snaps dir path do not exist return empty list
|
||||
// if !Path::new(SNAPS_DIR).exists() {
|
||||
// return Ok(res);
|
||||
// }
|
||||
fn iso_to_unix(time_str: &str) -> Result<i64, String> {
|
||||
use time::OffsetDateTime;
|
||||
use time::macros::format_description;
|
||||
let be_format = format_description!("[year]-[month]-[day]T[hour]-[minute]-[second]");
|
||||
let dt: OffsetDateTime =
|
||||
OffsetDateTime::parse(time_str, be_format).map_err(|r| r.to_string())?;
|
||||
Ok(dt.unix_timestamp())
|
||||
}
|
||||
///
|
||||
/// Cleaning old snapshots according to settings
|
||||
///
|
||||
pub fn clean_snaps(snaps_conf: &SnapshotsConfig) -> Result<(), ExecCommandError> {
|
||||
let current_time = time_format::now().unwrap();
|
||||
|
||||
// for maybe_entry in fs::read_dir(SNAPS_DIR)? {
|
||||
// let entry = maybe_entry?;
|
||||
// if entry.file_type()?.is_dir() {
|
||||
// if let Some(dir_name) = entry.file_name().to_str()
|
||||
// && re.is_match(dir_name)
|
||||
// {
|
||||
// res.push(dir_name.to_string());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// res.sort();
|
||||
// Ok(res)
|
||||
// }
|
||||
// get snapshots list (newest comes last)
|
||||
let snaps_list = list_bzzpss_snaps()?;
|
||||
let snaps_count = snaps_list.len();
|
||||
if snaps_count > 0 {
|
||||
let keep_days = snaps_conf.keep_days.unwrap_or(0) as u64;
|
||||
let keep_max = snaps_conf.keep_max.unwrap_or(0) as usize;
|
||||
let keep_min = snaps_conf.keep_max.unwrap_or(1) as usize;
|
||||
|
||||
let mut keep_num: usize = keep_min;
|
||||
|
||||
if keep_days > 0 {
|
||||
let mut remove_count = 0;
|
||||
// iteratingfrom oldest
|
||||
for dt in &snaps_list {
|
||||
// 86400 - sec in day
|
||||
let days_passed: u64 = (current_time - iso_to_unix(dt)?).unsigned_abs() / 86400;
|
||||
if days_passed < keep_days {
|
||||
break;
|
||||
}
|
||||
remove_count += 1;
|
||||
}
|
||||
keep_num = keep_min.max(snaps_count.checked_sub(remove_count).unwrap());
|
||||
}
|
||||
if keep_max > 0 {
|
||||
keep_num = keep_num.min(keep_max);
|
||||
}
|
||||
keep_num = keep_num.max(keep_min);
|
||||
|
||||
let remove_num = snaps_count.checked_sub(keep_num).unwrap();
|
||||
|
||||
println!("Snapshots to delete: {}", remove_num);
|
||||
|
||||
// deleting snapshots
|
||||
for snap_date_time in snaps_list.iter().take(remove_num) {
|
||||
let usr_snap = format!("{}/bzz-{}-{}", SNAPS_DIR, "usr", snap_date_time);
|
||||
let var_snap = format!("{}/bzz-{}-{}", SNAPS_DIR, "var", snap_date_time);
|
||||
println!("Deleting {}", &usr_snap);
|
||||
subvolume_delete(&usr_snap)?;
|
||||
println!("Deleting {}", &var_snap);
|
||||
subvolume_delete(&var_snap)?;
|
||||
}
|
||||
println!("Done.");
|
||||
} else {
|
||||
println!("No snapshots found. Skipping cleaning.")
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Function for pacman preTransaction hook
|
||||
///
|
||||
pub fn pac_start(hive_config: &HiveConfig) -> Result<(), ExecCommandError> {
|
||||
use std::path::Path;
|
||||
|
||||
// checking is PAC_LOCK_DIR ("/var/lib/hive-up") exist
|
||||
// and creating it if it does not.
|
||||
let pack_lock_dir_path = Path::new(PAC_LOCK_DIR);
|
||||
if !pack_lock_dir_path.exists() {
|
||||
println!("Warning! {} directory do not exist. Creating...", PAC_LOCK_DIR);
|
||||
fs::create_dir_all(pack_lock_dir_path)?;
|
||||
}
|
||||
|
||||
// if snapshots is configured
|
||||
if let Some(snaps_conf) = &hive_config.snapshots {
|
||||
if snaps_conf.enable.unwrap_or(false) {
|
||||
// if snaps dir path do not exist - exit
|
||||
let snaps_path = Path::new(SNAPS_DIR);
|
||||
if snaps_path.exists() {
|
||||
// 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(());
|
||||
}
|
||||
|
||||
// cleaning old snapshots
|
||||
clean_snaps(snaps_conf)?;
|
||||
|
||||
println!("Creating system snapshot...");
|
||||
let snap_time = snapshot_system()?;
|
||||
println!("Ok.");
|
||||
|
||||
// placing pac-lock file
|
||||
fs::write(PAC_LOCK_FILE, snap_time)?;
|
||||
} else {
|
||||
println!(
|
||||
"Warning! snapshot dir {} do not exists - skiping snapshot creation",
|
||||
SNAPS_DIR
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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!("Removing pac-lock...");
|
||||
fs::remove_file(pack_lock_path)?;
|
||||
} else {
|
||||
println!("Warning! Pac Lock file does not exist...");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
///
|
||||
/// Looking for snapshots in snaps_dir for usr and var
|
||||
/// And return list of date-time part of filename if both snapshots exists
|
||||
/// List sorted in ascending order - newest snapshots comes last.
|
||||
///
|
||||
pub fn list_bzzpss_snaps() -> Result<Vec<String>, ExecCommandError> {
|
||||
use regex_lite::Regex;
|
||||
use std::path::Path;
|
||||
// usr or var snapshoot in a form of bzz-usr|var-yyyy-mm-ddTHH-MM-SS
|
||||
let re = Regex::new(r"^bzz-(usr|var)-([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}-[0-9]{2}-[0-9]{2})$")
|
||||
.unwrap();
|
||||
|
||||
let mut res: Vec<String> = Vec::new();
|
||||
// if snaps dir path do not exist return empty list
|
||||
if !Path::new(SNAPS_DIR).exists() {
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
// contains only date-time part
|
||||
let mut usr_snaps: Vec<String> = Vec::new();
|
||||
let mut var_snaps: Vec<String> = Vec::new();
|
||||
|
||||
// collect snapshots date-time
|
||||
for maybe_entry in fs::read_dir(SNAPS_DIR)? {
|
||||
let entry = maybe_entry?;
|
||||
if entry.file_type()?.is_dir() {
|
||||
if let Some(dir_name) = entry.file_name().to_str() {
|
||||
if let Some(captured) = re.captures(&dir_name) {
|
||||
let subvol_name = &captured[1];
|
||||
let date_time = captured[2].to_string();
|
||||
if subvol_name == "usr" {
|
||||
usr_snaps.push(date_time);
|
||||
} else {
|
||||
var_snaps.push(date_time);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// now we need to make sure snapshots of /usr and /var both exist
|
||||
// just fools safe, may reconsider in future
|
||||
usr_snaps.sort();
|
||||
for snap_time in usr_snaps {
|
||||
if var_snaps.contains(&snap_time) {
|
||||
res.push(snap_time);
|
||||
}
|
||||
}
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
pub fn check_if_run_as_root() -> bool {
|
||||
use nix::unistd::Uid;
|
||||
@@ -492,8 +642,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
@@ -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
|
||||
Finish,
|
||||
}
|
||||
|
||||
#[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(&bzz_config)?,
|
||||
Pac::Finish => hive_system::pac_finish()?
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user