detect shell and make it configurable

This commit is contained in:
chrys 2018-03-25 23:03:53 +02:00
parent 26ff69b25e
commit 714ad94308
8 changed files with 58 additions and 4 deletions

View File

@ -178,6 +178,8 @@ commandPath=
#fenrirFontSize = the fontsize #fenrirFontSize = the fontsize
attributeFormatString=Background fenrirBGColor,Foreground fenrirFGColor,fenrirUnderline,fenrirBold,fenrirBlink, Font fenrirFont,Fontsize fenrirFontSize attributeFormatString=Background fenrirBGColor,Foreground fenrirFGColor,fenrirUnderline,fenrirBold,fenrirBlink, Font fenrirFont,Fontsize fenrirFontSize
autoPresentIndent=False autoPresentIndent=False
# shell for PTY emulatiun (empty = default shell)
shell=
[focus] [focus]
cursor=True cursor=True

View File

@ -186,6 +186,8 @@ commandPath=
#fenrirFontSize = the fontsize #fenrirFontSize = the fontsize
attributeFormatString=Background fenrirBGColor,Foreground fenrirFGColor,fenrirUnderline,fenrirBold,fenrirBlink, Font fenrirFont,Fontsize fenrirFontSize attributeFormatString=Background fenrirBGColor,Foreground fenrirFGColor,fenrirUnderline,fenrirBold,fenrirBlink, Font fenrirFont,Fontsize fenrirFontSize
autoPresentIndent=False autoPresentIndent=False
# shell for PTY emulatiun (empty = default shell)
shell=
[focus] [focus]
#follow the text cursor #follow the text cursor

View File

@ -187,6 +187,8 @@ commandPath=
#fenrirFontSize = the fontsize #fenrirFontSize = the fontsize
attributeFormatString=Background fenrirBGColor,Foreground fenrirFGColor,fenrirUnderline,fenrirBold,fenrirBlink, Font fenrirFont,Fontsize fenrirFontSize attributeFormatString=Background fenrirBGColor,Foreground fenrirFGColor,fenrirUnderline,fenrirBold,fenrirBlink, Font fenrirFont,Fontsize fenrirFontSize
autoPresentIndent=False autoPresentIndent=False
# shell for PTY emulatiun (empty = default shell)
shell=
[focus] [focus]
#follow the text cursor #follow the text cursor

View File

@ -132,6 +132,8 @@ commandPath=
#fenrirFontSize = the fontsize #fenrirFontSize = the fontsize
attributeFormatString=Background fenrirBGColor,Foreground fenrirFGColor,fenrirUnderline,fenrirBold,fenrirBlink, Font fenrirFont,Fontsize fenrirFontSize attributeFormatString=Background fenrirBGColor,Foreground fenrirFGColor,fenrirUnderline,fenrirBold,fenrirBlink, Font fenrirFont,Fontsize fenrirFontSize
autoPresentIndent=False autoPresentIndent=False
# shell for PTY emulatiun (empty = default shell)
shell=
[focus] [focus]
#follow the text cursor #follow the text cursor

View File

@ -186,6 +186,8 @@ commandPath=
#fenrirFontSize = the fontsize #fenrirFontSize = the fontsize
attributeFormatString=Background fenrirBGColor,Foreground fenrirFGColor,fenrirUnderline,fenrirBold,fenrirBlink, Font fenrirFont,Fontsize fenrirFontSize attributeFormatString=Background fenrirBGColor,Foreground fenrirFGColor,fenrirUnderline,fenrirBold,fenrirBlink, Font fenrirFont,Fontsize fenrirFontSize
autoPresentIndent=False autoPresentIndent=False
# shell for PTY emulatiun (empty = default shell)
shell=
[focus] [focus]
#follow the text cursor #follow the text cursor

View File

@ -41,6 +41,7 @@ class fenrirManager():
parser.add_argument('-d', '--debug', action='store_true', help='Turns on Debugmode') parser.add_argument('-d', '--debug', action='store_true', help='Turns on Debugmode')
parser.add_argument('-p', '--print', action='store_true', help='Print debug messages on screen') parser.add_argument('-p', '--print', action='store_true', help='Print debug messages on screen')
parser.add_argument('-e', '--emulation', action='store_true', help='Use PTY emulation') parser.add_argument('-e', '--emulation', action='store_true', help='Use PTY emulation')
parser.add_argument('-f', '--femulation', metavar='SHELL', default='', help='Use PTY emulation')
try: try:
args = parser.parse_args() args = parser.parse_args()
except Exception as e: except Exception as e:

