Beispiel #1
0
    def _make_python_zip(self):
        cc.n('make python.zip...')

        out_file = os.path.join(self.base_path, 'python.zip')
        if os.path.exists(out_file):
            utils.remove(out_file)

        _tmp_ = os.path.join(self.base_path, '_tmp_')
        if os.path.exists(_tmp_):
            cc.v('clear up temp folder...')
            utils.remove(_tmp_)

        cc.v('copying Python `Lib` folder...')
        shutil.copytree(self.py_lib_path, _tmp_)

        cc.v('remove useless folders and files...')
        for i in self.py_lib_remove:
            utils.remove(_tmp_, i)

        cc.v('compile .py to .pyc...')
        makepyo.make(_tmp_)

        cc.v('compress into python.zip...')
        utils.make_zip(_tmp_, out_file, from_parent=False)
        utils.ensure_file_exists(out_file)

        cc.v('remove temp folder...')
        utils.remove(_tmp_)
Beispiel #2
0
    def build_server(self):
        cc.n('build server app (tp_core/libtpssh/libtelnet/librdp/tp_web)...')

        out_path = os.path.join(env.root_path, 'out', 'server', ctx.bits_path,
                                'bin')
        out_files = list()
        out_files.append(os.path.join(out_path, 'tp_core'))
        out_files.append(os.path.join(out_path, 'tp_web'))
        out_files.append(os.path.join(out_path, 'libtpssh.so'))
        out_files.append(os.path.join(out_path, 'libtptelnet.so'))
        if with_rdp:
            out_files.append(os.path.join(out_path, 'libtprdp.so'))

        for f in out_files:
            if os.path.exists(f):
                utils.remove(f)

        utils.makedirs(out_path)

        utils.cmake(os.path.join(env.root_path, 'cmake-build'),
                    ctx.target_path, False)
        # utils.strip(out_file)

        for f in out_files:
            if os.path.exists(f):
                utils.ensure_file_exists(f)
Beispiel #3
0
    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'))
Beispiel #4
0
    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 _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')
Beispiel #6
0
    def _make_python_zip(self):
        cc.n('make python.zip...')

        out_file = os.path.join(self.base_path, 'python.zip')
        if os.path.exists(out_file):
            utils.remove(out_file)

        _tmp_ = os.path.join(self.base_path, '_tmp_')
        if os.path.exists(_tmp_):
            cc.v('clear up temp folder...')
            utils.remove(_tmp_)

        cc.v('copying Python `Lib` folder...')
        shutil.copytree(self.py_lib_path, _tmp_)

        cc.v('remove useless folders and files...')
        for i in self.py_lib_remove:
            utils.remove(_tmp_, i)

        cc.v('compile .py to .pyc...')
        makepyo.make(_tmp_)

        cc.v('compress into python.zip...')
        utils.make_zip(_tmp_, out_file, from_parent=False)
        utils.ensure_file_exists(out_file)

        cc.v('remove temp folder...')
        utils.remove(_tmp_)
Beispiel #7
0
 def build_player(self):
     cc.i('build tp-player...')
     prj_path = os.path.join(env.root_path, 'client', 'tp-player')
     out_file = os.path.join(env.root_path, 'out', 'client', ctx.bits_path, ctx.target_path, 'tp-player.exe')
     if os.path.exists(out_file):
         utils.remove(out_file)
     utils.qt_build(prj_path, 'tp-player', ctx.bits_path, ctx.target_path)
     utils.ensure_file_exists(out_file)
Beispiel #8
0
 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)
Beispiel #9
0
 def build_exe(self):
     cc.i('build tp_assist...')
     sln_file = os.path.join(env.root_path, 'client', 'tp_assist_win', 'tp_assist.vs2015.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)
Beispiel #10
0
    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)
Beispiel #11
0
    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)
Beispiel #12
0
    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.')
Beispiel #13
0
    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', ctx.target_path, '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'))
