(self, exec_path)
Add an interpreter for non binary executables (scripts)
Add an interpreter for non binary executables (scripts)
Add an interpreter for non binary executables ( scripts )
def _run_add_script_support(self, exec_path):
        """Add an interpreter for non binary executables (scripts)"""
        filetype = OSInfo(self.container_root).get_filetype(exec_path)
        if "ELF" in filetype and ("static" in filetype or
                                  "dynamic" in filetype):
            self.opt["cmd"][0] = exec_path
            return []
        env_exec = FileUtil("env").find_exec("/bin:/usr/bin",
                                             self.container_root)
        if  env_exec:
            return [self.container_root + '/' + env_exec, ]
        relc_path = exec_path.split(self.container_root, 1)[-1]
        real_path = FileUtil(self.container_root).cont2host(relc_path,
                                                            self.opt["vol"])
        hashbang = FileUtil(real_path).get1stline()
        match = re.match("#! *([^ ]+)(.*)", hashbang)
        if match and not match.group(1).startswith('/'):
            Msg().err("Error: no such file", match.group(1), "in", exec_path)
            sys.exit(1)
        elif match:
            interpreter = [self.container_root + '/' + match.group(1), ]
            if match.group(2):
                interpreter.extend(match.group(2).strip().split(' '))
            self.opt["cmd"][0] = exec_path.split(self.container_root, 1)[-1]
            return interpreter
        sh_exec = FileUtil("sh").find_exec(self.opt["env"].getenv("PATH"),
                                           self.container_root)
        if sh_exec:
            return [self.container_root + '/' + sh_exec, ]
        Msg().err("Error: sh not found")
        sys.exit(1)
def _run_add_script_support ( self , exec_path ) : filetype = OSInfo ( self . container_root ) . get_filetype ( exec_path ) if "ELF" in filetype and ( "static" in filetype or "dynamic" in filetype ) : self . opt [ "cmd" ] [ 0 ] = exec_path return [ ] env_exec = FileUtil ( "env" ) . find_exec ( "/bin:/usr/bin" , self . container_root ) if env_exec : return [ self . container_root + '/' + env_exec , ] relc_path = exec_path . split ( self . container_root , 1 ) [ - 1 ] real_path = FileUtil ( self . container_root ) . cont2host ( relc_path , self . opt [ "vol" ] ) hashbang = FileUtil ( real_path ) . get1stline ( ) match = re . match ( "#! *([^ ]+)(.*)" , hashbang ) if match and not match . group ( 1 ) . startswith ( '/' ) : Msg ( ) . err ( "Error: no such file" , match . group ( 1 ) , "in" , exec_path ) sys . exit ( 1 ) elif match : interpreter = [ self . container_root + '/' + match . group ( 1 ) , ] if match . group ( 2 ) : interpreter . extend ( match . group ( 2 ) . strip ( ) . split ( ' ' ) ) self . opt [ "cmd" ] [ 0 ] = exec_path . split ( self . container_root , 1 ) [ - 1 ] return interpreter sh_exec = FileUtil ( "sh" ) . find_exec ( self . opt [ "env" ] . getenv ( "PATH" ) , self . container_root ) if sh_exec : return [ self . container_root + '/' + sh_exec , ] Msg ( ) . err ( "Error: sh not found" ) sys . exit ( 1 )