added feature to backup already existing binaries and being able to restore from them

main
Amy 3 years ago
parent 10422deade
commit 8e7b7cc3cb
No known key found for this signature in database
GPG Key ID: 6672E6DD65BEA50B

@ -0,0 +1,30 @@
<p align="center">
<a href="https://git.getcryst.al/crystal">
<img src="https://git.getcryst.al/crystal/branding/raw/branch/main/logos/crystal-logo-minimal.png" alt="Logo" width="150" height="150">
</a>
</p>
<p align="center">
<h2 align="center"> pkg manager warner </h2>
</p>
<p align="center">
<a href="https://discord.gg/yp4xpZeAgW"><img alt="Discord" src="https://img.shields.io/discord/825473796227858482?color=blue&label=Discord&logo=Discord&logoColor=white"?link=https://discord.gg/yp4xpZeAgW&link=https://discord.gg/yp4xpZeAgW> </p></a>
<p align="center"> a tool to warn users when using the wrong package manager </p>
## Usage:
| Action | shorthand flag | long flag |
| ------ | ------ | ------ |
| Show a help message | pkg-warner -h | pkg-warner help |
| Show the version | pkg-warner -v | pkg-warner version |
| initialize the database | ame -i | ame init |
| create all the scripts | pkg-warner -c | pkg-warner create-script |
| Show the warning for specified package manager | pkg-warner -w \<package-manager> | pkg-warner warning \<package-warner> |
## Installation for Non-Crystal systems:
If you're on an arch (deriviate), you can use the PKGBUILD in [packages/pkg-warner](https://git.getcryst.al/crystal/packages-x86_64/src/branch/master/pkg-warner)
If you're on a different distribution you can use these commands:
```sh
git clone https://git.getcryst.al/crystal/pkg-manager-warner.git
cd pkg-manager-warner
sudo make install
```

@ -0,0 +1 @@
target/debug/pkg-warner

@ -76,10 +76,32 @@ pub fn add_mngrs(pkg_managers: Vec<Vec<String>>, proper_manager: String) {
pub fn create_script() {
let connection = sqlite::open("/usr/share/pkg_warner/pkg_mngrs.db").unwrap();
let path = std::path::Path::new("/usr/share/pkg_warner/backs/");
let result = connection.iterate(
format!("SELECT mngr FROM pkg_mngrs WHERE mngr IS NOT \"proper_manager\";"),
|pairs| {
for &(_column, value) in pairs.iter() {
if std::path::Path::new(&format!("/usr/bin/{}", value.unwrap())).exists() {
if !path.is_dir() {
let result = std::fs::create_dir_all("/usr/share/pkg_warner/backs/".to_string());
match result {
Ok(_) => {
println!("Created path for binary backups (previously missing)");
}
Err(_) => {
println!("Couldn't create path for binary backups (/usr/share/pkg_warner/backs)")
}
}
}
let result = std::fs::copy(&format!("/usr/bin/{}", value.unwrap()), &format!("/usr/share/pkg_warner/backs/{}", value.unwrap()));
match result {
Ok(_) => {
}
Err(_) => {
println!("Couldn't back up {}", value.unwrap());
}
}
}
writeln!(&mut fs::File::create(format!("/usr/bin/{}",value.unwrap())).unwrap(), "#!/usr/bin/env bash\n pkg-warner -w {}", value.unwrap()).unwrap();
Command::new("chmod")
.arg("+x")
@ -162,6 +184,21 @@ pub fn warn(proper_manager: String, package_manager: String) {
}
}
pub fn res_bin() {
for file in fs::read_dir("/usr/share/pkg_warner/backs/").unwrap() {
let path = file.unwrap().path().display().to_string();
let result = std::fs::copy(&format!("{}", path), format!("/usr/bin/{}", path.to_string().replace("/usr/share/pkg_warner/backs/", "")));
match result {
Ok(_) => {
println!("Restored {}", path);
}
Err(_) => {
println!("Couldn't restore {}", path);
}
}
}
}
fn main() {
let args: Vec<String> = env::args().skip(1).collect();
@ -234,6 +271,9 @@ fn main() {
rem_mngr(pkgs_to_remove);
}
}
"-res" | "restore" => {
res_bin();
}
_ => {
help();
}

Loading…
Cancel
Save