Last active
August 12, 2021 16:26
-
-
Save av1d/ea8f9b1ddd6bb35e742ddea7af16c041 to your computer and use it in GitHub Desktop.
Warn user when they issue sudo rm -rf, passes all other sudo commands otherwise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import sys | |
# Warns user before issuing deadly commands with sudo. | |
# | |
# add alias to ~/.bashrc like so: | |
# alias sudo="/home/users/sudo_rm.py" | |
# then reload bashrc: | |
# source ~/.bashrc | |
class alertColor: | |
OKGREEN = '\033[92m' | |
WARNYEL = '\033[93m' | |
WARNRED = '\033[91m' | |
ENDCOLOR = '\033[0m' | |
if sys.argv[1] == "rm": | |
if sys.argv[2] == "-rf": | |
print(alertColor.WARNYEL + "WARNING: you are about to execute " + alertColor.OKGREEN + "rm -rf" + alertColor.WARNYEL + " as sudo!" + alertColor.ENDCOLOR) | |
warnprompt = raw_input(alertColor.WARNYEL + "ARE YOU SURE you want to " + str(" ".join(sys.argv[1:])) + "(y/n) ??? " + alertColor.ENDCOLOR) | |
if warnprompt == "y": | |
cmd = "sudo " + (" ".join(sys.argv[1:])) | |
os.system(cmd) | |
sys.exit(1) | |
else: | |
print("Not executing command...") | |
sys.exit(1) | |
cmd = "sudo " + (" ".join(sys.argv[1:])) | |
os.system(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment