NAC_Blockchain/nvm_v2/nvm-l1/deploy.sh

122 lines
2.6 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# NAC公链独立部署脚本
# 版本: 1.0.0
# 日期: 2026-02-04
set -e
echo "========================================="
echo "NAC Blockchain 独立部署脚本"
echo "========================================="
echo ""
# 检查系统要求
check_requirements() {
echo "检查系统要求..."
# 检查Rust
if ! command -v rustc &> /dev/null; then
echo "❌ 未安装Rust正在安装..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
else
echo "✅ Rust已安装: $(rustc --version)"
fi
# 检查Cargo
if ! command -v cargo &> /dev/null; then
echo "❌ Cargo未找到"
exit 1
else
echo "✅ Cargo已安装: $(cargo --version)"
fi
echo ""
}
# 编译项目
build_project() {
echo "编译NAC公链..."
cargo build --release
if [ $? -eq 0 ]; then
echo "✅ 编译成功"
else
echo "❌ 编译失败"
exit 1
fi
echo ""
}
# 运行测试
run_tests() {
echo "运行测试套件..."
cargo test --release
if [ $? -eq 0 ]; then
echo "✅ 所有测试通过"
else
echo "❌ 测试失败"
exit 1
fi
echo ""
}
# 生成文档
generate_docs() {
echo "生成项目文档..."
cargo doc --no-deps
echo "✅ 文档已生成到 target/doc/"
echo ""
}
# 打包发布
package_release() {
echo "打包发布版本..."
VERSION="1.0.0"
PACKAGE_NAME="nac-blockchain-v${VERSION}"
mkdir -p releases/${PACKAGE_NAME}
# 复制二进制文件
if [ -f "target/release/libnvm_l1.rlib" ]; then
cp target/release/libnvm_l1.rlib releases/${PACKAGE_NAME}/
fi
# 复制源代码
cp -r src releases/${PACKAGE_NAME}/
cp Cargo.toml releases/${PACKAGE_NAME}/
cp README.md releases/${PACKAGE_NAME}/ 2>/dev/null || echo "README.md not found"
# 打包
cd releases
tar -czf ${PACKAGE_NAME}.tar.gz ${PACKAGE_NAME}/
cd ..
echo "✅ 发布包已生成: releases/${PACKAGE_NAME}.tar.gz"
echo ""
}
# 主函数
main() {
check_requirements
build_project
run_tests
generate_docs
package_release
echo "========================================="
echo "✅ NAC公链部署完成"
echo "========================================="
echo ""
echo "下一步:"
echo "1. 查看文档: target/doc/nvm_l1/index.html"
echo "2. 发布包位置: releases/"
echo "3. 运行测试: cargo test"
echo ""
}
main