Add version checking based on PKGBUILD file
This commit is contained in:
parent
a2076d472e
commit
9773e2ebdd
47
src/main.rs
47
src/main.rs
@ -1,3 +1,4 @@
|
|||||||
|
use std::str;
|
||||||
use std::env::args;
|
use std::env::args;
|
||||||
use std::fs::{File, create_dir_all, remove_dir_all};
|
use std::fs::{File, create_dir_all, remove_dir_all};
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
@ -79,17 +80,55 @@ fn process_package(packages_path: &String, package_name: &String, url: &String)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Git pull
|
// Git pull
|
||||||
let pull_output_u8 = Command::new("git")
|
Command::new("git")
|
||||||
.arg("-C")
|
.arg("-C")
|
||||||
.arg(folder_path.clone().to_str().unwrap())
|
.arg(folder_path.clone().to_str().unwrap())
|
||||||
.arg("pull")
|
.arg("pull")
|
||||||
.output()
|
.output()
|
||||||
.expect(&*format!("Could not clean repository for repository root at {}", folder_path.clone().to_str().unwrap()))
|
.expect(&*format!("Could not clean repository for repository root at {}", folder_path.clone().to_str().unwrap()));
|
||||||
|
|
||||||
|
let quoted_pacman_package_name_cmd = Command::new("awk")
|
||||||
|
.arg("-F")
|
||||||
|
.arg("=")
|
||||||
|
.arg("/^pkgname/{print $2}")
|
||||||
|
.arg(format!("{}/PKGBUILD", folder_path.clone().to_str().unwrap()))
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let pacman_package_name = Command::new("sed")
|
||||||
|
.arg("s/'//g")
|
||||||
|
.stdin(quoted_pacman_package_name_cmd.stdout.unwrap())
|
||||||
|
.output()
|
||||||
|
.expect(&*format!("Could not read PKGBUILD for repository root at {}", folder_path.clone().to_str().unwrap()))
|
||||||
.stdout;
|
.stdout;
|
||||||
|
|
||||||
let pull_output = std::str::from_utf8(&*pull_output_u8).unwrap();
|
let new_package_version = Command::new("awk")
|
||||||
|
.arg("-F")
|
||||||
|
.arg("=")
|
||||||
|
.arg("/^pkgver/{ver=$2}/^pkgrel/{rel=$2}/^pkgrel/{print ver\"-\"rel}")
|
||||||
|
.arg(format!("{}/PKGBUILD", folder_path.clone().to_str().unwrap()))
|
||||||
|
.output()
|
||||||
|
.expect(&*format!("Could not read PKGBUILD for repository root at {}", folder_path.clone().to_str().unwrap()))
|
||||||
|
.stdout;
|
||||||
|
|
||||||
if !folder_exists || !repo_exists || !pull_output.starts_with("Already up to date.") {
|
let full_installed_package_version_cmd = Command::new("pacman")
|
||||||
|
.arg("-Q")
|
||||||
|
.arg(str::from_utf8(&pacman_package_name).unwrap().trim())
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let installed_package_version = Command::new("awk")
|
||||||
|
.arg("{print $2}")
|
||||||
|
.stdin(full_installed_package_version_cmd.stdout.unwrap())
|
||||||
|
.output()
|
||||||
|
.expect(&*format!("Could not fetch current version of package {}", str::from_utf8(&pacman_package_name).unwrap()))
|
||||||
|
.stdout;
|
||||||
|
|
||||||
|
let updates_present = str::from_utf8(&installed_package_version).unwrap().trim() != str::from_utf8(&new_package_version).unwrap().trim();
|
||||||
|
|
||||||
|
if !folder_exists || !repo_exists || updates_present {
|
||||||
// makepkg -sicC
|
// makepkg -sicC
|
||||||
println!("Package out-of-date; running `makepkg -sicC`");
|
println!("Package out-of-date; running `makepkg -sicC`");
|
||||||
Command::new("makepkg")
|
Command::new("makepkg")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user