forked from huaigu/AlignedLayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Alignedlayer.sh
190 lines (162 loc) · 6.25 KB
/
Alignedlayer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/bin/bash
# 脚本保存路径
SCRIPT_PATH="$HOME/Alignedlayer.sh"
# 节点安装功能
function install_node() {
# 更新和安装依赖
sudo apt update && sudo apt upgrade -y
sudo apt install curl git jq lz4 build-essential -y
# 安装 Go
rm -rf $HOME/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
source $HOME/.bash_profile
go version
# 下载并安装 Aligned Layer 二进制文件
cd $HOME
wget https://github.com/yetanotherco/aligned_layer_tendermint/releases/download/v0.1.0/alignedlayerd
chmod +x alignedlayerd
sudo mv alignedlayerd /usr/local/bin/
# 创建节点名称
read -p "节点名称: " MONIKER
# 配置节点和创世文件
alignedlayerd init $MONIKER --chain-id alignedlayer
# 安装创世文件
curl -Ls https://raw.githubusercontent.com/molla202/AlignedLayer/main/genesis.json > $HOME/.alignedlayer/config/genesis.json
curl -Ls https://raw.githubusercontent.com/molla202/AlignedLayer/main/addrbook.json > $HOME/.alignedlayer/config/addrbook.json
# 设置配置文件
SEEDS="[email protected]:24210"
PERSISTENT_PEERS="[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656"
MINIMUM_GAS_PRICES="0.0001stake"
sed -i -e "s|^seeds *=.*|seeds = \"$SEEDS\"|" $HOME/.alignedlayer/config/config.toml
sed -i -e "s|^persistent_peers *=.*|persistent_peers = \"$PERSISTENT_PEERS\"|" $HOME/.alignedlayer/config/config.toml
sed -i -e "s|^minimum-gas-prices *=.*|minimum-gas-prices = \"$MINIMUM_GAS_PRICES\"|" $HOME/.alignedlayer/config/app.toml
# 设置启动服务
sudo tee /etc/systemd/system/alignedlayerd.service > /dev/null <<EOF
[Unit]
Description="Support by breaddog"
After=network-online.target
[Service]
User=$USER
ExecStart=$(which alignedlayerd) start
Restart=always
RestartSec=3
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOF
# 获取快照文件名
SNAP_FILENAME=$(curl -s https://services.staketab.org/backend/aligned-testnet/ | jq -r .snap_filename)
# 检查$HOME目录下快照文件是否已经存在
if [ ! -f "$HOME/$SNAP_FILENAME" ]; then
echo "快照文件不存在,开始下载..."
# 下载快照
wget $(curl -s https://services.staketab.org/backend/aligned-testnet/ | jq -r .snap_link) -O "$HOME/$SNAP_FILENAME"
fi
# 解压快照文件到指定的数据目录
tar -xf "$HOME/$SNAP_FILENAME" -C "$HOME/.alignedlayer/data/"
sudo systemctl daemon-reload
sudo systemctl enable alignedlayerd
sudo systemctl start alignedlayerd
echo "====================== 部署完成 ==========================="
}
# 创建钱包
function add_wallet() {
read -r -p "请输入钱包名称: " wallet_name
alignedlayerd keys add $wallet_name
echo "钱包已创建,请备份钱包信息。"
}
# 创建验证者
function add_validator() {
echo "钱包余额需大于1050000stake,否则创建失败..."
read -r -p "请输入你的钱包名称: " wallet_name
cd $HOME
wget -O setup_validator.sh https://raw.githubusercontent.com/yetanotherco/aligned_layer_tendermint/main/setup_validator.sh
chmod +x setup_validator.sh && bash setup_validator.sh $wallet_name 1050000stake
}
# 导入钱包
function import_wallet() {
read -r -p "请输入钱包名称: " wallet_name
alignedlayerd keys add $wallet_name --recover
}
# 查询余额
function check_balances() {
read -p "请输入钱包地址: " wallet_address
alignedlayerd query bank balances "$wallet_address"
}
# 查看节点同步状态
function check_sync_status() {
alignedlayerd status | jq .sync_info
}
# 查看Alignedlayer 服务状态
function check_service_status() {
systemctl status alignedlayerd
}
# 节点日志查询
function view_logs() {
sudo journalctl -f -u alignedlayerd.service
}
# 删除节点
function uninstall_node() {
sudo systemctl stop alignedlayerd
sudo systemctl disable alignedlayerd
sudo rm /etc/systemd/system/alignedlayerd.service
sudo systemctl daemon-reload
rm -rf $HOME/.alignedlayerd
rm -rf $HOME/alignedlayer
sudo rm -rf $(which alignedlayerd)
rm -rf aligned_layer_tendermint
rm -rf .alignedlayer
}
# 质押代币
function delegate_stake() {
read -p "请输入钱包名称: " wallet_name
read -p "请输入质押代币数量: " math
validator=$(alignedlayerd keys show $wallet_name --bech val -a)
# read -p "请输入质押给谁(默认为自己:$validator): " validator_addr
validator_addr=$validator
alignedlayerd tx staking delegate $validator_addr ${math}stake \
--from $wallet_name --chain-id alignedlayer \
--fees 50stake
}
# 主菜单
function main_menu() {
while true; do
clear
echo "===================AlignedLayer一键部署脚本==================="
echo "BreadDog出品,电报:https://t.me/breaddog"
echo "最低配置:2C4G150G,推荐配置:4C8G300G"
echo "请选择要执行的操作:"
echo "1. 部署节点"
echo "2. 创建钱包"
echo "3. 导入钱包"
echo "4. 查看余额"
echo "5. 同步状态"
echo "6. 创建验证者"
echo "7. 查看当前服务状态"
echo "8. 运行日志查询"
echo "9. 删除节点"
echo "10. 质押代币"
echo "0. 退出脚本exit"
read -r -p "请输入选项: " OPTION
case $OPTION in
1) install_node ;;
2) add_wallet ;;
3) import_wallet ;;
4) check_balances ;;
5) check_sync_status ;;
6) add_validator ;;
7) check_service_status ;;
8) view_logs ;;
9) uninstall_node ;;
10) delegate_stake ;;
0) echo "退出脚本。"; exit 0 ;;
*) echo "无效选项,请重新输入。"; sleep 3 ;;
esac
echo "按任意键返回主菜单..."
read -n 1
done
}
# 显示主菜单
main_menu