120 lines
3.5 KiB
Bash
120 lines
3.5 KiB
Bash
#!/bin/bash
|
|
SHELL_PREFIX="[SYNC]"
|
|
# 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"
|
|
|
|
c_prefix="${c_blue}${SHELL_PREFIX}>>${c_reset}"
|
|
|
|
dateStr() {
|
|
echo -e "[$(date '+%H:%M:%S')]"
|
|
}
|
|
|
|
info() {
|
|
echo -e "${c_prefix}$(dateStr) ${*}"
|
|
}
|
|
|
|
warn() {
|
|
echo -e "${c_prefix}$(dateStr) ${c_yellow}${*}${c_reset}"
|
|
}
|
|
|
|
error() {
|
|
echo -e "${c_prefix}$(dateStr) ${c_red}${*}${c_reset}"
|
|
}
|
|
#====================
|
|
|
|
ROOT=$(pwd)
|
|
clear
|
|
set -e
|
|
info "=============================="
|
|
info " 欢迎使用 Tera 一键挖矿系统"
|
|
info ""
|
|
info " by MiaoWoo"
|
|
info ""
|
|
info " 版本 v1.1"
|
|
info "=============================="
|
|
if [[ ! -f "OneKeyTera.sh" || ! -f ".lock" || $(cat .lock) -lt $(($(date +%s) - 86400)) ]]; then
|
|
info "更新脚本..."
|
|
curl -o OneKeyTera.sh https://git.yumc.pw/cloud/script/raw/master/tera/run.sh
|
|
fi
|
|
info $(date +%s) > .lock
|
|
info "程序将在 3秒 后运行... Ctrl + C 取消运行..."
|
|
sleep 2
|
|
info "开始检测安装依赖..."
|
|
if [[ -z "$(which node)" ]]; then
|
|
if [[ ! -d node ]]; then
|
|
warn "未安装NodeJS 开始下载二进制包 请稍候..."
|
|
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
|
|
fi
|
|
else
|
|
NODE=node
|
|
NPM=npm
|
|
fi
|
|
echo "NodeJS 二进制版本: $(${NODE} -v)"
|
|
if [[ ! -d tera ]]; then
|
|
warn "未找到 Tera 源代码 开始Clone项目 请稍候..."
|
|
git clone https://gitlab.com/terafoundation/tera.git
|
|
fi
|
|
TERA_ROOT=${ROOT}/tera/Source
|
|
cd "${TERA_ROOT}"
|
|
if [[ ! -d node_modules ]]; then
|
|
warn "未安装依赖 开始安装 请稍候..."
|
|
"${NPM}" install
|
|
fi
|
|
|
|
if [[ ! -f "${TERA_ROOT}/node_modules/secp256k1/build/Release/secp256k1.node" ]]; then
|
|
warn "未检测到 secp256k1.node 模块 开始下载 Windows 版本..."
|
|
curl -o "${TERA_ROOT}/node_modules/secp256k1/build/Release/secp256k1.node" https://git.yumc.pw/cloud/script/raw/master/tera/secp256k1.node
|
|
fi
|
|
|
|
# # 申请公网IP端口
|
|
# echo "开始申请公网IP端口 请稍候..."
|
|
# 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}
|
|
|
|
# 初始化配置
|
|
info "初始化配置参数..."
|
|
INIT_SCRIPT=${TERA_ROOT}/init.js
|
|
if [[ ! -f ${INIT_SCRIPT} ]]; then
|
|
warn "开始下载初始化脚本 请稍候..."
|
|
curl -o ${INIT_SCRIPT} https://git.yumc.pw/cloud/script/raw/master/tera/init.js
|
|
fi
|
|
"${NODE}" ${INIT_SCRIPT}
|
|
|
|
# 设置NTP服务器
|
|
TERA_NTP_SERVER=${TERA_NTP_SERVER:-ntp1.aliyun.com}
|
|
info "设置NTP服务器为阿里云地址 ${TERA_NTP_SERVER}"
|
|
sed -i s@pool.ntp.org@${TERA_NTP_SERVER}@g ${TERA_ROOT}/core/library.js
|
|
|
|
info "开始启动挖矿进程..."
|
|
echo "setTimeout(()=>require('child_process').exec('start http://127.0.0.1'), 3000)" > temp.js
|
|
"${NODE}" temp.js && info "启动完成 打开系统默认浏览器..." && rm -rf temp.js &
|
|
while true; do
|
|
"${NODE}" run-node.js
|
|
echo "程序已关闭 将在3秒后重启 Ctrl + C 取消运行..."
|
|
sleep 3
|
|
clear
|
|
done
|
|
info "程序运行完成 按任意键继续..."
|
|
read ANYKEY
|