Skip to content

Commit

Permalink
clean and try to add rpm unpack
Browse files Browse the repository at this point in the history
  • Loading branch information
LDprg committed Aug 4, 2024
1 parent e9b1da7 commit f2e5f45
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 247 deletions.
110 changes: 0 additions & 110 deletions scripts/install_quickemu.py

This file was deleted.

5 changes: 4 additions & 1 deletion winapps-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ default-run = "winapps-cli"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = "4.3.11"
clap = "4.3"
time = "0.3"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["time"] }
winapps = { path = "../winapps" }
52 changes: 10 additions & 42 deletions winapps-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::{arg, Command};
use tracing::info;
use winapps::freerdp::freerdp_back::Freerdp;
use winapps::quickemu::{create_vm, kill_vm, start_vm};
use winapps::{unwrap_or_panic, RemoteClient};

fn cli() -> Command {
Expand All @@ -16,19 +16,15 @@ fn cli() -> Command {
.about("Connects to app on remote")
.arg(arg!(<APP> "App to open")),
)
.subcommand(
Command::new("vm")
.about("Manage a windows 10 vm using quickemu")
.subcommand_required(true)
.arg_required_else_help(true)
.allow_external_subcommands(true)
.subcommand(Command::new("create").about("Create a windows 10 vm using quickget"))
.subcommand(Command::new("start").about("Start the vm"))
.subcommand(Command::new("kill").about("Kill the running VM")),
)
}

