Update Waku.sh

This commit is contained in:
sdohuajia 2024-07-27 21:27:25 +08:00 committed by GitHub
parent e1b7f42363
commit bcd07fe1f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

59
Waku.sh
View File

@ -13,8 +13,7 @@ function main_menu() {
echo "请选择要执行的操作:" echo "请选择要执行的操作:"
echo "1. 安装节点" echo "1. 安装节点"
echo "2. 修复错误" echo "2. 修复错误"
echo "3. 编辑 .env 文件" echo "3. 退出"
echo "4. 退出"
read -rp "请输入操作选项:" choice read -rp "请输入操作选项:" choice
case $choice in case $choice in
@ -25,9 +24,6 @@ function main_menu() {
fix_errors fix_errors
;; ;;
3) 3)
edit_env_file
;;
4)
echo "退出脚本,谢谢使用!" echo "退出脚本,谢谢使用!"
exit 0 exit 0
;; ;;
@ -74,17 +70,19 @@ function install_node() {
cd nwaku-compose || { echo "切换目录失败,请检查目录结构和权限。"; exit 1; } cd nwaku-compose || { echo "切换目录失败,请检查目录结构和权限。"; exit 1; }
cp .env.example .env cp .env.example .env
# 编辑 .env 文件 # 提示用户输入 ETH_CLIENT_ADDRESS
edit_env_file read -rp "请输入 ETH_CLIENT_ADDRESS如 https://sepolia.infura.io/v3/<key>" RLN_RELAY_ETH_CLIENT_ADDRESS
echo "请编辑 .env 文件并填写所需的信息:" # 提示用户输入 ETH_TESTNET_KEY
echo "nano .env" read -rp "请输入 ETH_TESTNET_KEY" ETH_TESTNET_KEY
# 注册节点 # 提示用户输入 RLN_RELAY_CRED_PASSWORD
./register_rln.sh || { echo "注册节点失败,请检查错误信息。"; exit 1; } read -rp "请输入 RLN_RELAY_CRED_PASSWORD" RLN_RELAY_CRED_PASSWORD
# 启动 Docker Compose # 将用户输入写入 .env 文件
docker-compose up -d || { echo "启动 Docker Compose 失败,请检查错误信息。"; exit 1; } echo "RLN_RELAY_ETH_CLIENT_ADDRESS=$RLN_RELAY_ETH_CLIENT_ADDRESS" >> .env
echo "ETH_TESTNET_KEY=$ETH_TESTNET_KEY" >> .env
echo "RLN_RELAY_CRED_PASSWORD=\"$RLN_RELAY_CRED_PASSWORD\"" >> .env
echo "Waku安装完成并已注册节点并启动。" echo "Waku安装完成并已注册节点并启动。"
read -rp "按 Enter 返回菜单。" read -rp "按 Enter 返回菜单。"
@ -108,9 +106,6 @@ function fix_errors() {
# 编辑 .env 文件 # 编辑 .env 文件
nano .env # 请修改 ETH_CLIENT_ADDRESS 为 RLN_RELAY_ETH_CLIENT_ADDRESS nano .env # 请修改 ETH_CLIENT_ADDRESS 为 RLN_RELAY_ETH_CLIENT_ADDRESS
# 注册节点
./register_rln.sh || { echo "注册节点失败,请检查错误信息。"; exit 1; }
# 启动 Docker Compose # 启动 Docker Compose
docker-compose up -d || { echo "启动 Docker Compose 失败,请检查错误信息。"; exit 1; } docker-compose up -d || { echo "启动 Docker Compose 失败,请检查错误信息。"; exit 1; }
@ -118,37 +113,5 @@ function fix_errors() {
read -rp "按 Enter 返回菜单。" read -rp "按 Enter 返回菜单。"
} }
# 编辑 .env 文件函数
function edit_env_file() {
clear
echo "正在编辑 /root/nwaku-compose/.env 文件 ..."
# 进入 nwaku-compose 目录
cd /root/nwaku-compose || { echo "进入目录失败,请检查目录结构和权限。"; exit 1; }
# 显示提示信息
echo "# 请填写以下内容,并按需修改:"
echo "# ETH_CLIENT_ADDRESS=https://sepolia.infura.io/v3/<key> # Sepolia ETH 的 RPC 地址"
echo "# ETH_TESTNET_KEY=<YOUR_TESTNET_PRIVATE_KEY_HERE> # 有测试网 ETH 的私钥(最好创建新钱包)"
echo "# RLN_RELAY_CRED_PASSWORD=\"my_secure_keystore_password\" # 设置密码"
# 打开编辑器编辑文件
nano .env
# 提示用户按 Enter 返回菜单
read -rp "按 Enter 返回菜单。"
# 替换 ETH_CLIENT_ADDRESS 为 RLN_RELAY_ETH_CLIENT_ADDRESS
RLN_RELAY_ETH_CLIENT_ADDRESS=$(grep '^ETH_CLIENT_ADDRESS=' .env | cut -d '=' -f 2-)
sed -i "s|ETH_CLIENT_ADDRESS=.*|RLN_RELAY_ETH_CLIENT_ADDRESS=$RLN_RELAY_ETH_CLIENT_ADDRESS|" .env
echo "已将 ETH_CLIENT_ADDRESS 替换为 RLN_RELAY_ETH_CLIENT_ADDRESS。"
read -rp "按 Enter 返回菜单。"
# 返回到脚本所在目录
cd - >/dev/null || { echo "返回目录失败,请检查目录结构和权限。"; exit 1; }
}
# 主程序开始 # 主程序开始
main_menu main_menu