def build_exe(self): cc.i('build tp_assist...') sln_file = os.path.join(env.root_path, 'client', 'tp_assist_win', 'tp_assist.vs2017.sln') out_file = os.path.join(env.root_path, 'out', 'client', ctx.bits_path, ctx.target_path, 'tp_assist.exe') if os.path.exists(out_file): utils.remove(out_file) utils.msvc_build(sln_file, 'tp_assist', ctx.target_path, ctx.bits_path, False) utils.ensure_file_exists(out_file)
def build_installer(self): cc.i('make tp_assist dmg file...') json_file = os.path.join(env.root_path, 'dist', 'client', 'macos', 'dmg.json') dmg_file = os.path.join(env.root_path, 'out', 'client', 'macos', 'teleport-assist-macos-{}.dmg'.format(VER_TP_ASSIST)) if os.path.exists(dmg_file): utils.remove(dmg_file) utils.make_dmg(json_file, dmg_file) utils.ensure_file_exists(dmg_file)
def _stop_service(self): cc.o(' - stop teleport core service ... ', end='') # old version, the daemon named `eom_ts`. if os.path.exists('/etc/init.d/eom_ts'): utils.sys_exec('/etc/init.d/eom_ts stop') # from 2.0.0.1, the daemon rename to `teleport`. if os.path.exists('/etc/init.d/teleport'): utils.sys_exec('/etc/init.d/teleport stop') cc.i('[done]')
def build_exe(self): cc.i('build tp_assist...') configuration = ctx.target_path.capitalize() proj_file = os.path.join(env.root_path, 'client', 'tp_assist_macos', 'TP-Assist.xcodeproj') out_file = os.path.join(env.root_path, 'client', 'tp_assist_macos', 'build', configuration, 'TP-Assist.app') if os.path.exists(out_file): utils.remove(out_file) utils.xcode_build(proj_file, 'TP-Assist', configuration, False) utils.ensure_file_exists(os.path.join(out_file, 'Contents', 'Info.plist'))
def _check_service(self): cc.o(' - check teleport core service status ... ', end='') _err, _o = utils.sys_exec(r'sc query "{}"'.format(self._core_service_name)) if _err == 1060 or _err == 0: cc.i('[running]') else: cc.e('[not running]') cc.o(' - check teleport web service status ... ', end='') _err, _o = utils.sys_exec(r'sc query "{}"'.format(self._web_service_name)) if _err == 1060 or _err == 0: cc.i('[running]') else: cc.e('[not running]')
def build_installer(self): cc.i('build assist installer...') name = 'teleport-assist-{}-{}'.format(ctx.dist, VER_TP_ASSIST) out_path = os.path.join(env.root_path, 'out', 'installer') utils.makedirs(out_path) out_file = os.path.join(out_path, '{}.exe'.format(name)) utils.remove(out_file) self._build_installer() utils.ensure_file_exists(out_file)
def _uninstall_service(self): _check_service_name = [self._old_core_service_name, self._old_web_service_name, self._core_service_name, self._web_service_name] for _service_name in _check_service_name: cc.o(' - remove service [{}] ... '.format(_service_name), end='') _err, _ = utils.sys_exec(r'sc delete "{}"'.format(_service_name)) if _err == 1060 or _err == 0: cc.i('[done]') elif _err == 1072: cc.e('[failed]') raise RuntimeError('can not remove service [{}]. please close Service Manager and try again.'.format(_service_name)) else: cc.e('[failed]') raise RuntimeError('can not remove service [{}].'.format(_service_name))
def _build_libssh(self, file_name): cc.n('build libssh static library from source code... ', end='') if not os.path.exists(self.LIBSSH_PATH_SRC): cc.v('') utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL) os.rename(os.path.join(PATH_EXTERNAL, 'libssh-{}'.format(env.ver_libssh)), self.LIBSSH_PATH_SRC) # cc.n('fix libssh source code... ', end='') # utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', 'src', 'sftp.c')) # utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'sftp.c') cc.n('fix libssh source code... ', end='') s_name = 'libssh-{}'.format(env.ver_libssh) utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'session.c')) utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'libcrypto.c')) utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'libcrypto-compat.c')) utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'session.c') utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'libcrypto.c') utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'libcrypto-compat.c') out_file_lib = os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path, 'ssh.lib') out_file_dll = os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path, 'ssh.dll') if os.path.exists(out_file_lib) and os.path.exists(out_file_dll): cc.w('already exists, skip.') return cc.v('') cc.w('On Windows, when build libssh, need you use cmake-gui.exe to generate solution file') cc.w('for Visual Studio 2017. Visit https://docs.tp4a.com for more details.') cc.w('\nOnce the libssh.sln generated, press Enter to continue or Q to quit...', end='') try: x = env.input() except EOFError: x = 'q' if x == 'q': return cc.i('build libssh...') sln_file = os.path.join(self.LIBSSH_PATH_SRC, 'build', 'libssh.sln') utils.msvc_build(sln_file, 'ssh_shared', ctx.target_path, 'win32', False) utils.ensure_file_exists(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path, 'ssh.lib')) utils.ensure_file_exists(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path, 'ssh.dll')) utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path), os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path), 'ssh.lib') utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path), os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path), 'ssh.dll') utils.ensure_file_exists(out_file_lib) utils.ensure_file_exists(out_file_dll)
def _start_service(self): cc.o(' - start teleport core service ... ', end='') _err, _o = utils.sys_exec(r'sc start "{}"'.format(self._core_service_name)) # print('start core', _err, _o) if _err == 0: cc.i('[done]') else: cc.e('[failed]') raise RuntimeError('Can not start core service.') cc.o(' - start teleport web service ...', end='') _err, _ = utils.sys_exec(r'sc start "{}"'.format(self._web_service_name)) if _err == 0: cc.i('[done]') else: cc.e('[failed]') raise RuntimeError('Can not start web service.')
def _check_installation(self): cc.o(' - check local installation ... ', end='') _check_service_name = [self._old_core_service_name, self._old_web_service_name, self._core_service_name, self._web_service_name] for _service_name in _check_service_name: _exec_file = self._get_service_exec(_service_name) if _exec_file is not None: self._is_installed = True self._install_path = os.path.abspath(os.path.join(os.path.dirname(_exec_file), '..')) break if self._is_installed: cc.i('[{}]'.format(self._install_path)) self._fix_path() else: cc.i('[not exists]') return
def _install_service(self): cc.o(' - install teleport core service ... ', end='') _core = os.path.join(self._install_path, 'bin', 'tp_core.exe') _err, _ = utils.sys_exec(r'"{}" -i'.format(_core)) if _err == 0 or _err == 1: cc.i('[done]') else: cc.e('[failed]') raise RuntimeError('Install core service failed. error code: {}'.format(_err)) cc.o(' - install teleport web service ... ', end='') _core = os.path.join(self._install_path, 'bin', 'tp_web.exe') _err, _ = utils.sys_exec(r'"{}" -i'.format(_core)) if _err == 0 or _err == 1: cc.i('[done]') else: cc.e('[failed]') raise RuntimeError('Install web service failed. error code: {}'.format(_err)) return True
def _check_installation_ver(self): if not self._is_installed: return # try to get the installed version from www/teleport/app/eom_ver.py cc.o(' - check installed version ... ', end='') ver_file = os.path.join(self._install_path, 'www', 'teleport', 'webroot', 'app', 'app_ver.py') try: with open(ver_file) as f: x = f.readlines() for i in x: s = i.split('=', 1) if 'TP_SERVER_VER' == s[0].strip(): self._installed_ver_str = s[1].strip()[1:-1] cc.i('[{}]'.format(self._installed_ver_str)) # self._installed_ver = self._ver_str_to_ver(self._installed_ver_str) break except FileNotFoundError: cc.e('[failed]') cc.e(' the installation maybe broken')
def _check_installation(self): cc.o(' - check local installation ... ', end='') # old version, the daemon named `eom_ts`. # from 2.0.0.1, the daemon rename to `teleport`. # we must check both. if os.path.exists('/etc/init.d/eom_ts'): self._is_installed = True self._install_path = '/usr/local/eom/teleport' # self._fix_path() elif os.path.exists('/etc/init.d/teleport'): self._is_installed = True self._install_path = '/usr/local/teleport' # self._fix_path() if self._is_installed: cc.i('[{}]'.format(self._install_path)) self._fix_path() else: cc.i('[not exists]') return
def _check_installation(self): cc.o(' - check local installation ... ', end='') _check_service_name = [ self._old_core_service_name, self._old_web_service_name, self._core_service_name, self._web_service_name ] for _service_name in _check_service_name: _exec_file = self._get_service_exec(_service_name) if _exec_file is not None: self._is_installed = True self._install_path = os.path.abspath( os.path.join(os.path.dirname(_exec_file), '..')) break if self._is_installed: cc.i('[{}]'.format(self._install_path)) self._fix_path() else: cc.i('[not exists]') return
def _build_libssh(self, file_name): cc.n('build libssh static library from source code... ', end='') out_file = os.path.join(self.LIBSSH_PATH_SRC, 'lib', 'libsshMT.lib') need_build = False if not os.path.exists(out_file): need_build = True if not need_build: cc.w('already exists, skip.') return cc.v('') cc.n('prepare libssh source code... ', end='') _include = os.path.join(self.LIBSSH_PATH_SRC, 'include', 'libssh') _src = os.path.join(self.LIBSSH_PATH_SRC, 'src') if not os.path.exists(_include) or not os.path.exists(_src): utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL) # os.rename(os.path.join(PATH_EXTERNAL, 'openssl-OpenSSL_{}'.format(_alt_ver)), self.OPENSSL_PATH_SRC) _unzipped_path = os.path.join(PATH_EXTERNAL, 'libssh-{}'.format(env.ver_libssh)) utils.copy_ex(os.path.join(_unzipped_path, 'include', 'libssh'), _include) utils.copy_ex(os.path.join(_unzipped_path, 'src'), _src) utils.remove(_unzipped_path) if not os.path.exists(_include) or not os.path.exists(_src): raise RuntimeError('\ncan not prepare libssh source code.') else: cc.w('already exists, skip.') cc.i('build libssh...') sln_file = os.path.join(self.LIBSSH_PATH_SRC, 'libssh.vs2015.sln') utils.msvc_build(sln_file, 'libssh', ctx.target_path, ctx.bits_path, False) utils.ensure_file_exists(out_file)
def _install_service(self): cc.o(' - install teleport core service ... ', end='') _core = os.path.join(self._install_path, 'bin', 'tp_core.exe') _err, _ = utils.sys_exec(r'"{}" -i'.format(_core)) if _err == 0 or _err == 1: cc.i('[done]') else: cc.e('[failed]') raise RuntimeError( 'Install core service failed. error code: {}'.format(_err)) cc.o(' - install teleport web service ... ', end='') _core = os.path.join(self._install_path, 'bin', 'tp_web.exe') _err, _ = utils.sys_exec(r'"{}" -i'.format(_core)) if _err == 0 or _err == 1: cc.i('[done]') else: cc.e('[failed]') raise RuntimeError( 'Install web service failed. error code: {}'.format(_err)) return True
def _build_libssh(self, file_name): if not self._download_libssh(file_name): return cc.n('build libssh library from source code... ', end='') if not os.path.exists(self.LIBSSH_PATH_SRC): cc.v('') utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL) os.rename( os.path.join(PATH_EXTERNAL, 'libssh-{}'.format(env.ver_libssh)), self.LIBSSH_PATH_SRC) cc.n('fix libssh source code... ', end='') s_name = 'libssh-{}'.format(env.ver_libssh) utils.ensure_file_exists( os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'session.c')) # # utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'libcrypto.c')) # utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'libcrypto-compat.c')) utils.copy_file( os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'session.c') # ## utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'libcrypto.c') # # utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'libcrypto-compat.c') out_file_lib = os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path, 'ssh.lib') out_file_dll = os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path, 'ssh.dll') if os.path.exists(out_file_lib) and os.path.exists(out_file_dll): cc.w('already exists, skip.') return cc.v('') build_path = os.path.join(self.LIBSSH_PATH_SRC, 'build') if not os.path.exists(build_path): utils.makedirs(build_path) openssl_path = os.path.join(PATH_EXTERNAL, 'OpenSSL') cmake_define = ' -DOPENSSL_INCLUDE_DIR={path_release}\include' \ ' -DOPENSSL_LIBRARIES={path_release}\lib\VC\static' \ ' -DWITH_SFTP=ON' \ ' -DWITH_SERVER=ON' \ ' -DWITH_GSSAPI=OFF' \ ' -DWITH_ZLIB=OFF' \ ' -DWITH_PCAP=OFF' \ ' -DWITH_STATIC_LIB=ON' \ ' -DUNIT_TESTING=OFF' \ ' -DWITH_EXAMPLES=OFF' \ ' -DWITH_BENCHMARKS=OFF' \ ' -DWITH_NACL=OFF' \ ''.format(path_release=openssl_path) # ' -DCMAKE_INSTALL_PREFIX={path_release}' # ' -DWITH_STATIC_LIB=ON' # ' -DBUILD_SHARED_LIBS=OFF' old_p = os.getcwd() try: os.chdir(build_path) utils.cmake(build_path, 'Release', False, cmake_define=cmake_define) os.chdir(build_path) # utils.sys_exec('make install') except: cc.e('can not make') raise os.chdir(old_p) # cc.w('On Windows, when build libssh, need you use cmake-gui.exe to generate solution file') # cc.w('for Visual Studio 2017. Visit https://docs.tp4a.com for more details.') # cc.w('\nOnce the libssh.sln generated, press Enter to continue or Q to quit...', end='') # try: # x = env.input() # except EOFError: # x = 'q' # if x == 'q': # return cc.i('build libssh...') sln_file = os.path.join(self.LIBSSH_PATH_SRC, 'build', 'libssh.sln') utils.msvc_build(sln_file, 'ssh_shared', ctx.target_path, 'win32', False) utils.ensure_file_exists( os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path, 'ssh.lib')) utils.ensure_file_exists( os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path, 'ssh.dll')) utils.copy_file( os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path), os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path), 'ssh.lib') utils.copy_file( os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path), os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path), 'ssh.dll') utils.ensure_file_exists(out_file_lib) utils.ensure_file_exists(out_file_dll)
def _build_libssh(self, file_name): cc.n('build libssh static library from source code... ', end='') if not os.path.exists(self.LIBSSH_PATH_SRC): cc.v('') utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL) os.rename( os.path.join(PATH_EXTERNAL, 'libssh-{}'.format(env.ver_libssh)), self.LIBSSH_PATH_SRC) # cc.n('fix libssh source code... ', end='') # utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', 'src', 'sftp.c')) # utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'sftp.c') cc.n('fix libssh source code... ', end='') s_name = 'libssh-{}'.format(env.ver_libssh) utils.ensure_file_exists( os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'session.c')) utils.ensure_file_exists( os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'libcrypto.c')) utils.ensure_file_exists( os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'libcrypto-compat.c')) utils.copy_file( os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'session.c') utils.copy_file( os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'libcrypto.c') utils.copy_file( os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'libcrypto-compat.c') out_file_lib = os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path, 'ssh.lib') out_file_dll = os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path, 'ssh.dll') if os.path.exists(out_file_lib) and os.path.exists(out_file_dll): cc.w('already exists, skip.') return cc.v('') cc.w( 'On Windows, when build libssh, need you use cmake-gui.exe to generate solution file' ) cc.w( 'for Visual Studio 2017. Visit https://docs.tp4a.com for more details.' ) cc.w( '\nOnce the libssh.sln generated, press Enter to continue or Q to quit...', end='') try: x = env.input() except EOFError: x = 'q' if x == 'q': return cc.i('build libssh...') sln_file = os.path.join(self.LIBSSH_PATH_SRC, 'build', 'libssh.sln') utils.msvc_build(sln_file, 'ssh_shared', ctx.target_path, 'win32', False) utils.ensure_file_exists( os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path, 'ssh.lib')) utils.ensure_file_exists( os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path, 'ssh.dll')) utils.copy_file( os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path), os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path), 'ssh.lib') utils.copy_file( os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path), os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path), 'ssh.dll') utils.ensure_file_exists(out_file_lib) utils.ensure_file_exists(out_file_dll)