Beispiel #14
0
    def build_player(self):
        cc.i('build tp-player...')
        prj_path = os.path.join(env.root_path, 'client', 'tp-player')
        out_file = os.path.join(env.root_path, 'out', 'client', ctx.bits_path, ctx.target_path, 'tp-player.app')
        if os.path.exists(out_file):
            utils.remove(out_file)
        utils.qt_build(prj_path, 'tp-player', ctx.bits_path, ctx.target_path)
        utils.ensure_file_exists(os.path.join(out_file, 'Contents', 'Info.plist'))

        # for deployment
        utils.qt_deploy(out_file)
Beispiel #15
0
    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'))
Beispiel #16
0
    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)
Beispiel #17
0
    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')
Beispiel #18
0
    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))
Beispiel #19
0
    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)
Beispiel #20
0
    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)
Beispiel #21
0
    def build_installer(self):
        cc.i('build assist package for website...')

        name = 'teleport-assist-{}'.format(VER_TELEPORT_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)
Beispiel #22
0
    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')
Beispiel #23
0
    def _prepare_python(self):
        cc.n('prepare python header and lib files ...')

        if os.path.exists(os.path.join(self.PATH_RELEASE, 'include', 'python', 'Python.h')):
            cc.w(' - header file already exists, skip.')
        else:
            utils.ensure_file_exists(os.path.join(self.PATH_RELEASE, 'include', 'python{}m'.format(ctx.py_dot_ver), 'Python.h'))
            utils.sys_exec('ln -s "{}" "{}"'.format(
                os.path.join(self.PATH_RELEASE, 'include', 'python{}m'.format(ctx.py_dot_ver)),
                os.path.join(self.PATH_RELEASE, 'include', 'python')
            ))

        lib_file = 'libpython{}m.a'.format(env.py_ver_dot)
        utils.ensure_file_exists(os.path.join(self.PATH_RELEASE, 'lib', lib_file))
Beispiel #24
0
    def build_installer(self):
        cc.i('make tp_assist dmg file...')

        # copy all files of tp-player.
        configuration = ctx.target_path.capitalize()
        player_path = os.path.join(env.root_path, 'out', 'client', ctx.bits_path, ctx.target_path)
        assist_path = os.path.join(env.root_path, 'client', 'tp_assist_macos', 'build', configuration, 'TP-Assist.app')
        utils.copy_ex(player_path, assist_path, 'tp-player.app')

        json_file = os.path.join(env.root_path, 'dist', 'client', 'macos', 'dmg.json')
        dmg_file = os.path.join(env.root_path, 'out', 'installer', '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)
Beispiel #25
0
    def build_server(self):
        cc.n('build web server ...')
        # notice: now we can not build debug version of tp_web.exe
        if ctx.target_path == 'debug':
            cc.w('cannot build debug version of tp_web, skip.')
        else:
            sln_file = os.path.join(env.root_path, 'server', 'tp_web', 'src', 'tp_web.vs2017.sln')
            out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path, 'tp_web.exe')
            if os.path.exists(out_file):
                utils.remove(out_file)
            utils.msvc_build(sln_file, 'tp_web', ctx.target_path, ctx.bits_path, False)
            utils.ensure_file_exists(out_file)

        cc.n('build core server ...')
        sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'core', 'tp_core.vs2017.sln')
        out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path, 'tp_core.exe')
        if os.path.exists(out_file):
            utils.remove(out_file)
        utils.msvc_build(sln_file, 'tp_core', ctx.target_path, ctx.bits_path, False)
        utils.ensure_file_exists(out_file)

        cc.n('build SSH protocol ...')
        sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'protocol', 'ssh', 'tpssh.vs2017.sln')
        out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path, 'tpssh.dll')
        if os.path.exists(out_file):
            utils.remove(out_file)
        utils.msvc_build(sln_file, 'tpssh', ctx.target_path, ctx.bits_path, False)
        utils.ensure_file_exists(out_file)
        utils.copy_file(os.path.join(env.root_path, 'external', 'libssh', 'lib', ctx.target_path), os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path), 'ssh.dll')

        cc.n('build TELNET protocol ...')
        sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'protocol', 'telnet', 'tptelnet.vs2017.sln')
        out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path, 'tptelnet.dll')
        if os.path.exists(out_file):
            utils.remove(out_file)
        utils.msvc_build(sln_file, 'tptelnet', ctx.target_path, ctx.bits_path, False)
        utils.ensure_file_exists(out_file)

        if with_rdp:
            cc.n('build RDP protocol ...')
            sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'protocol', 'rdp', 'tprdp.vs2017.sln')
            out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path, 'tprdp.dll')
            if os.path.exists(out_file):
                utils.remove(out_file)
            utils.msvc_build(sln_file, 'tprdp', ctx.target_path, ctx.bits_path, False)
            utils.ensure_file_exists(out_file)
Beispiel #26
0
    def _prepare_python(self):
        cc.n('prepare python header and lib files ...')

        if os.path.exists(
                os.path.join(self.PATH_RELEASE, 'include', 'python',
                             'Python.h')):
            cc.w('python header file already exists, skip.')
        else:
            utils.ensure_file_exists(
                os.path.join(self.PATH_RELEASE, 'include',
                             'python{}m'.format(ctx.py_dot_ver), 'Python.h'))
            utils.sys_exec('ln -s "{}" "{}"'.format(
                os.path.join(self.PATH_RELEASE, 'include',
                             'python{}m'.format(ctx.py_dot_ver)),
                os.path.join(self.PATH_RELEASE, 'include', 'python')))

        lib_file = 'libpython{}m.a'.format(env.py_ver_dot)
        utils.ensure_file_exists(
            os.path.join(self.PATH_RELEASE, 'lib', lib_file))
Beispiel #27
0
    def build_server(self):
        cc.n('build web server ...')
        # notice: now we can not build debug version of tp_web.exe
        if ctx.target_path == 'debug':
            cc.w('cannot build debug version of tp_web, skip.')
        else:
            sln_file = os.path.join(env.root_path, 'server', 'tp_web', 'src',
                                    'tp_web.vs2015.sln')
            out_file = os.path.join(env.root_path, 'out', 'server',
                                    ctx.bits_path, ctx.target_path,
                                    'tp_web.exe')
            if os.path.exists(out_file):
                utils.remove(out_file)
            utils.msvc_build(sln_file, 'tp_web', ctx.target_path,
                             ctx.bits_path, False)
            utils.ensure_file_exists(out_file)

        cc.n('build core server ...')
        sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'core',
                                'tp_core.vs2015.sln')
        out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path,
                                ctx.target_path, 'tp_core.exe')
        if os.path.exists(out_file):
            utils.remove(out_file)
        utils.msvc_build(sln_file, 'tp_core', ctx.target_path, ctx.bits_path,
                         False)
        utils.ensure_file_exists(out_file)

        cc.n('build SSH protocol ...')
        sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'protocol',
                                'ssh', 'tpssh.vs2015.sln')
        out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path,
                                ctx.target_path, 'tpssh.dll')
        if os.path.exists(out_file):
            utils.remove(out_file)
        utils.msvc_build(sln_file, 'tpssh', ctx.target_path, ctx.bits_path,
                         False)
        utils.ensure_file_exists(out_file)

        if os.path.exists(
                os.path.join(env.root_path, 'server', 'tp_core', 'protocol',
                             'ssh', 'tpssh.vs2015.sln')):
            cc.n('build RDP protocol ...')
            sln_file = os.path.join(env.root_path, 'server', 'tp_core',
                                    'protocol', 'rdp', 'tprdp.vs2015.sln')
            out_file = os.path.join(env.root_path, 'out', 'server',
                                    ctx.bits_path, ctx.target_path,
                                    'tprdp.dll')
            if os.path.exists(out_file):
                utils.remove(out_file)
            utils.msvc_build(sln_file, 'tprdp', ctx.target_path, ctx.bits_path,
                             False)
            utils.ensure_file_exists(out_file)
Beispiel #28
0
    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)
Beispiel #29
0
    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_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)
Beispiel #31
0
    def _build_zlib(self, file_name):
        # cc.w('skip build zlib again.')
        if not self._download_zlib(file_name):
            return
        if not os.path.exists(self.ZLIB_PATH_SRC):
            os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name,
                                                     self.PATH_TMP))

        cc.n('build zlib...', end='')
        out_file = os.path.join(self.PATH_RELEASE, 'lib', 'libz.a')
        if os.path.exists(out_file):
            cc.w('already exists, skip.')
            return
        cc.v('')

        build_path = os.path.join(self.ZLIB_PATH_SRC, 'build')

        cmake_define = ' -DCMAKE_INSTALL_PREFIX={path_release}' \
                       ' ..'.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')
            utils.sys_exec('make install')
        except:
            pass
        os.chdir(old_p)

        utils.ensure_file_exists(out_file)
        files = os.listdir(os.path.join(self.PATH_RELEASE, 'lib'))
        for i in files:
            if i.startswith('libz.so'):
                # use os.unlink() because some file should be a link.
                os.unlink(os.path.join(self.PATH_RELEASE, 'lib', i))
Beispiel #32
0
    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')
Beispiel #33
0
    def build_server(self):
        cc.n('build server app (tp_core/libtpssh/libtelnet/librdp/tp_web)...')

        out_path = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, 'bin')
        out_files = list()
        out_files.append(os.path.join(out_path, 'tp_core'))
        out_files.append(os.path.join(out_path, 'tp_web'))
        out_files.append(os.path.join(out_path, 'libtpssh.so'))
        out_files.append(os.path.join(out_path, 'libtptelnet.so'))
        if with_rdp:
            out_files.append(os.path.join(out_path, 'libtprdp.so'))

        for f in out_files:
            if os.path.exists(f):
                utils.remove(f)

        utils.makedirs(out_path)

        utils.cmake(os.path.join(env.root_path, 'cmake-build'), ctx.target_path, False)
        # utils.strip(out_file)

        for f in out_files:
            if os.path.exists(f):
                utils.ensure_file_exists(f)
Beispiel #34
0
    def _build_libssh(self, file_name):
        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='')
        out_file = os.path.join(self.PATH_RELEASE, 'lib64', 'libssh.a')
        if os.path.exists(out_file):
            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_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'

        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(out_file)
Beispiel #35
0
    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 _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 config.h
        # mkfile = os.path.join(self.MBEDTLS_PATH_SRC, 'include', 'mbedtls', 'config.h')
        # f = open(mkfile)
        # fl = f.readlines()
        # f.close()
        #
        # for i in range(len(fl)):
        #     if fl[i].find('#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED') >= 0:
        #         fl[i] = '//#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED\n'
        #     elif fl[i].find('#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED') >= 0:
        #         fl[i] = '//#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED\n'
        #     elif fl[i].find('#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED') >= 0:
        #         fl[i] = '//#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED\n'
        #     elif fl[i].find('#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED') >= 0:
        #         fl[i] = '//#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED\n'
        #     elif fl[i].find('#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED') >= 0:
        #         fl[i] = '//#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED\n'
        #     elif fl[i].find('#define MBEDTLS_SELF_TEST') >= 0:
        #         fl[i] = '//#define MBEDTLS_SELF_TEST\n'
        #     elif fl[i].find('#define MBEDTLS_SSL_RENEGOTIATION') >= 0:
        #         fl[i] = '//#define MBEDTLS_SSL_RENEGOTIATION\n'
        #     elif fl[i].find('#define MBEDTLS_ECDH_C') >= 0:
        #         fl[i] = '//#define MBEDTLS_ECDH_C\n'
        #     elif fl[i].find('#define MBEDTLS_ECDSA_C') >= 0:
        #         fl[i] = '//#define MBEDTLS_ECDSA_C\n'
        #     elif fl[i].find('#define MBEDTLS_ECP_C') >= 0:
        #         fl[i] = '//#define MBEDTLS_ECP_C\n'
        #     elif fl[i].find('#define MBEDTLS_NET_C') >= 0:
        #         fl[i] = '//#define MBEDTLS_NET_C\n'
        #
        #     elif fl[i].find('#define MBEDTLS_RSA_NO_CRT') >= 0:
        #         fl[i] = '#define MBEDTLS_RSA_NO_CRT\n'
        #     elif fl[i].find('#define MBEDTLS_SSL_PROTO_SSL3') >= 0:
        #         fl[i] = '#define MBEDTLS_SSL_PROTO_SSL3\n'
        #
        # 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)
Beispiel #37
0
    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):
        if not os.path.exists(self.LIBSSH_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))
            # os.rename(os.path.join(self.PATH_TMP, 'master'), os.path.join(self.PATH_TMP, 'libssh-{}'.format(LIBSSH_VER)))

        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')):
            cc.w('already exists, skip.')
            return
        cc.v('')

        build_path = os.path.join(self.LIBSSH_PATH_SRC, 'build')
        # utils.makedirs(build_path)

        # here is a bug in cmake v2.8.11 (default on ubuntu14), in FindOpenSSL.cmake,
        # it parse opensslv.h, use regex like this:
        #   REGEX "^#define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*")
        # but in openssl-1.0.2h, the version define line is:
        #   # define OPENSSL_VERSION_NUMBER  0x1000208fL
        # notice there is a space char between # and define, so find openssl always fail.

        # old_p = os.getcwd()
        # os.chdir(build_path)
        # cmd = 'cmake' \
        #       ' -DCMAKE_INSTALL_PREFIX={}' \
        #       ' -D_OPENSSL_VERSION={}' \
        #       ' -DOPENSSL_INCLUDE_DIR={}/include' \
        #       ' -DOPENSSL_LIBRARIES={}/lib' \
        #       ' -DCMAKE_BUILD_TYPE=Release' \
        #       ' -DWITH_GSSAPI=OFF' \
        #       ' -DWITH_ZLIB=OFF' \
        #       ' -DWITH_STATIC_LIB=ON' \
        #       ' -DWITH_PCAP=OFF' \
        #       ' -DWITH_EXAMPLES=OFF' \
        #       ' -DWITH_NACL=OFF' \
        #       ' ..'.format(self.PATH_RELEASE, OPENSSL_VER, self.PATH_RELEASE, self.PATH_RELEASE)
        # cc.n(cmd)
        # os.system(cmd)
        # # os.system('make ssh_static ssh_threads_static')
        # os.system('make ssh_static')
        # # os.system('make install')
        # os.chdir(old_p)

        cmake_define = ' -DCMAKE_INSTALL_PREFIX={}' \
                       ' -D_OPENSSL_VERSION={}' \
                       ' -DOPENSSL_INCLUDE_DIR={}/include' \
                       ' -DOPENSSL_LIBRARIES={}/lib' \
                       ' -DWITH_GSSAPI=OFF' \
                       ' -DWITH_ZLIB=OFF' \
                       ' -DWITH_STATIC_LIB=ON' \
                       ' -DWITH_PCAP=OFF' \
                       ' -DWITH_TESTING=OFF' \
                       ' -DWITH_CLIENT_TESTING=OFF' \
                       ' -DWITH_EXAMPLES=OFF' \
                       ' -DWITH_BENCHMARKS=OFF' \
                       ' -DWITH_NACL=OFF' \
                       ' ..'.format(self.PATH_RELEASE, env.ver_openssl_number, self.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')
Beispiel #39
0
    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)