Modify linux PBA so it doesn't give errors when running on windows

This commit is contained in:
Shreya 2020-06-22 18:30:06 +05:30
parent 6f6bfca9f9
commit 7efeff3ff0
1 changed files with 30 additions and 28 deletions

View File

@ -1,16 +1,21 @@
import subprocess
from infection_monkey.utils.environment import is_windows_os
HOME_DIR = "/home/"
def get_linux_commands_to_modify_shell_startup_files():
if is_windows_os():
return '', [], []
# get list of usernames
USERS = subprocess.check_output(
HOME_DIR = "/home/"
# get list of usernames
USERS = subprocess.check_output(
"cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1",
shell=True
).decode().split('\n')[:-1]
# get list of paths of different shell startup files with place for username
STARTUP_FILES = [
# get list of paths of different shell startup files with place for username
STARTUP_FILES = [
file_path.format(HOME_DIR) for file_path in
[
"{0}{{0}}/.profile", # bash, dash, ksh, sh
@ -24,14 +29,11 @@ STARTUP_FILES = [
"{0}{{0}}/.tcshrc", # tcsh
"{0}{{0}}/.cshrc", # csh
]
]
]
def get_linux_commands_to_modify_shell_startup_files():
return [
'3<{0} 3<&- &&', # check for existence of file
'echo \"# Succesfully modified {0}\" |',
'tee -a {0} &&', # append to file
'sed -i \'$d\' {0}', # remove last line of file (undo changes)
],\
STARTUP_FILES, USERS
], STARTUP_FILES, USERS