mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
initialize database better
This commit is contained in:
committed by
Aiden McClelland
parent
6093518e46
commit
e9db083004
@@ -5,8 +5,10 @@ use anyhow::anyhow;
|
|||||||
use embassy::context::{EitherContext, RpcContext};
|
use embassy::context::{EitherContext, RpcContext};
|
||||||
use embassy::db::model::Database;
|
use embassy::db::model::Database;
|
||||||
use embassy::db::subscribe;
|
use embassy::db::subscribe;
|
||||||
|
use embassy::hostname::{get_hostname, get_id};
|
||||||
use embassy::middleware::auth::auth;
|
use embassy::middleware::auth::auth;
|
||||||
use embassy::middleware::cors::cors;
|
use embassy::middleware::cors::cors;
|
||||||
|
use embassy::net::tor::os_key;
|
||||||
use embassy::status::{check_all, synchronize_all};
|
use embassy::status::{check_all, synchronize_all};
|
||||||
use embassy::util::daemon;
|
use embassy::util::daemon;
|
||||||
use embassy::{Error, ErrorKind, ResultExt};
|
use embassy::{Error, ErrorKind, ResultExt};
|
||||||
@@ -32,7 +34,15 @@ async fn inner_main(cfg_path: Option<&str>) -> Result<(), Error> {
|
|||||||
if !rpc_ctx.db.exists(&<JsonPointer>::default()).await? {
|
if !rpc_ctx.db.exists(&<JsonPointer>::default()).await? {
|
||||||
rpc_ctx
|
rpc_ctx
|
||||||
.db
|
.db
|
||||||
.put(&<JsonPointer>::default(), &Database::init(), None)
|
.put(
|
||||||
|
&<JsonPointer>::default(),
|
||||||
|
&Database::init(
|
||||||
|
get_id().await?,
|
||||||
|
&get_hostname().await?,
|
||||||
|
&os_key(&mut rpc_ctx.secret_store.acquire().await?).await?,
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
let auth = auth(rpc_ctx.clone());
|
let auth = auth(rpc_ctx.clone());
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use patch_db::{DbHandle, HasModel, Map, MapModel, OptionModel};
|
|||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
use torut::onion::TorSecretKeyV3;
|
||||||
|
|
||||||
use crate::config::spec::{PackagePointerSpecVariant, SystemPointerSpec};
|
use crate::config::spec::{PackagePointerSpecVariant, SystemPointerSpec};
|
||||||
use crate::install::progress::InstallProgress;
|
use crate::install::progress::InstallProgress;
|
||||||
@@ -28,17 +29,16 @@ pub struct Database {
|
|||||||
pub ui: Value,
|
pub ui: Value,
|
||||||
}
|
}
|
||||||
impl Database {
|
impl Database {
|
||||||
pub fn init() -> Self {
|
pub fn init(id: String, hostname: &str, tor_key: &TorSecretKeyV3) -> Self {
|
||||||
// TODO
|
// TODO
|
||||||
Database {
|
Database {
|
||||||
server_info: ServerInfo {
|
server_info: ServerInfo {
|
||||||
id: "c3ad21d8".to_owned(),
|
id,
|
||||||
version: emver::Version::new(0, 3, 0, 0).into(),
|
version: emver::Version::new(0, 3, 0, 0).into(),
|
||||||
lan_address: "https://start9-c3ad21d8.local".parse().unwrap(),
|
lan_address: format!("https://{}.local", hostname).parse().unwrap(),
|
||||||
tor_address:
|
tor_address: format!("http://{}", tor_key.public().get_onion_address())
|
||||||
"http://privacy34kn4ez3y3nijweec6w4g54i3g54sdv7r5mr6soma3w4begyd.onion"
|
.parse()
|
||||||
.parse()
|
.unwrap(),
|
||||||
.unwrap(),
|
|
||||||
status: ServerStatus::Running,
|
status: ServerStatus::Running,
|
||||||
eos_marketplace: "https://beta-registry-0-3.start9labs.com".parse().unwrap(),
|
eos_marketplace: "https://beta-registry-0-3.start9labs.com".parse().unwrap(),
|
||||||
package_marketplace: None,
|
package_marketplace: None,
|
||||||
|
|||||||
@@ -26,12 +26,16 @@ pub async fn get_product_key() -> Result<String, Error> {
|
|||||||
Ok(out.trim().to_owned())
|
Ok(out.trim().to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
// cat /boot/product_key.txt | shasum -a 256 | head -c 8 | awk '{print "start9-"$1}' | xargs hostnamectl set-hostname
|
pub async fn get_id() -> Result<String, Error> {
|
||||||
pub async fn sync_hostname() -> Result<(), Error> {
|
|
||||||
let key = get_product_key().await?;
|
let key = get_product_key().await?;
|
||||||
let mut hasher = sha2::Sha256::new();
|
let mut hasher = sha2::Sha256::new();
|
||||||
hasher.update(key.as_bytes());
|
hasher.update(key.as_bytes());
|
||||||
let res = hasher.finalize();
|
let res = hasher.finalize();
|
||||||
set_hostname(&format!("start9-{}", hex::encode(&res[0..4]))).await?;
|
Ok(hex::encode(&res[0..4]))
|
||||||
|
}
|
||||||
|
|
||||||
|
// cat /boot/product_key.txt | shasum -a 256 | head -c 8 | awk '{print "start9-"$1}' | xargs hostnamectl set-hostname
|
||||||
|
pub async fn sync_hostname() -> Result<(), Error> {
|
||||||
|
set_hostname(&format!("start9-{}", get_id().await?)).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user