2024-01-31 08:42:43 +00:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2024-03-20 08:18:22 +00:00
|
|
|
|
# 检查是否以root用户运行脚本
|
|
|
|
|
if [ "$(id -u)" != "0" ]; then
|
|
|
|
|
echo "此脚本需要以root用户权限运行。"
|
|
|
|
|
echo "请尝试使用 'sudo -i' 命令切换到root用户,然后再次运行此脚本。"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2024-04-01 07:14:20 +00:00
|
|
|
|
# 检查并安装 Node.js 和 npm
|
|
|
|
|
function install_nodejs_and_npm() {
|
|
|
|
|
if command -v node > /dev/null 2>&1; then
|
|
|
|
|
echo "Node.js 已安装"
|
|
|
|
|
else
|
|
|
|
|
echo "Node.js 未安装,正在安装..."
|
|
|
|
|
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
|
|
|
|
|
sudo apt-get install -y nodejs
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if command -v npm > /dev/null 2>&1; then
|
|
|
|
|
echo "npm 已安装"
|
|
|
|
|
else
|
|
|
|
|
echo "npm 未安装,正在安装..."
|
|
|
|
|
sudo apt-get install -y npm
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 检查并安装 PM2
|
|
|
|
|
function install_pm2() {
|
|
|
|
|
if command -v pm2 > /dev/null 2>&1; then
|
|
|
|
|
echo "PM2 已安装"
|
|
|
|
|
else
|
|
|
|
|
echo "PM2 未安装,正在安装..."
|
|
|
|
|
npm install pm2@latest -g
|
|
|
|
|
fi
|
|
|
|
|
}
|
2024-03-03 04:13:47 +00:00
|
|
|
|
|
2024-04-20 14:47:58 +00:00
|
|
|
|
# 检查Go环境
|
|
|
|
|
function check_go_installation() {
|
|
|
|
|
if command -v go > /dev/null 2>&1; then
|
|
|
|
|
echo "Go 环境已安装"
|
|
|
|
|
return 0
|
|
|
|
|
else
|
|
|
|
|
echo "Go 环境未安装,正在安装..."
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-03 04:13:47 +00:00
|
|
|
|
# 自动设置快捷键的功能
|
|
|
|
|
function check_and_set_alias() {
|
|
|
|
|
local alias_name="art"
|
|
|
|
|
local shell_rc="$HOME/.bashrc"
|
|
|
|
|
|
|
|
|
|
# 对于Zsh用户,使用.zshrc
|
|
|
|
|
if [ -n "$ZSH_VERSION" ]; then
|
|
|
|
|
shell_rc="$HOME/.zshrc"
|
|
|
|
|
elif [ -n "$BASH_VERSION" ]; then
|
|
|
|
|
shell_rc="$HOME/.bashrc"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# 检查快捷键是否已经设置
|
|
|
|
|
if ! grep -q "$alias_name" "$shell_rc"; then
|
|
|
|
|
echo "设置快捷键 '$alias_name' 到 $shell_rc"
|
|
|
|
|
echo "alias $alias_name='bash $SCRIPT_PATH'" >> "$shell_rc"
|
|
|
|
|
# 添加提醒用户激活快捷键的信息
|
|
|
|
|
echo "快捷键 '$alias_name' 已设置。请运行 'source $shell_rc' 来激活快捷键,或重新打开终端。"
|
|
|
|
|
else
|
|
|
|
|
# 如果快捷键已经设置,提供一个提示信息
|
|
|
|
|
echo "快捷键 '$alias_name' 已经设置在 $shell_rc。"
|
|
|
|
|
echo "如果快捷键不起作用,请尝试运行 'source $shell_rc' 或重新打开终端。"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 节点安装功能
|
|
|
|
|
function install_node() {
|
2024-04-01 07:14:20 +00:00
|
|
|
|
install_nodejs_and_npm
|
|
|
|
|
install_pm2
|
2024-03-03 04:13:47 +00:00
|
|
|
|
|
2024-04-01 07:14:20 +00:00
|
|
|
|
# 设置变量
|
2024-04-01 08:14:33 +00:00
|
|
|
|
read -r -p "请输入你想设置的节点名称: " NODE_MONIKER
|
2024-04-01 07:14:20 +00:00
|
|
|
|
export NODE_MONIKER=$NODE_MONIKER
|
|
|
|
|
|
|
|
|
|
# 更新和安装必要的软件
|
|
|
|
|
sudo apt update && sudo apt upgrade -y
|
|
|
|
|
sudo apt install -y curl iptables build-essential git wget jq make gcc nano tmux htop nvme-cli pkg-config libssl-dev libleveldb-dev tar clang bsdmainutils ncdu unzip libleveldb-dev lz4 snapd
|
|
|
|
|
|
2024-04-20 14:47:58 +00:00
|
|
|
|
# 安装 Go
|
|
|
|
|
if ! check_go_installation; then
|
|
|
|
|
sudo rm -rf /usr/local/go
|
|
|
|
|
curl -L https://go.dev/dl/go1.22.0.linux-amd64.tar.gz | sudo tar -xzf - -C /usr/local
|
|
|
|
|
echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> $HOME/.bash_profile
|
|
|
|
|
source $HOME/.bash_profile
|
|
|
|
|
go version
|
|
|
|
|
fi
|
2024-04-01 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
# 安装所有二进制文件
|
|
|
|
|
cd $HOME
|
|
|
|
|
git clone https://github.com/artela-network/artela
|
|
|
|
|
cd artela
|
2024-05-28 07:04:12 +00:00
|
|
|
|
git checkout v0.4.7-rc6
|
2024-04-01 07:14:20 +00:00
|
|
|
|
make install
|
|
|
|
|
|
|
|
|
|
# 配置artelad
|
2024-05-12 05:46:59 +00:00
|
|
|
|
artelad config chain-id artela_11822-1
|
|
|
|
|
artelad init "$NODE_MONIKER" --chain-id artela_11822-1
|
2024-04-18 14:37:11 +00:00
|
|
|
|
artelad config node tcp://localhost:3457
|
2024-04-01 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
# 获取初始文件和地址簿
|
2024-04-30 09:03:18 +00:00
|
|
|
|
curl -L https://snapshots-testnet.nodejumper.io/artela-testnet/genesis.json > $HOME/.artelad/config/genesis.json
|
|
|
|
|
curl -L https://snapshots-testnet.nodejumper.io/artela-testnet/addrbook.json > $HOME/.artelad/config/addrbook.json
|
2024-04-01 07:14:20 +00:00
|
|
|
|
|
|
|
|
|
# 配置节点
|
|
|
|
|
SEEDS=""
|
2024-05-26 05:34:37 +00:00
|
|
|
|
PEERS="ca8bce647088a12bc030971fbcce88ea7ffdac50@84.247.153.99:26656,a3501b87757ad6515d73e99c6d60987130b74185@85.239.235.104:3456,2c62fb73027022e0e4dcbdb5b54a9b9219c9b0c1@51.255.228.103:26687,fbe01325237dc6338c90ddee0134f3af0378141b@158.220.88.66:3456,fde2881b06a44246a893f37ecb710020e8b973d1@158.220.84.64:3456,12d057b98ecf7a24d0979c0fba2f341d28973005@116.202.162.188:10656,9e2fbfc4b32a1b013e53f3fc9b45638f4cddee36@47.254.66.177:26656,92d95c7133275573af25a2454283ebf26966b188@167.235.178.134:27856,2dd98f91eaea966b023edbc88aa23c7dfa1f733a@158.220.99.30:26680"
|
2024-04-30 13:28:29 +00:00
|
|
|
|
sed -i 's|^persistent_peers *=.*|persistent_peers = "'$PEERS'"|' $HOME/.artelad/config/config.toml
|
2024-04-01 07:14:20 +00:00
|
|
|
|
|
2024-04-18 14:31:44 +00:00
|
|
|
|
# 配置端口
|
2024-05-13 14:48:25 +00:00
|
|
|
|
node_address="tcp://localhost:3457"
|
2024-04-19 03:09:05 +00:00
|
|
|
|
sed -i -e "s%^proxy_app = \"tcp://127.0.0.1:26658\"%proxy_app = \"tcp://127.0.0.1:3458\"%; s%^laddr = \"tcp://127.0.0.1:26657\"%laddr = \"tcp://127.0.0.1:3457\"%; s%^pprof_laddr = \"localhost:6060\"%pprof_laddr = \"localhost:3460\"%; s%^laddr = \"tcp://0.0.0.0:26656\"%laddr = \"tcp://0.0.0.0:3456\"%; s%^prometheus_listen_addr = \":26660\"%prometheus_listen_addr = \":3466\"%" $HOME/.artelad/config/config.toml
|
2024-05-26 05:35:56 +00:00
|
|
|
|
sed -i -e "s%^address = \"tcp://localhost:1317\"%address = \"tcp://0.0.0.0:3417\"%; s%^address = \":8080\"%address = \":3480\"%; s%^address = \"localhost:9090\"%address = \"0.0.0.0:3490\"%; s%^address = \"localhost:9091\"%address = \"0.0.0.0:3491\"%; s%:8545%:3445%; s%:8546%:3446%; s%:6065%:3465%" $HOME/.artelad/config/app.toml
|
2024-04-18 14:43:05 +00:00
|
|
|
|
echo "export Artela_RPC_PORT=$node_address" >> $HOME/.bash_profile
|
2024-04-18 14:31:44 +00:00
|
|
|
|
source $HOME/.bash_profile
|
|
|
|
|
|
2024-04-30 02:57:40 +00:00
|
|
|
|
pm2 start artelad -- start && pm2 save && pm2 startup
|
|
|
|
|
|
2024-04-01 10:00:37 +00:00
|
|
|
|
# 下载快照
|
2024-05-15 09:56:34 +00:00
|
|
|
|
artelad tendermint unsafe-reset-all --home $HOME/.artelad --keep-addr-book
|
|
|
|
|
curl https://snapshots-testnet.nodejumper.io/artela-testnet/artela-testnet_latest.tar.lz4 | lz4 -dc - | tar -xf - -C $HOME/.artelad
|
2024-05-12 05:53:09 +00:00
|
|
|
|
mv $HOME/.artelad/priv_validator_state.json.backup $HOME/.artelad/data/priv_validator_state.json
|
2024-04-01 10:00:37 +00:00
|
|
|
|
|
2024-04-01 07:14:20 +00:00
|
|
|
|
# 使用 PM2 启动节点进程
|
2024-04-30 02:57:40 +00:00
|
|
|
|
|
|
|
|
|
pm2 restart artelad
|
2024-04-01 07:14:20 +00:00
|
|
|
|
|
2024-05-12 09:58:23 +00:00
|
|
|
|
echo '====================== 安装完成,请退出脚本后执行 source $HOME/.bash_profile 以加载环境变量 ==========================='
|
2024-04-02 09:06:40 +00:00
|
|
|
|
|
2024-03-03 04:16:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-01 08:14:33 +00:00
|
|
|
|
# 查看Artela 服务状态
|
2024-03-03 04:16:15 +00:00
|
|
|
|
function check_service_status() {
|
2024-04-01 07:14:20 +00:00
|
|
|
|
pm2 list
|
2024-03-03 04:16:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-01 08:14:33 +00:00
|
|
|
|
# Artela 节点日志查询
|
2024-03-03 04:16:15 +00:00
|
|
|
|
function view_logs() {
|
2024-04-01 15:16:19 +00:00
|
|
|
|
pm2 logs artelad
|
2024-03-03 04:16:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-26 09:15:03 +00:00
|
|
|
|
# 卸载节点功能
|
2024-03-26 08:56:52 +00:00
|
|
|
|
function uninstall_node() {
|
2024-04-01 07:54:52 +00:00
|
|
|
|
echo "你确定要卸载Artela 节点程序吗?这将会删除所有相关的数据。[Y/N]"
|
|
|
|
|
read -r -p "请确认: " response
|
|
|
|
|
|
|
|
|
|
case "$response" in
|
|
|
|
|
[yY][eE][sS]|[yY])
|
|
|
|
|
echo "开始卸载节点程序..."
|
2024-04-01 15:16:19 +00:00
|
|
|
|
pm2 stop artelad && pm2 delete artelad
|
2024-04-01 07:54:52 +00:00
|
|
|
|
rm -rf $HOME/.artelad $HOME/artela $(which artelad)
|
|
|
|
|
echo "节点程序卸载完成。"
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo "取消卸载操作。"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2024-03-03 04:16:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-01 08:22:20 +00:00
|
|
|
|
# 创建钱包
|
|
|
|
|
function add_wallet() {
|
|
|
|
|
artelad keys add wallet
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 导入钱包
|
|
|
|
|
function import_wallet() {
|
|
|
|
|
artelad keys add wallet --recover
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 查询余额
|
|
|
|
|
function check_balances() {
|
|
|
|
|
read -p "请输入钱包地址: " wallet_address
|
2024-05-21 08:57:16 +00:00
|
|
|
|
artelad query bank balances "$wallet_address"
|
2024-04-01 08:22:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 查看节点同步状态
|
|
|
|
|
function check_sync_status() {
|
2024-05-31 11:08:21 +00:00
|
|
|
|
artelad status | jq .SyncInfo
|
2024-04-01 08:22:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-02 06:56:35 +00:00
|
|
|
|
# 创建验证者
|
|
|
|
|
function add_validator() {
|
|
|
|
|
read -p "请输入您的钱包名称: " wallet_name
|
|
|
|
|
read -p "请输入您想设置的验证者的名字: " validator_name
|
2024-04-19 03:56:32 +00:00
|
|
|
|
|
2024-05-21 07:23:18 +00:00
|
|
|
|
artelad tx staking create-validator \
|
|
|
|
|
--amount="1art" \
|
|
|
|
|
--pubkey=$(artelad tendermint show-validator) \
|
|
|
|
|
--moniker="$validator_name" \
|
|
|
|
|
--commission-rate="0.10" \
|
|
|
|
|
--commission-max-rate="0.20" \
|
|
|
|
|
--commission-max-change-rate="0.01" \
|
|
|
|
|
--min-self-delegation="1" \
|
|
|
|
|
--gas="200000" \
|
|
|
|
|
--chain-id="artela_11822-1" \
|
|
|
|
|
--from="$wallet_name" \
|
2024-04-12 07:03:41 +00:00
|
|
|
|
|
2024-04-02 06:56:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-04-12 07:35:14 +00:00
|
|
|
|
# 给自己地址验证者质押
|
|
|
|
|
function delegate_self_validator() {
|
|
|
|
|
read -p "请输入质押代币数量: " math
|
|
|
|
|
read -p "请输入钱包名称: " wallet_name
|
2024-05-26 14:34:50 +00:00
|
|
|
|
artelad tx staking delegate $(artelad keys show $wallet_name --bech val -a) ${math}art --from $wallet_name --chain-id=artela_11822-1 --gas=300000
|
2024-04-12 07:35:14 +00:00
|
|
|
|
|
|
|
|
|
}
|
2024-04-01 08:22:20 +00:00
|
|
|
|
|
2024-05-16 05:06:23 +00:00
|
|
|
|
# 导出验证者key
|
2024-05-16 05:01:22 +00:00
|
|
|
|
function export_priv_validator_key() {
|
|
|
|
|
echo "====================请将下方所有内容备份到自己的记事本或者excel表格中记录==========================================="
|
|
|
|
|
cat ~/.artelad/config/priv_validator_key.json
|
|
|
|
|
|
|
|
|
|
}
|
2024-04-01 07:54:52 +00:00
|
|
|
|
|
2024-03-03 04:16:15 +00:00
|
|
|
|
# 主菜单
|
|
|
|
|
function main_menu() {
|
2024-03-26 08:56:52 +00:00
|
|
|
|
while true; do
|
|
|
|
|
clear
|
|
|
|
|
echo "脚本以及教程由推特用户大赌哥 @y95277777 编写,免费开源,请勿相信收费"
|
2024-05-28 07:22:23 +00:00
|
|
|
|
echo "============================Artela节点安装===================================="
|
2024-03-26 08:56:52 +00:00
|
|
|
|
echo "节点社区 Telegram 群组:https://t.me/niuwuriji"
|
|
|
|
|
echo "节点社区 Telegram 频道:https://t.me/niuwuriji"
|
2024-04-13 08:26:57 +00:00
|
|
|
|
echo "节点社区 Discord 社群:https://discord.gg/GbMV5EcNWF"
|
2024-03-26 08:56:52 +00:00
|
|
|
|
echo "退出脚本,请按键盘ctrl c退出即可"
|
|
|
|
|
echo "请选择要执行的操作:"
|
|
|
|
|
echo "1. 安装节点"
|
2024-04-01 08:22:20 +00:00
|
|
|
|
echo "2. 创建钱包"
|
|
|
|
|
echo "3. 导入钱包"
|
|
|
|
|
echo "4. 查看钱包地址余额"
|
|
|
|
|
echo "5. 查看节点同步状态"
|
|
|
|
|
echo "6. 查看当前服务状态"
|
|
|
|
|
echo "7. 运行日志查询"
|
|
|
|
|
echo "8. 卸载节点"
|
|
|
|
|
echo "9. 设置快捷键"
|
2024-04-02 06:56:35 +00:00
|
|
|
|
echo "10. 创建验证者"
|
2024-04-12 07:35:14 +00:00
|
|
|
|
echo "11. 给自己质押"
|
2024-05-16 05:06:23 +00:00
|
|
|
|
echo "12. 备份验证者私钥"
|
2024-04-12 07:35:14 +00:00
|
|
|
|
read -p "请输入选项(1-11): " OPTION
|
2024-03-26 08:56:52 +00:00
|
|
|
|
|
|
|
|
|
case $OPTION in
|
|
|
|
|
1) install_node ;;
|
2024-04-01 08:22:20 +00:00
|
|
|
|
2) add_wallet ;;
|
|
|
|
|
3) import_wallet ;;
|
|
|
|
|
4) check_balances ;;
|
|
|
|
|
5) check_sync_status ;;
|
|
|
|
|
6) check_service_status ;;
|
|
|
|
|
7) view_logs ;;
|
|
|
|
|
8) uninstall_node ;;
|
|
|
|
|
9) check_and_set_alias ;;
|
2024-04-02 06:56:35 +00:00
|
|
|
|
10) add_validator ;;
|
2024-04-12 07:35:14 +00:00
|
|
|
|
11) delegate_self_validator ;;
|
2024-05-16 05:01:22 +00:00
|
|
|
|
12) export_priv_validator_key ;;
|
2024-03-26 08:56:52 +00:00
|
|
|
|
*) echo "无效选项。" ;;
|
|
|
|
|
esac
|
|
|
|
|
echo "按任意键返回主菜单..."
|
|
|
|
|
read -n 1
|
|
|
|
|
done
|
2024-04-02 09:06:40 +00:00
|
|
|
|
|
2024-03-03 04:16:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 显示主菜单
|
|
|
|
|
main_menu
|