def _build_libuv(self, file_name): cc.w('build libuv...skip') return if not os.path.exists(self.LIBUV_PATH_SRC): # os.system('tar -zxvf "{}/{}" -C "{}"'.format(PATH_DOWNLOAD, file_name, PATH_TMP)) os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP)) cc.n('build libuv...', end='') if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libuv.a')): cc.w('already exists, skip.') return cc.v('') # we need following... # apt-get install autoconf aptitude libtool gcc-c++ old_p = os.getcwd() os.chdir(self.LIBUV_PATH_SRC) os.system('sh autogen.sh') os.system('./configure --prefix={} --with-pic'.format( self.PATH_RELEASE)) os.system('make') os.system('make install') os.chdir(old_p)
def make_assist_win_ver(self): ver_file = os.path.join(env.root_path, 'client', 'tp_assist_win', 'ts_ver.h') ver_content = '#ifndef __TS_ASSIST_VER_H__\n#define __TS_ASSIST_VER_H__\n\n#define TP_ASSIST_VER\tL"{}"\n\n#endif // __TS_ASSIST_VER_H__\n'.format( self.VER_TP_ASSIST) rewrite = False if not os.path.exists(ver_file): rewrite = True else: with open(ver_file, 'r') as f: old_content = f.read() if old_content != ver_content: rewrite = True if rewrite: cc.v(' update {}...'.format(ver_file)) with open(ver_file, 'w') as f: f.write(ver_content) rc_file = os.path.join(env.root_path, 'client', 'tp_assist_win', 'tp_assist.rc') self._update_ver_rc(rc_file, self.VER_TP_ASSIST) nsi_file = os.path.join(env.root_path, 'dist', 'client', 'windows', 'assist', 'installer.nsi') self._update_ver_nsi(nsi_file, self.VER_TP_ASSIST)
def _start_service(self): cc.v('') cc.o('start services...') _ret, _ = utils.sys_exec('/etc/init.d/teleport start', direct_output=True) if _ret != 0: raise RuntimeError('not all services started.')
def _prepare_python(self): cc.n('prepare python header files ...', end='') if os.path.exists( os.path.join(PATH_EXTERNAL, 'python', 'include', 'Python.h')): cc.w('already exists, skip.') return cc.v('') # if os.path.exists(os.path.join(env.path_py_inc, 'Python.h')): # cc.e('can not locate python development include path, make sure miniconda installed.') # return # cc.v('') # utils.copy_ex(env.path_py_inc, os.path.join(PATH_EXTERNAL, 'python', 'include')) _header_path = None for p in sys.path: if os.path.exists(os.path.join(p, 'include', 'Python.h')): _header_path = os.path.join(p, 'include') if _header_path is None: cc.e('\ncan not locate python development include path in:') for p in sys.path: cc.e(' ', p) raise RuntimeError() utils.copy_ex(_header_path, os.path.join(PATH_EXTERNAL, 'python', 'include'))
def _build_mbedtls(self, file_name): cc.n('prepare mbedtls source code... ', end='') if not os.path.exists(self.MBEDTLS_PATH_SRC): cc.v('') utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL) os.rename( os.path.join(PATH_EXTERNAL, 'mbedtls-mbedtls-{}'.format(env.ver_mbedtls)), self.MBEDTLS_PATH_SRC) else: cc.w('already exists, skip.') return cc.v('') # fix source file utils.ensure_file_exists( os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'include', 'mbedtls', 'config.h')) utils.copy_file( os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'include', 'mbedtls'), os.path.join(self.MBEDTLS_PATH_SRC, 'include', 'mbedtls'), 'config.h') utils.ensure_file_exists( os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'library', 'rsa.c')) utils.copy_file( os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'library'), os.path.join(self.MBEDTLS_PATH_SRC, 'library'), 'rsa.c')
def _do_install(self): while True: cc.v('') self._install_path = self._prompt_input('Set installation path', self._def_install_path) _use_anyway = False if os.path.exists(self._install_path): while True: cc.v('') x = self._prompt_choice( 'The target path `{}` has already exists,\ndo you want to use it anyway?' .format(self._install_path), [('Yes', 0, True), ('No', 0, False)]) if x in ['y', 'yes']: _use_anyway = True break elif x in ['n', 'no']: break if _use_anyway: break else: break self._fix_path() utils.make_dirs(self._install_path) self._copy_files() self._install_service() self._start_service() time.sleep(2) self._check_service()
def _build_libuv(self, file_name): if not self._download_libuv(file_name): return if not os.path.exists(self.LIBUV_PATH_SRC): os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP)) cc.n('build libuv...', end='') if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libuv.a')): cc.w('already exists, skip.') return cc.v('') # we need following... # apt-get install autoconf aptitude libtool gcc-c++ old_p = os.getcwd() os.chdir(self.LIBUV_PATH_SRC) os.system('sh autogen.sh') os.system('./configure --prefix={} --with-pic'.format( self.PATH_RELEASE)) os.system('make') os.system('make install') os.chdir(old_p) files = os.listdir(os.path.join(self.PATH_RELEASE, 'lib')) for i in files: if i.startswith('libuv.so') or i.startswith('libuv.la'): # use os.unlink() because some file should be a link. os.unlink(os.path.join(self.PATH_RELEASE, 'lib', i)) utils.ensure_file_exists( os.path.join(self.PATH_RELEASE, 'lib', 'libuv.a'))
def _build_openssl(self, file_name): cc.w('skip build openssl again.') return if not self._download_openssl(file_name): return cc.n('prepare openssl source code...', end='') if not os.path.exists(self.OPENSSL_PATH_SRC): os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP)) if not os.path.exists(self.OPENSSL_PATH_SRC): raise RuntimeError('can not prepare openssl source code.') else: cc.w('already exists, skip.') cc.n('build openssl static...', end='') out_file_lib = os.path.join(self.PATH_RELEASE, 'lib', 'libssl.a') if os.path.exists(out_file_lib): cc.w('already exists, skip.') return cc.v('') old_p = os.getcwd() os.chdir(self.OPENSSL_PATH_SRC) # os.system('./config --prefix={} --openssldir={}/openssl no-zlib no-shared'.format(self.PATH_RELEASE, self.PATH_RELEASE)) # os.system('./Configure darwin64-x86_64-cc') os.system( './Configure darwin64-x86_64-cc --prefix={} --openssldir={}/openssl -fPIC no-zlib no-shared' .format(self.PATH_RELEASE, self.PATH_RELEASE)) os.system('make') os.system('make install') os.chdir(old_p)
def _build_libuv(self, file_name): if not self._download_libuv(file_name): return cc.n('prepare libuv source code...', end='') if not os.path.exists(self.LIBUV_PATH_SRC): os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP)) cc.n('build libuv...', end='') if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libuv.a')): cc.w('already exists, skip.') return cc.v('') # we need following... # brew install automake libtool old_p = os.getcwd() os.chdir(self.LIBUV_PATH_SRC) os.system('sh autogen.sh') os.system('./configure --prefix={} --with-pic'.format( self.PATH_RELEASE)) os.system('make') os.system('make install') os.chdir(old_p) rm = [ 'libuv.la', 'libuv.dylib', 'libuv.so.1', 'libuv.so', 'libuv.so.1.0.0' ] for i in rm: _path = os.path.join(self.PATH_RELEASE, 'lib', i) if os.path.exists(_path): utils.remove(_path)
def _install_service(self): daemon_files = [ ['daemon.in', '/etc/init.d/teleport'], ['start.sh.in', os.path.join(self._install_path, 'start.sh')], ['stop.sh.in', os.path.join(self._install_path, 'stop.sh')], ['status.sh.in', os.path.join(self._install_path, 'status.sh')], ] for _d in daemon_files: cc.v('process [{}] to [{}]'.format(_d[0], _d[1])) _orig_file = os.path.join(env.root_path, 'daemon', _d[0]) with open(_orig_file, 'r') as f: _text = f.read() _text = _text.format(daemon_path=self._install_path) with open(_d[1], 'w') as f: f.write(_text) if not os.path.exists(_d[1]): raise RuntimeError('can not generate daemon file [{}].'.format( _d[1])) # owner: RWX, group: RX, others: RX os.chmod( _d[1], stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) # create symbolic link os.symlink('/etc/init.d/teleport', '/etc/rc2.d/S95teleport') os.symlink('/etc/init.d/teleport', '/etc/rc3.d/S95teleport') os.symlink('/etc/init.d/teleport', '/etc/rc4.d/S95teleport') os.symlink('/etc/init.d/teleport', '/etc/rc5.d/S95teleport')
def _do_uninstall(self): if not self._is_installed: return _del_settings = False while True: cc.v('') x = self._prompt_choice('Do you want to keep your database and settings?', [('Yes', 0, True), ('No', 0, False)]) if x in ['y', 'yes']: break elif x in ['n', 'no']: _del_settings = True break if _del_settings: while True: cc.v('') x = self._prompt_choice('Seriously!! Are you sure to remove all data and settings?', [('Yes', 0, False), ('No', 0, True)]) if x in ['y', 'yes']: break elif x in ['n', 'no']: _del_settings = False break self._stop_service() time.sleep(2) self._uninstall_service() self._delete_files(_del_settings)
def _install_service(self): daemon_files = [ ['daemon.in', '/etc/init.d/teleport'], ['start.sh.in', os.path.join(self._install_path, 'start.sh')], ['stop.sh.in', os.path.join(self._install_path, 'stop.sh')], ['status.sh.in', os.path.join(self._install_path, 'status.sh')], ] for _d in daemon_files: cc.v('process [{}] to [{}]'.format(_d[0], _d[1])) _orig_file = os.path.join(env.root_path, 'daemon', _d[0]) with open(_orig_file, 'r') as f: _text = f.read() _text = _text.format(daemon_path=self._install_path) with open(_d[1], 'w') as f: f.write(_text) if not os.path.exists(_d[1]): raise RuntimeError('can not generate daemon file [{}].'.format(_d[1])) # owner: RWX, group: RX, others: RX os.chmod(_d[1], stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) # create symbolic link os.symlink('/etc/init.d/teleport', '/etc/rc2.d/S95teleport') os.symlink('/etc/init.d/teleport', '/etc/rc3.d/S95teleport') os.symlink('/etc/init.d/teleport', '/etc/rc4.d/S95teleport') os.symlink('/etc/init.d/teleport', '/etc/rc5.d/S95teleport')
def _prompt_choice(message, choices): cc.v('{} ['.format(message), end='') def_choice = '' for i in range(len(choices)): if i > 0: cc.v('/', end='') msg = choices[i][0] idx = choices[i][1] if choices[i][2]: msg = msg.upper() def_choice = msg[idx].lower() cc.w(msg[:idx], end='') cc.n(msg[idx], end='') cc.w(msg[idx + 1:], end='') else: msg = msg.lower() cc.v(msg[:idx], end='') cc.n(msg[idx], end='') cc.v(msg[idx + 1:], end='') cc.v(']: ', end='') try: x = input().strip() if len(x) == 0: x = def_choice except EOFError: x = def_choice return x
def _build_openssl(self, file_name): cc.n('prepare OpenSSL pre-built package ... ', end='') if os.path.exists(self.OPENSSL_PATH_SRC): cc.w('already exists, skip.') return cc.v('') _alt_ver = '_'.join(env.ver_ossl.split('.')) file_name = 'Win32OpenSSL-{}.msi'.format(_alt_ver) installer = os.path.join(PATH_DOWNLOAD, file_name) if not os.path.exists(installer): if not utils.download_file( 'openssl installer', 'http://slproweb.com/download/{}'.format(filename), PATH_DOWNLOAD, file_name): cc.e('can not download pre-built installer of OpenSSL.') return utils.ensure_file_exists(installer) cc.w('On Windows, we use pre-built package of OpenSSL.') cc.w('The installer have been downloaded at "{}".'.format(installer)) cc.w('please install OpenSSL into "{}".'.format(self.OPENSSL_PATH_SRC)) cc.w( '\nOnce the OpenSSL installed, press Enter to continue or Q to quit...', end='') try: x = env.input() except EOFError: x = 'q' if x == 'q': return
def _do_install(self): while True: cc.v('') self._install_path = self._prompt_input('Set installation path', self._def_install_path) _use_anyway = False if os.path.exists(self._install_path): while True: cc.v('') x = self._prompt_choice( 'The target path `{}` has already exists,\ndo you want to use it anyway?'.format( self._install_path), [('Yes', 0, True), ('No', 0, False)]) if x in ['y', 'yes']: _use_anyway = True break elif x in ['n', 'no']: break if _use_anyway: break else: break self._fix_path() utils.make_dirs(self._install_path) self._copy_files() self._install_service() self._start_service() time.sleep(2) self._check_service()
def build(self): cc.n('update version...') if not os.path.exists(self.ver_in): raise RuntimeError('file `version.in` not exists.') with codecs.open(self.ver_in, 'r', 'utf-8') as f: lines = f.readlines() for l in lines: if l.startswith('TELEPORT_SERVER '): x = l.split(' ') self.VER_TELEPORT_SERVER = x[1].strip() elif l.startswith('TELEPORT_ASSIST '): x = l.split(' ') self.VER_TELEPORT_ASSIST = x[1].strip() elif l.startswith('TELEPORT_ASSIST_REQUIRE '): x = l.split(' ') self.VER_TELEPORT_ASSIST_REQUIRE = x[1].strip() # elif l.startswith('TELEPORT_MAKECERT '): # x = l.split(' ') # self.VER_TELEPORT_MAKECERT = x[1].strip() # cc.v('new version:') cc.v(' TELEPORT-Server : ', self.VER_TELEPORT_SERVER) cc.v(' TELEPORT-Assist : ', self.VER_TELEPORT_ASSIST) cc.v(' TELEPORT-Assist-require : ', self.VER_TELEPORT_ASSIST_REQUIRE) # cc.v(' TELEPORT-MakeCert : ', self.VER_TELEPORT_MAKECERT) cc.v('') self.make_build_ver() self.make_assist_ver() self.make_tp_core_ver() self.make_tp_web_ver() self.make_web_ver()
def make_server_ver(self): ver_file = os.path.join(env.root_path, 'server', 'www', 'teleport', 'webroot', 'app', 'app_ver.py') # ver_content = '# -*- coding: utf8 -*-\n\nTS_VER = "{}"\n'.format(self.VER_TELEPORT_SERVER) # ver_content = '# -*- coding: utf8 -*-\nTP_SERVER_VER = "{}"\n'.format(self.VER_TP_SERVER) ver_content = '' \ '# -*- coding: utf8 -*-\n' \ 'TP_SERVER_VER = "{}"\n' \ 'TP_ASSIST_REQUIRE_VER = "{}"\n' \ 'TP_STATE_VER = "{}"\n' \ ''.format(self.VER_TP_SERVER, self.VER_TP_ASSIST_REQUIRE, self.VER_TP_STATE) rewrite = False if not os.path.exists(ver_file): rewrite = True else: with open(ver_file, 'r') as f: old_content = f.read() if old_content != ver_content: rewrite = True if rewrite: cc.v(' update {}...'.format(ver_file)) with open(ver_file, 'w') as f: f.write(ver_content)
def _build_libuv(self, file_name): if not os.path.exists(self.LIBUV_PATH_SRC): os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP)) cc.n('build libuv...', end='') if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libuv.a')): cc.w('already exists, skip.') return cc.v('') # we need following... # apt-get install autoconf aptitude libtool gcc-c++ old_p = os.getcwd() os.chdir(self.LIBUV_PATH_SRC) os.system('sh autogen.sh') os.system('./configure --prefix={} --with-pic'.format(self.PATH_RELEASE)) os.system('make') os.system('make install') os.chdir(old_p) files = os.listdir(os.path.join(self.PATH_RELEASE, 'lib')) for i in files: if i.startswith('libuv.so') or i.startswith('libuv.la'): # use os.unlink() because some file should be a link. os.unlink(os.path.join(self.PATH_RELEASE, 'lib', i))
def _build_openssl(self, file_name): if not super()._build_openssl(file_name): return cc.n('prepare openssl source code...', end='') if not os.path.exists(self.OPENSSL_PATH_SRC): os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP)) if not os.path.exists(self.OPENSSL_PATH_SRC): raise RuntimeError('can not prepare openssl source code.') else: cc.w('already exists, skip.') cc.n('build openssl static...', end='') out_file_lib = os.path.join(self.PATH_RELEASE, 'lib', 'libssl.a') if os.path.exists(out_file_lib): cc.w('already exists, skip.') return cc.v('') old_p = os.getcwd() os.chdir(self.OPENSSL_PATH_SRC) # os.system('./config --prefix={} --openssldir={}/openssl no-zlib no-shared'.format(self.PATH_RELEASE, self.PATH_RELEASE)) # os.system('./Configure darwin64-x86_64-cc') os.system('./Configure darwin64-x86_64-cc --prefix={} --openssldir={}/openssl -fPIC no-zlib no-shared'.format(self.PATH_RELEASE, self.PATH_RELEASE)) os.system('make') os.system('make install') os.chdir(old_p)
def build(self): self.py_dll_path = self._locate_dll_path() self.py_lib_path = self._locate_lib_path() cc.v('python dll path :', self.py_dll_path) cc.v('python lib path :', self.py_lib_path) cc.n('upgrade pip ...') utils.sys_exec( '{} -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip --upgrade' .format(env.py_exec)) pip = self._get_pip() pypi_modules = [ 'ldap3', 'mako', 'Pillow', 'psutil', 'pymysql', 'qrcode', 'tornado', 'wheezy.captcha' ] for p in pypi_modules: cc.n('install {} ...'.format(p)) utils.sys_exec( '{} install -i https://pypi.tuna.tsinghua.edu.cn/simple {}'. format(pip, p), direct_output=True) self._make_base() self._make_python_zip() self._make_py_ver_file()
def _do_uninstall(self): if not self._is_installed: return _del_settings = False while True: cc.v('') x = self._prompt_choice( 'Do you want to keep your database and settings?', [('Yes', 0, True), ('No', 0, False)]) if x in ['y', 'yes']: break elif x in ['n', 'no']: _del_settings = True break if _del_settings: while True: cc.v('') x = self._prompt_choice( 'Seriously!! Are you sure to remove all data and settings?', [('Yes', 0, False), ('No', 0, True)]) if x in ['y', 'yes']: break elif x in ['n', 'no']: _del_settings = False break self._stop_service() time.sleep(2) self._uninstall_service() self._delete_files(_del_settings)
def _build_jsoncpp(self, file_name): cc.n('prepare jsoncpp source code...', end='') if not os.path.exists(self.JSONCPP_PATH_SRC): cc.v('') os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name, PATH_EXTERNAL)) os.rename(os.path.join(PATH_EXTERNAL, 'jsoncpp-{}'.format(env.ver_jsoncpp)), self.JSONCPP_PATH_SRC) else: cc.w('already exists, skip.')
def _build_mongoose(self, file_name): cc.n('prepare mongoose source code...', end='') if not os.path.exists(self.MONGOOSE_PATH_SRC): cc.v('') os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name, PATH_EXTERNAL)) os.rename(os.path.join(PATH_EXTERNAL, 'mongoose-{}'.format(env.ver_mongoose)), self.MONGOOSE_PATH_SRC) else: cc.w('already exists, skip.')
def _update_ver_nsi(self, nsiFilePath, ver): """ update nsis file version info """ t_ver = ver.split('.') while len(t_ver) < 3: t_ver.append('0') if len(t_ver) > 3: raise RuntimeError('Invalid version for nsis file.') bOK = False try: # open nsis file nsiFile = open(nsiFilePath, 'r', encoding='utf-16-le') # read out all lines of nsi file nsiLines = nsiFile.readlines() nsiFile.close() # for nsiline in nsiLines: for x in range(len(nsiLines)): nsiline = nsiLines[x] if nsiline.find('\n') != -1: nsiline = nsiline[:-1] if nsiline.startswith("!define FILE_VER"): nsiline = '!define FILE_VER \"%s.%s.%s.0\"\n' % (t_ver[0], t_ver[1], t_ver[2]) nsiLines[x] = "" nsiLines[x] = nsiline # cc.v('[ver] new ver: %s' % nsiLines[x]) bOK = True elif nsiline.startswith("!define OUT_VER"): nsiline = '!define OUT_VER \"%s.%s.%s\"\n' % (t_ver[0], t_ver[1], t_ver[2]) nsiLines[x] = "" nsiLines[x] = nsiline # cc.v('[ver] new ver: %s' % nsiLines[x]) bOK = True elif nsiline.startswith("!define PRODUCT_VER"): nsiline = '!define PRODUCT_VER \"%s.%s\"\n' % (t_ver[0], t_ver[1]) nsiLines[x] = "" nsiLines[x] = nsiline # cc.v('[ver] new ver: %s' % nsiLines[x]) bOK = True else: continue if bOK: cc.v(' update {}...'.format(nsiFilePath)) wnsiFile = open(nsiFilePath, 'w', encoding='utf-16-le') wnsiFile.writelines(nsiLines) wnsiFile.close() return bOK except IOError: raise RuntimeError('can not process nsi file.')
def _build_libuv(self, file_name): cc.n('prepare libuv source code... ', end='') if not os.path.exists(self.LIBUV_PATH_SRC): cc.v('') utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL) time.sleep(1) # wait for a while, otherwise rename may fail. os.rename(os.path.join(PATH_EXTERNAL, 'libuv-{}'.format(env.ver_libuv)), self.LIBUV_PATH_SRC) else: cc.w('already exists, skip.')
def _build_mbedtls(self, file_name): if not os.path.exists(self.MBEDTLS_PATH_SRC): # os.system('tar -zxvf "{}/{}" -C "{}"'.format(PATH_DOWNLOAD, file_name, PATH_TMP)) os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP)) cc.n('build mbedtls...', end='') if os.path.exists( os.path.join(self.PATH_RELEASE, 'lib', 'libmbedtls.a')): cc.w('already exists, skip.') return cc.v('') # fix the Makefile mkfile = os.path.join(self.MBEDTLS_PATH_SRC, 'Makefile') f = open(mkfile) fl = f.readlines() f.close() fixed = False for i in range(len(fl)): x = fl[i].split('=') if x[0] == 'DESTDIR': fl[i] = 'DESTDIR={}\n'.format(self.PATH_RELEASE) fixed = True break if not fixed: cc.e('can not fix Makefile of mbedtls.') return f = open(mkfile, 'w') f.writelines(fl) f.close() # fix source file utils.ensure_file_exists( os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'include', 'mbedtls', 'config.h')) utils.copy_file( os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'include', 'mbedtls'), os.path.join(self.MBEDTLS_PATH_SRC, 'include', 'mbedtls'), 'config.h') utils.ensure_file_exists( os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'library', 'rsa.c')) utils.copy_file( os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'library'), os.path.join(self.MBEDTLS_PATH_SRC, 'library'), 'rsa.c') old_p = os.getcwd() os.chdir(self.MBEDTLS_PATH_SRC) os.system('make CFLAGS="-fPIC" lib') os.system('make install') os.chdir(old_p)
def _make_base(self): if os.path.exists(self.base_path): cc.v('an exists version found, clean up...', self.base_path) utils.remove(self.base_path) cc.v('make pysrt folder...') utils.makedirs(self.base_path) cc.n('copy python extension dll...') utils.copy_ex(self.py_dll_path, os.path.join(self.base_path, 'modules'))
def build(self): self.py_dll_path = self._locate_dll_path() self.py_lib_path = self._locate_lib_path() cc.v('python dll path :', self.py_dll_path) cc.v('python lib path :', self.py_lib_path) self._make_base() self._make_python_zip() self._make_py_ver_file()
def _build_libuv(self, file_name): cc.n('prepare libuv source code... ', end='') if not os.path.exists(self.LIBUV_PATH_SRC): cc.v('') utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL) os.rename( os.path.join(PATH_EXTERNAL, 'libuv-{}'.format(env.ver_libuv)), self.LIBUV_PATH_SRC) else: cc.w('already exists, skip.')
def _build_openssl(self, file_name): cc.n('prepare OpenSSL pre-built package ... ', end='') if os.path.exists(self.OPENSSL_PATH_SRC): cc.w('already exists, skip.') return cc.v('') _alt_ver = '_'.join(env.ver_ossl.split('.')) file_name = 'Win32OpenSSL-{}.msi'.format(_alt_ver) installer = os.path.join(PATH_DOWNLOAD, file_name) if not os.path.exists(installer): if not utils.download_file( 'openssl installer', 'http://slproweb.com/download/{}'.format(filename), PATH_DOWNLOAD, file_name): cc.e('can not download pre-built installer of OpenSSL.') return utils.ensure_file_exists(installer) cc.w('On Windows, we use pre-built package of OpenSSL.') cc.w('The installer have been downloaded at "{}".'.format(installer)) cc.w('please install OpenSSL into "{}".'.format(self.OPENSSL_PATH_SRC)) cc.w( '\nOnce the OpenSSL installed, press Enter to continue or Q to quit...', end='') try: x = input() except EOFError: x = 'q' if x == 'q': return _chk_output = [ os.path.join(self.OPENSSL_PATH_SRC, 'include', 'openssl', 'aes.h'), os.path.join(self.OPENSSL_PATH_SRC, 'include', 'openssl', 'opensslv.h'), os.path.join(self.OPENSSL_PATH_SRC, 'lib', 'VC', 'libcrypto32MT.lib'), os.path.join(self.OPENSSL_PATH_SRC, 'lib', 'VC', 'libeay32MT.lib'), os.path.join(self.OPENSSL_PATH_SRC, 'lib', 'VC', 'ssleay32MT.lib'), os.path.join(self.OPENSSL_PATH_SRC, 'lib', 'VC', 'static', 'libcrypto32MT.lib'), os.path.join(self.OPENSSL_PATH_SRC, 'lib', 'VC', 'static', 'libeay32MT.lib'), os.path.join(self.OPENSSL_PATH_SRC, 'lib', 'VC', 'static', 'ssleay32MT.lib'), ] for f in _chk_output: if not os.path.exists(f): raise RuntimeError( 'build openssl static library from source code failed.')
def _build_mongoose(self, file_name): cc.n('prepare mongoose source code... ', end='') if not os.path.exists(self.MONGOOSE_PATH_SRC): cc.v('') utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL) os.rename( os.path.join(PATH_EXTERNAL, 'mongoose-{}'.format(env.ver_mongoose)), self.MONGOOSE_PATH_SRC) else: cc.w('already exists, skip.')
def _build_jsoncpp(self, file_name): cc.n('prepare jsoncpp source code... ', end='') if not os.path.exists(self.JSONCPP_PATH_SRC): cc.v('') utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL) os.rename( os.path.join(PATH_EXTERNAL, 'jsoncpp-{}'.format(env.ver_jsoncpp)), self.JSONCPP_PATH_SRC) else: cc.w('already exists, skip.')
def _build_libssh(self, file_name): # cc.n('skip build libssh on macOS.') # return if not self._download_libssh(file_name): return if not os.path.exists(self.LIBSSH_PATH_SRC): os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP)) cc.n('build libssh...', end='') # if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a')) and os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh_threads.a')): if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a')): cc.w('already exists, skip.') return cc.v('') build_path = os.path.join(self.LIBSSH_PATH_SRC, 'build') cmake_define = ' -DCMAKE_INSTALL_PREFIX={path_release}' \ ' -DOPENSSL_INCLUDE_DIR=/usr/local/opt/openssl/include' \ ' -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib' \ ' -DWITH_GCRYPT=OFF' \ ' -DWITH_GEX=OFF' \ ' -DWITH_SFTP=ON' \ ' -DWITH_SERVER=ON' \ ' -DWITH_GSSAPI=OFF' \ ' -DWITH_ZLIB=ON' \ ' -DWITH_PCAP=OFF' \ ' -DBUILD_SHARED_LIBS=OFF' \ ' -DUNIT_TESTING=OFF' \ ' -DWITH_EXAMPLES=OFF' \ ' -DWITH_BENCHMARKS=OFF' \ ' -DWITH_NACL=OFF' \ ''.format(path_release=self.PATH_RELEASE) # ' -DWITH_STATIC_LIB=ON' try: utils.cmake(build_path, 'Release', False, cmake_define) except: pass # because make install will fail because we can not disable ssh_shared target, # so we copy necessary files ourselves. utils.ensure_file_exists( os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'libssh.a')) # utils.ensure_file_exists(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads', 'libssh_threads.a')) utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src'), os.path.join(self.PATH_RELEASE, 'lib'), 'libssh.a') # utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads'), os.path.join(self.PATH_RELEASE, 'lib'), 'libssh_threads.a') utils.copy_ex(os.path.join(self.LIBSSH_PATH_SRC, 'include'), os.path.join(self.PATH_RELEASE, 'include'), 'libssh')
def _build_openssl(self, file_name): cc.n('build openssl static library from source code... ') if not super()._build_openssl(file_name): return _chk_output = [ os.path.join(self.OPENSSL_PATH_SRC, 'out32', 'libeay32.lib'), os.path.join(self.OPENSSL_PATH_SRC, 'out32', 'ssleay32.lib'), os.path.join(self.OPENSSL_PATH_SRC, 'inc32', 'openssl', 'opensslconf.h'), ] need_build = False for f in _chk_output: if not os.path.exists(f): need_build = True break if not need_build: cc.n('build openssl static library from source code... ', end='') cc.w('already exists, skip.') return cc.v('') cc.n('prepare openssl source code...') _alt_ver = '_'.join(env.ver_ossl.split('.')) if not os.path.exists(self.OPENSSL_PATH_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) if not os.path.exists(self.OPENSSL_PATH_SRC): raise RuntimeError('can not prepare openssl source code.') else: cc.w('already exists, skip.') os.chdir(self.OPENSSL_PATH_SRC) os.system('""{}" Configure VC-WIN32"'.format(env.perl)) os.system(r'ms\do_nasm') # for vs2015 # utils.sys_exec(r'"{}\VC\bin\vcvars32.bat" && nmake -f ms\nt.mak'.format(env.visual_studio_path), direct_output=True) # for vs2017 community utils.sys_exec( r'"{}VC\Auxiliary\Build\vcvars32.bat" && nmake -f ms\nt.mak'. format(env.visual_studio_path), direct_output=True) for f in _chk_output: if not os.path.exists(f): raise RuntimeError( 'build openssl static library from source code failed.')
def _build_zlib(self, file_name): if not self._download_zlib(file_name): return cc.n('build zlib library from source code... ', end='') if not os.path.exists(self.ZLIB_PATH_SRC): cc.v('') utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL) os.rename( os.path.join(PATH_EXTERNAL, 'zlib-{}'.format(env.ver_zlib)), self.ZLIB_PATH_SRC) if ctx.target_path == 'debug': olib = 'zlibd.lib' odll = 'zlibd.dll' else: olib = 'zlib.lib' odll = 'zlib.dll' out_file_lib = os.path.join(self.ZLIB_PATH_SRC, 'build', ctx.target_path, olib) out_file_dll = os.path.join(self.ZLIB_PATH_SRC, 'build', ctx.target_path, odll) 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 zlib, 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 zlib.sln generated, press Enter to continue or Q to quit...', end='') try: x = input() except EOFError: x = 'q' if x == 'q': return cc.i('build zlib...') sln_file = os.path.join(self.ZLIB_PATH_SRC, 'build', 'zlib.sln') utils.msvc_build(sln_file, 'zlib', ctx.target_path, 'win32', False) # utils.ensure_file_exists(os.path.join(self.ZLIB_PATH_SRC, 'build', ctx.target_path, 'zlib.lib')) # utils.ensure_file_exists(os.path.join(self.ZLIB_PATH_SRC, 'build', ctx.target_path, 'zlib.dll')) # utils.copy_file(os.path.join(self.ZLIB_PATH_SRC, 'build', ctx.target_path), os.path.join(self.ZLIB_PATH_SRC, 'lib', ctx.target_path), 'zlib.lib') # utils.copy_file(os.path.join(self.ZLIB_PATH_SRC, 'build', ctx.target_path), os.path.join(self.ZLIB_PATH_SRC, 'lib', ctx.target_path), 'zlib.dll') utils.ensure_file_exists(out_file_lib) utils.ensure_file_exists(out_file_dll)
def _build_libssh(self, file_name): if not os.path.exists(self.LIBSSH_PATH_SRC): os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP)) cc.n('build libssh...', end='') if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a')): cc.w('already exists, skip.') return cc.v('') build_path = os.path.join(self.LIBSSH_PATH_SRC, 'build') cmake_define = ' -DCMAKE_INSTALL_PREFIX={path_release}' \ ' -DOPENSSL_INCLUDE_DIR={path_release}/include' \ ' -DOPENSSL_LIBRARIES={path_release}/lib' \ ' -DWITH_SFTP=ON' \ ' -DWITH_SERVER=ON' \ ' -DWITH_STATIC_LIB=ON' \ ' -DWITH_GSSAPI=OFF' \ ' -DWITH_ZLIB=OFF' \ ' -DWITH_PCAP=OFF' \ ' -DUNIT_TESTING=OFF' \ ' -DWITH_EXAMPLES=OFF' \ ' -DWITH_BENCHMARKS=OFF' \ ' -DWITH_NACL=OFF' \ ' ..'.format(path_release=self.PATH_RELEASE) old_p = os.getcwd() try: utils.cmake(build_path, 'Release', False, cmake_define=cmake_define, cmake_pre_define='CFLAGS="-fPIC"') os.chdir(build_path) utils.sys_exec('make install') except: pass os.chdir(old_p) # utils.ensure_file_exists(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'libssh.a')) # utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src'), os.path.join(self.PATH_RELEASE, 'lib'), 'libssh.a') # utils.copy_ex(os.path.join(self.LIBSSH_PATH_SRC, 'include'), os.path.join(self.PATH_RELEASE, 'include'), 'libssh') utils.ensure_file_exists( os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a')) files = os.listdir(os.path.join(self.PATH_RELEASE, 'lib')) for i in files: if i.startswith('libssh.so'): # use os.unlink() because some file should be a link. os.unlink(os.path.join(self.PATH_RELEASE, 'lib', i))
def _build_libuv(self, file_name): if not self._download_libuv(file_name): return cc.n('prepare libuv source code... ', end='') if not os.path.exists(self.LIBUV_PATH_SRC): cc.v('') utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL) time.sleep(1) # wait for a while, otherwise rename may fail. os.rename( os.path.join(PATH_EXTERNAL, 'libuv-{}'.format(env.ver_libuv)), self.LIBUV_PATH_SRC) else: cc.w('already exists, skip.')
def _prompt_input(message, def_value): cc.v('{} ['.format(message), end='') cc.w(def_value, end='') cc.v(']: ', end='') try: x = input().strip() if len(x) == 0: x = def_value except EOFError: x = def_value return x
def _update_ver_plist(self, plist_file, ver): """ update plist file version info for MacOS app.""" t_ver = ver.split('.') if len(t_ver) < 3: raise RuntimeError('Invalid version for plist file.') bOK = False try: # open rc file f = codecs.open(plist_file, 'r', 'utf8') # read out all lines of rc file lines = f.readlines() f.close() is_ver = False for x in range(len(lines)): l = lines[x] if l.find('<key>CFBundleShortVersionString</key>') != -1: is_ver = True continue if l.find('<key>CFBundleVersion</key>') != -1: is_ver = True continue if is_ver: is_ver = False pos1 = l.find('<string>') pos2 = l.rfind('</string>') if pos1 == -1 or pos2 == -2: continue _ver = l[pos1 + 8: pos2].strip() v = _ver.split(".") if len(v) < 3: raise RuntimeError('Invalid .plist file.') old_ver = '.'.join(v) if old_ver == ver: continue lines[x] = '\t<string>{ver}</string>\n'.format(ver=ver) bOK = True if bOK: cc.v(' update {}...'.format(plist_file)) wrcFile = codecs.open(plist_file, 'w', 'utf8') wrcFile.writelines(lines) wrcFile.close() except IOError: raise RuntimeError('can not process plist file.')
def _build_libssh(self, file_name): if not os.path.exists(self.LIBSSH_PATH_SRC): os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP)) cc.n('build libssh...', end='') if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a')): cc.w('already exists, skip.') return cc.v('') 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') build_path = os.path.join(self.LIBSSH_PATH_SRC, 'build') cmake_define = ' -DCMAKE_INSTALL_PREFIX={path_release}' \ ' -DOPENSSL_INCLUDE_DIR={path_release}/include' \ ' -DOPENSSL_LIBRARIES={path_release}/lib' \ ' -DWITH_SFTP=ON' \ ' -DWITH_SERVER=ON' \ ' -DWITH_STATIC_LIB=ON' \ ' -DWITH_GSSAPI=OFF' \ ' -DWITH_ZLIB=OFF' \ ' -DWITH_PCAP=OFF' \ ' -DUNIT_TESTING=OFF' \ ' -DWITH_EXAMPLES=OFF' \ ' -DWITH_BENCHMARKS=OFF' \ ' -DWITH_NACL=OFF' \ ' ..'.format(path_release=self.PATH_RELEASE) old_p = os.getcwd() try: utils.cmake(build_path, 'Release', False, cmake_define=cmake_define, cmake_pre_define='CFLAGS="-fPIC"') os.chdir(build_path) utils.sys_exec('make install') except: pass os.chdir(old_p) utils.ensure_file_exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a')) files = os.listdir(os.path.join(self.PATH_RELEASE, 'lib')) for i in files: if i.startswith('libssh.so'): # use os.unlink() because some file should be a link. os.unlink(os.path.join(self.PATH_RELEASE, 'lib', i))
def _build_mbedtls(self, file_name): cc.n('prepare mbedtls source code... ', end='') if not os.path.exists(self.MBEDTLS_PATH_SRC): cc.v('') utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL) os.rename(os.path.join(PATH_EXTERNAL, 'mbedtls-mbedtls-{}'.format(env.ver_mbedtls)), self.MBEDTLS_PATH_SRC) else: cc.w('already exists, skip.') return cc.v('') # fix source file utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'include', 'mbedtls', 'config.h')) utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'include', 'mbedtls'), os.path.join(self.MBEDTLS_PATH_SRC, 'include', 'mbedtls'), 'config.h')
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 make_builder_ver(self): ver_file = os.path.join(env.root_path, 'build', 'builder', 'core', 'ver.py') ver_content = '# -*- coding: utf8 -*-\nVER_TP_SERVER = "{}"\nVER_TP_ASSIST = "{}"\n'.format(self.VER_TP_SERVER, self.VER_TP_ASSIST) rewrite = False if not os.path.exists(ver_file): rewrite = True else: with open(ver_file, 'r') as f: old_content = f.read() if old_content != ver_content: rewrite = True if rewrite: cc.v(' update {}...'.format(ver_file)) with open(ver_file, 'w') as f: f.write(ver_content)
def _build_openssl(self, file_name): cc.n('build openssl static library from source code... ') if not super()._build_openssl(file_name): return _chk_output = [ os.path.join(self.OPENSSL_PATH_SRC, 'out32', 'libeay32.lib'), os.path.join(self.OPENSSL_PATH_SRC, 'out32', 'ssleay32.lib'), os.path.join(self.OPENSSL_PATH_SRC, 'inc32', 'openssl', 'opensslconf.h'), ] need_build = False for f in _chk_output: if not os.path.exists(f): need_build = True break if not need_build: cc.n('build openssl static library from source code... ', end='') cc.w('already exists, skip.') return cc.v('') cc.n('prepare openssl source code...') _alt_ver = '_'.join(env.ver_ossl.split('.')) if not os.path.exists(self.OPENSSL_PATH_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) if not os.path.exists(self.OPENSSL_PATH_SRC): raise RuntimeError('can not prepare openssl source code.') else: cc.w('already exists, skip.') os.chdir(self.OPENSSL_PATH_SRC) os.system('""{}" Configure VC-WIN32"'.format(env.perl)) os.system(r'ms\do_nasm') # for vs2015 # utils.sys_exec(r'"{}\VC\bin\vcvars32.bat" && nmake -f ms\nt.mak'.format(env.visual_studio_path), direct_output=True) # for vs2017 community utils.sys_exec(r'"{}VC\Auxiliary\Build\vcvars32.bat" && nmake -f ms\nt.mak'.format(env.visual_studio_path), direct_output=True) for f in _chk_output: if not os.path.exists(f): raise RuntimeError('build openssl static library from source code failed.')
def make_server_ver(self): ver_file = os.path.join(env.root_path, 'server', 'www', 'teleport', 'webroot', 'app', 'app_ver.py') # ver_content = '# -*- coding: utf8 -*-\n\nTS_VER = "{}"\n'.format(self.VER_TELEPORT_SERVER) ver_content = '# -*- coding: utf8 -*-\nTP_SERVER_VER = "{}"\n'.format(self.VER_TP_SERVER) rewrite = False if not os.path.exists(ver_file): rewrite = True else: with open(ver_file, 'r') as f: old_content = f.read() if old_content != ver_content: rewrite = True if rewrite: cc.v(' update {}...'.format(ver_file)) with open(ver_file, 'w') as f: f.write(ver_content)
def _do_upgrade(self): x = self._ver_compare(self._current_ver, self._installed_ver_str) if x == 0: while True: cc.v('') x = self._prompt_choice( 'The same version `{}` installed, are you sure to overwrite?'.format(self._current_ver), [('Yes', 0, False), ('No', 0, True)]) if x in ['y', 'yes']: break elif x in ['n', 'no']: return elif x < 0: while True: cc.v('') x = self._prompt_choice( 'A new version `{}` installed, rollback to old version `{}` may cause Teleport Server not functionally.\nAre you sure to rollback to old version?'.format( self._installed_ver_str, self._current_ver), [('Yes', 0, False), ('No', 0, True)]) if x in ['y', 'yes']: break elif x in ['n', 'no']: return else: while True: cc.v('') x = self._prompt_choice( 'Now upgrade from version `{}` to `{}`, \nAre you sure to upgrade to new version?'.format( self._installed_ver_str, self._current_ver), [('Yes', 0, False), ('No', 0, True)]) if x in ['y', 'yes']: break elif x in ['n', 'no']: return while True: cc.v('') x = self._prompt_choice('Make sure you have backup your database and settings.\nAre you sure to continue?', [('Yes', 0, False), ('No', 0, True)]) x = x.lower() if x in ['y', 'yes']: break elif x in ['n', 'yes']: return self._stop_service() time.sleep(2) self._uninstall_service() self._delete_files(False) time.sleep(1) self._copy_files() self._install_service() self._start_service() time.sleep(2) self._check_service()
def _build_mbedtls(self, file_name): if not os.path.exists(self.MBEDTLS_PATH_SRC): os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP)) cc.n('build mbedtls...', end='') if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libmbedtls.a')): cc.w('already exists, skip.') return cc.v('') # fix the Makefile mkfile = os.path.join(self.MBEDTLS_PATH_SRC, 'Makefile') f = open(mkfile) fl = f.readlines() f.close() fixed = False for i in range(len(fl)): x = fl[i].split('=') if x[0] == 'DESTDIR': fl[i] = 'DESTDIR={}\n'.format(self.PATH_RELEASE) fixed = True break if not fixed: cc.e('can not fix Makefile of mbedtls.') return f = open(mkfile, 'w') f.writelines(fl) f.close() # fix source file utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'include', 'mbedtls', 'config.h')) utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'include', 'mbedtls'), os.path.join(self.MBEDTLS_PATH_SRC, 'include', 'mbedtls'), 'config.h') # utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'library', 'rsa.c')) # utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'library'), os.path.join(self.MBEDTLS_PATH_SRC, 'library'), 'rsa.c') old_p = os.getcwd() os.chdir(self.MBEDTLS_PATH_SRC) os.system('make CFLAGS="-fPIC" lib') os.system('make install') os.chdir(old_p)
def run(self): self._init() if not self._is_installed: self._do_install() else: cc.v('') cc.v('Found teleport server have installed at `{}` already.'.format(self._install_path)) while True: x = self._prompt_choice('What are you wanna to do?', [('upgrade', 2, True), ('uninstall', 0, False), ('quit', 0, False)]) if x in ['q', 'quit']: break elif x in ['u', 'uninstall']: self._do_uninstall() break elif x in ['g', 'upgrade']: self._do_upgrade() break
def _prepare_python(self): cc.n('prepare python header files ...', end='') if os.path.exists(os.path.join(PATH_EXTERNAL, 'python', 'include', 'Python.h')): cc.w('already exists, skip.') return cc.v('') _header_path = None for p in sys.path: if os.path.exists(os.path.join(p, 'include', 'Python.h')): _header_path = os.path.join(p, 'include') if _header_path is None: cc.e('\ncan not locate python development include path in:') for p in sys.path: cc.e(' ', p) raise RuntimeError() utils.copy_ex(_header_path, os.path.join(PATH_EXTERNAL, 'python', 'include'))
def build(self): self.py_dll_path = self._locate_dll_path() self.py_lib_path = self._locate_lib_path() cc.v('python dll path :', self.py_dll_path) cc.v('python lib path :', self.py_lib_path) cc.n('upgrade pip ...') utils.sys_exec('{} -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip --upgrade'.format(env.py_exec)) pip = self._get_pip() pypi_modules = ['ldap3', 'mako', 'Pillow', 'psutil', 'pymysql', 'qrcode', 'tornado', 'wheezy.captcha'] for p in pypi_modules: cc.n('install {} ...'.format(p)) utils.sys_exec('{} install -i https://pypi.tuna.tsinghua.edu.cn/simple {}'.format(pip, p), direct_output=True) self._make_base() self._make_python_zip() self._make_py_ver_file()
def make_assist_macos_ver(self): plist_file = os.path.join(env.root_path, 'client', 'tp_assist_macos', 'src', 'TP-Assist-Info.plist') self._update_ver_plist(plist_file, self.VER_TP_ASSIST) ver_file = os.path.join(env.root_path, 'client', 'tp_assist_macos', 'src', 'csrc', 'ts_ver.h') ver_content = '#ifndef __TS_ASSIST_VER_H__\n#define __TS_ASSIST_VER_H__\n\n#define TP_ASSIST_VER\tL"{}"\n\n#endif // __TS_ASSIST_VER_H__\n'.format(self.VER_TP_ASSIST) rewrite = False if not os.path.exists(ver_file): rewrite = True else: with open(ver_file, 'r') as f: old_content = f.read() if old_content != ver_content: rewrite = True if rewrite: cc.v(' update {}...'.format(ver_file)) with open(ver_file, 'w') as f: f.write(ver_content)
def make_tpcore_ver(self): ver_file = os.path.join(env.root_path, 'server', 'tp_core', 'core', 'ts_ver.h') ver_content = '#ifndef __TS_SERVER_VER_H__\n#define __TS_SERVER_VER_H__\n\n#define TP_SERVER_VER\tL"{}"\n\n#endif // __TS_SERVER_VER_H__\n'.format(self.VER_TP_TPCORE) rewrite = False if not os.path.exists(ver_file): rewrite = True else: with open(ver_file, 'r') as f: old_content = f.read() if old_content != ver_content: rewrite = True if rewrite: cc.v(' update {}...'.format(ver_file)) with open(ver_file, 'w') as f: f.write(ver_content) rc_file = os.path.join(env.root_path, 'server', 'tp_core', 'core', 'tp_core.rc') self._update_ver_rc(rc_file, self.VER_TP_TPCORE)
def _build_libuv(self, file_name): cc.n('prepare libuv source code...', end='') if not os.path.exists(self.LIBUV_PATH_SRC): os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP)) cc.n('build libuv...', end='') if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libuv.a')): cc.w('already exists, skip.') return cc.v('') # we need following... # brew install automake libtool old_p = os.getcwd() os.chdir(self.LIBUV_PATH_SRC) os.system('sh autogen.sh') os.system('./configure --prefix={} --with-pic'.format(self.PATH_RELEASE)) os.system('make') os.system('make install') os.chdir(old_p)
def _build_libssh(self, file_name): if not os.path.exists(self.LIBSSH_PATH_SRC): os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP)) cc.n('build libssh...', end='') # if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a')) and os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh_threads.a')): if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a')): cc.w('already exists, skip.') return cc.v('') build_path = os.path.join(self.LIBSSH_PATH_SRC, 'build') cmake_define = ' -DCMAKE_INSTALL_PREFIX={path_release}' \ ' -DOPENSSL_INCLUDE_DIR={path_release}/include' \ ' -DOPENSSL_LIBRARIES={path_release}/lib' \ ' -DWITH_SFTP=ON' \ ' -DWITH_SERVER=ON' \ ' -DWITH_STATIC_LIB=ON' \ ' -DWITH_GSSAPI=OFF' \ ' -DWITH_ZLIB=OFF' \ ' -DWITH_PCAP=OFF' \ ' -DUNIT_TESTING=OFF' \ ' -DWITH_EXAMPLES=OFF' \ ' -DWITH_BENCHMARKS=OFF' \ ' -DWITH_NACL=OFF' \ ''.format(path_release=self.PATH_RELEASE) try: utils.cmake(build_path, 'Release', False, cmake_define) except: pass # because make install will fail because we can not disable ssh_shared target, # so we copy necessary files ourselves. utils.ensure_file_exists(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'libssh.a')) # utils.ensure_file_exists(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads', 'libssh_threads.a')) utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src'), os.path.join(self.PATH_RELEASE, 'lib'), 'libssh.a') # utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads'), os.path.join(self.PATH_RELEASE, 'lib'), 'libssh_threads.a') utils.copy_ex(os.path.join(self.LIBSSH_PATH_SRC, 'include'), os.path.join(self.PATH_RELEASE, 'include'), 'libssh')
def _make_base(self): if os.path.exists(self.base_path): cc.v('an exists version found, clean up...', self.base_path) utils.remove(self.base_path) cc.v('make pysbase folder...') utils.makedirs(self.base_path) cc.v('copy python core dll...') _exec_path = os.path.dirname(env.py_exec) # _win_system_path = os.path.join(os.getenv('SystemRoot'), 'system32') # if ctx.bits == BITS_32 and ctx.host_os_is_win_x64: # _win_system_path = os.path.join(os.getenv('SystemRoot'), 'SysWOW64') if not os.path.exists(_exec_path): raise RuntimeError('can not locate python folder at:', _exec_path) pydll = self._get_py_dll_name() shutil.copy(os.path.join(_exec_path, pydll), os.path.join(self.base_path, pydll)) if ctx.py_ver == '34': msvcrdll = 'msvcr100.dll' elif ctx.py_ver == '37': msvcrdll = 'vcruntime140.dll' else: raise RuntimeError('unknown msvc runtime for this python version.') shutil.copy(os.path.join(_exec_path, msvcrdll), os.path.join(self.base_path, msvcrdll)) super()._copy_modules()
def main(): try: _main() cc.v('\n--==[ ALL DONE ]==--\n') return 0 except KeyboardInterrupt: return 1 except RuntimeError as err: cc.v('') cc.v('') cc.e(err.__str__()) cc.v('') return 2 except: cc.f('got exception.') return 3
def make_assist_win_ver(self): ver_file = os.path.join(env.root_path, 'client', 'tp_assist_win', 'ts_ver.h') ver_content = '#ifndef __TS_ASSIST_VER_H__\n#define __TS_ASSIST_VER_H__\n\n#define TP_ASSIST_VER\tL"{}"\n\n#endif // __TS_ASSIST_VER_H__\n'.format(self.VER_TP_ASSIST) rewrite = False if not os.path.exists(ver_file): rewrite = True else: with open(ver_file, 'r') as f: old_content = f.read() if old_content != ver_content: rewrite = True if rewrite: cc.v(' update {}...'.format(ver_file)) with open(ver_file, 'w') as f: f.write(ver_content) rc_file = os.path.join(env.root_path, 'client', 'tp_assist_win', 'tp_assist.rc') self._update_ver_rc(rc_file, self.VER_TP_ASSIST) nsi_file = os.path.join(env.root_path, 'dist', 'client', 'windows', 'assist', 'installer.nsi') self._update_ver_nsi(nsi_file, self.VER_TP_ASSIST)
def _copy_modules(self): cc.n('copy python extension dll...') utils.makedirs(self.modules_path) ext = utils.extension_suffixes() cc.v('extension ext:', ext) for m in self.modules: for n in ext: s = os.path.join(self.py_dll_path, m) + n if os.path.exists(s): cc.v('copy %s' % s) cc.v(' -> %s' % os.path.join(self.modules_path, m) + n) shutil.copy(s, os.path.join(self.modules_path, m) + n)