feat: Added install support
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
1907
Cargo.lock
generated
Normal file
1907
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
17
Cargo.toml
Normal file
17
Cargo.toml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
[package]
|
||||||
|
name = "eiipm"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Eiipm - A simple package manager for ewwii"
|
||||||
|
authors = ["Byson94 <byson94wastaken@gmail.com>"]
|
||||||
|
license = "MIT"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
anyhow = "1.0.98"
|
||||||
|
clap = { version = "4.5.43", features = ["derive"] }
|
||||||
|
colored = "3.0.0"
|
||||||
|
env_logger = "0.11.8"
|
||||||
|
log = "0.4.27"
|
||||||
|
reqwest = { version = "0.12.22", features = ["blocking", "json"] }
|
||||||
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
|
toml = "0.9.5"
|
||||||
7
LICENSE
Normal file
7
LICENSE
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
Copyright 2025 Byson94
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
3
README.md
Normal file
3
README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# eiipm
|
||||||
|
|
||||||
|
**Eiipm** pronounced as `e-pm` is the package manager of Ewwii (Elkowar's Wacky Widgets Improved Interface) which is a fork of Eww (Elkowar's Widgets Widgets).
|
||||||
124
src/functions/install.rs
Normal file
124
src/functions/install.rs
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
use reqwest::blocking::get;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use std::error::Error;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::process::Command;
|
||||||
|
use log::{debug, info, error, trace};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use colored::{Colorize, ColoredString};
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
struct PackageRootMeta {
|
||||||
|
metadata: PackageMeta,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
struct PackageMeta {
|
||||||
|
name: String,
|
||||||
|
version: f32,
|
||||||
|
install_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn install_package(package_name: &str) -> Result<(), Box<dyn Error>> {
|
||||||
|
info!("> Installing package '{}'", package_name.yellow().bold());
|
||||||
|
|
||||||
|
let raw_manifest_url = format!(
|
||||||
|
"https://raw.githubusercontent.com/Ewwii-sh/eii-manifests/main/manifests/{}.toml",
|
||||||
|
package_name
|
||||||
|
);
|
||||||
|
trace!(" Constructed manifest URL:\n {}", raw_manifest_url.underline());
|
||||||
|
|
||||||
|
let toml_content = http_get_string(&raw_manifest_url).map_err(|e| {
|
||||||
|
error!(" [ERROR] Error fetching manifest for package '{}': {}", package_name.yellow(), e.to_string().red());
|
||||||
|
e
|
||||||
|
})?;
|
||||||
|
debug!(" Fetched manifest content:\n{}", toml_content.dimmed());
|
||||||
|
|
||||||
|
let root_meta: PackageRootMeta = toml::from_str(&toml_content).map_err(|e| {
|
||||||
|
error!(" [ERROR] Failed to parse manifest TOML for package '{}': {}", package_name.yellow(), e.to_string().red());
|
||||||
|
e
|
||||||
|
})?;
|
||||||
|
trace!(" Parsed manifest metadata:\n {:?}", root_meta.metadata);
|
||||||
|
|
||||||
|
let mut install_script_path = std::env::temp_dir();
|
||||||
|
install_script_path.push(format!("{}.sh", package_name));
|
||||||
|
|
||||||
|
info!(" Downloading install script:");
|
||||||
|
info!(" From: {}", root_meta.metadata.install_url.underline());
|
||||||
|
info!(" To: {}", install_script_path.display().to_string().bright_yellow());
|
||||||
|
|
||||||
|
download_file(&root_meta.metadata.install_url, install_script_path.to_str().unwrap()).map_err(|e| {
|
||||||
|
error!(" [ERROR] Failed to download install script for package '{}': {}", package_name.yellow(), e.to_string().red());
|
||||||
|
e
|
||||||
|
})?;
|
||||||
|
|
||||||
|
info!(" Running install script: {}", install_script_path.display().to_string().yellow());
|
||||||
|
|
||||||
|
run_script(install_script_path.to_str().unwrap(), package_name)?;
|
||||||
|
|
||||||
|
info!(" Installation completed successfully for package '{}'", package_name.yellow().bold());
|
||||||
|
|
||||||
|
std::fs::remove_file(install_script_path)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn http_get_string(url: &str) -> Result<String, Box<dyn Error>> {
|
||||||
|
debug!(" Sending GET request to {}", url.dimmed());
|
||||||
|
|
||||||
|
let response = get(url)?;
|
||||||
|
|
||||||
|
if !response.status().is_success() {
|
||||||
|
error!(" [ERROR] Failed to fetch URL {}: HTTP {}", url.yellow(), response.status());
|
||||||
|
return Err(format!("Failed to fetch URL {}: HTTP {}", url, response.status()).into());
|
||||||
|
}
|
||||||
|
|
||||||
|
let body = response.text()?;
|
||||||
|
debug!(" Received response body ({} bytes)", body.len());
|
||||||
|
Ok(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn download_file(url: &str, output_path: &str) -> Result<(), Box<dyn Error>> {
|
||||||
|
debug!(" Sending GET request to download file from {}", url.dimmed());
|
||||||
|
|
||||||
|
let response = get(url)?;
|
||||||
|
|
||||||
|
if !response.status().is_success() {
|
||||||
|
error!(" [ERROR] Failed to download file from {}: HTTP {}", url.yellow(), response.status());
|
||||||
|
return Err(format!("Failed to download file from {}: HTTP {}", url, response.status()).into());
|
||||||
|
}
|
||||||
|
|
||||||
|
let content = response.text()?;
|
||||||
|
debug!(" Downloaded file content length: {} bytes", content.len());
|
||||||
|
debug!(" Creating file at '{}'", output_path.dimmed());
|
||||||
|
|
||||||
|
let mut file = File::create(output_path)?;
|
||||||
|
file.write_all(content.as_bytes())?;
|
||||||
|
|
||||||
|
trace!(" Successfully wrote to '{}'", output_path.bright_green());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_script(script_path: &str, package_name: &str) -> Result<(), Box<dyn Error>> {
|
||||||
|
info!(" Executing script: {}", script_path.yellow());
|
||||||
|
|
||||||
|
let output = Command::new("sh")
|
||||||
|
.arg(script_path)
|
||||||
|
.output()?; // capture output
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
error!(" [ERROR] Script failed with status: {}", format!("{:?}", output.status).red());
|
||||||
|
error!(" [ERROR] stderr:");
|
||||||
|
for line in String::from_utf8_lossy(&output.stderr).lines() {
|
||||||
|
error!(" {}", line.red());
|
||||||
|
}
|
||||||
|
return Err(format!("Script execution failed with status: {:?}", output.status).into());
|
||||||
|
} else {
|
||||||
|
info!("{}", " Script executed successfully.".bright_green());
|
||||||
|
debug!(" Script stdout:\n{}", String::from_utf8_lossy(&output.stdout).dimmed());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
1
src/functions/mod.rs
Normal file
1
src/functions/mod.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod install;
|
||||||
48
src/main.rs
Normal file
48
src/main.rs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
use clap::Parser;
|
||||||
|
use std::env;
|
||||||
|
use std::io::Write;
|
||||||
|
use log::Level;
|
||||||
|
|
||||||
|
mod opts;
|
||||||
|
mod functions;
|
||||||
|
use opts::Args;
|
||||||
|
use crate::functions::install::install_package;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let args = Args::parse();
|
||||||
|
|
||||||
|
set_debug_levels(args.debug);
|
||||||
|
|
||||||
|
if let Some(install_pkg_name) = args.install.as_deref() {
|
||||||
|
install_package(install_pkg_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(uninstall_pkg_name) = args.uninstall.as_deref() {
|
||||||
|
log::debug!("Uninstalling package: {}", uninstall_pkg_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_debug_levels(debug_mode: bool) {
|
||||||
|
let mut builder = env_logger::Builder::from_default_env();
|
||||||
|
|
||||||
|
if debug_mode {
|
||||||
|
builder
|
||||||
|
.filter_level(log::LevelFilter::Debug)
|
||||||
|
.format_timestamp_secs()
|
||||||
|
.format_module_path(true)
|
||||||
|
.format_level(true);
|
||||||
|
} else {
|
||||||
|
builder.format(|buf, record| {
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
|
match record.level() {
|
||||||
|
Level::Warn => writeln!(buf, "[WARN] {}", record.args()),
|
||||||
|
Level::Error => writeln!(buf, "[ERROR] {}", record.args()),
|
||||||
|
_ => writeln!(buf, "{}", record.args()),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter_level(log::LevelFilter::Info);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.init();
|
||||||
|
}
|
||||||
19
src/opts.rs
Normal file
19
src/opts.rs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
/// Eiipm package manager for ewwii.
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
#[command(version, about, long_about = None)]
|
||||||
|
pub struct Args {
|
||||||
|
/// Name of the package to install
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub install: Option<String>,
|
||||||
|
|
||||||
|
/// Name of the package to uninstall
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub uninstall: Option<String>,
|
||||||
|
|
||||||
|
/// Show debug logs
|
||||||
|
#[arg(long)]
|
||||||
|
pub debug: bool,
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user