#!/bin/bash # 检查是否以root用户运行脚本 if [ "$(id -u)" != "0" ]; then echo "此脚本需要以root用户权限运行。" echo "请尝试使用 'sudo -i' 命令切换到root用户,然后再次运行此脚本。" exit 1 fi # 检查并安装 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 } # 检查Go环境 function check_go_installation() { if command -v go > /dev/null 2>&1; then echo "Go 环境已安装" return 0 else echo "Go 环境未安装,正在安装..." return 1 fi } # 节点安装功能 function install_node() { install_nodejs_and_npm install_pm2 # 检查curl是否安装,如果没有则安装 if ! command -v curl > /dev/null; then sudo apt update && sudo apt install curl git -y fi # 更新和安装必要的软件 sudo apt update && sudo apt upgrade -y sudo apt install curl git wget htop tmux build-essential jq make lz4 gcc unzip liblz4-tool -y # 安装 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 # 安装所有二进制文件 git clone -b v0.2.3 https://github.com/0glabs/0g-chain.git ./0g-chain/networks/testnet/install.sh source ~/.profile # 配置0gchaind export MONIKER="My_Node" export WALLET_NAME="wallet" # 获取初始文件和地址簿 cd $HOME 0gchaind init $MONIKER --chain-id zgtendermint_16600-1 0gchaind config chain-id zgtendermint_16600-1 0gchaind config node tcp://localhost:13457 # 配置节点 rm ~/.0gchain/config/genesis.json wget -P ~/.0gchain/config https://github.com/0glabs/0g-chain/releases/download/v0.2.3/genesis.json 0gchaind validate-genesis # 配置节点 SEEDS="265120a9bb170cf21198aabf88f7908c9944897c@54.241.167.190:26656,497f865d8a0f6c830e2b73009a01b3edefb22577@54.176.175.48:26656,ffc49903241a4e442465ec78b8f421c56b3ae3d4@54.193.250.204:26656,f37bc8623bfa4d8e519207b965a24a288f3213d8@18.166.164.232:26656" PEERS="" sed -i "s/persistent_peers = \"\"/persistent_peers = \"$PEERS\"/" $HOME/.0gchain/config/config.toml sed -i "s/seeds = \"\"/seeds = \"$SEEDS\"/" $HOME/.0gchain/config/config.toml # 配置裁剪 sed -i -e "s/^pruning *=.*/pruning = \"custom\"/" $HOME/.artelad/config/app.toml sed -i -e "s/^pruning-keep-recent *=.*/pruning-keep-recent = \"100\"/" $HOME/.0gchain/config/app.toml sed -i -e "s/^pruning-keep-every *=.*/pruning-keep-every = \"0\"/" $HOME/.0gchain/config/app.toml sed -i -e "s/^pruning-interval *=.*/pruning-interval = \"10\"/" $HOME/.0gchain/config/app.toml sed -i -e "s/^indexer *=.*/indexer = \"null\"/" $HOME/.0gchain/config/config.toml sed -i -e 's/max_num_inbound_peers = 40/max_num_inbound_peers = 100/' -e 's/max_num_outbound_peers = 10/max_num_outbound_peers = 100/' $HOME/.0gchain/config/config.toml # 配置端口 sed -i -e "s%^proxy_app = \"tcp://127.0.0.1:26658\"%proxy_app = \"tcp://127.0.0.1:13458\"%; s%^laddr = \"tcp://127.0.0.1:26657\"%laddr = \"tcp://127.0.0.1:13457\"%; s%^pprof_laddr = \"localhost:6060\"%pprof_laddr = \"localhost:13460\"%; s%^laddr = \"tcp://0.0.0.0:26656\"%laddr = \"tcp://0.0.0.0:13456\"%; s%^prometheus_listen_addr = \":26660\"%prometheus_listen_addr = \":13466\"%" $HOME/.0gchain/config/config.toml sed -i -e "s%^address = \"tcp://localhost:1317\"%address = \"tcp://0.0.0.0:13417\"%; s%^address = \":8080\"%address = \":13480\"%; s%^address = \"0.0.0.0:9090\"%address = \"0.0.0.0:13490\"%; s%^address = \"localhost:9091\"%address = \"0.0.0.0:13491\"%; s%:8545%:13445%; s%:8546%:13446%; s%:6065%:13465%" $HOME/.0gchain/config/app.toml source $HOME/.bash_profile # 使用 PM2 启动节点进程 pm2 start 0gchaind -- start && pm2 save && pm2 startup curl -L https://snapshots.dadunode.com/0gchain/0gchaind_latest_tar.lz4 | tar -I lz4 -xf - -C $HOME/.0gchain/data pm2 restart 0gchaind echo '====================== 安装完成,请退出脚本后执行 source $HOME/.bash_profile 以加载环境变量===========================' } # 查看0gai 服务状态 function check_service_status() { pm2 list } # 0gai 节点日志查询 function view_logs() { pm2 logs 0gchaind } # 卸载节点功能 function uninstall_node() { echo "你确定要卸载0gchain 节点程序吗?这将会删除所有相关的数据。[Y/N]" read -r -p "请确认: " response case "$response" in [yY][eE][sS]|[yY]) echo "开始卸载节点程序..." pm2 stop 0gchaind && pm2 delete 0gchaind rm -rf $HOME/.0gchain $HOME/0gchain $(which 0gchaind) && rm -rf 0g-chain echo "节点程序卸载完成。" ;; *) echo "取消卸载操作。" ;; esac } # 创建钱包 function add_wallet() { read -p "请输入你想设置的钱包名称: " wallet_name 0gchaind keys add $wallet_name --eth } # 导入钱包 function import_wallet() { read -p "请输入你想设置的钱包名称: " wallet_name 0gchaind keys add $wallet_name --recover --eth } # 查询余额 function check_balances() { read -p "请输入钱包地址: " wallet_address 0gchaind query bank balances "$wallet_address" } # 查看节点同步状态 function check_sync_status() { 0gchaind status | jq .sync_info } # 创建验证者 function add_validator() { read -p "请输入您的钱包名称: " wallet_name read -p "请输入您想设置的验证者的名字: " validator_name read -p "请输入您的验证者详情(例如'吊毛资本'): " details 0gchaind tx staking create-validator \ --amount=1000000ua0gi \ --pubkey=$(0gchaind tendermint show-validator) \ --moniker=$validator_name \ --chain-id=zgtendermint_16600-1 \ --commission-rate=0.05 \ --commission-max-rate=0.10 \ --commission-max-change-rate=0.01 \ --min-self-delegation=1 \ --from=$wallet_name \ --identity="" \ --website="" \ --details="$details" \ --gas=auto \ --gas-adjustment=1.4 } function install_storage_node() { sudo apt-get update sudo apt-get install clang cmake build-essential git screen cargo -y # 安装Go 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 export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin source $HOME/.bash_profile # 克隆仓库 git clone -b v0.3.0 https://github.com/0glabs/0g-storage-node.git #进入对应目录构建 cd 0g-storage-node git submodule update --init # 构建代码 cargo build --release #后台运行 cd run read -p "请输入你想导入的EVM钱包私钥,不要有0x: " minerkey sed -i "s/miner_key = \"\"/miner_key = \"$minerkey\"/" config.toml screen -dmS zgs_node_session ../target/release/zgs_node --config config.toml echo '====================== 安装完成,使用screen命令查询即可 ===========================' } function install_storage_kv() { # 克隆仓库 git clone https://github.com/0glabs/0g-storage-kv.git #进入对应目录构建 cd 0g-storage-kv git submodule update --init # 构建代码 cargo build --release #后台运行 cd run echo "请输入RPC节点信息: " read blockchain_rpc_endpoint cat > config.toml <