immediatly terminate when running as root

i18n
axtlos 3 years ago
parent bcf1806915
commit e2fa9dbf89

@ -18,3 +18,4 @@ regex = "*"
toml_edit = "0.5.0"
toml = "*"
bytes = "*"
nix = "*"

@ -22,7 +22,8 @@ Made for Crystal, compatible with any Arch-based Linux distribution.</p>
| 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`
<br>
<br>
`echo "AME_UWU=YES" >> ~/.zshrc`, self explanatory
```sh
echo "AME_UWU=YES" >> ~/.zshrc # for zsh
echo "AME_UWU=YES" >> ~/.bashrc # for bash
set -Ux AME_UWU YES # for fish
```
self explanatory

@ -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<String> = env::args().collect();
let mut pkgs: Vec<String> = 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."))
}}
}
}

@ -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<String> = env::args().collect();
let mut pkgs: Vec<String> = env::args().skip(2).collect();

Loading…
Cancel
Save