Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StartOS 0.3.4.3 #2304

Merged
merged 32 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a03e62f
deser full server info
dr-bonez Jun 12, 2023
02e50c9
re-add server version and version range
dr-bonez Jun 12, 2023
c40b9a9
bookworm
dr-bonez Jun 12, 2023
1f874eb
backup luks headers
dr-bonez Jun 12, 2023
d5de9d8
suite independent
dr-bonez Jun 12, 2023
23614ef
btrfs
dr-bonez Jun 14, 2023
9c5c208
gpu acceleration
dr-bonez Jun 14, 2023
d37bc01
don't wait for install to complete on sideload
dr-bonez Jun 14, 2023
206380f
do not load array buffer into memory
elvece Jun 14, 2023
3a7266b
backup target mount/umount
dr-bonez Jun 14, 2023
79427fc
ipv6
dr-bonez Jun 15, 2023
4e1d1e6
fix tor listener bug
dr-bonez Jun 16, 2023
813f46c
fix ipv6
dr-bonez Jun 16, 2023
ea32e92
postgresql migration
dr-bonez Jun 16, 2023
16c1824
fix build
dr-bonez Jun 16, 2023
43a0913
improve `invoke` error reporting
dr-bonez Jun 16, 2023
99e8a55
include old pg
dr-bonez Jun 16, 2023
14d460c
use postgres user
dr-bonez Jun 16, 2023
1b1c924
force btrfs creation
dr-bonez Jun 16, 2023
8a1b28f
install fixes
dr-bonez Jun 16, 2023
d9a2af1
fix update-grub2
dr-bonez Jun 17, 2023
d2e368c
fix postgres migration
dr-bonez Jun 17, 2023
f877a48
fix ipv6
dr-bonez Jun 17, 2023
3589977
fix build
dr-bonez Jun 17, 2023
2bf5c28
use fsck instead of e2fsck
dr-bonez Jun 19, 2023
052ff6d
trim fs name
dr-bonez Jun 19, 2023
949d3f1
reset config after pg_upgrade
dr-bonez Jun 19, 2023
7a04a37
update marketplace project to include mime type pipe for icons
elvece Jun 19, 2023
6dafbb9
add grub-common to build
dr-bonez Jun 19, 2023
2d3e206
Add qemu-guest-agent for advanced VM shutdown options (#2309)
gStart9 Jun 20, 2023
735fc50
fix btrfs rootflags
dr-bonez Jun 20, 2023
c5d8915
don't use cp when over cifs
dr-bonez Jun 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/startos-iso.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ jobs:
- uses: actions/cache@v3
with:
path: /var/lib/debspawn
key: ${{ runner.os }}-debspawn-init-bullseye

- name: Make build container
run: "debspawn list | grep bullseye || debspawn create bullseye"
key: ${{ runner.os }}-debspawn-init

- run: "mkdir -p overlays/deb"

Expand Down
19 changes: 17 additions & 2 deletions backend/src/backup/backup_bulk.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::{BTreeMap, BTreeSet};
use std::path::PathBuf;
use std::path::{Path, PathBuf};

use chrono::Utc;
use clap::ArgMatches;
Expand All @@ -8,6 +8,7 @@ use helpers::AtomicFile;
use patch_db::{DbHandle, LockType, PatchDbHandle};
use rpc_toolkit::command;
use tokio::io::AsyncWriteExt;
use tokio::process::Command;
use tracing::instrument;

use super::target::BackupTargetId;
Expand All @@ -23,8 +24,9 @@ use crate::disk::mount::guard::TmpMountGuard;
use crate::notifications::NotificationLevel;
use crate::s9pk::manifest::PackageId;
use crate::status::MainStatus;
use crate::util::display_none;
use crate::util::io::dir_copy;
use crate::util::serde::IoFormat;
use crate::util::{display_none, Invoke};
use crate::version::VersionT;
use crate::{Error, ErrorKind, ResultExt};

Expand Down Expand Up @@ -358,6 +360,19 @@ async fn perform_backup<Db: DbHandle>(
.await
.with_kind(ErrorKind::Filesystem)?;

let luks_folder_old = backup_guard.as_ref().join("luks.old");
if tokio::fs::metadata(&luks_folder_old).await.is_ok() {
tokio::fs::remove_dir_all(&luks_folder_old).await?;
}
let luks_folder_bak = backup_guard.as_ref().join("luks");
if tokio::fs::metadata(&luks_folder_bak).await.is_ok() {
tokio::fs::rename(&luks_folder_bak, &luks_folder_old).await?;
}
let luks_folder = Path::new("/media/embassy/config/luks");
if tokio::fs::metadata(&luks_folder).await.is_ok() {
dir_copy(&luks_folder, &luks_folder_bak).await?;
}

let timestamp = Some(Utc::now());

backup_guard.unencrypted_metadata.version = crate::version::Current::new().semver().into();
Expand Down
2 changes: 1 addition & 1 deletion backend/src/backup/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ async fn restore_package<'a>(
Ok((
progress.clone(),
async move {
download_install_s9pk(&ctx, &manifest, None, progress, file).await?;
download_install_s9pk(&ctx, &manifest, None, progress, file, None).await?;

guard.unmount().await?;

Expand Down
66 changes: 63 additions & 3 deletions backend/src/backup/target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ use clap::ArgMatches;
use color_eyre::eyre::eyre;
use digest::generic_array::GenericArray;
use digest::OutputSizeUser;
use lazy_static::lazy_static;
use rpc_toolkit::command;
use serde::{Deserialize, Serialize};
use sha2::Sha256;
use sqlx::{Executor, Postgres};
use tokio::sync::Mutex;
use tracing::instrument;

use self::cifs::CifsBackupTarget;
Expand All @@ -23,7 +25,7 @@ use crate::disk::mount::guard::TmpMountGuard;
use crate::disk::util::PartitionInfo;
use crate::s9pk::manifest::PackageId;
use crate::util::serde::{deserialize_from_str, display_serializable, serialize_display};
use crate::util::Version;
use crate::util::{display_none, Version};
use crate::Error;

pub mod cifs;
Expand All @@ -42,7 +44,7 @@ pub enum BackupTarget {
Cifs(CifsBackupTarget),
}

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum BackupTargetId {
Disk { logicalname: PathBuf },
Cifs { id: i32 },
Expand Down Expand Up @@ -129,7 +131,7 @@ impl FileSystem for BackupTargetFS {
}
}

#[command(subcommands(cifs::cifs, list, info))]
#[command(subcommands(cifs::cifs, list, info, mount, umount))]
pub fn target() -> Result<(), Error> {
Ok(())
}
Expand Down Expand Up @@ -247,3 +249,61 @@ pub async fn info(

Ok(res)
}

lazy_static! {
static ref USER_MOUNTS: Mutex<BTreeMap<BackupTargetId, BackupMountGuard<TmpMountGuard>>> =
Mutex::new(BTreeMap::new());
}

#[command]
#[instrument(skip_all)]
pub async fn mount(
#[context] ctx: RpcContext,
#[arg(rename = "target-id")] target_id: BackupTargetId,
#[arg] password: String,
) -> Result<String, Error> {
let mut mounts = USER_MOUNTS.lock().await;

if let Some(existing) = mounts.get(&target_id) {
return Ok(existing.as_ref().display().to_string());
}

let guard = BackupMountGuard::mount(
TmpMountGuard::mount(
&target_id
.clone()
.load(&mut ctx.secret_store.acquire().await?)
.await?,
ReadWrite,
)
.await?,
&password,
)
.await?;

let res = guard.as_ref().display().to_string();

mounts.insert(target_id, guard);

Ok(res)
}

#[command(display(display_none))]
#[instrument(skip_all)]
pub async fn umount(
#[context] ctx: RpcContext,
#[arg(rename = "target-id")] target_id: Option<BackupTargetId>,
) -> Result<(), Error> {
let mut mounts = USER_MOUNTS.lock().await;
if let Some(target_id) = target_id {
if let Some(existing) = mounts.remove(&target_id) {
existing.unmount().await?;
}
} else {
for (_, existing) in std::mem::take(&mut *mounts) {
existing.unmount().await?;
}
}

Ok(())
}
19 changes: 16 additions & 3 deletions backend/src/bin/embassy-init.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::net::{Ipv6Addr, SocketAddr};
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::Duration;
Expand Down Expand Up @@ -59,7 +60,11 @@ async fn setup_or_init(cfg_path: Option<PathBuf>) -> Result<(), Error> {

let ctx = InstallContext::init(cfg_path).await?;

let server = WebServer::install(([0, 0, 0, 0], 80).into(), ctx.clone()).await?;
let server = WebServer::install(
SocketAddr::new(Ipv6Addr::UNSPECIFIED.into(), 80),
ctx.clone(),
)
.await?;

tokio::time::sleep(Duration::from_secs(1)).await; // let the record state that I hate this
CHIME.play().await?;
Expand All @@ -81,7 +86,11 @@ async fn setup_or_init(cfg_path: Option<PathBuf>) -> Result<(), Error> {
{
let ctx = SetupContext::init(cfg_path).await?;

let server = WebServer::setup(([0, 0, 0, 0], 80).into(), ctx.clone()).await?;
let server = WebServer::setup(
SocketAddr::new(Ipv6Addr::UNSPECIFIED.into(), 80),
ctx.clone(),
)
.await?;

tokio::time::sleep(Duration::from_secs(1)).await; // let the record state that I hate this
CHIME.play().await?;
Expand Down Expand Up @@ -192,7 +201,11 @@ async fn inner_main(cfg_path: Option<PathBuf>) -> Result<Option<Shutdown>, Error
)
.await?;

let server = WebServer::diagnostic(([0, 0, 0, 0], 80).into(), ctx.clone()).await?;
let server = WebServer::diagnostic(
SocketAddr::new(Ipv6Addr::UNSPECIFIED.into(), 80),
ctx.clone(),
)
.await?;

let shutdown = ctx.shutdown.subscribe().recv().await.unwrap();

Expand Down
14 changes: 11 additions & 3 deletions backend/src/bin/embassyd.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::net::{Ipv6Addr, SocketAddr};
use std::path::{Path, PathBuf};
use std::sync::Arc;

Expand Down Expand Up @@ -26,7 +27,11 @@ async fn inner_main(cfg_path: Option<PathBuf>) -> Result<Option<Shutdown>, Error
)
.await?;
embassy::hostname::sync_hostname(&rpc_ctx.account.read().await.hostname).await?;
let server = WebServer::main(([0, 0, 0, 0], 80).into(), rpc_ctx.clone()).await?;
let server = WebServer::main(
SocketAddr::new(Ipv6Addr::UNSPECIFIED.into(), 80),
rpc_ctx.clone(),
)
.await?;

let mut shutdown_recv = rpc_ctx.shutdown.subscribe();

Expand Down Expand Up @@ -141,8 +146,11 @@ fn main() {
)
.await?;

let server =
WebServer::diagnostic(([0, 0, 0, 0], 80).into(), ctx.clone()).await?;
let server = WebServer::diagnostic(
SocketAddr::new(Ipv6Addr::UNSPECIFIED.into(), 80),
ctx.clone(),
)
.await?;

let mut shutdown = ctx.shutdown.subscribe();

Expand Down
31 changes: 31 additions & 0 deletions backend/src/disk/fsck/btrfs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::path::Path;

use tokio::process::Command;
use tracing::instrument;

use crate::disk::fsck::RequiresReboot;
use crate::util::Invoke;
use crate::Error;

#[instrument(skip_all)]
pub async fn btrfs_check_readonly(logicalname: impl AsRef<Path>) -> Result<RequiresReboot, Error> {
Command::new("btrfs")
.arg("check")
.arg("--readonly")
.arg(logicalname.as_ref())
.invoke(crate::ErrorKind::DiskManagement)
.await?;

Ok(RequiresReboot(false))
}

pub async fn btrfs_check_repair(logicalname: impl AsRef<Path>) -> Result<RequiresReboot, Error> {
Command::new("btrfs")
.arg("check")
.arg("--repair")
.arg(logicalname.as_ref())
.invoke(crate::ErrorKind::DiskManagement)
.await?;

Ok(RequiresReboot(false))
}
27 changes: 1 addition & 26 deletions backend/src/disk/fsck.rs → backend/src/disk/fsck/ext4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,9 @@ use futures::FutureExt;
use tokio::process::Command;
use tracing::instrument;

use crate::disk::fsck::RequiresReboot;
use crate::Error;

#[derive(Debug, Clone, Copy)]
#[must_use]
pub struct RequiresReboot(pub bool);
impl std::ops::BitOrAssign for RequiresReboot {
fn bitor_assign(&mut self, rhs: Self) {
self.0 |= rhs.0
}
}

#[derive(Debug, Clone, Copy)]
pub enum RepairStrategy {
Preen,
Aggressive,
}
impl RepairStrategy {
pub async fn e2fsck(
&self,
logicalname: impl AsRef<Path> + std::fmt::Debug,
) -> Result<RequiresReboot, Error> {
match self {
RepairStrategy::Preen => e2fsck_preen(logicalname).await,
RepairStrategy::Aggressive => e2fsck_aggressive(logicalname).await,
}
}
}

#[instrument(skip_all)]
pub async fn e2fsck_preen(
logicalname: impl AsRef<Path> + std::fmt::Debug,
Expand Down
70 changes: 70 additions & 0 deletions backend/src/disk/fsck/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use std::path::Path;

use color_eyre::eyre::eyre;
use tokio::process::Command;

use crate::disk::fsck::btrfs::{btrfs_check_readonly, btrfs_check_repair};
use crate::disk::fsck::ext4::{e2fsck_aggressive, e2fsck_preen};
use crate::util::Invoke;
use crate::Error;

pub mod btrfs;
pub mod ext4;

#[derive(Debug, Clone, Copy)]
#[must_use]
pub struct RequiresReboot(pub bool);
impl std::ops::BitOrAssign for RequiresReboot {
fn bitor_assign(&mut self, rhs: Self) {
self.0 |= rhs.0
}
}

#[derive(Debug, Clone, Copy)]
pub enum RepairStrategy {
Preen,
Aggressive,
}
impl RepairStrategy {
pub async fn fsck(
&self,
logicalname: impl AsRef<Path> + std::fmt::Debug,
) -> Result<RequiresReboot, Error> {
match &*String::from_utf8(
Command::new("grub-probe")
.arg("-d")
.arg(logicalname.as_ref())
.invoke(crate::ErrorKind::DiskManagement)
.await?,
)?
.trim()
{
"ext2" => self.e2fsck(logicalname).await,
"btrfs" => self.btrfs_check(logicalname).await,
fs => {
return Err(Error::new(
eyre!("Unknown filesystem {fs}"),
crate::ErrorKind::DiskManagement,
))
}
}
}
pub async fn e2fsck(
&self,
logicalname: impl AsRef<Path> + std::fmt::Debug,
) -> Result<RequiresReboot, Error> {
match self {
RepairStrategy::Preen => e2fsck_preen(logicalname).await,
RepairStrategy::Aggressive => e2fsck_aggressive(logicalname).await,
}
}
pub async fn btrfs_check(
&self,
logicalname: impl AsRef<Path> + std::fmt::Debug,
) -> Result<RequiresReboot, Error> {
match self {
RepairStrategy::Preen => btrfs_check_readonly(logicalname).await,
RepairStrategy::Aggressive => btrfs_check_repair(logicalname).await,
}
}
}
Loading