From ddf22fb5af6058796c6abbe95f4f57aae960ca13 Mon Sep 17 00:00:00 2001 From: oscarg Date: Sun, 31 Aug 2025 01:18:08 +1200 Subject: [PATCH] Initial Commit --- .gitignore | 1 + Cargo.lock | 7 ++++++ Cargo.toml | 6 ++++++ README.md | 15 +++++++++++++ src/main.rs | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 91 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 README.md create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..4c80084 --- /dev/null +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..6757523 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "orange" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/README.md b/README.md new file mode 100644 index 0000000..98ce226 --- /dev/null +++ b/README.md @@ -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. \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..1425c96 --- /dev/null +++ b/src/main.rs @@ -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 = args_iter.collect(); + + if args.is_empty() { + eprintln!("Usage: {} [package_names...]", program_name); + std::process::exit(1); + } + + println!("Preparing to install the following packages:"); + + let apt_packages: Vec = 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..."); + } +}