Implement bashrc module code

This commit is contained in:
Lucas Noki 2020-07-25 04:50:30 +02:00
parent b1a34aabd4
commit 1d4e6a3f8d
2 changed files with 29 additions and 1 deletions

View File

@ -8,6 +8,7 @@ from modules.vim.VimModule import VimModule
from modules.teamspeak.Teamspeak import Teamspeak from modules.teamspeak.Teamspeak import Teamspeak
from modules.hacker.Hacker import Hacker from modules.hacker.Hacker import Hacker
import modules.fail2ban.Fail2BanModule as fail2ban import modules.fail2ban.Fail2BanModule as fail2ban
from modules.bashrc.BashrcModule import BashrcModule
modules = { modules = {
"helloworld": HelloWorld().run, "helloworld": HelloWorld().run,
@ -17,7 +18,8 @@ modules = {
"vim": VimModule().run, "vim": VimModule().run,
"teamspeak": Teamspeak, "teamspeak": Teamspeak,
"hacker": Hacker, "hacker": Hacker,
"fail2ban": fail2ban.run() "fail2ban": fail2ban.run(),
"bashrc": BashrcModule().run
} }
fire.Fire(modules) fire.Fire(modules)

View File

@ -0,0 +1,26 @@
from PyInquirer import prompt
import os
from shutil import copyfile
from print_helpers import print_gr, print_warn, print_fail
class BashrcModule:
def run(self):
bashrc_path = os.path.join(os.path.expanduser('~'), ".bashrc")
bashrc_exists = os.path.exists(bashrc_path)
if bashrc_exists:
print_gr(f"Found .bashrc in {bashrc_path}")
ask_to_keep = {
'type': 'confirm',
'message': 'Do you want to overwrite the existing .bashrc?',
'name': 'overwrite',
'default': False,
}
if not prompt(ask_to_keep)['overwrite']:
print_fail("Stopping")
return
copyfile("./modules/bashrc/bashrc_default", bashrc_path)
print_gr("Overwritten") if bashrc_exists else print_gr("Created")