2019-07-09 02:58:05 +00:00
|
|
|
#!/bin/bash
|
2019-07-09 03:17:50 +00:00
|
|
|
SHELL_PREFIX="[OneKeyTera]"
|
2019-07-09 02:58:05 +00:00
|
|
|
# Shell Base Script
|
|
|
|
set -e
|
|
|
|
|
|
|
|
c_red="\033[38;5;1m"
|
|
|
|
c_blue="\033[38;5;4m"
|
|
|
|
c_green="\033[38;5;2m"
|
|
|
|
c_reset="\033[0m"
|
|
|
|
c_yellow="\033[38;5;3m"
|
|
|
|
|
2019-07-09 16:06:54 +00:00
|
|
|
c_prefix="${c_green}${SHELL_PREFIX}>>${c_reset}"
|
2019-07-09 02:58:05 +00:00
|
|
|
|
|
|
|
dateStr() {
|
|
|
|
echo -e "[$(date '+%H:%M:%S')]"
|
|
|
|
}
|
|
|
|
|
|
|
|
info() {
|
2019-07-09 16:06:54 +00:00
|
|
|
echo -e "$(dateStr)${c_prefix} ${*}"
|
2019-07-09 02:58:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
warn() {
|
2019-07-09 16:06:54 +00:00
|
|
|
echo -e "$(dateStr)${c_prefix} ${c_yellow}${*}${c_reset}"
|
2019-07-09 02:58:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
error() {
|
2019-07-09 16:06:54 +00:00
|
|
|
echo -e "$(dateStr)${c_prefix} ${c_red}${*}${c_reset}"
|
2019-07-09 02:58:05 +00:00
|
|
|
}
|
|
|
|
#====================
|
|
|
|
|
2019-06-14 06:52:08 +00:00
|
|
|
ROOT=$(pwd)
|
|
|
|
clear
|
|
|
|
set -e
|
2019-07-09 02:58:05 +00:00
|
|
|
info "=============================="
|
|
|
|
info " 欢迎使用 Tera 一键挖矿系统"
|
|
|
|
info ""
|
|
|
|
info " by MiaoWoo"
|
|
|
|
info ""
|
|
|
|
info " 版本 v1.1"
|
|
|
|
info "=============================="
|
2019-07-09 16:39:44 +00:00
|
|
|
|
2019-06-14 07:21:53 +00:00
|
|
|
if [[ ! -f "OneKeyTera.sh" || ! -f ".lock" || $(cat .lock) -lt $(($(date +%s) - 86400)) ]]; then
|
2019-07-09 02:58:05 +00:00
|
|
|
info "更新脚本..."
|
2019-06-14 07:03:31 +00:00
|
|
|
curl -o OneKeyTera.sh https://git.yumc.pw/cloud/script/raw/master/tera/run.sh
|
2019-07-09 16:39:44 +00:00
|
|
|
echo $(date +%s) > .lock
|
2019-07-09 16:41:27 +00:00
|
|
|
bash OneKeyTera.sh
|
2019-07-09 16:18:34 +00:00
|
|
|
exit 0
|
2019-06-14 07:03:31 +00:00
|
|
|
fi
|
2019-07-09 16:39:44 +00:00
|
|
|
|
2019-07-09 02:58:05 +00:00
|
|
|
info "程序将在 3秒 后运行... Ctrl + C 取消运行..."
|
2019-06-14 07:21:53 +00:00
|
|
|
sleep 2
|
2019-07-09 16:06:54 +00:00
|
|
|
info "开始检测运行环境..."
|
2019-07-09 16:54:41 +00:00
|
|
|
if [[ ! -d node ]]; then
|
|
|
|
warn "未安装NodeJS 开始下载二进制包 请稍候..."
|
|
|
|
info "下载过程根据您的网络状况可能需要 1-10 分钟..."
|
|
|
|
curl -o node.zip https://nodejs.org/dist/v10.16.0/node-v10.16.0-win-x64.zip
|
|
|
|
info "下载完成 开始解压Node环境 请稍候..."
|
|
|
|
unzip -q node.zip
|
|
|
|
mv node-v10.16.0-win-x64 node
|
|
|
|
rm -rf node.zip
|
|
|
|
fi
|
|
|
|
NODE=$(pwd)/node/node.exe
|
|
|
|
NPM=$(pwd)/node/npm
|
|
|
|
if [[ ! -f "${NODE}" ]]; then
|
|
|
|
error "Node 安装检测未通过 请检查网络是否正常 或删除 node 目录 重新运行本脚本..."
|
|
|
|
read
|
|
|
|
exit 1
|
2019-06-14 06:52:08 +00:00
|
|
|
fi
|
|
|
|
echo "NodeJS 二进制版本: $(${NODE} -v)"
|
|
|
|
if [[ ! -d tera ]]; then
|
2019-07-09 02:58:05 +00:00
|
|
|
warn "未找到 Tera 源代码 开始Clone项目 请稍候..."
|
2019-07-09 16:16:03 +00:00
|
|
|
info "下载过程根据您的网络状况可能需要 1-5 分钟..."
|
2019-07-09 15:55:52 +00:00
|
|
|
git clone https://git.yumc.pw/502647092/tera.git
|
2019-06-14 06:52:08 +00:00
|
|
|
fi
|
|
|
|
TERA_ROOT=${ROOT}/tera/Source
|
2019-06-20 07:38:16 +00:00
|
|
|
cd "${TERA_ROOT}"
|
2019-06-14 06:52:08 +00:00
|
|
|
if [[ ! -d node_modules ]]; then
|
2019-07-09 02:58:05 +00:00
|
|
|
warn "未安装依赖 开始安装 请稍候..."
|
2019-07-09 16:16:03 +00:00
|
|
|
info "设置镜像源为 https://registry.npm.taobao.org"
|
|
|
|
"${NPM}" config set registry https://registry.npm.taobao.org
|
|
|
|
info "安装过程根据您的网络状况可能需要 1-5 分钟..."
|
2019-06-20 07:38:16 +00:00
|
|
|
"${NPM}" install
|
2019-06-14 06:52:08 +00:00
|
|
|
fi
|
|
|
|
|
2019-07-09 02:58:05 +00:00
|
|
|
if [[ ! -f "${TERA_ROOT}/node_modules/secp256k1/build/Release/secp256k1.node" ]]; then
|
|
|
|
warn "未检测到 secp256k1.node 模块 开始下载 Windows 版本..."
|
2019-07-09 16:06:54 +00:00
|
|
|
mkdir -p "${TERA_ROOT}/node_modules/secp256k1/build/Release"
|
2019-07-09 02:58:05 +00:00
|
|
|
curl -o "${TERA_ROOT}/node_modules/secp256k1/build/Release/secp256k1.node" https://git.yumc.pw/cloud/script/raw/master/tera/secp256k1.node
|
|
|
|
fi
|
2019-06-14 06:52:08 +00:00
|
|
|
|
2019-07-09 15:55:52 +00:00
|
|
|
# 申请公网IP端口
|
|
|
|
info "开始申请公网IP端口 请稍候..."
|
|
|
|
warn "公网IP端口自动映射功能开发中..."
|
2019-06-14 06:52:08 +00:00
|
|
|
# FRP_SCRIPT=${TERA_ROOT}/frp.js
|
|
|
|
# if [[ ! -f ${FRP_SCRIPT} ]]; then
|
|
|
|
# echo "开始下载FRP脚本 请稍候..."
|
|
|
|
# #curl -o ${FRP_SCRIPT} https://git.yumc.pw/cloud/script/raw/master/tera/frp.js
|
|
|
|
# fi
|
|
|
|
# ${NODE} ${FRP_SCRIPT}
|
|
|
|
|
|
|
|
# 初始化配置
|
2019-07-09 02:58:05 +00:00
|
|
|
info "初始化配置参数..."
|
2019-06-14 06:52:08 +00:00
|
|
|
INIT_SCRIPT=${TERA_ROOT}/init.js
|
|
|
|
if [[ ! -f ${INIT_SCRIPT} ]]; then
|
2019-07-09 02:58:05 +00:00
|
|
|
warn "开始下载初始化脚本 请稍候..."
|
2019-06-14 06:52:08 +00:00
|
|
|
curl -o ${INIT_SCRIPT} https://git.yumc.pw/cloud/script/raw/master/tera/init.js
|
|
|
|
fi
|
2019-06-20 07:38:16 +00:00
|
|
|
"${NODE}" ${INIT_SCRIPT}
|
2019-06-14 06:52:08 +00:00
|
|
|
|
|
|
|
# 设置NTP服务器
|
|
|
|
TERA_NTP_SERVER=${TERA_NTP_SERVER:-ntp1.aliyun.com}
|
2019-07-09 02:58:05 +00:00
|
|
|
info "设置NTP服务器为阿里云地址 ${TERA_NTP_SERVER}"
|
2019-06-14 06:52:08 +00:00
|
|
|
sed -i s@pool.ntp.org@${TERA_NTP_SERVER}@g ${TERA_ROOT}/core/library.js
|
|
|
|
|
2019-07-09 16:45:13 +00:00
|
|
|
info "开始检测是否存在遗留Node进程..."
|
2019-07-09 16:39:44 +00:00
|
|
|
NODE_RUNNING=$(ps -ef | grep node | awk '{print $2}')
|
|
|
|
if [[ -n "${NODE_RUNNING}" ]]; then
|
|
|
|
warn "检测到已经在运行的 node 进程 PID 为 ${NODE_RUNNING} ..."
|
2019-07-09 16:49:06 +00:00
|
|
|
warn "程序将在 5 秒 后自动关闭所有的 node 进程 ..."
|
|
|
|
warn "终止执行 请按 Ctrl + C 退出 ..."
|
2019-07-09 16:39:44 +00:00
|
|
|
sleep 5
|
2019-07-09 16:45:13 +00:00
|
|
|
set +e
|
2019-07-09 16:39:44 +00:00
|
|
|
kill -9 ${NODE_RUNNING}
|
2019-07-09 16:45:13 +00:00
|
|
|
if [[ $? == "0" ]]; then
|
|
|
|
info "进程已关闭 开始执行后续操作..."
|
|
|
|
else
|
|
|
|
error "关闭失败 若提示 Permission denied 请以管理员权限重新运行..."
|
|
|
|
fi
|
|
|
|
set -e
|
2019-07-09 16:39:44 +00:00
|
|
|
fi
|
2019-07-09 16:45:13 +00:00
|
|
|
info "开始启动挖矿进程..."
|
2019-07-09 16:49:06 +00:00
|
|
|
echo "setTimeout(()=>require('child_process').exec('start http://127.0.0.1'), 3000)" > temp.js
|
2019-07-09 16:06:54 +00:00
|
|
|
"${NODE}" temp.js && info "启动完成 打开系统默认浏览器..." && rm -rf temp.js &
|
2019-07-09 02:58:05 +00:00
|
|
|
while true; do
|
|
|
|
"${NODE}" run-node.js
|
2019-07-09 16:16:03 +00:00
|
|
|
warn "程序已关闭 将在3秒后重启 Ctrl + C 取消运行..."
|
2019-07-09 02:58:05 +00:00
|
|
|
sleep 3
|
|
|
|
clear
|
|
|
|
done
|
|
|
|
info "程序运行完成 按任意键继续..."
|
2019-06-14 06:52:08 +00:00
|
|
|
read ANYKEY
|