mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +00:00
pack
This commit is contained in:
committed by
Aiden McClelland
parent
172ef71c8d
commit
8b3a7c6df5
@@ -1,5 +1,15 @@
|
||||
{
|
||||
"db": "SQLite",
|
||||
"121a1c1c0c11c5588c17bbd9b2baeca4d27d1a6d82d6487fad142ffb58d1da0c": {
|
||||
"query": "INSERT INTO tor (package, interface, key) VALUES (?, ?, ?)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 3
|
||||
},
|
||||
"nullable": []
|
||||
}
|
||||
},
|
||||
"3e57a0e52b69f33e9411c13b03a5d82c5856d63f0375eb4c23b255a09c54f8b1": {
|
||||
"query": "SELECT key FROM tor WHERE package = ? AND interface = ?",
|
||||
"describe": {
|
||||
|
||||
@@ -7,7 +7,7 @@ fn inner_main() -> Result<(), Error> {
|
||||
simple_logging::log_to_stderr(log::LevelFilter::Info);
|
||||
run_cli!(
|
||||
embassy::main_api,
|
||||
app => app
|
||||
app => app.name("Embassy CLI")
|
||||
.arg(Arg::with_name("host").long("host").short("h").takes_value(true))
|
||||
.arg(Arg::with_name("port").long("port").short("p").takes_value(true)),
|
||||
matches => EitherContext::Cli(CliContext::init(matches)?),
|
||||
|
||||
@@ -7,9 +7,7 @@ fn inner_main() -> Result<(), Error> {
|
||||
simple_logging::log_to_stderr(log::LevelFilter::Info);
|
||||
run_cli!(
|
||||
embassy::portable_api,
|
||||
app => app
|
||||
.arg(Arg::with_name("host").long("host").short("h").takes_value(true))
|
||||
.arg(Arg::with_name("port").long("port").short("p").takes_value(true)),
|
||||
app => app.name("Embassy SDK"),
|
||||
matches => EitherContext::Cli(CliContext::init(matches)?),
|
||||
|code| if code < 0 { 1 } else { code }
|
||||
)
|
||||
|
||||
@@ -41,12 +41,17 @@ use rpc_toolkit::command;
|
||||
use rpc_toolkit::yajrc::RpcError;
|
||||
pub use version::{init, self_update};
|
||||
|
||||
#[command(subcommands(config::config, version::git_info))]
|
||||
#[command]
|
||||
pub fn echo(#[context] _ctx: EitherContext, #[arg] message: String) -> Result<String, RpcError> {
|
||||
Ok(message)
|
||||
}
|
||||
|
||||
#[command(subcommands(config::config, version::git_info, echo, s9pk::pack, s9pk::verify))]
|
||||
pub fn main_api(#[context] ctx: EitherContext) -> Result<EitherContext, RpcError> {
|
||||
Ok(ctx)
|
||||
}
|
||||
|
||||
#[command(subcommands(version::git_info))]
|
||||
#[command(subcommands(version::git_info, s9pk::pack, s9pk::verify))]
|
||||
pub fn portable_api(#[context] ctx: EitherContext) -> Result<EitherContext, RpcError> {
|
||||
Ok(ctx)
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ use tokio::sync::RwLock;
|
||||
use crate::util::Apply;
|
||||
use crate::Error;
|
||||
|
||||
const HOSTNAME_LEN: usize = 1 + 15 + 1 + 5; // leading byte, main address, dot, "local"
|
||||
|
||||
pub struct MdnsController(RwLock<MdnsControllerInner>);
|
||||
impl MdnsController {
|
||||
pub async fn init<Db: DbHandle>(db: &mut Db) -> Result<Self, Error> {
|
||||
@@ -24,8 +22,7 @@ impl MdnsController {
|
||||
}
|
||||
|
||||
pub struct MdnsControllerInner {
|
||||
hostname: [u8; HOSTNAME_LEN + 1],
|
||||
client: *mut AvahiClient,
|
||||
hostname: Vec<u8>,
|
||||
entry_group: *mut AvahiEntryGroup,
|
||||
}
|
||||
unsafe impl Send for MdnsControllerInner {}
|
||||
@@ -107,24 +104,26 @@ impl MdnsControllerInner {
|
||||
);
|
||||
let group =
|
||||
avahi_sys::avahi_entry_group_new(avahi_client, Some(noop), std::ptr::null_mut());
|
||||
let mut hostname_buf = [0; HOSTNAME_LEN + 1];
|
||||
let mut hostname_buf = vec![0];
|
||||
{
|
||||
let hostname_raw = avahi_sys::avahi_client_get_host_name_fqdn(avahi_client);
|
||||
hostname_buf[1..]
|
||||
.copy_from_slice(std::ffi::CStr::from_ptr(hostname_raw).to_bytes_with_nul());
|
||||
hostname_buf
|
||||
.extend_from_slice(std::ffi::CStr::from_ptr(hostname_raw).to_bytes_with_nul());
|
||||
avahi_free(hostname_raw as *mut c_void);
|
||||
}
|
||||
let buflen = hostname_buf.len();
|
||||
debug_assert!(hostname_buf.ends_with(b".local\0"));
|
||||
debug_assert!(!hostname_buf[..(buflen - 7)].contains(&b'.'));
|
||||
// assume fixed length prefix on hostname due to local address
|
||||
hostname_buf[0] = 15; // set the prefix length to 15 for the main address
|
||||
hostname_buf[16] = 5; // set the prefix length to 5 for "local"
|
||||
hostname_buf[0] = (buflen - 8) as u8; // set the prefix length to len - 8 (leading byte, .local, nul) for the main address
|
||||
hostname_buf[buflen - 7] = 5; // set the prefix length to 5 for "local"
|
||||
|
||||
let mut ctrl = MdnsControllerInner {
|
||||
hostname: hostname_buf,
|
||||
client: avahi_client,
|
||||
entry_group: group,
|
||||
};
|
||||
avahi_entry_group_commit(group);
|
||||
ctrl.load_services(db).await?;
|
||||
avahi_entry_group_commit(group);
|
||||
Ok(ctrl)
|
||||
}
|
||||
}
|
||||
@@ -141,7 +140,6 @@ impl Drop for MdnsControllerInner {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
avahi_entry_group_free(self.entry_group);
|
||||
avahi_client_free(self.client);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,64 @@
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::anyhow;
|
||||
use rpc_toolkit::command;
|
||||
use rpc_toolkit::yajrc::RpcError;
|
||||
|
||||
use crate::context::{CliContext, EitherContext};
|
||||
use crate::s9pk::builder::S9pkPacker;
|
||||
use crate::s9pk::manifest::Manifest;
|
||||
use crate::s9pk::reader::S9pkReader;
|
||||
use crate::util::display_none;
|
||||
use crate::{Error, ResultExt};
|
||||
|
||||
pub mod builder;
|
||||
pub mod header;
|
||||
pub mod manifest;
|
||||
pub mod reader;
|
||||
|
||||
pub const SIG_CONTEXT: &'static [u8] = b"s9pk";
|
||||
|
||||
#[command(cli_only, display(display_none), blocking)]
|
||||
pub fn pack(#[context] _ctx: EitherContext, #[arg] path: Option<PathBuf>) -> Result<(), Error> {
|
||||
use std::fs::File;
|
||||
|
||||
let path = if let Some(path) = path {
|
||||
path
|
||||
} else {
|
||||
std::env::current_dir()?
|
||||
};
|
||||
let manifest: Manifest = if path.join("manifest.toml").exists() {
|
||||
let mut s = String::new();
|
||||
File::open(path.join("manifest.toml"))?.read_to_string(&mut s)?;
|
||||
serde_toml::from_str(&s).with_kind(crate::ErrorKind::Deserialization)?
|
||||
} else {
|
||||
return Err(Error::new(
|
||||
anyhow!("manifest not found"),
|
||||
crate::ErrorKind::Pack,
|
||||
));
|
||||
};
|
||||
|
||||
let outfile_path = path.join(format!("{}.s9pk", manifest.id));
|
||||
let mut outfile = File::create(outfile_path)?;
|
||||
S9pkPacker::builder()
|
||||
.manifest(&manifest)
|
||||
.writer(&mut outfile)
|
||||
.license(File::open(path.join(manifest.assets.license_path()))?)
|
||||
.icon(File::open(path.join(manifest.assets.icon_path()))?)
|
||||
.instructions(File::open(path.join(manifest.assets.instructions_path()))?)
|
||||
.docker_images(File::open(path.join(manifest.assets.docker_images_path()))?)
|
||||
.build()
|
||||
.pack()?;
|
||||
outfile.sync_all()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command(cli_only, display(display_none))]
|
||||
pub async fn verify(#[context] _ctx: EitherContext, #[arg] path: PathBuf) -> Result<(), Error> {
|
||||
let mut s9pk = S9pkReader::open(path).await?;
|
||||
s9pk.validate().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user