can now properly install from repos and aur

i18n
axtloss 3 years ago
parent 85c02b91af
commit e88e0e0950

@ -9,4 +9,5 @@ description = "a fast and efficient aur helper."
[dependencies] [dependencies]
git2 = "*" git2 = "*"
raur = "2.0.2" raur = "2.0.2"
runas = "*"

@ -5,4 +5,4 @@ pub fn clearcache() {
fs::remove_dir_all(&path).unwrap(); fs::remove_dir_all(&path).unwrap();
fs::create_dir(&path).unwrap(); fs::create_dir(&path).unwrap();
} }

@ -6,20 +6,17 @@ pub fn clone(pkg: &str) {
let error = format!("Couldn't install {}", &pkg); let error = format!("Couldn't install {}", &pkg);
let path = Path::new(&cachedir); let path = Path::new(&cachedir);
let results = raur::search(&pkg).expect(&error); let results = raur::search(&pkg).expect(&error);
let url = format!("https://aur.archlinux.org/{}.git", &pkg); let url = format!("https://aur.archlinux.org/{}.git", results[0].name);
if path.exists() { if path.exists() {
fs::remove_dir_all(path).unwrap(); fs::remove_dir_all(path).unwrap();
} }
println!("Cloning {} ...", pkg);
for _res in results.first() { Repository::clone(&url, &path).unwrap();
println!("Cloning {} ...", pkg); println!("Installing {} ...", pkg);
Repository::clone(&url, &path).unwrap(); Command::new("makepkg")
println!("Installing {} ...", pkg); .current_dir(&cachedir)
Command::new("makepkg") .arg("--noconfirm")
.current_dir(&cachedir) .arg("-si")
.arg("--noconfirm") .status()
.arg("-si") .expect(&error);
.output()
.expect(&error);
}
} }

@ -0,0 +1,6 @@
use runas::Command;
pub fn install(pkg: &str) {
let errstr = format!("Something went wrong");
Command::new("pacman").arg("-S").arg(&pkg).status().expect(&errstr);
}

@ -1,14 +1,16 @@
mod clone;
mod uninstall; mod uninstall;
mod help; mod help;
mod upgrade; mod upgrade;
mod search; mod search;
mod clearcache; mod clearcache;
use crate::{clone::clone, help::help, uninstall::uninstall, upgrade::upgrade, search::a_search, search::r_search, clearcache::clearcache}; mod install;
use std::{env, process::exit}; mod clone;
use crate::{clone::clone, help::help, uninstall::uninstall, upgrade::upgrade, search::a_search, search::r_search, clearcache::clearcache, install::install};
use std::{env, process::exit, process::Command};
fn main() { fn main() {
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
if args.len() <= 1 { if args.len() <= 1 {
help(); help();
exit(1); exit(1);
@ -16,7 +18,12 @@ fn main() {
let oper = &args[1]; let oper = &args[1];
if oper == "-S" { if oper == "-S" {
for arg in env::args().skip(2) { for arg in env::args().skip(2) {
clone(&arg); let out = Command::new("pacman").arg("-Ss").arg(&arg).status().unwrap();
if out.success() {
install(&arg);
} else {
clone(&arg);
}
} }
} else if oper == "-R" { } else if oper == "-R" {
for arg in env::args().skip(2) { for arg in env::args().skip(2) {
@ -43,4 +50,4 @@ fn main() {
help(); help();
exit(0); exit(0);
} }
} }

@ -12,7 +12,6 @@ pub fn r_search(pkg: &str) {
Command::new("pacman") Command::new("pacman")
.arg("-Ss") .arg("-Ss")
.arg(&pkg) .arg(&pkg)
.spawn() .status()
//.status() TODO: for some reason cant use both .spawn and .status at the same time, need fix
.expect(&errstr); .expect(&errstr);
} }

@ -7,7 +7,6 @@ pub fn uninstall(pkg: &str) {
.arg("-R") .arg("-R")
.arg("--noconfirm") .arg("--noconfirm")
.arg(&pkg) .arg(&pkg)
.spawn() .status()
//.status() TODO: for some reason cant use both .spawn and .status at the same time, need fix
.expect(&errstr); .expect(&errstr);
} }

@ -4,7 +4,6 @@ pub fn upgrade() {
let errstr = format!("Something happened"); let errstr = format!("Something happened");
Command::new("pacman") Command::new("pacman")
.arg("-Syu") .arg("-Syu")
.spawn() .status()
//.status() TODO: for some reason cant use both .spawn and .status at the same time, need fix
.expect(&errstr); .expect(&errstr);
} }

Loading…
Cancel
Save