代码如下,代码中,对节点名称 密码进行了随机生成,请修改为自己的,配置文件使用了自身服务器web服务。请对防火墙等做好调整,封闭服务器不需要的端口,私钥等数据进行保护。
#!/bin/bash
echo "安装必要环境"
programs=("curl" "tar" "wget" "clang" "pkg-config" "libssl-dev" "jq" "build-essential" "git" "make" "ncdu" "expect" "apache2")
for program in "${programs[@]}"; do
if ! command -v "$program" > /dev/null; then
apt-get update
apt-get install -y "$program"
fi
done
echo "启动WEB"
sudo systemctl start apache2
echo "安装docker"
curl -o get-docker.sh https://get.docker.com && sh get-docker.sh && rm -f get-docker.sh
systemctl start docker
systemctl enable docker
curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
if ! command -v docker > /dev/null; then
apt-get update
apt install -y docker.io
fi
if ! command -v docker-compose > /dev/null; then
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sleep 5
sudo chmod +x /usr/local/bin/docker-compose
fi
echo "安装GO"
MAX_RETRIES=5
function download_go() {
local retries=0
while true; do
echo "下载 Go 版本: $GO_VERSION"
wget https://golang.org/dl/$GO_VERSION.linux-amd64.tar.gz -O go.linux-amd64.tar.gz
if [ $? -eq 0 ]; then
break
fi
retries=$((retries + 1))
if [ $retries -ge $MAX_RETRIES ]; then
echo "下载失败,达到最大重试次数。"
exit 1
fi
echo "下载失败,正在重试(第 $retries 次)。"
done
}
function install_go() {
local retries=0
while true; do
echo "安装 Go 版本: $GO_VERSION"
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go.linux-amd64.tar.gz
if [ $? -eq 0 ]; then
break
fi
retries=$((retries + 1))
if [ $retries -ge $MAX_RETRIES ]; then
echo "安装失败,达到最大重试次数。"
exit 1
fi
echo "安装失败,正在重试(第 $retries 次)。"
done
}
echo "安装 Go 最新版"
# 获取最新版本号
GO_VERSION=$(curl -s https://go.dev/dl/?mode=json | jq -r '.[0].version')
echo $GO_VERSION
# 下载并安装最新版本
download_go
install_go
# 设置环境变量
export PATH=$PATH:/usr/local/go/bin
echo "生成钱包以及密码"
NAME=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $(($RANDOM % 3 + 4)) | head -n 1)
passwd=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9!@#$%^&*()_+' | fold -w $(($RANDOM % 8 + 10)) | head -n 1)
echo "节点名称:$NAME" >> /root/eigenlayer.txt
echo "钱包解锁密码: $passwd " >> /root/eigenlayer.txt
echo "写入web文件"
content="{
\"name\": \"$NAME\",
\"website\": \"https://www.danny.hk\",
\"description\": \"Web3 Community $NAME\",
\"logo\": \"https://www.danny.hk/wp-content/uploads/2022/12/cropped-2601-%E5%89%AF%E6%9C%AC-2.png\",
\"twitter\": \"https://twitter.com/$NAME\"
}
"
echo "$content" > /var/www/html/metadata.json
echo "安装 Github Eigenlaye"
cd
git clone https://github.com/Layr-Labs/eigenlayer-cli.git
cd eigenlayer-cli
mkdir -p build
go build -o build/eigenlayer cmd/eigenlayer/main.go
cp ./build/eigenlayer /usr/local/bin/
echo "生成Eigenlaye钱包"
echo $passwd | eigenlayer operator keys create --key-type ecdsa $NAME >> /root/eigenlayer.txt
echo $passwd | eigenlayer operator keys create --key-type bls $NAME >> /root/eigenlayer.txt
echo "生成Eigenlaye文件"
sudo cat > /root/eigenlayer-cli/Eigenlaye.exp << EOF
#!/usr/bin/expect
spawn eigenlayer operator config create
expect "(y/N) " { send "n\r" }
interact
EOF
chmod +x /root/eigenlayer-cli/Eigenlaye.exp
cd /root/eigenlayer-cli
./Eigenlaye.exp
sudo rm -rf /root/eigenlayer-cli/Eigenlaye.exp
wget -O operator.yaml https://api.danny.hk/operator.yaml
private_key=$(cat /root/eigenlayer.txt | grep "Key location:" | head -n 1 | awk '{print $3}')
address=$(cat /root/eigenlayer.txt | grep "Ethereum Address:" | awk '{print $3}')
address_key=$(sed -n '13p' /root/eigenlayer.txt | awk '{print $2}')
sed -i "s#0xf8C35e86cf7eDE712b85F86296CA49106c2a7d47#$address#" operator.yaml
sed -i "s#/root/.eigenlayer/operator_keys/JyfqO7.ecdsa.key.json#$private_key#" operator.yaml
echo "钱包文件: /root/.eigenlayer/operator_keys/2fFF.ecdsa.key.json"
echo "钱包地址:$address"
echo "节点名称:$NAME"
echo "钱包密码:$passwd"
echo "钱包私钥:$address_key"
sleep 300
echo $passwd | eigenlayer operator register operator.yaml