fn main() {
tracing_subscriber::fmt()
// .with_timer(tracing_subscriber::fmt::time::uptime())
.without_time()
.with_target(false)
.init();

let cli = cli();
let matches = cli.clone().get_matches();

Expand All @@ -37,48 +33,20 @@ fn main() {

match matches.subcommand() {
Some(("check", _)) => {
println!("Checking remote connection");
info!("Checking remote connection");

client.check_depends(config);
}
Some(("connect", _)) => {
println!("Connecting to remote");
info!("Connecting to remote");

client.run_app(config, None);
}
Some(("run", sub_matches)) => {
println!("Connecting to app on remote");
info!("Connecting to app on remote");

client.run_app(config, sub_matches.get_one::<String>("APP"));
}

Some(("vm", command)) => {
match command.subcommand() {
Some(("create", _)) => {
println!("Creating windows 10 vm..");
create_vm(config);
}
Some(("start", _)) => {
println!("Starting vm..");
start_vm(config);
}

Some(("kill", _)) => {
println!("Killing vm..");
kill_vm(config);
}

Some((_, _)) => {
unwrap_or_panic!(
cli.about("Command not found, try existing ones!")
.print_help(),
"Couldn't print help"
);
}
_ => unreachable!(),
};
}

Some((_, _)) => {
unwrap_or_panic!(
cli.about("Command not found, try existing ones!")
Expand Down
23 changes: 16 additions & 7 deletions winapps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.75"
derive-new = "0.5.9"
home = "0.5.5"
serde = { version = "1.0.171", features = ["derive"] }
thiserror = "1.0.49"
toml = "0.8.2"
tracing = "0.1.37"
anyhow = "1.0"
decompress = "0.6.0"
derive-new = "0.5"
home = "0.5"
indicatif = { version="0.17", features = ["tokio"] }
regex = "1.10.6"
reqwest = { version = "0.12", features = ["stream"] }
serde = { version = "1.0", features = ["derive"] }
tempfile = "3.11.0"
thiserror = "1.0"
tokio = { version = "1.37", features = ["full"] }
tokio-stream = "0.1"
tokio-util = {version="0.7", features=["io"]}
toml = "0.8"
tracing = "0.1"
tracing-subscriber = "0.3"
117 changes: 113 additions & 4 deletions winapps/src/freerdp.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,123 @@
pub mod freerdp_back {
use crate::{get_data_dir, unwrap_or_exit, Config, RemoteClient};
use decompress::{decompressors, ExtractOptsBuilder};
use indicatif::ProgressBar;
use regex::Regex;
use std::cmp::min;
use std::process::{Command, Stdio};
use tokio_stream::StreamExt;
use tracing::{info, warn};

use crate::{unwrap_or_exit, Config, RemoteClient};

pub struct Freerdp {}

impl Freerdp {
fn get_freerdp() -> Command {
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap()
.block_on(Freerdp::install_freerdp());
Command::new(get_data_dir().join("bin/xfreerdp"))
}

// fn get_freerdp_dir() -> PathBuf {
// let path = get_data_dir().join("bin");

// if !path.exists() {
// let dir = path.clone();
// info!(
// "Freerdp directory {:?} does not exist! Creating...",
// dir.to_str()
// );
// fs::create_dir_all(dir).expect("Failed to create directory");
// }

// if !path.is_dir() {
// error!("Freerdp directory {:?} is not a directory", path).panic();
// }

// path
// }

async fn install_freerdp() {
let freerdp_file = "freerdp-3.6.3-1.fc41.x86_64.rpm";
let bar = ProgressBar::new(1);

bar.set_style(indicatif::ProgressStyle::with_template(
"{spinner:.green} [{elapsed}] {wide_bar:.cyan/blue} {bytes}/{total_bytes} {bytes_per_sec} {msg} ({eta})",
).unwrap().progress_chars("#>-"));
bar.set_message(format!("Starting {}", freerdp_file));

bar.tick();

let response = reqwest::get(
"https://kojipkgs.fedoraproject.org//packages/freerdp/3.6.3/1.fc41/x86_64/"
.to_owned()
+ freerdp_file,
)
.await
.unwrap();

let total_size = response.content_length().unwrap_or(0);

bar.set_length(total_size);
bar.set_message(format!("Downloading {}", freerdp_file));

let mut downloaded: u64 = 0;

let mut stream = response.bytes_stream().map(|result| {
result
.inspect(|result| {
let new = min(downloaded + (result.len() as u64), total_size);
downloaded = new;
bar.set_position(new);
})
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))
});

let mut tmp_file = tokio::fs::File::create(get_data_dir().join(freerdp_file))
.await
.unwrap();

while let Some(item) = stream.next().await {
tokio::io::copy(&mut item.unwrap().as_ref(), &mut tmp_file)
.await
.unwrap();
}

// let mut decoder =
// async_compression::tokio::bufread::ZstdDecoder::new(StreamReader::new(stream));

// let mut target = tokio::fs::File::create(get_data_dir().join("bin1"))
// .await
// .unwrap();

// io::copy(&mut decoder, &mut target).await.unwrap();

// let file = tokio::fs::File::create(get_data_dir().join("bin1"))
// .await
// .unwrap();

let decompressor =
decompress::Decompress::build(vec![decompressors::zstd::Zstd::build(Some(
Regex::new(r".*").unwrap(),
))]);

let res = decompressor.decompress(
get_data_dir()
.join("freerdp-3.6.3-1.fc41.x86_64.zst")
.as_path(),
get_data_dir().join("bin").as_path(),
&ExtractOptsBuilder::default().build().unwrap(),
);

info!("{res:?}");
}
}

impl RemoteClient for Freerdp {
fn check_depends(&self, config: Config) {
let mut xfreerdp = Command::new("xfreerdp");
let mut xfreerdp = Freerdp::get_freerdp();
xfreerdp.stdout(Stdio::null());
xfreerdp.stderr(Stdio::null());
xfreerdp.args(["-h"]);
Expand All @@ -30,7 +139,7 @@ pub mod freerdp_back {
}

fn run_app(&self, config: Config, app: Option<&String>) {
let mut xfreerdp = Command::new("xfreerdp");
let mut xfreerdp = Freerdp::get_freerdp();
xfreerdp.stdout(Stdio::null());
xfreerdp.stderr(Stdio::null());
match app {
Expand Down
Loading

0 comments on commit f2e5f45

Please sign in to comment.