View File

@ -74,6 +74,7 @@ settingsData = {
'commandPath': '/usr/share/fenrir/commands', 'commandPath': '/usr/share/fenrir/commands',
'attributeFormatString': 'Background fenrirBGColor,Foreground fenrirFGColor,fenrirUnderline,fenrirBold,fenrirBlink, Font fenrirFont,Fontsize fenrirFontSize', 'attributeFormatString': 'Background fenrirBGColor,Foreground fenrirFGColor,fenrirUnderline,fenrirBold,fenrirBlink, Font fenrirFont,Fontsize fenrirFontSize',
'autoPresentIndent': False, 'autoPresentIndent': False,
'shell': '',
}, },
'focus':{ 'focus':{
'cursor': True, 'cursor': True,

View File

@ -57,6 +57,7 @@ class driver(screenDriver):
signal.signal(signal.SIGWINCH, self.handleSigwinch) signal.signal(signal.SIGWINCH, self.handleSigwinch)
def initialize(self, environment): def initialize(self, environment):
self.env = environment self.env = environment
self.command = self.env['runtime']['settingsManager'].getSetting('general','shell')
self.env['runtime']['processManager'].addCustomEventThread(self.terminalEmulation) self.env['runtime']['processManager'].addCustomEventThread(self.terminalEmulation)
def getCurrScreen(self): def getCurrScreen(self):
self.env['screen']['oldTTY'] = '1' self.env['screen']['oldTTY'] = '1'
@ -65,7 +66,47 @@ class driver(screenDriver):
def injectTextToScreen(self, msgBytes, screen = None): def injectTextToScreen(self, msgBytes, screen = None):
#os.write(p_out.fileno(), msgBytes) #os.write(p_out.fileno(), msgBytes)
pass pass
def getShell(self):
shell = ''
try:
if self.command != '':
shell = self.command
if os.path.isfile(shell):
return shell
except:
pass
try:
shell = os.environ["FENRIRSHELL"]
if os.path.isfile(shell):
return shell
except:
pass
try:
shell = os.environ["SHELL"]
if os.path.isfile(shell):
return shell
except:
pass
try:
if os.acess('/etc/passwd'):
with open('/etc/passwd') as f:
users = f.readlines()
for user in users:
(username, encrypwd, uid, gid, gecos, homedir, shell) = user.split(':')
shell = shell.replace('\n','')
if username == getpass.getuser():
if shell != '':
if os.path.isfile(shell):
return shell
except:
pass
try:
if os.path.isfile('/bin/bash'):
shell = '/bin/bash'
return shell
except:
pass
return '/bin/sh'
def getSessionInformation(self): def getSessionInformation(self):
self.env['screen']['autoIgnoreScreens'] = [] self.env['screen']['autoIgnoreScreens'] = []
self.env['general']['prevUser'] = getpass.getuser() self.env['general']['prevUser'] = getpass.getuser()
@ -83,7 +124,7 @@ class driver(screenDriver):
def hasMore(self,fd): def hasMore(self,fd):
r, w, e = select.select([fd], [], [], 0.02) r, w, e = select.select([fd], [], [], 0.02)
return (fd in r) return (fd in r)
def openTerminal(self, columns, lines, command="bash"): def openTerminal(self, columns, lines, command):
p_pid, master_fd = pty.fork() p_pid, master_fd = pty.fork()
if p_pid == 0: # Child. if p_pid == 0: # Child.
argv = shlex.split(command) argv = shlex.split(command)
@ -112,7 +153,8 @@ class driver(screenDriver):
old_attr = termios.tcgetattr(sys.stdin) old_attr = termios.tcgetattr(sys.stdin)
tty.setraw(0) tty.setraw(0)
lines, columns = self.getTerminalSize(0) lines, columns = self.getTerminalSize(0)
terminal, p_pid, p_out = self.openTerminal(columns, lines) shell = self.getShell()
terminal, p_pid, p_out = self.openTerminal(columns, lines, shell)
std_out = os.fdopen(sys.stdout.fileno(), "w+b", 0) std_out = os.fdopen(sys.stdout.fileno(), "w+b", 0)
while active.value: while active.value: