mirror of https://github.com/tp4a/teleport
temp.
parent
3d4ae79fbb
commit
685cd29edf
|
@ -110,8 +110,8 @@ class BuilderWin(BuilderBase):
|
|||
if os.path.exists(os.path.join(PATH_EXTERNAL, 'python', 'include', 'pyctype.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', 'pyctype.h')):
|
||||
|
@ -141,8 +141,8 @@ class BuilderWin(BuilderBase):
|
|||
if not need_build:
|
||||
cc.w('already exists, skip.')
|
||||
return
|
||||
|
||||
cc.v('')
|
||||
|
||||
cc.n('prepare openssl source code...')
|
||||
_alt_ver = '_'.join(env.ver_openssl.split('.'))
|
||||
if not os.path.exists(self.OPENSSL_PATH_SRC):
|
||||
|
@ -173,9 +173,9 @@ class BuilderWin(BuilderBase):
|
|||
if not need_build:
|
||||
cc.w('already exists, skip.')
|
||||
return
|
||||
cc.v('')
|
||||
|
||||
cc.n('\nprepare libssh source code... ', end='')
|
||||
|
||||
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')
|
||||
|
||||
|
@ -203,6 +203,7 @@ class BuilderWin(BuilderBase):
|
|||
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:
|
||||
|
@ -254,16 +255,18 @@ class BuilderLinux(BuilderBase):
|
|||
utils.makedirs(self.PATH_TMP)
|
||||
|
||||
def _build_jsoncpp(self, file_name):
|
||||
cc.n('prepare jsoncpp source code...')
|
||||
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...')
|
||||
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:
|
||||
|
@ -293,10 +296,11 @@ class BuilderLinux(BuilderBase):
|
|||
# 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...')
|
||||
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++
|
||||
|
@ -314,10 +318,11 @@ class BuilderLinux(BuilderBase):
|
|||
# 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...')
|
||||
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')
|
||||
|
@ -396,10 +401,11 @@ class BuilderLinux(BuilderBase):
|
|||
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...')
|
||||
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')
|
||||
# utils.makedirs(build_path)
|
||||
|
@ -460,10 +466,11 @@ class BuilderLinux(BuilderBase):
|
|||
if not os.path.exists(self.SQLITE_PATH_SRC):
|
||||
os.system('tar -zxvf "{}/{}" -C "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP))
|
||||
|
||||
cc.n('build sqlite static...')
|
||||
cc.n('build sqlite static...', end='')
|
||||
if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libsqlite3.a')):
|
||||
cc.w('already exists, skip.')
|
||||
return
|
||||
cc.v('')
|
||||
|
||||
old_p = os.getcwd()
|
||||
os.chdir(self.SQLITE_PATH_SRC)
|
||||
|
|
|
@ -158,12 +158,12 @@ class BuilderLinux(BuilderBase):
|
|||
# shutil.copy(os.path.join(self.dist_path, 'script', i), os.path.abspath(os.path.join(self.tmp_path, '..', '..', i)))
|
||||
|
||||
# 复制安装所需的脚本
|
||||
utils.copy_ex(os.path.join(self.dist_path, 'script'), self.path_tmp, 'install.sh')
|
||||
utils.copy_ex(os.path.join(self.dist_path, 'script'), self.path_tmp, 'uninst.sh')
|
||||
# utils.copy_ex(os.path.join(self.dist_path, 'script'), self.path_tmp, 'install.sh')
|
||||
# utils.copy_ex(os.path.join(self.dist_path, 'script'), self.path_tmp, 'uninst.sh')
|
||||
utils.copy_ex(os.path.join(self.dist_path, 'script'), self.path_tmp, 'setup.sh')
|
||||
utils.copy_ex(os.path.join(self.dist_path, 'script'), self.path_tmp, 'script')
|
||||
utils.copy_ex(os.path.join(self.dist_path, 'script'), self.path_tmp, 'daemon')
|
||||
|
||||
# utils.make_zip(os.path.join(self.base_tmp, self.name), out_file)
|
||||
if os.path.exists(self._final_file):
|
||||
utils.remove(self._final_file)
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
# -*- coding: utf8 -*-
|
||||
|
||||
import os
|
||||
import platform
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
@ -10,28 +9,12 @@ import time
|
|||
from . import colorconsole as cc
|
||||
from .env import env
|
||||
|
||||
# from .configs import cfg
|
||||
#
|
||||
# try:
|
||||
# CONFIG_FILE = os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..')), 'config.ini')
|
||||
# if not cfg.init(CONFIG_FILE):
|
||||
# sys.exit(1)
|
||||
# except:
|
||||
# cc.e('can not load configuration.\n\nplease copy `config.ini.in` into `config.ini` and modify it to fit your condition and try again.')
|
||||
# sys.exit(1)
|
||||
|
||||
if env.is_py2:
|
||||
import imp
|
||||
elif env.is_py3:
|
||||
import importlib
|
||||
import importlib.machinery
|
||||
|
||||
# if sys.platform == 'win32':
|
||||
# import winreg
|
||||
|
||||
THIS_PATH = os.path.abspath(os.path.dirname(__file__))
|
||||
ROOT_PATH = os.path.abspath(os.path.join(THIS_PATH, '..'))
|
||||
|
||||
|
||||
def _check_download_file(file_name):
|
||||
if env.is_win:
|
||||
|
@ -40,7 +23,7 @@ def _check_download_file(file_name):
|
|||
if 'Everything is Ok' in output:
|
||||
return True
|
||||
else:
|
||||
cc.w('[fixme] how to check file on Linux?')
|
||||
cc.w('[fixme] how to test file on Linux? ', end='')
|
||||
return True
|
||||
|
||||
|
||||
|
@ -250,78 +233,6 @@ def ensure_file_exists(filename):
|
|||
raise RuntimeError('path exists but not a file: {}'.format(filename))
|
||||
|
||||
|
||||
# def root_path():
|
||||
# return os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
|
||||
|
||||
|
||||
def python_exec():
|
||||
if not os.path.exists(sys.executable):
|
||||
raise RuntimeError('Can not locate Python execute file.')
|
||||
return sys.executable
|
||||
|
||||
|
||||
# def msbuild_path():
|
||||
# if cfg.toolchain.msbuild is not None:
|
||||
# return cfg.toolchain.msbuild
|
||||
#
|
||||
# # 14.0 = VS2015
|
||||
# # 12.0 = VS2012
|
||||
# # 4.0 = VS2008
|
||||
# chk = ['14.0', '4.0', '12.0']
|
||||
#
|
||||
# msp = None
|
||||
# for c in chk:
|
||||
# msp = winreg_read("SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\{}".format(c), 'MSBuildToolsPath')
|
||||
# if msp is not None:
|
||||
# break
|
||||
#
|
||||
# if msp is None:
|
||||
# raise RuntimeError('Can not locate MSBuild.')
|
||||
#
|
||||
# msb = os.path.join(msp[0], 'MSBuild.exe')
|
||||
# if not os.path.exists(msb):
|
||||
# raise RuntimeError('Can not locate MSBuild at {}'.format(msp))
|
||||
#
|
||||
# cfg.toolchain.msbuild = msb
|
||||
# return msb
|
||||
|
||||
|
||||
# def nsis_path():
|
||||
# if cfg.toolchain.nsis is not None:
|
||||
# return cfg.toolchain.nsis
|
||||
#
|
||||
# p = winreg_read_wow64_32(r'SOFTWARE\NSIS\Unicode', '')
|
||||
# if p is None:
|
||||
# raise RuntimeError('Can not locate unicode version of NSIS.')
|
||||
#
|
||||
# p = os.path.join(p[0], 'makensis.exe')
|
||||
# if not os.path.exists(p):
|
||||
# raise RuntimeError('Can not locate NSIS at {}'.format(p))
|
||||
#
|
||||
# cfg.toolchain.nsis = p
|
||||
# return p
|
||||
|
||||
|
||||
# def winreg_read(path, key):
|
||||
# try:
|
||||
# hkey = winreg.CreateKeyEx(winreg.HKEY_LOCAL_MACHINE, path, 0, winreg.KEY_READ)
|
||||
# value = winreg.QueryValueEx(hkey, key)
|
||||
# except OSError:
|
||||
# return None
|
||||
#
|
||||
# return value
|
||||
|
||||
|
||||
# def winreg_read_wow64_32(path, key):
|
||||
# try:
|
||||
# hkey = winreg.CreateKeyEx(winreg.HKEY_LOCAL_MACHINE, path, 0, winreg.KEY_READ | winreg.KEY_WOW64_32KEY)
|
||||
# value = winreg.QueryValueEx(hkey, key)
|
||||
# except OSError:
|
||||
# return None
|
||||
#
|
||||
# return value
|
||||
|
||||
|
||||
def sys_exec(cmd, direct_output=False, output_codec=None):
|
||||
if output_codec is None:
|
||||
if env.is_win:
|
||||
|
@ -334,7 +245,8 @@ def sys_exec(cmd, direct_output=False, output_codec=None):
|
|||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, shell=True)
|
||||
|
||||
else:
|
||||
p = subprocess.Popen(cmd, close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, shell=True)
|
||||
p = subprocess.Popen(cmd, close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||
universal_newlines=True, shell=True)
|
||||
|
||||
output = list()
|
||||
f = p.stdout
|
||||
|
@ -360,11 +272,13 @@ def msvc_build(sln_file, proj_name, target, platform, force_rebuild):
|
|||
raise RuntimeError('where is `msbuild`?')
|
||||
|
||||
if force_rebuild:
|
||||
cmd = '"{}" "{}" "/target:clean" "/property:Configuration={};Platform={}"'.format(env.msbuild, sln_file, target, platform)
|
||||
cmd = '"{}" "{}" "/target:clean" "/property:Configuration={};Platform={}"'.format(env.msbuild, sln_file, target,
|
||||
platform)
|
||||
ret, _ = sys_exec(cmd, direct_output=True)
|
||||
cc.v('ret:', ret)
|
||||
|
||||
cmd = '"{}" "{}" "/target:{}" "/property:Configuration={};Platform={}"'.format(env.msbuild, sln_file, proj_name, target, platform)
|
||||
cmd = '"{}" "{}" "/target:{}" "/property:Configuration={};Platform={}"'.format(env.msbuild, sln_file, proj_name,
|
||||
target, platform)
|
||||
ret, _ = sys_exec(cmd, direct_output=True)
|
||||
if ret != 0:
|
||||
raise RuntimeError('build MSVC project `{}` failed.'.format(proj_name))
|
||||
|
@ -381,16 +295,13 @@ def nsis_build(nsi_file, _define=''):
|
|||
|
||||
|
||||
def cmake(work_path, target, force_rebuild, cmake_define=''):
|
||||
# because cmake v2.8 shipped with Ubuntu 14.04LTS, but we need 3.5.
|
||||
# I use a v3.5 one from CLion.
|
||||
# I use cmake v3.5 which shipped with CLion.
|
||||
if env.cmake is None:
|
||||
raise RuntimeError('where is `cmake`?')
|
||||
|
||||
cc.n('make by cmake', target, sep=': ')
|
||||
old_p = os.getcwd()
|
||||
# new_p = os.path.dirname(wscript_file)
|
||||
|
||||
# work_path = os.path.join(root_path(), 'cmake-build')
|
||||
if os.path.exists(work_path):
|
||||
if force_rebuild:
|
||||
remove(work_path)
|
||||
|
@ -422,22 +333,14 @@ def strip(filename):
|
|||
|
||||
def make_zip(src_path, to_file):
|
||||
cc.v('compress folder into .zip...')
|
||||
# n, _ = os.path.splitext(to_file)
|
||||
# # x = os.path.split(to_file)[1].split('.')
|
||||
# p = os.path.dirname(to_file)
|
||||
# shutil.make_archive(os.path.join(p, n), 'zip', src_path)
|
||||
# ensure_file_exists(to_file)
|
||||
if env.is_win:
|
||||
src_path = os.path.abspath(src_path)
|
||||
print('src_path', src_path)
|
||||
_parent = os.path.abspath(os.path.join(src_path, '..'))
|
||||
print('_parent', _parent)
|
||||
_folder = src_path[len(_parent) + 1:]
|
||||
|
||||
old_p = os.getcwd()
|
||||
os.chdir(_parent)
|
||||
cmd = '""{}" a "{}" "{}""'.format(env.zip7, to_file, _folder)
|
||||
print(cmd)
|
||||
os.system(cmd)
|
||||
os.chdir(old_p)
|
||||
elif env.is_linux:
|
||||
|
|
|
@ -11,12 +11,10 @@
|
|||
### END INIT INFO
|
||||
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
||||
DAEMON_PATH=/usr/local/eom/teleport
|
||||
DAEMON_PATH={daemon_path}
|
||||
NAME=teleport
|
||||
DESC=teleport
|
||||
|
||||
# test -f "$DAEMON_PATH/teleport.sh" || exit 0
|
||||
|
||||
test -f "$DAEMON_PATH/start.sh" || exit 0
|
||||
test -f "$DAEMON_PATH/stop.sh" || exit 0
|
||||
test -f "$DAEMON_PATH/status.sh" || exit 0
|
||||
|
@ -51,7 +49,7 @@ case "$1" in
|
|||
$DAEMON_PATH/status.sh $SRV
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $NAME {start|stop|restart|status}" >&2
|
||||
echo "Usage: $NAME {{start|stop|restart|status}}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
|
@ -5,43 +5,47 @@ if [ x$1 != x ]; then
|
|||
SRV=$1
|
||||
fi
|
||||
|
||||
APP_PATH=/usr/local/eom/teleport
|
||||
DAEMON_PATH={daemon_path}
|
||||
shell_ret=0
|
||||
|
||||
cd "${APP_PATH}"
|
||||
cd "$DAEMON_PATH"
|
||||
|
||||
# start teleport core server...
|
||||
if [ $SRV == all ] || [ $SRV == core ] ; then
|
||||
echo -n "starting teleport core server ... "
|
||||
result=$( ps ax | grep "${APP_PATH}/bin/tp_core start" | grep -v grep | wc -l )
|
||||
result=$( ps ax | grep "$DAEMON_PATH/bin/tp_core start" | grep -v grep | wc -l )
|
||||
if [ $result -gt 0 ]; then
|
||||
echo "already running, skip."
|
||||
else
|
||||
${APP_PATH}/bin/tp_core start
|
||||
$DAEMON_PATH/bin/tp_core start
|
||||
|
||||
result=$( ps ax | grep "${APP_PATH}/bin/tp_core start" | grep -v grep | wc -l )
|
||||
result=$( ps ax | grep "$DAEMON_PATH/bin/tp_core start" | grep -v grep | wc -l )
|
||||
if [ ! $result -gt 0 ]; then
|
||||
echo -e "\e[31m[FAILED]\033[0m"
|
||||
shell_ret=1
|
||||
else
|
||||
echo -e "\e[32m[done]\033[0m"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# start web
|
||||
if [ $SRV == all ] || [ $SRV == web ] ; then
|
||||
echo -n "starting teleport web ... "
|
||||
result=$( ps ax | grep "${APP_PATH}/bin/tp_web start" | grep -v grep | wc -l )
|
||||
result=$( ps ax | grep "$DAEMON_PATH/bin/tp_web start" | grep -v grep | wc -l )
|
||||
if [ $result -gt 0 ]; then
|
||||
echo "already running, skip."
|
||||
else
|
||||
${APP_PATH}/bin/tp_web start
|
||||
$DAEMON_PATH/bin/tp_web start
|
||||
|
||||
result=$( ps ax | grep "${APP_PATH}/bin/tp_web start" | grep -v grep | wc -l )
|
||||
result=$( ps ax | grep "$DAEMON_PATH/bin/tp_web start" | grep -v grep | wc -l )
|
||||
if [ ! $result -gt 0 ]; then
|
||||
echo -e "\e[31m[FAILED]\033[0m"
|
||||
shell_ret=1
|
||||
else
|
||||
echo -e "\e[32m[done]\033[0m"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
exit $shell_ret
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
APP_PATH=/usr/local/eom/teleport
|
||||
|
||||
result=$( ps ax | grep "${APP_PATH}/bin/tp_core start" | grep -v grep | wc -l )
|
||||
if [ $result -gt 0 ]; then
|
||||
# echo "teleport core server is running."
|
||||
echo -e "teleport core server is \e[32mrunning\033[0m."
|
||||
else
|
||||
# echo "teleport core server is not running."
|
||||
echo -e "teleport core server is \e[31mnot running\033[0m."
|
||||
fi
|
||||
|
||||
result=$( ps ax | grep "${APP_PATH}/bin/tp_web start" | grep -v grep | wc -l )
|
||||
if [ $result -gt 0 ]; then
|
||||
# echo "teleport web is running."
|
||||
echo -e "teleport web server is \e[32mrunning\033[0m."
|
||||
else
|
||||
# echo "teleport web is not running."
|
||||
echo -e "teleport web server is \e[31mnot running\033[0m."
|
||||
fi
|
|
@ -0,0 +1,23 @@
|
|||
#!/bin/bash
|
||||
|
||||
DAEMON_PATH={daemon_path}
|
||||
shell_ret=0
|
||||
|
||||
result=$( ps ax | grep "$DAEMON_PATH/bin/tp_core start" | grep -v grep | wc -l )
|
||||
if [ $result -gt 0 ]; then
|
||||
echo -e "teleport core server is \e[32mrunning\033[0m."
|
||||
else
|
||||
echo -e "teleport core server is \e[31mnot running\033[0m."
|
||||
shell_ret=1
|
||||
fi
|
||||
|
||||
result=$( ps ax | grep "$DAEMON_PATH/bin/tp_web start" | grep -v grep | wc -l )
|
||||
if [ $result -gt 0 ]; then
|
||||
echo -e "teleport web server is \e[32mrunning\033[0m."
|
||||
else
|
||||
echo -e "teleport web server is \e[31mnot running\033[0m."
|
||||
shell_ret=1
|
||||
fi
|
||||
|
||||
exit $shell_ret
|
||||
|
|
@ -5,28 +5,29 @@ if [ x$1 != x ]; then
|
|||
SRV=$1
|
||||
fi
|
||||
|
||||
APP_PATH=/usr/local/eom/teleport
|
||||
DAEMON_PATH={daemon_path}
|
||||
|
||||
# start teleport core server...
|
||||
if [ $SRV == all ] || [ $SRV == core ] ; then
|
||||
echo -n "stoping teleport core server ... "
|
||||
result=$( ps ax | grep "${APP_PATH}/bin/tp_core start" | grep -v grep | wc -l )
|
||||
result=$( ps ax | grep "$DAEMON_PATH/bin/tp_core start" | grep -v grep | wc -l )
|
||||
if [ $result -gt 0 ]; then
|
||||
ps ax | grep "${APP_PATH}/bin/tp_core start" | grep -v grep | kill `awk '{print $1}'`
|
||||
ps ax | grep "$DAEMON_PATH/bin/tp_core start" | grep -v grep | kill `awk '{{print $1}}'`
|
||||
echo 'done.'
|
||||
else
|
||||
echo "not running, skip."
|
||||
fi
|
||||
fi
|
||||
|
||||
# stop web
|
||||
if [ $SRV == all ] || [ $SRV == web ] ; then
|
||||
echo -n "stoping teleport web ... "
|
||||
result=$( ps ax | grep "${APP_PATH}/bin/tp_web start" | grep -v grep | wc -l )
|
||||
result=$( ps ax | grep "$DAEMON_PATH/bin/tp_web start" | grep -v grep | wc -l )
|
||||
if [ $result -gt 0 ]; then
|
||||
ps ax | grep "${APP_PATH}/bin/tp_web start" | grep -v grep | kill `awk '{print $1}'`
|
||||
ps ax | grep "$DAEMON_PATH/bin/tp_web start" | grep -v grep | kill `awk '{{print $1}}'`
|
||||
echo 'done.'
|
||||
else
|
||||
echo "not running, skip."
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
|
@ -10,95 +10,12 @@ import time
|
|||
from . import colorconsole as cc
|
||||
from .env import env
|
||||
|
||||
# from .configs import cfg
|
||||
|
||||
# try:
|
||||
# CONFIG_FILE = os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..')), 'config.ini')
|
||||
# if not cfg.init(CONFIG_FILE):
|
||||
# sys.exit(1)
|
||||
# except:
|
||||
# cc.e('can not load configuration.\n\nplease copy `config.ini.in` into `config.ini` and modify it to fit your condition and try again.')
|
||||
# sys.exit(1)
|
||||
|
||||
|
||||
# THIS_PATH = os.path.abspath(os.path.dirname(__file__))
|
||||
# ROOT_PATH = os.path.abspath(os.path.join(THIS_PATH, '..'))
|
||||
|
||||
|
||||
# def _check_download_file(file_name):
|
||||
# if env.is_win:
|
||||
# # use 7z to test integrity of downloaded
|
||||
# ret, output = sys_exec('"{}" t "{}"'.format(env.zip7, file_name), False)
|
||||
# if 'Everything is Ok' in output:
|
||||
# return True
|
||||
# else:
|
||||
# cc.e('fixme.')
|
||||
# return False
|
||||
#
|
||||
#
|
||||
# def download_file(desc, url, target_path, file_name):
|
||||
# cc.n('download {} ... '.format(desc), end='')
|
||||
#
|
||||
# local_file_name = os.path.join(target_path, file_name)
|
||||
# if os.path.exists(local_file_name):
|
||||
# if not _check_download_file(local_file_name):
|
||||
# cc.w('already exists but broken, download it again...')
|
||||
# else:
|
||||
# cc.w('already exists, skip.')
|
||||
# return True
|
||||
#
|
||||
# cc.v('')
|
||||
# # 因为下载过程会在命令行显示进度,所以不能使用subprocess.Popen()的方式捕获输出,会很难看!
|
||||
# if env.is_win:
|
||||
# cmd = '""{}" --no-check-certificate {} -O "{}""'.format(env.wget, url, local_file_name)
|
||||
# os.system(cmd)
|
||||
# elif env.is_linux:
|
||||
# os.system('wget --no-check-certificate {} -O "{}"'.format(url, local_file_name))
|
||||
# else:
|
||||
# return False
|
||||
#
|
||||
# if not os.path.exists(local_file_name) or not _check_download_file(local_file_name):
|
||||
# cc.e('downloading {} from {} failed.'.format(desc, url))
|
||||
# return False
|
||||
#
|
||||
# return True
|
||||
#
|
||||
|
||||
# def extension_suffixes():
|
||||
# # imp.get_suffixes()
|
||||
# # 返回3元组列表(suffix, mode, type), 获得特殊模块的描述
|
||||
# # .suffix为文件后缀名;
|
||||
# # mode为打开文件模式;
|
||||
# # type为文件类型, 1代表PY_SOURCE, 2代表PY_COMPILED, 3代表C_EXTENSION
|
||||
#
|
||||
# EXTENSION_SUFFIXES = list()
|
||||
# if cfg.is_py2:
|
||||
# suf = imp.get_suffixes()
|
||||
# for s in suf:
|
||||
# if s[2] == 3:
|
||||
# EXTENSION_SUFFIXES.append(s[0])
|
||||
# else:
|
||||
# EXTENSION_SUFFIXES = importlib.machinery.EXTENSION_SUFFIXES
|
||||
#
|
||||
# if cfg.dist == 'windows':
|
||||
# if '.dll' not in EXTENSION_SUFFIXES:
|
||||
# EXTENSION_SUFFIXES.append('.dll')
|
||||
#
|
||||
# elif cfg.dist == 'linux':
|
||||
# if '.so' not in EXTENSION_SUFFIXES:
|
||||
# EXTENSION_SUFFIXES.append('.so')
|
||||
#
|
||||
# elif cfg.dist == 'macos':
|
||||
# raise RuntimeError('not support MacOS now.')
|
||||
#
|
||||
# return EXTENSION_SUFFIXES
|
||||
|
||||
|
||||
def remove(*args):
|
||||
path = os.path.join(*args)
|
||||
|
||||
cc.v(' - remove [%s] ... ' % path, end='')
|
||||
if not os.path.exists(path):
|
||||
if not (os.path.exists(path) or os.path.islink(path)):
|
||||
cc.v('not exists, skip.')
|
||||
return
|
||||
|
||||
|
@ -125,7 +42,7 @@ def remove(*args):
|
|||
cc.i('[done]')
|
||||
|
||||
|
||||
def makedirs(path, exist_ok=True):
|
||||
def make_dirs(path, exist_ok=True):
|
||||
if os.path.exists(path):
|
||||
if not exist_ok:
|
||||
raise RuntimeError('path already exists: %s' % path)
|
||||
|
@ -148,32 +65,6 @@ def makedirs(path, exist_ok=True):
|
|||
raise RuntimeError('can not create: %s' % path)
|
||||
|
||||
|
||||
# def copy_file(s_path, t_path, f_name, force=True):
|
||||
# if isinstance(f_name, str):
|
||||
# f_from = f_name
|
||||
# f_to = f_name
|
||||
# elif isinstance(f_name, tuple):
|
||||
# f_from = f_name[0]
|
||||
# f_to = f_name[1]
|
||||
# else:
|
||||
# raise RuntimeError('utils.copy_file() got invalid param.')
|
||||
#
|
||||
# s = os.path.join(s_path, f_from)
|
||||
# t = os.path.join(t_path, f_to)
|
||||
# if os.path.exists(t):
|
||||
# if force:
|
||||
# cc.v(' an exists version found, clean up...')
|
||||
# remove(t)
|
||||
# else:
|
||||
# cc.w(' an exists version found, skip copy.')
|
||||
# return
|
||||
#
|
||||
# if not os.path.exists(t_path):
|
||||
# makedirs(t_path)
|
||||
# cc.v('copy [%s]\n -> [%s]' % (s, t))
|
||||
# shutil.copy(s, t)
|
||||
|
||||
|
||||
def copy_ex(s_path, t_path, item_name=None, force=True):
|
||||
if item_name is None:
|
||||
s = s_path
|
||||
|
@ -208,33 +99,6 @@ def copy_ex(s_path, t_path, item_name=None, force=True):
|
|||
shutil.copy(s, t)
|
||||
|
||||
|
||||
# def update_file(s_path, t_path, f_name):
|
||||
# if isinstance(f_name, str):
|
||||
# f_from = f_name
|
||||
# f_to = f_name
|
||||
# elif isinstance(f_name, tuple):
|
||||
# f_from = f_name[0]
|
||||
# f_to = f_name[1]
|
||||
# else:
|
||||
# raise RuntimeError('utils.update_file() got invalid param.')
|
||||
#
|
||||
# s = os.path.join(s_path, f_from)
|
||||
# t = os.path.join(t_path, f_to)
|
||||
# if not os.path.exists(s):
|
||||
# cc.w('try update file `%s` but not exists, skip.' % f_from)
|
||||
# return
|
||||
#
|
||||
# # TODO: check file MD5 and update time.
|
||||
#
|
||||
# if os.path.exists(t):
|
||||
# remove(t)
|
||||
#
|
||||
# if not os.path.exists(t_path):
|
||||
# makedirs(t_path)
|
||||
# cc.v('update [%s]\n -> [%s]' % (s, t))
|
||||
# shutil.copy(os.path.join(s_path, f_from), t)
|
||||
|
||||
|
||||
def ensure_file_exists(filename):
|
||||
if not os.path.exists(filename):
|
||||
raise RuntimeError('file not exists: {}'.format(filename))
|
||||
|
@ -242,16 +106,6 @@ def ensure_file_exists(filename):
|
|||
raise RuntimeError('path exists but not a file: {}'.format(filename))
|
||||
|
||||
|
||||
# def root_path():
|
||||
# return os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
|
||||
|
||||
|
||||
# def python_exec():
|
||||
# if not os.path.exists(sys.executable):
|
||||
# raise RuntimeError('Can not locate Python execute file.')
|
||||
# return sys.executable
|
||||
|
||||
|
||||
def sys_exec(cmd, direct_output=False, output_codec=None):
|
||||
if output_codec is None:
|
||||
if env.is_win:
|
||||
|
@ -276,7 +130,8 @@ def sys_exec(cmd, direct_output=False, output_codec=None):
|
|||
line = line.rstrip('\r\n')
|
||||
|
||||
if direct_output:
|
||||
cc.o((cc.CR_GRAY, line), end='\n')
|
||||
# cc.o((cc.CR_GRAY, line), end='\n')
|
||||
cc.v(line, end='\n')
|
||||
|
||||
output.append(line)
|
||||
|
||||
|
@ -286,5 +141,4 @@ def sys_exec(cmd, direct_output=False, output_codec=None):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# test()
|
||||
pass
|
||||
|
|
|
@ -3,13 +3,11 @@
|
|||
import os
|
||||
import sys
|
||||
import time
|
||||
import stat
|
||||
from core.env import env
|
||||
import core.colorconsole as cc
|
||||
import core.utils as utils
|
||||
|
||||
WIN_CORE_SERVICE_NAME = 'EOM Teleport Core Service'
|
||||
WIN_WEB_SERVICE_NAME = 'EOM Teleport Web Service'
|
||||
|
||||
|
||||
class InstallerBase:
|
||||
def __init__(self):
|
||||
|
@ -39,14 +37,15 @@ class InstallerBase:
|
|||
except FileNotFoundError:
|
||||
raise RuntimeError('Cannot detect installer version.')
|
||||
|
||||
def init(self):
|
||||
def _init(self):
|
||||
_width = 79
|
||||
cc.v('')
|
||||
cc.v('[]{}[]'.format('=' * (_width - 4)))
|
||||
_str = 'Teleport Server Installation'
|
||||
cc.o((cc.CR_VERBOSE, ' | '), (cc.CR_INFO, _str), (cc.CR_VERBOSE, '{}|'.format(' ' * (_width - 5 - len(_str)))))
|
||||
cc.v(' |{}|'.format('=' * (_width - 4)))
|
||||
cc.o((cc.CR_VERBOSE, ' | ver: '), (cc.CR_NORMAL, self._current_ver), (cc.CR_VERBOSE, '{}|'.format(' ' * (_width - 13 - len(self._current_ver)))))
|
||||
cc.o((cc.CR_VERBOSE, ' | ver: '), (cc.CR_NORMAL, self._current_ver),
|
||||
(cc.CR_VERBOSE, '{}|'.format(' ' * (_width - 13 - len(self._current_ver)))))
|
||||
_str = 'author: apexliu@eomsoft.net'
|
||||
cc.v(' | {}{}|'.format(_str, ' ' * (_width - 5 - len(_str))))
|
||||
cc.v('[]{}[]'.format('=' * (_width - 4)))
|
||||
|
@ -54,8 +53,11 @@ class InstallerBase:
|
|||
cc.v('Welcome to install Teleport Server!')
|
||||
cc.v('')
|
||||
# cc.v(' NOTICE: if you want to use the default settings, just press `Enter`...')
|
||||
cc.o((cc.CR_VERBOSE, 'NOTICE: There are a few steps need you enter information or make choice,\n if you want to use the '), (cc.CR_WARN, 'default settings'), (cc.CR_VERBOSE, ', just press `Enter` key.'))
|
||||
cc.o((cc.CR_VERBOSE, ' Otherwise you need enter the '), (cc.CR_NORMAL, 'highlight character'), (cc.CR_VERBOSE, ' to make choice.'))
|
||||
cc.o((cc.CR_VERBOSE,
|
||||
'NOTICE: There are a few steps need you enter information or make choice,\n if you want to use the '),
|
||||
(cc.CR_WARN, 'default settings'), (cc.CR_VERBOSE, ', just press `Enter` key.'))
|
||||
cc.o((cc.CR_VERBOSE, ' Otherwise you need enter the '), (cc.CR_NORMAL, 'highlight character'),
|
||||
(cc.CR_VERBOSE, ' to make choice.'))
|
||||
cc.v('')
|
||||
cc.v('')
|
||||
|
||||
|
@ -65,65 +67,67 @@ class InstallerBase:
|
|||
cc.v('')
|
||||
|
||||
def run(self):
|
||||
self._init()
|
||||
|
||||
if not self._is_installed:
|
||||
self.install()
|
||||
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)])
|
||||
x = self._prompt_choice('What are you wanna to do?',
|
||||
[('upgrade', 2, True), ('uninstall', 0, False), ('quit', 0, False)])
|
||||
x = x.lower()
|
||||
if 'q' == x:
|
||||
return
|
||||
break
|
||||
elif 'u' == x:
|
||||
self.uninstall()
|
||||
return
|
||||
self._do_uninstall()
|
||||
break
|
||||
elif 'g' == x:
|
||||
self._upgrade()
|
||||
return
|
||||
self._do_upgrade()
|
||||
break
|
||||
|
||||
def install(self):
|
||||
def _do_install(self):
|
||||
while True:
|
||||
cc.v('')
|
||||
self._install_path = self._prompt_input('Set installation path', self._def_install_path)
|
||||
_use_always = False
|
||||
_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)])
|
||||
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)])
|
||||
x = x.lower()
|
||||
if 'y' == x:
|
||||
_use_always = True
|
||||
_use_anyway = True
|
||||
break
|
||||
elif 'n' == x:
|
||||
break
|
||||
|
||||
if _use_always:
|
||||
if _use_anyway:
|
||||
break
|
||||
else:
|
||||
break
|
||||
|
||||
self._config_path = os.path.join(self._install_path, 'etc')
|
||||
self._data_path = os.path.join(self._install_path, 'data')
|
||||
self._log_path = os.path.join(self._install_path, 'log')
|
||||
self._fix_path()
|
||||
|
||||
utils.makedirs(self._install_path)
|
||||
utils.make_dirs(self._install_path)
|
||||
self._copy_files()
|
||||
self._install_service()
|
||||
self._start_service()
|
||||
time.sleep(2)
|
||||
self._check_service()
|
||||
|
||||
cc.v('\nall done..')
|
||||
|
||||
def uninstall(self):
|
||||
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)])
|
||||
x = self._prompt_choice('Do you want to keep your database and settings?',
|
||||
[('Yes', 0, True), ('No', 0, False)])
|
||||
x = x.lower()
|
||||
if 'y' == x:
|
||||
break
|
||||
|
@ -134,7 +138,8 @@ class InstallerBase:
|
|||
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)])
|
||||
x = self._prompt_choice('Seriously!! Are you sure to remove all data and settings?',
|
||||
[('Yes', 0, False), ('No', 0, True)])
|
||||
x = x.lower()
|
||||
if 'y' == x:
|
||||
break
|
||||
|
@ -147,15 +152,14 @@ class InstallerBase:
|
|||
self._uninstall_service()
|
||||
self._delete_files(_del_settings)
|
||||
|
||||
cc.v('\nall done..')
|
||||
pass
|
||||
|
||||
def _upgrade(self):
|
||||
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)])
|
||||
x = self._prompt_choice(
|
||||
'The same version `{}` installed, are you sure to overwrite?'.format(self._current_ver),
|
||||
[('Yes', 0, False), ('No', 0, True)])
|
||||
x = x.lower()
|
||||
if 'y' == x:
|
||||
break
|
||||
|
@ -164,7 +168,9 @@ class InstallerBase:
|
|||
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)])
|
||||
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)])
|
||||
x = x.lower()
|
||||
if 'y' == x:
|
||||
break
|
||||
|
@ -173,7 +179,9 @@ class InstallerBase:
|
|||
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)])
|
||||
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)])
|
||||
x = x.lower()
|
||||
if 'y' == x:
|
||||
break
|
||||
|
@ -182,7 +190,8 @@ class InstallerBase:
|
|||
|
||||
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 = 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 'y' == x:
|
||||
break
|
||||
|
@ -200,8 +209,6 @@ class InstallerBase:
|
|||
time.sleep(2)
|
||||
self._check_service()
|
||||
|
||||
cc.v('All done.')
|
||||
|
||||
@staticmethod
|
||||
def _prompt_choice(message, choices):
|
||||
cc.v('{} ['.format(message), end='')
|
||||
|
@ -275,7 +282,7 @@ class InstallerBase:
|
|||
return 0
|
||||
|
||||
def _check_installation(self):
|
||||
pass
|
||||
raise RuntimeError('`check_installation` not implement.')
|
||||
|
||||
def _check_installation_ver(self):
|
||||
if not self._is_installed:
|
||||
|
@ -298,76 +305,113 @@ class InstallerBase:
|
|||
cc.e('[failed]')
|
||||
cc.e(' the installation maybe broken')
|
||||
|
||||
def _fix_path(self):
|
||||
raise RuntimeError('`_fix_path` not implement.')
|
||||
|
||||
def _copy_files(self):
|
||||
pass
|
||||
raise RuntimeError('`copy_files` not implement.')
|
||||
|
||||
def _delete_files(self, del_settings):
|
||||
pass
|
||||
raise RuntimeError('`delete_files` not implement.')
|
||||
|
||||
def _install_service(self):
|
||||
pass
|
||||
raise RuntimeError('`install_service` not implement.')
|
||||
|
||||
def _start_service(self):
|
||||
pass
|
||||
raise RuntimeError('`start_service` not implement.')
|
||||
|
||||
def _stop_service(self):
|
||||
pass
|
||||
raise RuntimeError('`stop_service` not implement.')
|
||||
|
||||
def _uninstall_service(self):
|
||||
pass
|
||||
raise RuntimeError('`uninstall_service` not implement.')
|
||||
|
||||
def _check_service(self):
|
||||
pass
|
||||
raise RuntimeError('`check_service` not implement.')
|
||||
|
||||
|
||||
class InstallerWin(InstallerBase):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._core_service_name = 'Teleport Core Service'
|
||||
self._web_service_name = 'Teleport Web Service'
|
||||
self._old_core_service_name = 'EOM Teleport Core Service'
|
||||
self._old_web_service_name = 'EOM Teleport Web Service'
|
||||
|
||||
self._def_install_path = r'{}\teleport-server'.format(os.environ['SystemDrive'])
|
||||
|
||||
def _get_service_exec(self, service_name):
|
||||
_err, _ = utils.sys_exec(r'sc query "{}"'.format(service_name))
|
||||
if 1060 == _err:
|
||||
return None
|
||||
else:
|
||||
_err, _o = utils.sys_exec(r'sc qc "{}"'.format(service_name))
|
||||
if _err != 0:
|
||||
raise RuntimeError('Can not get execute file path of service `{}`.'.format(service_name))
|
||||
for i in _o:
|
||||
_x = i.split(':', 1)
|
||||
if 'BINARY_PATH_NAME' == _x[0].strip():
|
||||
_path = _x[1].strip()
|
||||
return _path
|
||||
|
||||
return None
|
||||
|
||||
def _check_installation(self):
|
||||
cc.o(' - check local installation ... ', end='')
|
||||
_err, _ = utils.sys_exec(r'sc query "{}"'.format(WIN_CORE_SERVICE_NAME))
|
||||
if 1060 == _err:
|
||||
# core service not install
|
||||
pass
|
||||
else:
|
||||
self._is_installed = True
|
||||
_err, _o = utils.sys_exec(r'sc qc "{}"'.format(WIN_CORE_SERVICE_NAME))
|
||||
if _err != 0:
|
||||
raise RuntimeError('Can not get core service installation information.')
|
||||
for i in _o:
|
||||
_x = i.split(':', 1)
|
||||
if 'BINARY_PATH_NAME' == _x[0].strip():
|
||||
_path = _x[1].strip()
|
||||
self._install_path = os.path.abspath(os.path.join(os.path.dirname(_path), '..'))
|
||||
break
|
||||
|
||||
_err, _ = utils.sys_exec(r'sc query "{}"'.format(WIN_WEB_SERVICE_NAME))
|
||||
if 1060 == _err:
|
||||
# web service not install.
|
||||
pass
|
||||
else:
|
||||
self._is_installed = True
|
||||
_err, _o = utils.sys_exec(r'sc qc "{}"'.format(WIN_WEB_SERVICE_NAME))
|
||||
if _err != 0:
|
||||
raise RuntimeError('Can not get web service installation information.')
|
||||
for i in _o:
|
||||
_x = i.split(':', 1)
|
||||
if 'BINARY_PATH_NAME' == _x[0].strip():
|
||||
_path = _x[1].strip()
|
||||
self._install_path = os.path.abspath(os.path.join(os.path.dirname(_path), '..'))
|
||||
break
|
||||
_check_service_name = [self._old_core_service_name, self._old_web_service_name, self._core_service_name,
|
||||
self._web_service_name]
|
||||
for _service_name in _check_service_name:
|
||||
_exec_file = self._get_service_exec(_service_name)
|
||||
if _exec_file is not None:
|
||||
self._is_installed = True
|
||||
self._install_path = os.path.abspath(os.path.join(os.path.dirname(_exec_file), '..'))
|
||||
break
|
||||
|
||||
# _err, _ = utils.sys_exec(r'sc query "{}"'.format(WIN_CORE_SERVICE_NAME))
|
||||
# if 1060 == _err:
|
||||
# # core service not install
|
||||
# pass
|
||||
# else:
|
||||
# self._is_installed = True
|
||||
# _err, _o = utils.sys_exec(r'sc qc "{}"'.format(WIN_CORE_SERVICE_NAME))
|
||||
# if _err != 0:
|
||||
# raise RuntimeError('Can not get core service installation information.')
|
||||
# for i in _o:
|
||||
# _x = i.split(':', 1)
|
||||
# if 'BINARY_PATH_NAME' == _x[0].strip():
|
||||
# _path = _x[1].strip()
|
||||
# self._install_path = os.path.abspath(os.path.join(os.path.dirname(_path), '..'))
|
||||
# break
|
||||
#
|
||||
# _err, _ = utils.sys_exec(r'sc query "{}"'.format(WIN_WEB_SERVICE_NAME))
|
||||
# if 1060 == _err:
|
||||
# # web service not install.
|
||||
# pass
|
||||
# else:
|
||||
# self._is_installed = True
|
||||
# _err, _o = utils.sys_exec(r'sc qc "{}"'.format(WIN_WEB_SERVICE_NAME))
|
||||
# if _err != 0:
|
||||
# raise RuntimeError('Can not get web service installation information.')
|
||||
# for i in _o:
|
||||
# _x = i.split(':', 1)
|
||||
# if 'BINARY_PATH_NAME' == _x[0].strip():
|
||||
# _path = _x[1].strip()
|
||||
# self._install_path = os.path.abspath(os.path.join(os.path.dirname(_path), '..'))
|
||||
# break
|
||||
|
||||
if self._is_installed:
|
||||
cc.i('[exists]')
|
||||
self._config_path = os.path.join(self._install_path, 'etc')
|
||||
self._data_path = os.path.join(self._install_path, 'data')
|
||||
self._log_path = os.path.join(self._install_path, 'log')
|
||||
self._fix_path()
|
||||
else:
|
||||
cc.i('[not exists]')
|
||||
return
|
||||
|
||||
def _fix_path(self):
|
||||
self._config_path = os.path.join(self._install_path, 'etc')
|
||||
self._data_path = os.path.join(self._install_path, 'data')
|
||||
self._log_path = os.path.join(self._install_path, 'log')
|
||||
|
||||
def _copy_files(self):
|
||||
utils.copy_ex(os.path.join(env.src_path, 'bin'), os.path.join(self._install_path, 'bin'))
|
||||
utils.copy_ex(os.path.join(env.src_path, 'www'), os.path.join(self._install_path, 'www'))
|
||||
|
@ -409,7 +453,7 @@ class InstallerWin(InstallerBase):
|
|||
|
||||
def _start_service(self):
|
||||
cc.o(' - start teleport core service ... ', end='')
|
||||
_err, _o = utils.sys_exec(r'sc start "{}"'.format(WIN_CORE_SERVICE_NAME))
|
||||
_err, _o = utils.sys_exec(r'sc start "{}"'.format(self._core_service_name))
|
||||
# print('start core', _err, _o)
|
||||
if _err == 0:
|
||||
cc.i('[done]')
|
||||
|
@ -418,7 +462,7 @@ class InstallerWin(InstallerBase):
|
|||
raise RuntimeError('Can not start core service.')
|
||||
|
||||
cc.o(' - start teleport web service ...', end='')
|
||||
_err, _o = utils.sys_exec(r'sc start "{}"'.format(WIN_WEB_SERVICE_NAME))
|
||||
_err, _o = utils.sys_exec(r'sc start "{}"'.format(self._web_service_name))
|
||||
# print('start web', _err, _o)
|
||||
if _err == 0:
|
||||
cc.i('[done]')
|
||||
|
@ -428,26 +472,26 @@ class InstallerWin(InstallerBase):
|
|||
|
||||
def _stop_service(self):
|
||||
cc.o(' - stop teleport core service ... ', end='')
|
||||
_err, _o = utils.sys_exec(r'sc stop "{}"'.format(WIN_CORE_SERVICE_NAME))
|
||||
_err, _o = utils.sys_exec(r'sc stop "{}"'.format(self._core_service_name))
|
||||
# print('stop core', _err, _o)
|
||||
if _err == 1060 or _err == 1062 or _err == 0:
|
||||
cc.i('[done]')
|
||||
else:
|
||||
cc.e('[failed]')
|
||||
raise RuntimeError('Can not stop core service.')
|
||||
raise RuntimeError('can not stop core service.')
|
||||
|
||||
cc.o(' - stop teleport web service ... ', end='')
|
||||
_err, _o = utils.sys_exec(r'sc stop "{}"'.format(WIN_WEB_SERVICE_NAME))
|
||||
_err, _o = utils.sys_exec(r'sc stop "{}"'.format(self._web_service_name))
|
||||
# print('stop web', _err, _o)
|
||||
if _err == 1060 or _err == 1062 or _err == 0:
|
||||
cc.i('[done]')
|
||||
else:
|
||||
cc.e('[failed]')
|
||||
raise RuntimeError('Can not stop web service.')
|
||||
raise RuntimeError('can not stop web service.')
|
||||
|
||||
def _uninstall_service(self):
|
||||
cc.o(' - delete teleport core service ... ', end='')
|
||||
_err, _o = utils.sys_exec(r'sc delete "{}"'.format(WIN_CORE_SERVICE_NAME))
|
||||
_err, _o = utils.sys_exec(r'sc delete "{}"'.format(self._core_service_name))
|
||||
# print('del core', _err, _o)
|
||||
if _err == 1060 or _err == 0:
|
||||
cc.i('[done]')
|
||||
|
@ -456,7 +500,7 @@ class InstallerWin(InstallerBase):
|
|||
raise RuntimeError('Can not uninstall core service.')
|
||||
|
||||
cc.o(' - delete teleport web service ... ', end='')
|
||||
_err, _o = utils.sys_exec(r'sc delete "{}"'.format(WIN_WEB_SERVICE_NAME))
|
||||
_err, _o = utils.sys_exec(r'sc delete "{}"'.format(self._web_service_name))
|
||||
# print('del web', _err, _o)
|
||||
if _err == 1060 or _err == 0:
|
||||
cc.i('[done]')
|
||||
|
@ -466,7 +510,7 @@ class InstallerWin(InstallerBase):
|
|||
|
||||
def _check_service(self):
|
||||
cc.o(' - check teleport core service status ... ', end='')
|
||||
_err, _o = utils.sys_exec(r'sc query "{}"'.format(WIN_CORE_SERVICE_NAME))
|
||||
_err, _o = utils.sys_exec(r'sc query "{}"'.format(self._core_service_name))
|
||||
# print('chk core', _err, _o)
|
||||
if _err == 1060 or _err == 0:
|
||||
cc.i('[running]')
|
||||
|
@ -474,7 +518,7 @@ class InstallerWin(InstallerBase):
|
|||
cc.e('[not running]')
|
||||
|
||||
cc.o(' - check teleport web service status ... ', end='')
|
||||
_err, _o = utils.sys_exec(r'sc delete "{}"'.format(WIN_WEB_SERVICE_NAME))
|
||||
_err, _o = utils.sys_exec(r'sc delete "{}"'.format(self._web_service_name))
|
||||
# print('chk web', _err, _o)
|
||||
if _err == 1060 or _err == 0:
|
||||
cc.i('[running]')
|
||||
|
@ -485,196 +529,114 @@ class InstallerWin(InstallerBase):
|
|||
class InstallerLinux(InstallerBase):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._is_installed = False
|
||||
self._install_path = ''
|
||||
self._def_install_path = '/usr/local/teleport'
|
||||
|
||||
if env.is_win:
|
||||
self._def_install_path = r'{}\teleport-server'.format(os.environ['SystemDrive'])
|
||||
self._check_installation = self._check_installation_win
|
||||
self._copy_files = self._copy_files_win
|
||||
self._install_service = self._install_service_win
|
||||
self._stop_service = self._stop_service_win
|
||||
self._delete_service = self._delete_service_win
|
||||
else:
|
||||
self._def_install_path = r'/usr/local/eom/teleport'
|
||||
self._check_installation = self._check_installation_linux
|
||||
self._copy_files = self._copy_files_linux
|
||||
self._install_service = self._install_service_linux
|
||||
self._stop_service = self._stop_service_linux
|
||||
self._delete_service = self._delete_service_linux
|
||||
|
||||
self._check_installation()
|
||||
|
||||
def init(self):
|
||||
pass
|
||||
# check if teleport server installed or not.
|
||||
|
||||
def run(self):
|
||||
cc.v('')
|
||||
cc.v('Welcome to install Teleport Server for Windows!')
|
||||
if not self._is_installed:
|
||||
self.install()
|
||||
else:
|
||||
cc.v('')
|
||||
cc.v('Found teleport server already installed, now what are you want to do?')
|
||||
while True:
|
||||
x = self._prompt_choice('Please choice', [('Upgrade', 2, True), ('Uninstall', 0, False), ('Quit', 0, False)])
|
||||
x = x.lower()
|
||||
if 'q' == x:
|
||||
return
|
||||
elif 'u' == x:
|
||||
self.uninstall()
|
||||
return
|
||||
elif 'g' == x:
|
||||
self._upgrade()
|
||||
return
|
||||
|
||||
def install(self):
|
||||
cc.n('Notice: if you want to use the default settings, just press `Enter`...')
|
||||
cc.v('')
|
||||
self._install_path = self._prompt_input('Set installation path', self._def_install_path)
|
||||
|
||||
utils.makedirs(self._install_path)
|
||||
# self._copy_files()
|
||||
self._install_service()
|
||||
|
||||
pass
|
||||
# if self._check_installation():
|
||||
# self._install()
|
||||
|
||||
def uninstall(self):
|
||||
if not self._is_installed:
|
||||
return
|
||||
|
||||
self._stop_service()
|
||||
self._delete_service()
|
||||
|
||||
cc.e('uninstall not implemented.')
|
||||
pass
|
||||
|
||||
def _upgrade(self):
|
||||
cc.e('upgrade not implemented.')
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def _prompt_choice(message, choices):
|
||||
cc.v('{} ['.format(message), end='')
|
||||
|
||||
def_choice = ''
|
||||
|
||||
# cc.v('(', end='')
|
||||
for i in range(len(choices)):
|
||||
if i > 0:
|
||||
cc.v('/', end='')
|
||||
msg = choices[i][0]
|
||||
idx = choices[i][1]
|
||||
if choices[i][2]:
|
||||
def_choice = msg[idx]
|
||||
cc.w(msg[:idx], end='')
|
||||
cc.n(msg[idx], end='')
|
||||
cc.w(msg[idx + 1:], end='')
|
||||
else:
|
||||
cc.v(msg[:idx], end='')
|
||||
cc.n(msg[idx], end='')
|
||||
cc.v(msg[idx + 1:], end='')
|
||||
|
||||
# cc.v(') ', end='')
|
||||
|
||||
# cc.v('[', end='')
|
||||
|
||||
# cc.w(def_choice, end='')
|
||||
cc.v(']: ', end='')
|
||||
try:
|
||||
x = input().strip()
|
||||
if len(x) == 0:
|
||||
x = def_choice
|
||||
except EOFError:
|
||||
x = def_choice
|
||||
|
||||
return x
|
||||
|
||||
@staticmethod
|
||||
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 _check_installation_win(self):
|
||||
_err, _ = utils.sys_exec(r'sc query "{}"'.format(WIN_CORE_SERVICE_NAME))
|
||||
if 1060 == _err:
|
||||
# core service not install
|
||||
pass
|
||||
else:
|
||||
def _check_installation(self):
|
||||
# old version, the daemon named `eom_ts`.
|
||||
# from 2.0.0.1, the daemon rename to `teleport`.
|
||||
# we must check both.
|
||||
if os.path.exists('/etc/init.d/eom_ts') or os.path.exists('/etc/init.d/teleport'):
|
||||
self._is_installed = True
|
||||
_err, _o = utils.sys_exec(r'sc qc "{}"'.format(WIN_CORE_SERVICE_NAME))
|
||||
if _err != 0:
|
||||
raise RuntimeError('Can not get core service installation information.')
|
||||
for i in _o:
|
||||
_x = i.split(':', 1)
|
||||
if 'BINARY_PATH_NAME' == _x[0].strip():
|
||||
_path = _x[1].strip()
|
||||
self._install_path = os.path.abspath(os.path.join(os.path.dirname(_path), '..'))
|
||||
return
|
||||
self._install_path = '/usr/local/teleport'
|
||||
self._fix_path()
|
||||
|
||||
_err, _ = utils.sys_exec(r'sc query "{}"'.format(WIN_WEB_SERVICE_NAME))
|
||||
if 1060 == _err:
|
||||
# web service not install.
|
||||
pass
|
||||
else:
|
||||
self._is_installed = True
|
||||
_err, _o = utils.sys_exec(r'sc qc "{}"'.format(WIN_WEB_SERVICE_NAME))
|
||||
if _err != 0:
|
||||
raise RuntimeError('Can not get web service installation information.')
|
||||
for i in _o:
|
||||
_x = i.split(':', 1)
|
||||
if 'BINARY_PATH_NAME' == _x[0].strip():
|
||||
_path = _x[1].strip()
|
||||
self._install_path = os.path.abspath(os.path.join(os.path.dirname(_path), '..'))
|
||||
return
|
||||
def _fix_path(self):
|
||||
self._config_path = '/etc/teleport'
|
||||
self._data_path = os.path.join('/var/teleport')
|
||||
self._log_path = os.path.join('/var/log/teleport')
|
||||
|
||||
def _copy_files_win(self):
|
||||
def _copy_files(self):
|
||||
utils.copy_ex(os.path.join(env.src_path, 'bin'), os.path.join(self._install_path, 'bin'))
|
||||
utils.copy_ex(os.path.join(env.src_path, 'www'), os.path.join(self._install_path, 'www'))
|
||||
|
||||
_tmp = os.path.join(self._install_path, 'etc')
|
||||
if not os.path.exists(_tmp):
|
||||
utils.copy_ex(os.path.join(env.src_path, 'etc'), _tmp)
|
||||
if not os.path.exists(self._config_path):
|
||||
utils.copy_ex(os.path.join(env.src_path, 'tmp', 'etc'), self._config_path)
|
||||
|
||||
def _install_service_win(self):
|
||||
_core = os.path.join(self._install_path, 'bin', 'tp_core.exe')
|
||||
_err, _o = utils.sys_exec(r'"{}" -i'.format(_core))
|
||||
if _err == 0:
|
||||
return True
|
||||
elif _err == 1:
|
||||
cc.v('Core service has been installed already.')
|
||||
else:
|
||||
cc.e('Install core service failed. error code: ', _err)
|
||||
return False
|
||||
def _delete_files(self, del_settings):
|
||||
utils.remove(os.path.join(self._install_path, 'bin'))
|
||||
utils.remove(os.path.join(self._install_path, 'www'))
|
||||
|
||||
def _stop_service_win(self):
|
||||
_err, _o = utils.sys_exec(r'sc stop "{}"'.format(WIN_CORE_SERVICE_NAME))
|
||||
if _err == 1060 or _err == 1062 or _err == 0:
|
||||
# 1060 = 服务尚未安装
|
||||
# 1062 = 服务尚未启动
|
||||
# 0 = 操作成功
|
||||
pass
|
||||
else:
|
||||
raise RuntimeError('Can not stop core service.')
|
||||
utils.remove(os.path.join(self._install_path, 'start.sh'))
|
||||
utils.remove(os.path.join(self._install_path, 'stop.sh'))
|
||||
utils.remove(os.path.join(self._install_path, 'status.sh'))
|
||||
|
||||
_err, _o = utils.sys_exec(r'sc stop "{}"'.format(WIN_WEB_SERVICE_NAME))
|
||||
if _err == 1060 or _err == 1062 or _err == 0:
|
||||
pass
|
||||
else:
|
||||
raise RuntimeError('Can not stop web service.')
|
||||
# only remove the installation path when it empty.
|
||||
try:
|
||||
os.rmdir(self._install_path)
|
||||
except OSError:
|
||||
pass # maybe the install path not empty.
|
||||
|
||||
if del_settings:
|
||||
utils.remove(self._data_path)
|
||||
utils.remove(self._config_path)
|
||||
utils.remove(self._log_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/S50teleport')
|
||||
os.symlink('/etc/init.d/teleport', '/etc/rc3.d/S50teleport')
|
||||
os.symlink('/etc/init.d/teleport', '/etc/rc4.d/S50teleport')
|
||||
os.symlink('/etc/init.d/teleport', '/etc/rc5.d/S50teleport')
|
||||
|
||||
def _start_service(self):
|
||||
cc.v('')
|
||||
cc.o('start services...')
|
||||
utils.sys_exec('service teleport start', direct_output=True)
|
||||
# raise RuntimeError('`start_service` not implement.')
|
||||
|
||||
def _stop_service(self):
|
||||
cc.o(' - stop teleport core service ... ', end='')
|
||||
|
||||
# old version, the daemon named `eom_ts`.
|
||||
if os.path.exists('/etc/init.d/eom_ts'):
|
||||
utils.sys_exec('/etc/init.d/eom_ts stop')
|
||||
# from 2.0.0.1, the daemon rename to `teleport`.
|
||||
if os.path.exists('/etc/init.d/teleport'):
|
||||
utils.sys_exec('/etc/init.d/teleport stop')
|
||||
|
||||
cc.i('[done]')
|
||||
|
||||
def _uninstall_service(self):
|
||||
# old version, the daemon named `eom_ts`.
|
||||
utils.remove('/etc/init.d/eom_ts')
|
||||
utils.remove('/etc/rc2.d/S50eom_ts')
|
||||
utils.remove('/etc/rc3.d/S50eom_ts')
|
||||
utils.remove('/etc/rc4.d/S50eom_ts')
|
||||
utils.remove('/etc/rc5.d/S50eom_ts')
|
||||
# from 2.0.0.1, the daemon rename to `teleport`.
|
||||
utils.remove('/etc/init.d/teleport')
|
||||
utils.remove('/etc/rc2.d/S50teleport')
|
||||
utils.remove('/etc/rc3.d/S50teleport')
|
||||
utils.remove('/etc/rc4.d/S50teleport')
|
||||
utils.remove('/etc/rc5.d/S50teleport')
|
||||
|
||||
def _check_service(self):
|
||||
cc.v('')
|
||||
cc.o('check services status...')
|
||||
utils.sys_exec('service teleport status', direct_output=True)
|
||||
|
||||
|
||||
def _main():
|
||||
|
@ -688,31 +650,25 @@ def _main():
|
|||
else:
|
||||
raise RuntimeError('Sorry, teleport server does not support this platform yet.')
|
||||
|
||||
_installer.init()
|
||||
|
||||
if len(sys.argv) > 0:
|
||||
_cmd = sys.argv[0].lower()
|
||||
if 'uninstall' == _cmd:
|
||||
_installer.uninstall()
|
||||
return
|
||||
|
||||
_installer.run()
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
_main()
|
||||
cc.i('\n--==[ ALL DONE ]==--\n')
|
||||
return 0
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
return 1
|
||||
except RuntimeError as err:
|
||||
cc.v('')
|
||||
cc.v('')
|
||||
cc.e(err.__str__())
|
||||
cc.v('')
|
||||
return 2
|
||||
except:
|
||||
cc.f('got exception.')
|
||||
|
||||
return 0
|
||||
return 3
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ `id -u` -ne 0 ];then
|
||||
echo ""
|
||||
echo -e "\e[31mPlease run setup with ROOT.\033[0m"
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
PATH_ROOT=$(cd "$(dirname "$0")"; pwd)
|
||||
PATH_TARGET=/usr/local/eom
|
||||
|
||||
"${PATH_ROOT}/data/bin/tp_web" --py "${PATH_ROOT}/script/main.py"
|
||||
exit 0
|
||||
|
||||
|
||||
if [ ! -d "${PATH_TARGET}" ]; then
|
||||
mkdir -p "${PATH_TARGET}"
|
||||
fi
|
||||
|
||||
if [ -f /etc/init.d/eom_ts ]; then
|
||||
service eom_ts stop
|
||||
rm -rf /etc/init.d/eom_ts
|
||||
fi
|
||||
rm -rf /etc/rc2.d/S50eom_ts
|
||||
rm -rf /etc/rc3.d/S50eom_ts
|
||||
rm -rf /etc/rc4.d/S50eom_ts
|
||||
rm -rf /etc/rc5.d/S50eom_ts
|
||||
|
||||
|
||||
if [ -f /etc/init.d/teleport ]; then
|
||||
service teleport stop
|
||||
rm -rf /etc/init.d/teleport
|
||||
fi
|
||||
rm -rf /etc/rc2.d/S50teleport
|
||||
rm -rf /etc/rc3.d/S50teleport
|
||||
rm -rf /etc/rc4.d/S50teleport
|
||||
rm -rf /etc/rc5.d/S50teleport
|
||||
|
||||
sleep 1
|
||||
echo ""
|
||||
echo "Installing EOM Teleport Server..."
|
||||
|
||||
cd "${PATH_TARGET}"
|
||||
tar -zxvf "${PATH_ROOT}/data/teleport.tar.gz" >/dev/null
|
||||
cd "${PATH_ROOT}"
|
||||
|
||||
if [ ! -d "${PATH_TARGET}/teleport/etc" ]; then
|
||||
cp -r "${PATH_TARGET}/teleport/tmp/etc" "${PATH_TARGET}/teleport/etc"
|
||||
else
|
||||
if [ ! -f "${PATH_TARGET}/teleport/etc/web.ini" ]; then
|
||||
cp "${PATH_TARGET}/teleport/tmp/etc/web.ini" "${PATH_TARGET}/teleport/etc/web.ini"
|
||||
fi
|
||||
if [ ! -f "${PATH_TARGET}/teleport/etc/core.ini" ]; then
|
||||
cp "${PATH_TARGET}/teleport/tmp/etc/core.ini" "${PATH_TARGET}/teleport/etc/core.ini"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -d "${PATH_TARGET}/teleport/data" ]; then
|
||||
cp -r "${PATH_TARGET}/teleport/tmp/data" "${PATH_TARGET}/teleport/data"
|
||||
fi
|
||||
|
||||
chmod +x "${PATH_TARGET}/teleport/bin/tp_core"
|
||||
chmod +x "${PATH_TARGET}/teleport/bin/tp_web"
|
||||
|
||||
echo "Generate daemon startup script..."
|
||||
|
||||
cp "${PATH_ROOT}/data/start.sh" "${PATH_TARGET}/teleport/."
|
||||
chmod +x "${PATH_TARGET}/teleport/start.sh"
|
||||
cp "${PATH_ROOT}/data/stop.sh" "${PATH_TARGET}/teleport/."
|
||||
chmod +x "${PATH_TARGET}/teleport/stop.sh"
|
||||
cp "${PATH_ROOT}/data/status.sh" "${PATH_TARGET}/teleport/."
|
||||
chmod +x "${PATH_TARGET}/teleport/status.sh"
|
||||
|
||||
cp "${PATH_ROOT}/data/daemon" /etc/init.d/teleport
|
||||
chmod +x /etc/init.d/teleport
|
||||
|
||||
ln -s /etc/init.d/teleport /etc/rc2.d/S50teleport
|
||||
ln -s /etc/init.d/teleport /etc/rc3.d/S50teleport
|
||||
ln -s /etc/init.d/teleport /etc/rc4.d/S50teleport
|
||||
ln -s /etc/init.d/teleport /etc/rc5.d/S50teleport
|
||||
|
||||
# Upgrade database...
|
||||
"${PATH_TARGET}/teleport/bin/tp_web" --py "${PATH_TARGET}/teleport/www/teleport/app/eom_upgrade.py"
|
||||
|
||||
echo ""
|
||||
echo "Start teleport server..."
|
||||
echo ""
|
||||
service teleport start
|
||||
echo ""
|
||||
sleep 1
|
||||
echo "Check teleport server status..."
|
||||
echo ""
|
||||
service teleport status
|
||||
echo ""
|
||||
|
||||
|
||||
echo ""
|
||||
echo -e "\e[32mInstallation done.\033[0m"
|
||||
echo ""
|
|
@ -10,89 +10,6 @@ import time
|
|||
from . import colorconsole as cc
|
||||
from .env import env
|
||||
|
||||
# from .configs import cfg
|
||||
|
||||
# try:
|
||||
# CONFIG_FILE = os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..')), 'config.ini')
|
||||
# if not cfg.init(CONFIG_FILE):
|
||||
# sys.exit(1)
|
||||
# except:
|
||||
# cc.e('can not load configuration.\n\nplease copy `config.ini.in` into `config.ini` and modify it to fit your condition and try again.')
|
||||
# sys.exit(1)
|
||||
|
||||
|
||||
# THIS_PATH = os.path.abspath(os.path.dirname(__file__))
|
||||
# ROOT_PATH = os.path.abspath(os.path.join(THIS_PATH, '..'))
|
||||
|
||||
|
||||
# def _check_download_file(file_name):
|
||||
# if env.is_win:
|
||||
# # use 7z to test integrity of downloaded
|
||||
# ret, output = sys_exec('"{}" t "{}"'.format(env.zip7, file_name), False)
|
||||
# if 'Everything is Ok' in output:
|
||||
# return True
|
||||
# else:
|
||||
# cc.e('fixme.')
|
||||
# return False
|
||||
#
|
||||
#
|
||||
# def download_file(desc, url, target_path, file_name):
|
||||
# cc.n('download {} ... '.format(desc), end='')
|
||||
#
|
||||
# local_file_name = os.path.join(target_path, file_name)
|
||||
# if os.path.exists(local_file_name):
|
||||
# if not _check_download_file(local_file_name):
|
||||
# cc.w('already exists but broken, download it again...')
|
||||
# else:
|
||||
# cc.w('already exists, skip.')
|
||||
# return True
|
||||
#
|
||||
# cc.v('')
|
||||
# # 因为下载过程会在命令行显示进度,所以不能使用subprocess.Popen()的方式捕获输出,会很难看!
|
||||
# if env.is_win:
|
||||
# cmd = '""{}" --no-check-certificate {} -O "{}""'.format(env.wget, url, local_file_name)
|
||||
# os.system(cmd)
|
||||
# elif env.is_linux:
|
||||
# os.system('wget --no-check-certificate {} -O "{}"'.format(url, local_file_name))
|
||||
# else:
|
||||
# return False
|
||||
#
|
||||
# if not os.path.exists(local_file_name) or not _check_download_file(local_file_name):
|
||||
# cc.e('downloading {} from {} failed.'.format(desc, url))
|
||||
# return False
|
||||
#
|
||||
# return True
|
||||
#
|
||||
|
||||
# def extension_suffixes():
|
||||
# # imp.get_suffixes()
|
||||
# # 返回3元组列表(suffix, mode, type), 获得特殊模块的描述
|
||||
# # .suffix为文件后缀名;
|
||||
# # mode为打开文件模式;
|
||||
# # type为文件类型, 1代表PY_SOURCE, 2代表PY_COMPILED, 3代表C_EXTENSION
|
||||
#
|
||||
# EXTENSION_SUFFIXES = list()
|
||||
# if cfg.is_py2:
|
||||
# suf = imp.get_suffixes()
|
||||
# for s in suf:
|
||||
# if s[2] == 3:
|
||||
# EXTENSION_SUFFIXES.append(s[0])
|
||||
# else:
|
||||
# EXTENSION_SUFFIXES = importlib.machinery.EXTENSION_SUFFIXES
|
||||
#
|
||||
# if cfg.dist == 'windows':
|
||||
# if '.dll' not in EXTENSION_SUFFIXES:
|
||||
# EXTENSION_SUFFIXES.append('.dll')
|
||||
#
|
||||
# elif cfg.dist == 'linux':
|
||||
# if '.so' not in EXTENSION_SUFFIXES:
|
||||
# EXTENSION_SUFFIXES.append('.so')
|
||||
#
|
||||
# elif cfg.dist == 'macos':
|
||||
# raise RuntimeError('not support MacOS now.')
|
||||
#
|
||||
# return EXTENSION_SUFFIXES
|
||||
|
||||
|
||||
def remove(*args):
|
||||
path = os.path.join(*args)
|
||||
|
@ -125,53 +42,28 @@ def remove(*args):
|
|||
cc.i('[done]')
|
||||
|
||||
|
||||
def makedirs(path, exist_ok=True):
|
||||
def make_dirs(path, exist_ok=True):
|
||||
if os.path.exists(path):
|
||||
if not exist_ok:
|
||||
raise RuntimeError('path already exists: %s' % path)
|
||||
raise RuntimeError('already exists [{}].'.format(path))
|
||||
else:
|
||||
return
|
||||
return True
|
||||
|
||||
for i in range(5):
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except:
|
||||
time.sleep(1)
|
||||
pass
|
||||
time.sleep(0.5)
|
||||
|
||||
if not os.path.exists(path):
|
||||
time.sleep(1)
|
||||
time.sleep(0.5)
|
||||
else:
|
||||
break
|
||||
|
||||
if not os.path.exists(path):
|
||||
raise RuntimeError('can not create: %s' % path)
|
||||
|
||||
|
||||
# def copy_file(s_path, t_path, f_name, force=True):
|
||||
# if isinstance(f_name, str):
|
||||
# f_from = f_name
|
||||
# f_to = f_name
|
||||
# elif isinstance(f_name, tuple):
|
||||
# f_from = f_name[0]
|
||||
# f_to = f_name[1]
|
||||
# else:
|
||||
# raise RuntimeError('utils.copy_file() got invalid param.')
|
||||
#
|
||||
# s = os.path.join(s_path, f_from)
|
||||
# t = os.path.join(t_path, f_to)
|
||||
# if os.path.exists(t):
|
||||
# if force:
|
||||
# cc.v(' an exists version found, clean up...')
|
||||
# remove(t)
|
||||
# else:
|
||||
# cc.w(' an exists version found, skip copy.')
|
||||
# return
|
||||
#
|
||||
# if not os.path.exists(t_path):
|
||||
# makedirs(t_path)
|
||||
# cc.v('copy [%s]\n -> [%s]' % (s, t))
|
||||
# shutil.copy(s, t)
|
||||
if os.path.exists(path):
|
||||
return True
|
||||
else:
|
||||
raise RuntimeError('can not create path [{}].'.format(path))
|
||||
|
||||
|
||||
def copy_ex(s_path, t_path, item_name=None, force=True):
|
||||
|
@ -208,33 +100,6 @@ def copy_ex(s_path, t_path, item_name=None, force=True):
|
|||
shutil.copy(s, t)
|
||||
|
||||
|
||||
# def update_file(s_path, t_path, f_name):
|
||||
# if isinstance(f_name, str):
|
||||
# f_from = f_name
|
||||
# f_to = f_name
|
||||
# elif isinstance(f_name, tuple):
|
||||
# f_from = f_name[0]
|
||||
# f_to = f_name[1]
|
||||
# else:
|
||||
# raise RuntimeError('utils.update_file() got invalid param.')
|
||||
#
|
||||
# s = os.path.join(s_path, f_from)
|
||||
# t = os.path.join(t_path, f_to)
|
||||
# if not os.path.exists(s):
|
||||
# cc.w('try update file `%s` but not exists, skip.' % f_from)
|
||||
# return
|
||||
#
|
||||
# # TODO: check file MD5 and update time.
|
||||
#
|
||||
# if os.path.exists(t):
|
||||
# remove(t)
|
||||
#
|
||||
# if not os.path.exists(t_path):
|
||||
# makedirs(t_path)
|
||||
# cc.v('update [%s]\n -> [%s]' % (s, t))
|
||||
# shutil.copy(os.path.join(s_path, f_from), t)
|
||||
|
||||
|
||||
def ensure_file_exists(filename):
|
||||
if not os.path.exists(filename):
|
||||
raise RuntimeError('file not exists: {}'.format(filename))
|
||||
|
@ -242,16 +107,6 @@ def ensure_file_exists(filename):
|
|||
raise RuntimeError('path exists but not a file: {}'.format(filename))
|
||||
|
||||
|
||||
# def root_path():
|
||||
# return os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
|
||||
|
||||
|
||||
# def python_exec():
|
||||
# if not os.path.exists(sys.executable):
|
||||
# raise RuntimeError('Can not locate Python execute file.')
|
||||
# return sys.executable
|
||||
|
||||
|
||||
def sys_exec(cmd, direct_output=False, output_codec=None):
|
||||
if output_codec is None:
|
||||
if env.is_win:
|
||||
|
@ -286,5 +141,4 @@ def sys_exec(cmd, direct_output=False, output_codec=None):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# test()
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue