beginning a longgg process
parent
19f0b5b021
commit
38e94b6a8c
@ -1,19 +1,13 @@
|
||||
[package]
|
||||
name = "ame"
|
||||
version = "0.0.0"
|
||||
version = "3.0.0"
|
||||
authors = [ "jnats <michal@tar.black>", "axtlos <axtlos@tar.black>" ]
|
||||
edition = "2018"
|
||||
description = "a fast and efficient aur helper."
|
||||
description = "A fast and efficient aur helper."
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
runas = "0.2.1"
|
||||
ansi_term = "0.12.1"
|
||||
uwuizer = "0.2.1"
|
||||
moins = "0.5.0"
|
||||
regex = { version = "1.5.4", default-features = false }
|
||||
toml = "0.5.8"
|
||||
sqlite = "0.26.0"
|
||||
clap = "*"
|
||||
reqwest = { version = "0.11.7", default-features = false, features = [ "blocking", "json", "default-tls" ] }
|
||||
serde = { version = "1.0.90", default-features = false, features = [ "derive" ] }
|
@ -1,11 +0,0 @@
|
||||
debug:
|
||||
cargo build
|
||||
ln -sf target/debug/ame .
|
||||
release:
|
||||
cargo build --release
|
||||
ln -sf target/release/ame .
|
||||
clean:
|
||||
rm -rf target/ Cargo.lock ame
|
||||
install:
|
||||
cargo build --release
|
||||
sudo cp target/release/ame /usr/bin/ame
|
@ -1,118 +1,38 @@
|
||||
mod mods;
|
||||
use mods::{
|
||||
clearcache::clearcache,
|
||||
clone::clone,
|
||||
database::create_database,
|
||||
help::help,
|
||||
inssort::{inssort, inssort_from_file},
|
||||
install::install,
|
||||
purge::{purge, purge_from_file},
|
||||
search::{a_search, r_search},
|
||||
stat_database::*,
|
||||
statpkgs::*,
|
||||
strs::err_rec,
|
||||
strs::err_unrec,
|
||||
strs::inf,
|
||||
uninstall::{uninstall, uninstall_from_file},
|
||||
update::update,
|
||||
upgrade::upgrade,
|
||||
ver::ver,
|
||||
xargs::*,
|
||||
};
|
||||
use std::{env, process::exit};
|
||||
use clap::{App, Arg, SubCommand};
|
||||
|
||||
fn main() {
|
||||
extern "C" {
|
||||
fn geteuid() -> u32;
|
||||
}
|
||||
|
||||
if unsafe { geteuid() } == 0 {
|
||||
// check if user runs ame as root
|
||||
err_unrec(
|
||||
"Do not run ame as root! this can cause serious damage to your system!".to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
let args: Vec<String> = env::args().skip(1).collect();
|
||||
let mut pkgs: Vec<String> = env::args().skip(2).collect();
|
||||
|
||||
if args.is_empty() {
|
||||
help();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
let file = format!("{}/.local/share/ame/aur_pkgs.db", env::var("HOME").unwrap());
|
||||
if !std::path::Path::new(&file).exists() {
|
||||
create_database();
|
||||
}
|
||||
|
||||
let oper = &args[0];
|
||||
let noconfirm: bool = noconf(&args);
|
||||
|
||||
argssort(&mut pkgs);
|
||||
match oper.as_str() {
|
||||
// match oper
|
||||
"-S" | "-Sn" | "ins" => {
|
||||
inssort(noconfirm, false, pkgs); // install
|
||||
}
|
||||
"-Sl" | "-Sln" | "insl" => {
|
||||
inssort_from_file(noconfirm, false, &pkgs[0]); // install from file
|
||||
}
|
||||
"-B" | "-Bn" | "build" => {
|
||||
rebuild(noconfirm); // install as a dependency
|
||||
}
|
||||
"-R" | "-Rn" | "rm" => {
|
||||
uninstall(noconfirm, pkgs); // uninstall
|
||||
}
|
||||
"-Rs" | "-Rsn" | "purge" => {
|
||||
purge(noconfirm, pkgs); // purge
|
||||
}
|
||||
"-Rl" | "-Rln" | "rml" => {
|
||||
uninstall_from_file(noconfirm, &pkgs[0]); // uninstall from file
|
||||
}
|
||||
"-Rsl" | "-Rsln" | "purgel" => {
|
||||
purge_from_file(noconfirm, &pkgs[0]); // purge from file
|
||||
}
|
||||
"-Syu" | "-Syun" | "upg" => {
|
||||
upgrade(noconfirm); // upgrade
|
||||
}
|
||||
"-Sy" | "upd" => {
|
||||
update(); // update
|
||||
}
|
||||
"-Ss" | "sea" => {
|
||||
r_search(&args[1]); // search for packages in the repository
|
||||
a_search(&args[1]); // search for packages in the aur
|
||||
}
|
||||
"-Sa" | "aursea" => {
|
||||
a_search(&args[1]); // search for packages in the aur
|
||||
}
|
||||
"-Sr" | "repsea" => {
|
||||
r_search(&args[1]); // search for packages in the repository
|
||||
}
|
||||
"-Cc" | "clr" => {
|
||||
clearcache(); // clear cache
|
||||
}
|
||||
"-v" | "-V" | "ver" => {
|
||||
ver(); // version
|
||||
}
|
||||
"-h" | "help" => {
|
||||
help(); // help
|
||||
}
|
||||
_ => {
|
||||
// if oper is not valid it either passes the args to pacman or prints an error
|
||||
let pass = runas::Command::new("pacman")
|
||||
.args(&args)
|
||||
.status()
|
||||
.expect("Something has gone wrong.");
|
||||
|
||||
match pass.code() {
|
||||
Some(1) => {
|
||||
err_rec(format!("No such operation \"{}\"", args.join(" ")));
|
||||
inf("Try running \"ame help\" for an overview of how to use ame".to_string())
|
||||
}
|
||||
Some(_) => {}
|
||||
None => err_unrec("Something has gone terribly wrong.".to_string()),
|
||||
}
|
||||
let matches = App::new("Amethyst")
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
.about(env!("CARGO_PKG_DESCRIPTION"))
|
||||
.arg(
|
||||
Arg::with_name("verbose")
|
||||
.short("v")
|
||||
.multiple(true)
|
||||
.help("Sets the level of verbosity"),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name ("install")
|
||||
.about("Installs a package from either the AUR or the PacMan-defined repositories")
|
||||
.arg(
|
||||
Arg::with_name("noconfirm")
|
||||
.short("y")
|
||||
.long("noconfirm")
|
||||
.help("Do not ask for confirmation before installing the package")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("package")
|
||||
.help("The name of the package to install")
|
||||
.required(true)
|
||||
.index(1)
|
||||
)
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
match matches.occurrences_of("verbose") {
|
||||
0 => println!("No verbosity"),
|
||||
1 => println!("Some extra information"),
|
||||
2 => println!("Plenty of debug text"),
|
||||
_ => println!("Screensaver mode"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1 @@
|
||||
pub mod clearcache;
|
||||
pub mod clone;
|
||||
pub mod database;
|
||||
pub mod help;
|
||||
pub mod inssort;
|
||||
pub mod install;
|
||||
pub mod purge;
|
||||
pub mod rpc;
|
||||
pub mod search;
|
||||
pub mod stat_database;
|
||||
pub mod statpkgs;
|
||||
pub mod strs;
|
||||
pub mod uninstall;
|
||||
pub mod update;
|
||||
pub mod upgrade;
|
||||
pub mod ver;
|
||||
pub mod xargs;
|
||||
|
@ -1,12 +0,0 @@
|
||||
use crate::mods::strs::err_rec;
|
||||
use std::fs;
|
||||
|
||||
pub fn clearcache() {
|
||||
// delete all files in cache
|
||||
let path = format!("{}/.cache/ame/", std::env::var("HOME").unwrap());
|
||||
|
||||
err_rec("Clearing cache".to_string());
|
||||
|
||||
fs::remove_dir_all(&path).unwrap();
|
||||
fs::create_dir(&path).unwrap();
|
||||
}
|
@ -1,180 +0,0 @@
|
||||
use crate::{
|
||||
err_unrec, inf, mods::database::add_pkg, mods::purge::purge, mods::rpc::*, mods::strs::prompt,
|
||||
mods::strs::sec, mods::strs::succ, inssort
|
||||
};
|
||||
use moins::Moins;
|
||||
use std::{env, fs, path::Path, process::Command};
|
||||
|
||||
fn uninstall_make_depend(pkg: &str) {
|
||||
// uninstall make depends of a package
|
||||
let make_depends = rpcinfo(pkg).make_depends;
|
||||
|
||||
let explicit_packages = Command::new("pacman")
|
||||
.arg("-Qetq")
|
||||
.stdout(std::process::Stdio::piped())
|
||||
.output()
|
||||
.expect("Something has gone terribly wrong");
|
||||
|
||||
let expl_pkgs_parse = String::from_utf8(explicit_packages.stdout).unwrap();
|
||||
let expl_pkgs_parse = expl_pkgs_parse.split('\n').collect::<Vec<&str>>();
|
||||
|
||||
let mut rem_pkgs: Vec<String> = Vec::new();
|
||||
for pkg in expl_pkgs_parse {
|
||||
for md in &make_depends {
|
||||
if let false = md.contains(pkg) {
|
||||
if let false = rem_pkgs.contains(md) {
|
||||
rem_pkgs.push(md.as_str().to_string());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if !rem_pkgs.is_empty() {
|
||||
inf(format!(
|
||||
"{} installed following make dependencies: {}",
|
||||
pkg,
|
||||
rem_pkgs.join(", ")
|
||||
));
|
||||
let remove = prompt("Would you like to remove them?".to_string());
|
||||
if remove {
|
||||
purge(true, rem_pkgs);
|
||||
}
|
||||
}
|
||||
succ(format!("Succesfully installed {}", pkg));
|
||||
}
|
||||
|
||||
pub fn clone(noconfirm: bool, as_dep: bool, pkg: &str) {
|
||||
// clone a package from aur
|
||||
let cachedir = format!("{}/.cache/ame", env::var("HOME").unwrap());
|
||||
let path = Path::new(&cachedir);
|
||||
let pkgdir = format!("{}/{}", &cachedir, &pkg);
|
||||
let search = rpcsearch(pkg).results;
|
||||
let package = search.first().unwrap();
|
||||
if search.is_empty() {
|
||||
err_unrec("No matching AUR packages found".to_string());
|
||||
}
|
||||
|
||||
let url = format!("https://aur.archlinux.org/{}.git", pkg);
|
||||
|
||||
if !Path::new(&format!("{}/.cache", env::var("HOME").unwrap())).exists() {
|
||||
fs::create_dir_all(format!("{}/.cache", env::var("HOME").unwrap()))
|
||||
.expect("Failed to create ~/.cache directory");
|
||||
}
|
||||
if !path.is_dir() {
|
||||
let cache_result = fs::create_dir(&path);
|
||||
match cache_result {
|
||||
Ok(_) => inf("Created cache path (first run)".to_string()),
|
||||
Err(_) => err_unrec("Could not create cache path".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
inf(format!("Cloning {} ...", pkg));
|
||||
|
||||
if Path::new(&pkgdir).is_dir() {
|
||||
let rm_result = fs::remove_dir_all(&pkgdir);
|
||||
match rm_result {
|
||||
Ok(_) => inf(format!(
|
||||
"Package path for {} already found. Removing to reinstall",
|
||||
pkg
|
||||
)),
|
||||
Err(_) => err_unrec(format!(
|
||||
"Package path for {} already found, but could not remove to reinstall",
|
||||
pkg
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
let dir_result = fs::create_dir(&pkgdir);
|
||||
match dir_result {
|
||||
Ok(_) => inf(format!("Created package directory for {}", pkg)),
|
||||
Err(_) => err_unrec(format!("Couldn't create package directory for {}", pkg)),
|
||||
}
|
||||
|
||||
let cd_result = env::set_current_dir(&pkgdir);
|
||||
match cd_result {
|
||||
Ok(_) => inf("Entered package directory".to_string()),
|
||||
Err(_) => err_unrec("Could not enter package directory".to_string()),
|
||||
}
|
||||
|
||||
sec("Installing AUR package depends".to_string());
|
||||
|
||||
let clone = std::process::Command::new("git")
|
||||
.arg("clone")
|
||||
.arg(&url)
|
||||
.arg(&pkgdir)
|
||||
.status()
|
||||
.expect("Couldn't clone repository");
|
||||
match clone.code() {
|
||||
Some(0) => {
|
||||
inf(format!("Cloning {} into package directory", pkg));
|
||||
}
|
||||
Some(_) => err_unrec(format!("Failed cloning {} into package directory", pkg)),
|
||||
_ => err_unrec(format!("Failed cloning {} into package directory", pkg)),
|
||||
}
|
||||
if !as_dep {
|
||||
if !noconfirm {
|
||||
let pkgbuild = prompt("View PKGBUILD?".to_string());
|
||||
|
||||
if pkgbuild {
|
||||
let mut pkgbld = fs::read_to_string(format!("{}/PKGBUILD", &pkgdir)).unwrap();
|
||||
Moins::run(&mut pkgbld, None);
|
||||
}
|
||||
}
|
||||
|
||||
sec(format!("Installing {} ...", pkg));
|
||||
if noconfirm {
|
||||
let install_result = Command::new("makepkg")
|
||||
.arg("-si")
|
||||
.arg("--noconfirm")
|
||||
.arg("--needed")
|
||||
.status();
|
||||
match install_result {
|
||||
Ok(_) => {
|
||||
uninstall_make_depend(pkg);
|
||||
let vec = vec![pkg];
|
||||
add_pkg(false, &vec);
|
||||
}
|
||||
Err(_) => {
|
||||
err_unrec(format!("Couldn't install {}", pkg));
|
||||
}
|
||||
};
|
||||
} else {
|
||||
let install_result = Command::new("makepkg")
|
||||
.arg("-si")
|
||||
.arg("--needed")
|
||||
.status()
|
||||
.expect("Couldn't call makepkg");
|
||||
match install_result.code() {
|
||||
Some(0) => {
|
||||
uninstall_make_depend(pkg);
|
||||
let vec = vec![pkg];
|
||||
add_pkg(false, &vec);
|
||||
}
|
||||
Some(_) => {
|
||||
err_unrec(format!("Couldn't install {}", pkg));
|
||||
}
|
||||
None => {
|
||||
err_unrec(format!("Couldn't install {}", pkg));
|
||||
}
|
||||
};
|
||||
}
|
||||
} else {
|
||||
sec(format!("Installing {} ...", pkg));
|
||||
let install_result = Command::new("makepkg")
|
||||
.arg("-si")
|
||||
.arg("--noconfirm")
|
||||
.arg("--needed")
|
||||
.arg("--asdeps")
|
||||
.status();
|
||||
match install_result {
|
||||
Ok(_) => {
|
||||
uninstall_make_depend(pkg);
|
||||
let vec = vec![pkg];
|
||||
add_pkg(false, &vec);
|
||||
}
|
||||
Err(_) => {
|
||||
err_unrec(format!("Couldn't install {}", pkg));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -1,127 +0,0 @@
|
||||
use crate::{err_unrec, inf, mods::rpc::*};
|
||||
use std::{env, fs};
|
||||
|
||||
pub fn create_database() {
|
||||
let homepath = env::var("HOME").unwrap();
|
||||
let file = format!("{}/.local/share/ame/aur_pkgs.db", env::var("HOME").unwrap());
|
||||
if !std::path::Path::new(&format!("{}/.local", env::var("HOME").unwrap())).exists() {
|
||||
fs::create_dir_all(format!("{}/.local", env::var("HOME").unwrap()))
|
||||
.expect("Failed to create ~/.local");
|
||||
}
|
||||
if !std::path::Path::new(&format!("{}/.local/share/ame/", env::var("HOME").unwrap())).is_dir() {
|
||||
let _cdar = fs::create_dir_all(format!("/{}/.local/ame/", homepath));
|
||||
match _cdar {
|
||||
Ok(_) => {
|
||||
inf("Created path for database (previously missing)".to_string());
|
||||
}
|
||||
Err(_) => {
|
||||
err_unrec("Couldn't create path for database (~/.local/share/ame)".to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
let connection = sqlite::open(file).unwrap();
|
||||
connection
|
||||
.execute(
|
||||
"
|
||||
CREATE TABLE pkgs (name TEXT, version TEXT);
|
||||
",
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn get_value(pkg: &str, sear_value: &str) -> String {
|
||||
let file = format!("{}/.local/share/ame/aur_pkgs.db", env::var("HOME").unwrap());
|
||||
let connection = sqlite::open(file).unwrap();
|
||||
let mut return_val = String::new();
|
||||
match sear_value {
|
||||
"name" => {
|
||||
let result = connection.iterate(
|
||||
format!("SELECT name FROM pkgs WHERE name = {};", &pkg),
|
||||
|pairs| {
|
||||
for &(_column, value) in pairs.iter() {
|
||||
return_val = value.unwrap().to_string();
|
||||
}
|
||||
true
|
||||
},
|
||||
);
|
||||
match result {
|
||||
Ok(_) => {}
|
||||
Err(_) => err_unrec("Couldn't get value from database".to_string()),
|
||||
}
|
||||
}
|
||||
"version" => {
|
||||
let result = connection.iterate(
|
||||
format!("SELECT version FROM pkgs WHERE name = {};", &pkg),
|
||||
|pairs| {
|
||||
for &(_column, value) in pairs.iter() {
|
||||
return_val = value.unwrap().to_string();
|
||||
}
|
||||
true
|
||||
},
|
||||
);
|
||||
match result {
|
||||
Ok(_) => {}
|
||||
Err(_) => err_unrec("Couldn't get value from database".to_string()),
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
return_val = "error".to_string();
|
||||
}
|
||||
}
|
||||
return_val
|
||||
}
|
||||
|
||||
pub fn rem_pkg(pkgs: &[String]) {
|
||||
let file = format!("{}/.local/share/ame/aur_pkgs.db", env::var("HOME").unwrap());
|
||||
let connection = sqlite::open(file).unwrap();
|
||||
|
||||
for i in pkgs {
|
||||
let result = connection.execute(format!(
|
||||
"
|
||||
DELETE FROM pkgs WHERE name = \"{}\";
|
||||
",
|
||||
i
|
||||
));
|
||||
match result {
|
||||
Ok(_) => inf(format!("Removed {} from database", i)),
|
||||
Err(_) => err_unrec(format!("Couldn't remove {} from database", i)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_pkg(from_repo: bool, pkgs: &[&str]) {
|
||||
for pkg in pkgs {
|
||||
let file = format!("{}/.local/share/ame/aur_pkgs.db", env::var("HOME").unwrap());
|
||||
let connection = sqlite::open(file).unwrap();
|
||||
let results = rpcsearch(pkg).results;
|
||||
let mut package_name = String::new();
|
||||
let mut package_version = String::new();
|
||||
for res in &results {
|
||||
package_name = res.name.clone();
|
||||
package_version = res.version.clone();
|
||||
}
|
||||
if !from_repo{
|
||||
let result = connection.execute(format!(
|
||||
"
|
||||
INSERT INTO pkgs (name, version) VALUES (\"{}\", \"{}\");
|
||||
",
|
||||
package_name, package_version
|
||||
));
|
||||
match result {
|
||||
Ok(_) => inf(format!("Added {} to database", package_name)),
|
||||
Err(_) => err_unrec(format!("Couldn't add {} to database", package_name)),
|
||||
}
|
||||
} else {
|
||||
let result = connection.execute(format!(
|
||||
"
|
||||
INSERT INTO pkgs (name, version) VALUES (\"{}\", \"{}\");
|
||||
",
|
||||
pkg, "from_repo"
|
||||
));
|
||||
match result {
|
||||
Ok(_) => inf(format!("Added {} to database", pkg)),
|
||||
Err(_) => err_unrec(format!("Couldn't add {} to database", pkg)),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
use crate::mods::strs::{err_rec, inf};
|
||||
|
||||
pub fn help() {
|
||||
// print help message
|
||||
println!();
|
||||
inf("Usage:".to_string());
|
||||
println!(
|
||||
"
|
||||
ame -S(n) / ins <pkg> - install a package
|
||||
ame -R(n) / rm <pkg> - remove a package
|
||||
ame -Rs(n) / purge <pkg> - remove a package with it dependencies
|
||||
ame -Syu(n) / upg - upgrade all packages to latest version
|
||||
ame -Ss / sea <pkg> - search for a package
|
||||
ame -Sa / aursea <pkg> - search for a package in the aur
|
||||
ame -Sr / repsea <pkg> - search for a package in the repos
|
||||
ame -v / ver - contributors and version info
|
||||
ame -h / help - display this help message
|
||||
|
||||
ame <any valid pacman flags> - passes said flags to be processed by pacman"
|
||||
);
|
||||
println!();
|
||||
err_rec("Appending 'n' where (n) is present passes '--noconfirm' to pacman. Use at your own risk. (alternatively, using '--noconfirm' as a flag works too.)".to_string());
|
||||
println!();
|
||||
}
|
@ -1,208 +0,0 @@
|
||||
use crate::{clone, err_unrec, install, mods::strs::sec, mods::rpc::*};
|
||||
use regex::Regex;
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec<String>) {
|
||||
// TODO: understand what the fuck is actually going on here
|
||||
let mut repo = vec![];
|
||||
let mut aur = vec![];
|
||||
let re = Regex::new(r"(\S+)((?:>=|<=|>|<)\S+$)").unwrap();
|
||||
let reg = Regex::new(r"((?:>=|<=|>|<)\S+$)").unwrap();
|
||||
for pkg in pkgs {
|
||||
match pkg.contains('/') {
|
||||
true => match pkg.split('/').collect::<Vec<&str>>()[0] == "aur" {
|
||||
true => {
|
||||
aur.push(pkg.split('/').collect::<Vec<&str>>()[1].to_string());
|
||||
}
|
||||
false => {
|
||||
let out = Command::new("bash")
|
||||
.arg("-c")
|
||||
.arg(format!(
|
||||
"pacman -Sl {} | grep {}",
|
||||
pkg.split('/').collect::<Vec<&str>>()[0],
|
||||
pkg.split('/').collect::<Vec<&str>>()[1]
|
||||
))
|
||||
.stdout(Stdio::null())
|
||||
.status()
|
||||
.expect("Something has gone wrong.");
|
||||
match out.code() {
|
||||
Some(0) => repo.push(reg.replace_all(&pkg, "").to_string()),
|
||||
Some(1) => err_unrec(format!(
|
||||
"Package {} not found in repository {}",
|
||||
pkg.split('/').collect::<Vec<&str>>()[1],
|
||||
pkg.split('/').collect::<Vec<&str>>()[0]
|
||||
)),
|
||||
Some(_) => err_unrec("Something has gone terribly wrong".to_string()),
|
||||
None => err_unrec("Process terminated".to_string()),
|
||||
}
|
||||
}
|
||||
},
|
||||
false => {
|
||||
let caps = re.captures(&pkg);
|
||||
match caps {
|
||||
Some(_) => {
|
||||
let out = Command::new("pacman")
|
||||
.arg("-Ss")
|
||||
.arg(format!(
|
||||
"^{}$",
|
||||
caps.unwrap().get(1).map_or("", |m| m.as_str())
|
||||
))
|
||||
.stdout(Stdio::null())
|
||||
.status()
|
||||
.expect("Something has gone wrong.");
|
||||
match out.code() {
|
||||
Some(0) => repo.push(reg.replace_all(&pkg, "").to_string()),
|
||||
Some(1) => aur.push(pkg),
|
||||
Some(_) => err_unrec("Something has gone terribly wrong".to_string()),
|
||||
None => err_unrec("Process terminated".to_string()),
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let out = Command::new("pacman")
|
||||
.arg("-Ss")
|
||||
.arg(format!("^{}$", &pkg))
|
||||
.stdout(Stdio::null())
|
||||
.status()
|
||||
.expect("Something has gone wrong.");
|
||||
match out.code() {
|
||||
Some(0) => repo.push(pkg),
|
||||
Some(1) => aur.push(pkg),
|
||||
Some(_) => err_unrec("Something has gone terribly wrong".to_string()),
|
||||
None => err_unrec("Process terminated".to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !as_dep {
|
||||
if !repo.is_empty() {
|
||||
sec(format!("Installing repo packages: {}", &repo.join(", ")));
|
||||
install(noconfirm, false, &repo.join(" "));
|
||||
}
|
||||
|
||||
for a in aur {
|
||||
sec(format!("Couldn't find {} in repos. Searching AUR", a));
|
||||
let md = &rpcinfo(&a).make_depends;
|
||||
inssort(noconfirm, true, md.to_vec());
|
||||
clone(noconfirm, false, &a);
|
||||
}
|
||||
} else {
|
||||
if !repo.is_empty() {
|
||||
sec(format!("Installing repo packages: {}", &repo.join(", ")));
|
||||
install(noconfirm, true, &repo.join(" "));
|
||||
}
|
||||
|
||||
for a in aur {
|
||||
sec(format!("Couldn't find {} in repos. Searching AUR", a));
|
||||
let md = &rpcinfo(&a).make_depends;
|
||||
inssort(noconfirm, true, md.to_vec());
|
||||
clone(noconfirm, true, &a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inssort_from_file(noconfirm: bool, as_dep: bool, file: &str) {
|
||||
// same thing as above but with a list of packages from a file
|
||||
let mut pkgs: Vec<String> = Vec::new();
|
||||
let contents = std::fs::read_to_string(&file).expect("Couldn't read file");
|
||||
for line in contents.lines() {
|
||||
pkgs.push(line.to_string());
|
||||
}
|
||||
let mut repo = vec![];
|
||||
let mut aur = vec![];
|
||||
let re = Regex::new(r"(\S+)((?:>=|<=)\S+$)").unwrap();
|
||||
let reg = Regex::new(r"((?:>=|<=)\S+$)").unwrap();
|
||||
for pkg in pkgs {
|
||||
match pkg.contains('/') {
|
||||
true => match pkg.split('/').collect::<Vec<&str>>()[0] == "aur" {
|
||||
true => {
|
||||
aur.push(pkg.split('/').collect::<Vec<&str>>()[1].to_string());
|
||||
}
|
||||
false => {
|
||||
let out = Command::new("bash")
|
||||
.arg("-c")
|
||||
.arg(format!(
|
||||
"pacman -Sl {} | grep {}",
|
||||
pkg.split('/').collect::<Vec<&str>>()[0],
|
||||
pkg.split('/').collect::<Vec<&str>>()[1]
|
||||
))
|
||||
.stdout(Stdio::null())
|
||||
.status()
|
||||
.expect("Something has gone wrong.");
|
||||
match out.code() {
|
||||
Some(0) => repo.push(reg.replace_all(&pkg, "").to_string()),
|
||||
Some(1) => err_unrec(format!(
|
||||
"Package {} not found in repository {}",
|
||||
pkg.split('/').collect::<Vec<&str>>()[1],
|
||||
pkg.split('/').collect::<Vec<&str>>()[0]
|
||||
)),
|
||||
Some(_) => err_unrec("Something has gone terribly wrong".to_string()),
|
||||
None => err_unrec("Process terminated".to_string()),
|
||||
}
|
||||
}
|
||||
},
|
||||
false => {
|
||||
let caps = re.captures(&pkg);
|
||||
match caps {
|
||||
Some(_) => {
|
||||
let out = Command::new("pacman")
|
||||
.arg("-Ss")
|
||||
.arg(format!(
|
||||
"^{}$",
|
||||
caps.unwrap().get(1).map_or("", |m| m.as_str())
|
||||
))
|
||||
.stdout(Stdio::null())
|
||||
.status()
|
||||
.expect("Something has gone wrong.");
|
||||
match out.code() {
|
||||
Some(0) => repo.push(reg.replace_all(&pkg, "").to_string()),
|
||||
Some(1) => aur.push(pkg),
|
||||
Some(_) => err_unrec("Something has gone terribly wrong".to_string()),
|
||||
None => err_unrec("Process terminated".to_string()),
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let out = Command::new("pacman")
|
||||
.arg("-Ss")
|
||||
.arg(format!("^{}$", &pkg))
|
||||
.stdout(Stdio::null())
|
||||
.status()
|
||||
.expect("Something has gone wrong.");
|
||||
match out.code() {
|
||||
Some(0) => repo.push(pkg),
|
||||
Some(1) => aur.push(pkg),
|
||||
Some(_) => err_unrec("Something has gone terribly wrong".to_string()),
|
||||
None => err_unrec("Process terminated".to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !as_dep {
|
||||
if !repo.is_empty() {
|
||||
sec(format!("Installing repo packages: {}", &repo.join(", ")));
|
||||
install(noconfirm, false, &repo.join(" "));
|
||||
}
|
||||
|
||||
for a in aur {
|
||||
sec(format!("Couldn't find {} in repos. Searching AUR", a));
|
||||
let md = &rpcinfo(&a).make_depends;
|
||||
inssort(noconfirm, true, md.to_vec());
|
||||
clone(noconfirm, false, &a);
|
||||
}
|
||||
} else {
|
||||
if !repo.is_empty() {
|
||||
sec(format!("Installing repo packages: {}", &repo.join(", ")));
|
||||
install(noconfirm, true, &repo.join(" "));
|
||||
}
|
||||
|
||||
for a in aur {
|
||||
sec(format!("Couldn't find {} in repos. Searching AUR", a));
|
||||
let md = &rpcinfo(&a).make_depends;
|
||||
inssort(noconfirm, true, md.to_vec());
|
||||
clone(noconfirm, true, &a);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
use crate::mods::database::add_pkg;
|
||||
use crate::mods::strs::{err_unrec, succ};
|
||||
use runas::Command;
|
||||
|
||||
pub fn install(noconfirm: bool, as_dep: bool, pkg: &str) {
|
||||
// install a package
|
||||
let pkgs: Vec<&str> = pkg.split(' ').collect();
|
||||
if !as_dep {
|
||||
if noconfirm {
|
||||
let result = Command::new("pacman")
|
||||
.arg("-S")
|
||||
.arg("--noconfirm")
|
||||
.arg("--needed")
|
||||
.args(&pkgs)
|
||||
.status()
|
||||
.expect("Couldn't call pacman");
|
||||
match result.code() {
|
||||
Some(0) => {
|
||||
succ(format!("Succesfully installed packages: {}", pkg));
|
||||
add_pkg(true, &pkgs);
|
||||
}
|
||||
Some(_) => err_unrec(format!("Couldn't install packages: {}", pkg)),
|
||||
None => err_unrec(format!("Couldn't install packages: {}", pkg)),
|
||||
};
|
||||
} else {
|
||||
let result = Command::new("pacman")
|
||||
.arg("-S")
|
||||
.arg("--needed")
|
||||
.args(&pkgs)
|
||||
.status()
|
||||
.expect("Couldn't call pacman");
|
||||
match result.code() {
|
||||
Some(0) => {
|
||||
succ(format!("Succesfully installed packages: {}", pkg));
|
||||
add_pkg(true, &pkgs);
|
||||
}
|
||||
Some(_) => err_unrec(format!("Couldn't install packages: {}", pkg)),
|
||||
None => err_unrec(format!("Couldn't install packages: {}", pkg)),
|
||||
};
|
||||
}
|
||||
} else {
|
||||
let result = Command::new("pacman")
|
||||
.arg("-S")
|
||||
.arg("--noconfirm")
|
||||
.arg("--needed")
|
||||
.arg("--asdeps")
|
||||
.args(&pkgs)
|
||||
.status()
|
||||
.expect("Couldn't call pacman");
|
||||
match result.code() {
|
||||
Some(0) => {
|
||||
succ(format!("Succesfully installed packages: {}", pkg));
|
||||
add_pkg(true, &pkgs);
|
||||
}
|
||||
Some(_) => err_unrec(format!("Couldn't install packages: {}", pkg)),
|
||||
None => err_unrec(format!("Couldn't install packages: {}", pkg)),
|
||||
};
|
||||
}
|
||||
}
|
@ -1,121 +0,0 @@
|
||||
use crate::mods::{
|
||||
database::rem_pkg,
|
||||
strs::{err_rec, err_unrec, sec, succ},
|
||||
};
|
||||
use runas::Command;
|
||||
use std::{fs, path::Path};
|
||||
|
||||
pub fn purge(noconfirm: bool, pkgs: Vec<String>) {
|
||||
// purge packages
|
||||
sec(format!(
|
||||
"Attempting to uninstall packages: {}",
|
||||
&pkgs.join(" ")
|
||||
));
|
||||
if noconfirm {
|
||||
let result = Command::new("pacman")
|
||||
.arg("-Rsu")
|
||||
.args(&pkgs)
|
||||
.arg("--noconfirm")
|
||||
.status()
|
||||
.expect("Couldn't call pacman");
|
||||
match result.code() {
|
||||
Some(0) => {
|
||||
succ(format!(
|
||||
"Succesfully uninstalled packages: {}",
|
||||
&pkgs.join(" ")
|
||||
));
|
||||
rem_pkg(&pkgs);
|
||||
}
|
||||
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
|
||||
None => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
|
||||
};
|
||||
} else {
|
||||
let result = Command::new("pacman")
|
||||
.arg("-Rsu")
|
||||
.args(&pkgs)
|
||||
.status()
|
||||
.expect("Couldn't call pacman");
|
||||
match result.code() {
|
||||
Some(0) => {
|
||||
succ(format!(
|
||||
"Succesfully uninstalled packages: {}",
|
||||
&pkgs.join(" ")
|
||||
));
|
||||
rem_pkg(&pkgs);
|
||||
}
|
||||
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
|
||||
None => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
|
||||
};
|
||||
}
|
||||
for pkg in &pkgs {
|
||||
let pkgdir = format!("{}/.cache/ame/{}", std::env::var("HOME").unwrap(), pkg);
|
||||
let path = Path::new(&pkgdir);
|
||||
if path.is_dir() {
|
||||
let rm_result = fs::remove_dir_all(&path);
|
||||
match rm_result {
|
||||
Ok(_) => succ(format!("Removed AUR cache directory for {}", pkg)),
|
||||
Err(_) => err_unrec(format!("Failed to remove AUR cache directory for {}", pkg)),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn purge_from_file(noconfirm: bool, file: &str) {
|
||||
// purge packages from list of packages
|
||||
let mut pkgs: Vec<String> = Vec::new();
|
||||
let contents = std::fs::read_to_string(&file).expect("Couldn't read file");
|
||||
for line in contents.lines() {
|
||||
pkgs.push(line.to_string());
|
||||
}
|
||||
sec(format!(
|
||||
"Attempting to uninstall packages: {}",
|
||||
&pkgs.join(" ")
|
||||
));
|
||||
if noconfirm {
|
||||
let result = Command::new("pacman")
|
||||
.arg("-Rsu")
|
||||
.args(&pkgs)
|
||||
.arg("--noconfirm")
|
||||
.status()
|
||||
.expect("Couldn't call pacman");
|
||||
match result.code() {
|
||||
Some(0) => {
|
||||
succ(format!(
|
||||
"Succesfully uninstalled packages: {}",
|
||||
&pkgs.join(" ")
|
||||
));
|
||||
rem_pkg(&pkgs);
|
||||
}
|
||||
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
|
||||
None => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
|
||||
};
|
||||
} else {
|
||||
let result = Command::new("pacman")
|
||||
.arg("-Rsu")
|
||||
.args(&pkgs)
|
||||
.status()
|
||||
.expect("Couldn't call pacman");
|
||||
match result.code() {
|
||||
Some(0) => {
|
||||
succ(format!(
|
||||
"Succesfully uninstalled packages: {}",
|
||||
&pkgs.join(" ")
|
||||
));
|
||||
rem_pkg(&pkgs);
|
||||
}
|
||||
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
|
||||
None => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
|
||||
};
|
||||
}
|
||||
for pkg in &pkgs {
|
||||
let pkgdir = format!("{}/.cache/ame/{}", std::env::var("HOME").unwrap(), pkg);
|
||||
let path = Path::new(&pkgdir);
|
||||
if path.is_dir() {
|
||||
let rm_result = fs::remove_dir_all(&path);
|
||||
match rm_result {
|
||||
Ok(_) => succ(format!("Removed AUR cache directory for {}", pkg)),
|
||||
Err(_) => err_unrec(format!("Failed to remove AUR cache directory for {}", pkg)),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
use crate::mods::rpc::*;
|
||||
use crate::mods::strs::{err_rec, err_unrec, succ};
|
||||
use ansi_term::Colour;
|
||||
use std::process::Command;
|
||||
|
||||
pub fn a_search(pkg: &str) {
|
||||
// search for a package in the AUR
|
||||
let results = rpcsearch(pkg).results;
|
||||
|
||||
for r in &results {
|
||||
if results.is_empty() {
|
||||
err_rec("No matching AUR packages found".to_string());
|
||||
}
|
||||
println!(
|
||||
"{}{} {}\n {}",
|
||||
Colour::Cyan.bold().paint("aur/"),
|
||||
Colour::White.bold().paint(&r.name),
|
||||
Colour::Green.bold().paint(&r.version),
|
||||
Colour::White.paint(
|
||||
r.description
|
||||
.as_ref()
|
||||
.unwrap_or(&"No description available".to_string())
|
||||
)
|
||||
);
|
||||
}
|
||||
if !results.is_empty() {
|
||||
succ("AUR search successful".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn r_search(pkg: &str) {
|
||||
// search for a package in the repositories
|
||||
let result = Command::new("pacman")
|
||||
.arg("-Ss")
|
||||
.arg(&pkg)
|
||||
.status()
|
||||
.unwrap();
|
||||
match result.code() {
|
||||
Some(0) => succ("Repo search successful".to_string()),
|
||||
Some(1) => err_rec("No matching repo packages found".to_string()),
|
||||
Some(_) => err_unrec("Someting went terribly wrong".to_string()),
|
||||
None => err_unrec("Couldn't search pacman repos".to_string()),
|
||||
};
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
use crate::{err_unrec, inf};
|
||||
use std::env;
|
||||
|
||||
pub fn stat_dump_dat() -> Vec<String> {
|
||||
let file = format!("{}/.local/share/ame/aur_pkgs.db", env::var("HOME").unwrap());
|
||||
let connection = sqlite::open(file).unwrap();
|
||||
let mut dat_pkgs = Vec::new();
|
||||
let result = connection.iterate("SELECT name FROM static_pkgs", |pairs| {
|
||||
for &(_column, value) in pairs.iter() {
|
||||
dat_pkgs.push(value.unwrap().to_string());
|
||||
}
|
||||
true
|
||||
});
|
||||
match result {
|
||||
Ok(_) => {
|
||||
//inf("Dumped static packages".to_string());
|
||||
}
|
||||
Err(_) => err_unrec("Couldn't dump packages from database".to_string()),
|
||||
}
|
||||
dat_pkgs
|
||||
}
|
||||
|
||||
pub fn stat_get_value(pkg: &str, sear_value: &str) -> bool {
|
||||
let file = format!("{}/.local/share/ame/aur_pkgs.db", env::var("HOME").unwrap());
|
||||
let connection = sqlite::open(file).unwrap();
|
||||
let mut return_val = false;
|
||||
match sear_value {
|
||||
"name" => {
|
||||
let result = connection.iterate(
|
||||
format!("SELECT name FROM static_pkgs WHERE name = \"{}\";", &pkg),
|
||||
|pairs| {
|
||||
for &(_column, _value) in pairs.iter() {
|
||||
return_val = true;
|
||||
}
|
||||
return_val
|
||||
},
|
||||
);
|
||||
match result {
|
||||
Ok(_) => {}
|
||||
Err(_) => err_unrec("Couldn't get value from database".to_string()),
|
||||
}
|
||||
return return_val;
|
||||
}
|
||||
"update" => {
|
||||
let result = connection.iterate(
|
||||
format!("SELECT pin FROM static_pkgs WHERE name = \"{}\";", &pkg),
|
||||
|pairs| {
|
||||
for &(_column, _value) in pairs.iter() {
|
||||
return_val = true;
|
||||
}
|
||||
return_val
|
||||
},
|
||||
);
|
||||
match result {
|
||||
Ok(_) => {}
|
||||
Err(_) => err_unrec("Couldn't get value from database".to_string()),
|
||||
}
|
||||
return return_val;
|
||||
}
|
||||
_ => return_val = false,
|
||||
}
|
||||
return_val
|
||||
}
|
||||
|
||||
pub fn stat_rem_pkg(static_pkgs: &[String]) {
|
||||
let file = format!("{}/.local/share/ame/aur_pkgs.db", env::var("HOME").unwrap());
|
||||
let connection = sqlite::open(file).unwrap();
|
||||
print!("{:?}", static_pkgs);
|
||||
for i in static_pkgs {
|
||||
let result = connection.execute(format!(
|
||||
"
|
||||
DELETE FROM static_pkgs WHERE name = \"{}\";
|
||||
",
|
||||
i
|
||||
));
|
||||
match result {
|
||||
Ok(_) => inf(format!("Removed {} from database", i)),
|
||||
Err(_) => err_unrec(format!(
|
||||
"Couldn't remove {} from database (static packages table)",
|
||||
i
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stat_add_pkg(update: &str, pkg: &str) {
|
||||
let file = format!("{}/.local/share/ame/aur_pkgs.db", env::var("HOME").unwrap());
|
||||
let connection = sqlite::open(file).unwrap();
|
||||
let pin = if update == "true" { 1 } else { 0 };
|
||||
let result = connection.execute(format!(
|
||||
"
|
||||
INSERT INTO static_pkgs (name, pin) VALUES (\"{}\", {});
|
||||
",
|
||||
pkg, pin
|
||||
));
|
||||
match result {
|
||||
Ok(_) => inf(format!("Added {} to database", pkg)),
|
||||
Err(_) => err_unrec(format!("Couldn't add {} to database", pkg)),
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
use crate::inf;
|
||||
use crate::{
|
||||
err_rec, inssort, stat_add_pkg, stat_dump_dat, stat_get_value, stat_rem_pkg, uninstall,
|
||||
};
|
||||
use std::{env, fs};
|
||||
|
||||
pub fn rebuild(noconfirm: bool) {
|
||||
let file = format!("{}/.config/ame/pkgs.toml", env::var("HOME").unwrap());
|
||||
let database = fs::read_to_string(&file).expect("Can't Open Database");
|
||||
inf("installing crystal config".to_string());
|
||||
|
||||
let file = format!("{}/.local/share/ame/aur_pkgs.db", env::var("HOME").unwrap());
|
||||
let connection = sqlite::open(file).unwrap();
|
||||
connection
|
||||
.execute(
|
||||
"
|
||||
CREATE TABLE IF NOT EXISTS static_pkgs (name TEXT, pin INTEGER);
|
||||
",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let db_parsed = database.parse::<toml::Value>().expect("Invalid Database");
|
||||
let mut pkgs = Vec::new();
|
||||
if let Some(entry) = db_parsed.as_table() {
|
||||
for (key, value) in &*entry {
|
||||
let mut tempvec = Vec::new();
|
||||
// println!("{}", key);
|
||||
// println!("{}", format!("{}",value).replace("update = ", ""));
|
||||
tempvec.push(key.to_string());
|
||||
tempvec.push(format!("{}", value).replace("update = ", ""));
|
||||
pkgs.push(tempvec);
|
||||
}
|
||||
}
|
||||
let mut pkgs_to_add: Vec<Vec<String>> = Vec::new();
|
||||
let mut pkgs_to_install: Vec<String> = Vec::new();
|
||||
for i in pkgs {
|
||||
if !stat_get_value(&i[0], "name") {
|
||||
let tempvec = vec![i[0].to_string(), i[1].to_string()];
|
||||
pkgs_to_add.push(tempvec);
|
||||
pkgs_to_install.push(i[0].to_string());
|
||||
}
|
||||
}
|
||||
let mut config_no_change = 0;
|
||||
if !pkgs_to_install.is_empty() {
|
||||
inf(format!("Installing {}", pkgs_to_install.join(", ")));
|
||||
inssort(noconfirm, false, pkgs_to_install);
|
||||
for i in pkgs_to_add {
|
||||
stat_add_pkg(&i[1], &i[0]);
|
||||
}
|
||||
config_no_change += 1;
|
||||
}
|
||||
let dat_pkgs = stat_dump_dat();
|
||||
|
||||
let mut pkgs = Vec::new();
|
||||
if let Some(entry) = db_parsed.as_table() {
|
||||
for (key, _value) in &*entry {
|
||||
pkgs.push(key);
|
||||
}
|
||||
}
|
||||
|
||||
let mut pkgs_to_remove: Vec<String> = Vec::new();
|
||||
for i in dat_pkgs {
|
||||
if !pkgs.contains(&&i) {
|
||||
pkgs_to_remove.push(i.to_string());
|
||||
}
|
||||
config_no_change += 1;
|
||||
}
|
||||
if !pkgs_to_remove.is_empty() {
|
||||
inf(format!("Removing {}", pkgs_to_remove.join(", ")));
|
||||
stat_rem_pkg(&pkgs_to_remove);
|
||||
uninstall(noconfirm, pkgs_to_remove);
|
||||
}
|
||||
|
||||
if config_no_change != 0 {
|
||||
inf("Rebuild Complete".to_string());
|
||||
} else {
|
||||
err_rec("Configuration not changed!".to_string());
|
||||
}
|
||||
}
|
@ -1,109 +0,0 @@
|
||||
use ansi_term::Colour;
|
||||
use std::{env, io, io::Write, process, string};
|
||||
use uwuizer::*;
|
||||
|
||||
pub fn inf(a: string::String) {
|
||||
// info
|
||||
if env::var("AME_UWU").unwrap_or_else(|_| "n/a".to_string()) == "YES" {
|
||||
println!(
|
||||
"{} {}",
|
||||
Colour::Purple.paint("❖"),
|
||||
Colour::White.paint(uwuize!(&a))
|
||||
);
|
||||
} else {
|
||||
println!("{} {}", Colour::Purple.paint("❖"), Colour::White.paint(a));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sec(a: string::String) {
|
||||
if env::var("AME_UWU").unwrap_or_else(|_| "n/a".to_string()) == "YES" {
|
||||
println!(
|
||||
"{} {}",
|
||||
Colour::Purple.bold().paint("❖"),
|
||||
Colour::White.bold().paint(uwuize!(&a))
|
||||
);
|
||||
} else {
|
||||
println!(
|
||||
"{} {}",
|
||||
Colour::Purple.bold().paint("❖"),
|
||||
Colour::White.bold().paint(a)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn succ(a: string::String) {
|
||||
// success
|
||||
if env::var("AME_UWU").unwrap_or_else(|_| "n/a".to_string()) == "YES" {
|
||||
println!(
|
||||
"{} {}",
|
||||
Colour::Green.bold().paint("✓"),
|
||||
Colour::Green.paint(uwuize!(&a))
|
||||
);
|
||||
} else {
|
||||
println!(
|
||||
"{} {}",
|
||||
Colour::Green.bold().paint("✓"),
|
||||
Colour::Green.paint(&a)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prompt(a: string::String) -> bool {
|
||||
// prompt
|
||||
if env::var("AME_UWU").unwrap_or_else(|_| "n/a".to_string()) == "YES" {
|
||||
print!(
|
||||
"{} {} {}",
|
||||
Colour::Purple.bold().paint("❖"),
|
||||
Colour::White.bold().paint(uwuize!(&a)),
|
||||
Colour::White.bold().paint("(Y/n): ")
|
||||
);
|
||||
} else {
|
||||
print!(
|
||||
"{} {} {}",
|
||||
Colour::Purple.bold().paint("❖"),
|
||||
Colour::White.bold().paint(&a),
|
||||
Colour::White.bold().paint("(Y/n): ")
|
||||
);
|
||||
}
|
||||
io::stdout().flush().ok();
|
||||
let mut yn: String = String::new();
|
||||
let _ = std::io::stdin().read_line(&mut yn);
|
||||
!(yn.trim() == "n" || yn.trim() == "N" || yn.trim() == "no" || yn.trim() == "No")
|
||||
}
|
||||
|
||||
pub fn err_unrec(a: string::String) {
|
||||
// unrecoverable error
|
||||
if env::var("AME_UWU").unwrap_or_else(|_| "n/a".to_string()) == "YES" {
|
||||
println!(
|
||||
"{} {} {}",
|
||||
Colour::Red.bold().paint(uwuize!("✖ Unrecoverable error:")),
|
||||
Colour::Red.paint(uwuize!(&a)),
|
||||
Colour::Red.bold().paint(uwuize!("Terminating."))
|
||||
);
|
||||
} else {
|
||||
println!(
|
||||
"{} {} {}",
|
||||
Colour::Red.bold().paint("✖ Unrecoverable error:"),
|
||||
Colour::Red.paint(a),
|
||||
Colour::Red.bold().paint("Terminating.")
|
||||
);
|
||||
}
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
pub fn err_rec(a: string::String) {
|
||||
// recoverable error
|
||||
if env::var("AME_UWU").unwrap_or_else(|_| "n/a".to_string()) == "YES" {
|
||||
println!(
|
||||
"{} {}",
|
||||
Colour::Yellow.bold().paint(uwuize!("⚠ WARNING:")),
|
||||
Colour::Yellow.paint(uwuize!(&a))
|
||||
);
|
||||
} else {
|
||||
println!(
|
||||
"{} {}",
|
||||
Colour::Yellow.bold().paint("⚠ WARNING:"),
|
||||
Colour::Yellow.paint(a)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,160 +0,0 @@
|
||||
use crate::mods::{
|
||||
database::rem_pkg,
|
||||
strs::{err_rec, err_unrec, sec, succ},
|
||||
};
|
||||
use runas::Command;
|
||||
use std::{fs, path::Path};
|
||||
|
||||
pub fn uninstall(noconfirm: bool, pkgs: Vec<String>) {
|
||||
// uninstall a package
|
||||
sec(format!(
|
||||
"Attempting to uninstall packages: {}",
|
||||
&pkgs.join(" ")
|
||||
));
|
||||
|
||||
let important = [
|
||||
"base",
|
||||
"linux",
|
||||
"linux-firmware",
|
||||
"systemd-sysvcompat",
|
||||
"networkmanager",
|
||||
"man-db",
|
||||
"man-pages",
|
||||
"texinfo",
|
||||
"sudo",
|
||||
"curl",
|
||||
"archlinux-keyring",
|
||||
"btrfs-progs",
|
||||
"timeshift",
|
||||
"timeshift-autosnap",
|
||||
];
|
||||
|
||||
let mut overrides: Vec<String> = Vec::new();
|
||||
if Path::new("/etc/ame/overrides.conf").exists() {
|
||||
overrides = fs::read_to_string("/etc/ame/overrides.conf")
|
||||
.expect("Failed to read overrides.conf")
|
||||
.lines()
|
||||
.map(|s| s.to_string())
|
||||
.collect();
|
||||
}
|
||||
|
||||
let mut matches: Vec<String> = Vec::new();
|
||||
for pkg in pkgs.iter() {
|
||||
for imp in important.iter() {
|
||||
if pkg == imp && !overrides.contains(pkg) {
|
||||
matches.push(pkg.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
if !matches.is_empty() {
|
||||
err_unrec(format!("The action you called for tries to uninstall packages: {} . This is disallowed by default as these are important system packages. If you fully know what you are doing and would like to uninstall these, please create an override in /etc/ame/overrides.conf.", matches.join(" ")));
|
||||
}
|
||||
|
||||
if noconfirm {
|
||||
let result = Command::new("pacman")
|
||||
.arg("-Ru")
|
||||
.args(&pkgs)
|
||||
.arg("--noconfirm")
|
||||
.status()
|
||||
.expect("Couldn't call pacman");
|
||||
match result.code() {
|
||||
Some(0) => {
|
||||
succ(format!(
|
||||
"Succesfully uninstalled packages: {}",
|
||||
&pkgs.join(" ")
|
||||
));
|
||||
rem_pkg(&pkgs);
|
||||
}
|
||||
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
|
||||
None => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
|
||||
};
|
||||
} else {
|
||||
let result = Command::new("pacman")
|
||||
.arg("-Ru")
|
||||
.args(&pkgs)
|
||||
.status()
|
||||
.expect("Couldn't call pacman");
|
||||
match result.code() {
|
||||
Some(0) => {
|
||||
succ(format!(
|
||||
"Succesfully uninstalled packages: {}",
|
||||
&pkgs.join(" ")
|
||||
));
|
||||
rem_pkg(&pkgs);
|
||||
}
|
||||
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
|
||||
None => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
|
||||
};
|
||||
}
|
||||
for pkg in &pkgs {
|
||||
let pkgdir = format!("{}/.cache/ame/{}", std::env::var("HOME").unwrap(), pkg);
|
||||
let path = Path::new(&pkgdir);
|
||||
if path.is_dir() {
|
||||
let rm_result = fs::remove_dir_all(&path);
|
||||
match rm_result {
|
||||
Ok(_) => succ(format!("Removed AUR cache directory for {}", pkg)),
|
||||
Err(_) => err_unrec(format!("Failed to remove AUR cache directory for {}", pkg)),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn uninstall_from_file(noconfirm: bool, file: &str) {
|
||||
// uninstall a package from a list of packages
|
||||
let mut pkgs: Vec<String> = Vec::new();
|
||||
let contents = std::fs::read_to_string(&file).expect("Couldn't read file");
|
||||
for line in contents.lines() {
|
||||
pkgs.push(line.to_string());
|
||||
}
|
||||
sec(format!(
|
||||
"Attempting to uninstall packages: {}",
|
||||
&pkgs.join(" ")
|
||||
));
|
||||
if noconfirm {
|
||||
let result = Command::new("pacman")
|
||||
.arg("-Ru")
|
||||
.args(&pkgs)
|
||||
.arg("--noconfirm")
|
||||
.status()
|
||||
.expect("Couldn't call pacman");
|
||||
match result.code() {
|
||||
Some(0) => {
|
||||
succ(format!(
|
||||
"Succesfully uninstalled packages: {}",
|
||||
&pkgs.join(" ")
|
||||
));
|
||||
rem_pkg(&pkgs);
|
||||
}
|
||||
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
|
||||
None => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
|
||||
};
|
||||
} else {
|
||||
let result = Command::new("pacman")
|
||||
.arg("-Ru")
|
||||
.args(&pkgs)
|
||||
.status()
|
||||
.expect("Couldn't call pacman");
|
||||
match result.code() {
|
||||
Some(0) => {
|
||||
succ(format!(
|
||||
"Succesfully uninstalled packages: {}",
|
||||
&pkgs.join(" ")
|
||||
));
|
||||
rem_pkg(&pkgs);
|
||||
}
|
||||
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
|
||||
None => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
|
||||
};
|
||||
}
|
||||
for pkg in &pkgs {
|
||||
let pkgdir = format!("{}/.cache/ame/{}", std::env::var("HOME").unwrap(), pkg);
|
||||
let path = Path::new(&pkgdir);
|
||||
if path.is_dir() {
|
||||
let rm_result = fs::remove_dir_all(&path);
|
||||
match rm_result {
|
||||
Ok(_) => succ(format!("Removed AUR cache directory for {}", pkg)),
|
||||
Err(_) => err_unrec(format!("Failed to remove AUR cache directory for {}", pkg)),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
use crate::mods::strs::{err_unrec, sec, succ};
|
||||
use runas::Command;
|
||||
|
||||
pub fn update() {
|
||||
// update the repositories
|
||||
sec("Syncing package repos".to_string());
|
||||
|
||||
let result = Command::new("pacman")
|
||||
.arg("-Sy")
|
||||
.status()
|
||||
.expect("Couldn't call pacman");
|
||||
match result.code() {
|
||||
Some(0) => succ("Repos succesfully synced".to_string()),
|
||||
Some(_) => err_unrec("Couldn't sync package repos".to_string()),
|
||||
None => err_unrec("Couldn't sync package repos".to_string()),
|
||||
}
|
||||
}
|
@ -1,213 +0,0 @@
|
||||
use crate::{
|
||||
err_rec, err_unrec, inf, inssort, mods::database::get_value, mods::rpc::*, mods::strs::prompt,
|
||||
mods::strs::sec, mods::strs::succ, uninstall,
|
||||
};
|
||||
use runas::Command;
|
||||
use std::{env, fs, path::Path};
|
||||
use toml;
|
||||
|
||||
fn uninstall_make_depend(pkg: &str) {
|
||||
// uninstall make depends installed by ame itself
|
||||
let make_depends = rpcinfo(pkg).make_depends;
|
||||
|
||||
if !make_depends.is_empty() {
|
||||
inf(format!(
|
||||
"{} installed following make dependencies: {}",
|
||||
pkg,
|
||||
make_depends.join(", ")
|
||||
));
|
||||
let remove = prompt("Would you like to remove them?".to_string());
|
||||
if remove {
|
||||
uninstall(true, make_depends);
|
||||
}
|
||||
}
|
||||
succ(format!("Succesfully upgraded {}", pkg));
|
||||
}
|
||||
|
||||
pub fn upgrade(noconfirm: bool) {
|
||||
// upgrade all packages
|
||||
let homepath = env::var("HOME").unwrap();
|
||||
let cachedir = format!("/{}/.cache/ame/", homepath);
|
||||
let cache_exists = Path::new(&format!("/{}/.cache/ame/", homepath)).is_dir();
|
||||
let file = format!("{}/.local/ame/aurPkgs.db", env::var("HOME").unwrap());
|
||||
let database = String::new();
|
||||
if Path::new(&file).exists() {
|
||||
let _db = fs::read_to_string(&file).expect("Can't Open Database");
|
||||
} else {
|
||||
let _cdar = fs::create_dir_all(format!("/{}/.local/ame/", homepath));
|
||||
match _cdar {
|
||||
Ok(_) => inf("Created cache directory (previously missing)".to_string()),
|
||||
Err(_) => err_unrec("Couldn't create cache directory".to_string()),
|
||||
}
|
||||
err_rec(String::from("Database wasn't found, creating new one"));
|
||||
let _dbfile = fs::File::create(&file);
|
||||
let _db = String::new();
|
||||
}
|
||||
let db_parsed = database.parse::<toml::Value>().expect("Invalid Database");
|
||||
|
||||
if !cache_exists {
|
||||
let cachecreate = fs::create_dir_all(&cachedir);
|
||||
match cachecreate {
|
||||
Ok(_) => inf("Creating cachedir. (didn't exist previously)".to_string()),
|
||||
Err(_) => err_unrec("Couldn't create cachedir".to_string()),
|
||||
}
|
||||
}
|
||||
sec("Performing system upgrade".to_string());
|
||||
if noconfirm {
|
||||
let result = Command::new("pacman")
|
||||
.arg("-Syu")
|
||||
.arg("--noconfirm")
|
||||
.status()
|
||||
.expect("Couldn't call pacman");
|
||||
match result.code() {
|
||||
Some(0) => succ("All repo packages upgraded".to_string()),
|
||||
Some(_) => err_unrec("Couldn't upgrade packages".to_string()),
|
||||
None => err_unrec("Couldn't upgrade packages".to_string()),
|
||||
};
|
||||
} else {
|
||||
let result = Command::new("pacman")
|
||||
.arg("-Syu")
|
||||
.status()
|
||||
.expect("Couldn't call pacman");
|
||||
match result.code() {
|
||||
Some(0) => succ("All repo packages upgraded".to_string()),
|
||||
Some(_) => err_unrec("Couldn't upgrade packages".to_string()),
|
||||
None => err_unrec("Couldn't upgrade packages".to_string()),
|
||||
};
|
||||
}
|
||||
|
||||
if let Some(entry) = db_parsed.as_table() {
|
||||
for (key, _value) in &*entry {
|
||||
let results = rpcsearch(&key.to_string()).results;
|
||||
let url = format!("https://aur.archlinux.org/{}.git", key);
|
||||
let package = rpcinfo(&key.to_string());
|
||||
let version = get_value(key, "version");
|
||||
if results[0].version.contains(&version) {
|
||||
let keydir = format!("{}{}", &cachedir, &key);
|
||||
if Path::new(&keydir).is_dir() {
|
||||
let cd_result = env::set_current_dir(&keydir);
|
||||
match cd_result {
|
||||
Ok(_) => inf("Entered package directory".to_string()),
|
||||
Err(_) => err_unrec("Could not enter package directory".to_string()),
|
||||
}
|
||||
inssort(true, true, package.depends.clone());
|
||||
|
||||
sec(format!("Installing {} ...", &key));
|
||||
let install_result = std::process::Command::new("makepkg")
|
||||
.arg("-si")
|
||||
.arg("--noconfirm")
|
||||
.arg("--needed")
|
||||
.status();
|
||||
match install_result {
|
||||
Ok(_) => {
|
||||
uninstall_make_depend(key);
|
||||
}
|
||||
Err(_) => {
|
||||
err_unrec(format!("Couldn't install {}", &key));
|
||||
}
|
||||
};
|
||||
|
||||
sec(format!("Installing {} ...", &key));
|
||||
let install_result = std::process::Command::new("makepkg")
|
||||
.arg("-si")
|
||||
.arg("--needed")
|
||||
.status()
|
||||
.expect("Couldn't call makepkg");
|
||||
match install_result.code() {
|
||||
Some(0) => {
|
||||
uninstall_make_depend(key);
|
||||
}
|
||||
Some(_) => {
|
||||
err_unrec(format!("Couldn't install {}", &key));
|
||||
}
|
||||
None => {
|
||||
err_unrec(format!("Couldn't install {}", &key));
|
||||
}
|
||||
};
|
||||
} else {
|
||||
inf(format!("Cloning {} ...", &key));
|
||||
|
||||
if Path::new(&keydir).is_dir() {
|
||||
let rm_result = fs::remove_dir_all(&keydir);
|
||||
match rm_result {
|
||||
Ok(_) => inf(format!(
|
||||
"Package path for {} already found. Removing to reinstall",
|
||||
&key
|
||||
)),
|
||||
Err(_) => err_unrec(format!(
|
||||
"Package path for {} already found, but could not remove to reinstall",
|
||||
&key
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
let dir_result = fs::create_dir(&keydir);
|
||||
match dir_result {
|
||||
Ok(_) => inf(format!("Created package directory for {}", &key)),
|
||||
Err(_) => {
|
||||
err_unrec(format!("Couldn't create package directory for {}", &key))
|
||||
}
|
||||
}
|
||||
|
||||
let cd_result = env::set_current_dir(&keydir);
|
||||
match cd_result {
|
||||
Ok(_) => inf("Entered package directory".to_string()),
|
||||
Err(_) => err_unrec("Could not enter package directory".to_string()),
|
||||
}
|
||||
|
||||
inssort(true, true, package.depends.clone());
|
||||
|
||||
let clone = std::process::Command::new("git")
|
||||
.arg("clone")
|
||||
.arg(&url)
|
||||
.arg(&keydir)
|
||||
.status()
|
||||
.expect("Couldn't clone repo");
|
||||
match clone.code() {
|
||||
Some(0) => {
|
||||
inf(format!("Cloning {} into package directory", &key));
|
||||
}
|
||||
Some(_) => {
|
||||
err_unrec(format!("Failed cloning {} into package directory", &key))
|
||||
}
|
||||
_ => err_unrec(format!("Failed cloning {} into package directory", &key)),
|
||||
}
|
||||
}
|
||||
|
||||
sec(format!("Installing {} ...", &key));
|
||||
let install_result = std::process::Command::new("makepkg")
|
||||
.arg("-si")
|
||||
.arg("--noconfirm")
|
||||
.arg("--needed")
|
||||
.status();
|
||||
match install_result {
|
||||
Ok(_) => {
|
||||
uninstall_make_depend(key);
|
||||
}
|
||||
Err(_) => {
|
||||
err_unrec(format!("Couldn't install {}", &key));
|
||||
}
|
||||
};
|
||||
sec(format!("Installing {} ...", &key));
|
||||
let install_result = std::process::Command::new("makepkg")
|
||||
.arg("-si")
|
||||
.arg("--needed")
|
||||
.status()
|
||||
.expect("Couldn't call makepkg");
|
||||
match install_result.code() {
|
||||
Some(0) => {
|
||||
uninstall_make_depend(key);
|
||||
}
|
||||
Some(_) => {
|
||||
err_unrec(format!("Couldn't install {}", &key));
|
||||
}
|
||||
None => {
|
||||
err_unrec(format!("Couldn't install {}", &key));
|
||||
}
|
||||
};
|
||||
} else {
|
||||
inf(format!("Package {} already up to date", &key));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
use crate::inf;
|
||||
use ansi_term::Colour;
|
||||
|
||||
pub fn ver() {
|
||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
// print version and contributors
|
||||
println!();
|
||||
inf(format!("ame - {}", VERSION));
|
||||
println!();
|
||||
inf("Contributors:".to_string());
|
||||
println!("- axtlos <axtlos@tar.black>");
|
||||
println!("- jnats <michal@tar.black>");
|
||||
println!("- jasio <jasiobene@icloud.com>");
|
||||
println!("- generic <mdc028@bucknell.edu>");
|
||||
println!();
|
||||
inf("This software is licensed under the BSD 3-Clause license.".to_string());
|
||||
inf("All source code is available at:".to_string());
|
||||
println!();
|
||||
println!(
|
||||
"{}",
|
||||
Colour::Purple
|
||||
.bold()
|
||||
.paint("https://git.getcryst.al/crystal/ame")
|
||||
);
|
||||
println!();
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
pub fn noconf(args: &[String]) -> bool {
|
||||
// noconfirm if user passed --noconfirm or added n to the end of the arg
|
||||
args.contains(&"--noconfirm".to_string()) || args[0].ends_with(&"n".to_string())
|
||||
}
|
||||
|
||||
pub fn argssort(args: &mut Vec<String>) -> &Vec<String> {
|
||||
// sort the args
|
||||
if args.contains(&"--noconfirm".to_string()) {
|
||||
args.retain(|x| x != &"--noconfirm".to_string());
|
||||
return args;
|
||||
}
|
||||
args
|
||||
}
|
Loading…
Reference in New Issue