SHA256
Cleaning and wrapping things up. Bump of version.
This commit is contained in:
+54
-54
@@ -143,46 +143,46 @@ pub fn exec_command_out(cmd: &str, args: &Vec<&str>) -> Result<String, ExecComma
|
||||
/// pacman -Sy
|
||||
/// pacman -Qu
|
||||
/// returns number of updatable packages, returns 0 if there is no updates awailable
|
||||
pub fn check_updates() -> Result<u32, ExecCommandError> {
|
||||
// Synchronize pacman DB
|
||||
exec_command("pacman", &vec!["-Sy"])?;
|
||||
// Check for updates
|
||||
let out = Command::new("pacman").arg("-Qu").output()?;
|
||||
if out.status.success() {
|
||||
Ok(String::from_utf8(out.stdout)?
|
||||
.lines()
|
||||
.count()
|
||||
.try_into()
|
||||
.unwrap())
|
||||
} else {
|
||||
if let Some(code) = out.status.code()
|
||||
&& code == 1
|
||||
{
|
||||
Ok(0)
|
||||
} else {
|
||||
Err(ExecCommandError::Other(format!(
|
||||
"pacman -Qu failed: {}",
|
||||
String::from_utf8(out.stderr)?
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
// pub fn check_updates() -> Result<u32, ExecCommandError> {
|
||||
// // Synchronize pacman DB
|
||||
// exec_command("pacman", &vec!["-Sy"])?;
|
||||
// // Check for updates
|
||||
// let out = Command::new("pacman").arg("-Qu").output()?;
|
||||
// if out.status.success() {
|
||||
// Ok(String::from_utf8(out.stdout)?
|
||||
// .lines()
|
||||
// .count()
|
||||
// .try_into()
|
||||
// .unwrap())
|
||||
// } else {
|
||||
// if let Some(code) = out.status.code()
|
||||
// && code == 1
|
||||
// {
|
||||
// Ok(0)
|
||||
// } else {
|
||||
// Err(ExecCommandError::Other(format!(
|
||||
// "pacman -Qu failed: {}",
|
||||
// String::from_utf8(out.stderr)?
|
||||
// )))
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
///
|
||||
/// sudo pacman -Suw --noconfirm --noprogressbar
|
||||
/// Download updates (need to check for updates first)
|
||||
///
|
||||
pub fn download_updates() -> Result<(), ExecCommandError> {
|
||||
exec_command("pacman", &vec!["-Suw", "--noconfirm", "--noprogressbar"])
|
||||
}
|
||||
// pub fn download_updates() -> Result<(), ExecCommandError> {
|
||||
// exec_command("pacman", &vec!["-Suw", "--noconfirm", "--noprogressbar"])
|
||||
// }
|
||||
|
||||
///
|
||||
/// sudo pacman -Su --noconfirm --noprogressbar
|
||||
/// Perform updates
|
||||
///
|
||||
pub fn pkg_upgrade() -> Result<(), ExecCommandError> {
|
||||
exec_command("pacman", &vec!["-Su", "--noconfirm", "--noprogressbar"])
|
||||
}
|
||||
// pub fn pkg_upgrade() -> Result<(), ExecCommandError> {
|
||||
// exec_command("pacman", &vec!["-Su", "--noconfirm", "--noprogressbar"])
|
||||
// }
|
||||
|
||||
|
||||
///
|
||||
@@ -264,38 +264,38 @@ pub fn check_if_run_as_root() -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SysUpgradeError {
|
||||
SnapshotError(ExecCommandError),
|
||||
PkgUpgradeErr((String, ExecCommandError)),
|
||||
}
|
||||
// #[derive(Debug)]
|
||||
// pub enum SysUpgradeError {
|
||||
// SnapshotError(ExecCommandError),
|
||||
// PkgUpgradeErr((String, ExecCommandError)),
|
||||
// }
|
||||
|
||||
impl std::fmt::Display for SysUpgradeError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
SysUpgradeError::SnapshotError(e) => write!(f, "Snapshot creation error: {}", e),
|
||||
SysUpgradeError::PkgUpgradeErr((_, e)) => write!(f, "Packages upgrade error: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
// impl std::fmt::Display for SysUpgradeError {
|
||||
// fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
// match self {
|
||||
// SysUpgradeError::SnapshotError(e) => write!(f, "Snapshot creation error: {}", e),
|
||||
// SysUpgradeError::PkgUpgradeErr((_, e)) => write!(f, "Packages upgrade error: {}", e),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// Implement std::error::Error
|
||||
impl std::error::Error for SysUpgradeError {}
|
||||
// // Implement std::error::Error
|
||||
// impl std::error::Error for SysUpgradeError {}
|
||||
|
||||
///
|
||||
/// Perform system upgrade
|
||||
/// Reruns root snapshot name on success
|
||||
/// In case of upgrade error SysUpgradeError::PkgUpgradeErr contains snapshot time is str format
|
||||
///
|
||||
pub fn sys_upgrade() -> Result<String, SysUpgradeError> {
|
||||
// snapshooting root
|
||||
let snap_time = snapshot_system().map_err(SysUpgradeError::SnapshotError)?;
|
||||
// try to perform packages upgrade
|
||||
match pkg_upgrade() {
|
||||
Ok(_) => Ok(snap_time),
|
||||
Err(ex) => Err(SysUpgradeError::PkgUpgradeErr((snap_time, ex))),
|
||||
}
|
||||
}
|
||||
// pub fn sys_upgrade() -> Result<String, SysUpgradeError> {
|
||||
// // snapshooting root
|
||||
// let snap_time = snapshot_system().map_err(SysUpgradeError::SnapshotError)?;
|
||||
// // try to perform packages upgrade
|
||||
// match pkg_upgrade() {
|
||||
// Ok(_) => Ok(snap_time),
|
||||
// Err(ex) => Err(SysUpgradeError::PkgUpgradeErr((snap_time, ex))),
|
||||
// }
|
||||
// }
|
||||
|
||||
/// Gets device node aka /dev/sda1 from gpr partition label
|
||||
/// blkid -s PARTLABEL --match-token PARTLABEL="bzz-primary"
|
||||
|
||||
+24
-5
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use clap::{Args, Parser, Subcommand};
|
||||
use clap::{Parser, Subcommand};
|
||||
use signal_hook;
|
||||
use std;
|
||||
use std::sync::Arc;
|
||||
@@ -82,17 +82,28 @@ enum BootCommand {
|
||||
/// Install new kernel into boot partition
|
||||
Update,
|
||||
/// Cleans up and recreates UFI boot menu
|
||||
InitEfiMenu,
|
||||
EfiMenuInit,
|
||||
/// Cleans up and recreates UFI boot menu and /EFI dir content
|
||||
Init,
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
#[group(required = true)]
|
||||
enum Pac {
|
||||
/// Creates snapshoots of /usr and /var subvolumea
|
||||
SnapshotSystem,
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
#[group(required = true)] // 'multiple = false' enforces exclusivity
|
||||
enum HiveUpMode {
|
||||
/// Manage system boot
|
||||
#[command(subcommand)]
|
||||
Boot(BootCommand),
|
||||
|
||||
/// Intended to be used by pacman hooks
|
||||
#[command(subcommand)]
|
||||
Pac(Pac),
|
||||
}
|
||||
|
||||
/// Update program fot Kira Linux :3
|
||||
@@ -106,11 +117,12 @@ struct Cli {
|
||||
|
||||
fn main() -> Result<(), HiveUpError> {
|
||||
// registering signals handling
|
||||
// we really do not want for this program to get terminated in a middle of something,
|
||||
// so doing nothing with signals.
|
||||
// second sigtrm should kill it tho
|
||||
let term_flag: Arc<AtomicBool> = Arc::new(AtomicBool::new(false));
|
||||
let reload_flag = Arc::new(AtomicBool::new(false));
|
||||
signal_hook::flag::register(signal_hook::consts::SIGTERM, Arc::clone(&term_flag)).unwrap();
|
||||
signal_hook::flag::register(signal_hook::consts::SIGINT, Arc::clone(&term_flag)).unwrap();
|
||||
signal_hook::flag::register(signal_hook::consts::SIGHUP, Arc::clone(&reload_flag)).unwrap();
|
||||
|
||||
let args = Cli::parse();
|
||||
|
||||
@@ -127,7 +139,7 @@ fn main() -> Result<(), HiveUpError> {
|
||||
println!("Updating boot...");
|
||||
hive_system::boot_update()?;
|
||||
}
|
||||
BootCommand::InitEfiMenu => {
|
||||
BootCommand::EfiMenuInit => {
|
||||
println!("Init EFI boot menu...");
|
||||
let kernel_cmd = bzz_config.kernel.and_then(|kk| kk.cmd.clone());
|
||||
hive_system::init_efi_boot_record(&kernel_cmd)?;
|
||||
@@ -141,6 +153,13 @@ fn main() -> Result<(), HiveUpError> {
|
||||
hive_system::init_efi_boot_partition_content()?;
|
||||
}
|
||||
},
|
||||
HiveUpMode::Pac(pac_mode) => match pac_mode {
|
||||
Pac::SnapshotSystem => {
|
||||
println!("Creating system snapshot...");
|
||||
let _ = hive_system::snapshot_system()?;
|
||||
println!("Ok.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user