Initial Commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "orange"
|
||||
version = "0.1.0"
|
||||
6
Cargo.toml
Normal file
6
Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "orange"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
15
README.md
Normal file
15
README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Orange
|
||||
Why "Orange"? It's a fruit with a pip. The name doesn't matter as long as it doesn't conflict, and you can symlink it.
|
||||
```
|
||||
oscarg@ws01:~$ orange
|
||||
orange: command not found
|
||||
oscarg@ws01:~$ sudo apt install orange
|
||||
[sudo] password for oscarg:
|
||||
Error: Unable to locate package orange
|
||||
oscarg@ws01:~$
|
||||
```
|
||||
I do not see `orange` here.
|
||||
|
||||
---
|
||||
## What's this?
|
||||
A small stub thing for Debian-based Linux distributions that simply redirects your `pip` instruction to `apt`. Really, that's all it does.
|
||||
62
src/main.rs
Normal file
62
src/main.rs
Normal file
@@ -0,0 +1,62 @@
|
||||
use std::env;
|
||||
use std::io::{self, Write};
|
||||
use std::process::Command;
|
||||
|
||||
fn get_user_confirmation(prompt: &str) -> bool {
|
||||
loop {
|
||||
print!("{} (y/n): ", prompt);
|
||||
io::stdout().flush().unwrap();
|
||||
|
||||
let mut input = String::new();
|
||||
io::stdin().read_line(&mut input).expect("Failed to read line");
|
||||
|
||||
match input.trim().to_lowercase().as_str() {
|
||||
"y" | "yes" => return true,
|
||||
"n" | "no" => return false,
|
||||
_ => {
|
||||
println!("Please enter 'y' or 'n'.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut args_iter = env::args();
|
||||
let program_name = args_iter.next().unwrap_or_else(|| "program".to_string());
|
||||
let args: Vec<String> = args_iter.collect();
|
||||
|
||||
if args.is_empty() {
|
||||
eprintln!("Usage: {} <package_name> [package_names...]", program_name);
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
println!("Preparing to install the following packages:");
|
||||
|
||||
let apt_packages: Vec<String> = args
|
||||
.iter()
|
||||
.map(|p| format!("python3-{}", p))
|
||||
.collect();
|
||||
|
||||
for pkg in &apt_packages {
|
||||
println!(" - {}", pkg);
|
||||
}
|
||||
|
||||
if get_user_confirmation("\nWould you like to proceed with apt") {
|
||||
let mut command = Command::new("sudo");
|
||||
command.arg("apt").arg("install").args(&apt_packages).arg("-y");
|
||||
|
||||
match command.status() {
|
||||
Ok(status) => {
|
||||
if status.success() {
|
||||
println!("Packages installed successfully.");
|
||||
} else {
|
||||
eprintln!("apt failed with status: {}", status);
|
||||
}
|
||||
}
|
||||
Err(e) => eprintln!("Failed to execute apt: {}", e),
|
||||
}
|
||||
} else {
|
||||
println!("Cancelling...");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user