From e2fa9dbf890eb38f8e211a5995066570f8c83cf1 Mon Sep 17 00:00:00 2001
From: axtlos <3alouchi2006@gmail.com>
Date: Tue, 19 Oct 2021 13:08:59 +0200
Subject: [PATCH] immediatly terminate when running as root
---
Cargo.toml | 1 +
README.md | 12 +++++--
main.rs | 79 -----------------------------------------
src/main.rs | 6 ++++
src/mods/clone.rs:31:43 | 0
5 files changed, 17 insertions(+), 81 deletions(-)
delete mode 100644 main.rs
delete mode 100644 src/mods/clone.rs:31:43
diff --git a/Cargo.toml b/Cargo.toml
index 4466920..c77911a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,3 +18,4 @@ regex = "*"
toml_edit = "0.5.0"
toml = "*"
bytes = "*"
+nix = "*"
\ No newline at end of file
diff --git a/README.md b/README.md
index b4f7e8b..5003c83 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,8 @@ Made for Crystal, compatible with any Arch-based Linux distribution.
| Action | FreeBSD pkg-style alias | Pacman-style flag(s) |
| ------ | ------ | ------ |
| Install a package | ame ins | ame -S |
-| Remove a package | ame rm | ame -R / -Rs |
+| Remove a package | ame rm | ame -R |
+| Remove a package with its dependencies | ame purge | ame -Rs |
| Update repository | ame upd | ame -Sy |
| Upgrade a package | ame upg | ame -Syu |
| Search for a package in general | ame sea | ame -Ss |
@@ -43,5 +44,12 @@ For general debug/test:
Clean all build directories:
- `make clean`
+
+
-`echo "AME_UWU=YES" >> ~/.zshrc`, self explanatory
\ No newline at end of file
+```sh
+echo "AME_UWU=YES" >> ~/.zshrc # for zsh
+echo "AME_UWU=YES" >> ~/.bashrc # for bash
+set -Ux AME_UWU YES # for fish
+```
+self explanatory
diff --git a/main.rs b/main.rs
deleted file mode 100644
index 99d68c7..0000000
--- a/main.rs
+++ /dev/null
@@ -1,79 +0,0 @@
-
-mod mods;
-use mods::{clearcache::clearcache, clone::clone, help::help, install::install, inssort::inssort, search::{a_search, r_search}, uninstall::uninstall, upgrade::upgrade, update::update, ver::ver, strs::inf, strs::err_unrec, strs::err_rec, xargs::*, database::addPkg};
-use std::{env, process::exit, process::Command};
-
-fn main() {
- // let statements
- let args: Vec = env::args().collect();
- let mut pkgs: Vec = env::args().skip(2).collect();
-
- // args catch
- if args.len() <= 1 {
- help();
- exit(1);
- }
-
- let oper = &args[1];
- let noconfirm: bool = noconf(&args);
-
- argssort(&mut pkgs);
-
- // install
- if oper == "-S" || oper == "-Sn" || oper == "ins" {
- inssort(noconfirm, pkgs);
-
- // remove
- } else if oper == "-R" || oper == "-Rn " || oper == "-Rsn" || oper == "-Rs" || oper == "rm" {
- uninstall(noconfirm, pkgs);
-
- // upgrade
- } else if oper == "-Syu" || oper == "-Syun" || oper == "upg" {
- upgrade(noconfirm);
-
- // update
- } else if oper == "-Sy" || oper == "upd" {
- update();
-
- // general search
- } else if oper == "-Ss" || oper == "sea" {
- r_search(&args[2]);
- a_search(&args[2]);
-
- // aur search
- } else if oper == "-Sa" || oper == "aursea" {
- a_search(&args[2]);
-
- // repo search
- } else if oper == "-Sr" || oper == "repsea" {
- r_search(&args[2]);
-
- // clear cache !! DEBUG ONLY !! DO NOT DO THIS IF YOU DONT KNOW WHAT YOURE DOING !!
- } else if oper == "-Cc" || oper == "clr" {
- clearcache();
-
- // version / contrib
- } else if oper == "-v" || oper == "-V" || oper == "ver" {
- ver();
-
- // help
- } else if oper == "-h" || oper == "help" {
- help();
- // pacman passthrough
- } else {
- let pass = Command::new("pacman")
- .args(env::args().skip(1))
- .status()
- .expect("Something has gone wrong.");
-
- match pass.code() {
- Some(1) => {
- err_rec(format!("No such operation \"{}\"", args.join(" ")));
- inf(format!("Try running \"ame help\" for an overview of how to use ame"))
- }
- Some(_) => {}
- None => {
- err_unrec(format!("Something has gone terribly wrong."))
- }}
- }
-}
diff --git a/src/main.rs b/src/main.rs
index b71b114..906a734 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,8 +1,14 @@
mod mods;
use mods::{clearcache::{clearcache}, clone::clone, help::help, inssort::inssort, install::install, purge::{purge}, search::{a_search, r_search}, strs::err_rec, strs::err_unrec, strs::inf, uninstall::{uninstall}, update::{update}, upgrade::{upgrade}, ver::ver, xargs::*};
use std::{env, process::exit, process::Command};
+use nix::unistd::Uid;
fn main() {
+
+ if Uid::effective().is_root() {
+ err_unrec(format!("Do not run ame as root! this can cause serious damage to your system!"));
+ }
+
let args: Vec = env::args().collect();
let mut pkgs: Vec = env::args().skip(2).collect();
diff --git a/src/mods/clone.rs:31:43 b/src/mods/clone.rs:31:43
deleted file mode 100644
index e69de29..0000000