144 lines
3.9 KiB
Bash
Executable File
144 lines
3.9 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
# signer (Rust) — Local Deploy Script
|
|
#
|
|
# Builds binaries and installs them to /usr/local/bin/.
|
|
#
|
|
# USAGE:
|
|
# ./deploy_local.sh # native release build + install
|
|
# ./deploy_local.sh --musl # portable static musl release + install
|
|
# ./deploy_local.sh --debug # native debug build + install
|
|
# ./deploy_local.sh -h, --help
|
|
#
|
|
# Installs:
|
|
# /usr/local/bin/signer (the signing daemon)
|
|
# /usr/local/bin/signer-client (the CLI client)
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
|
|
print_status() { echo -e "${BLUE}[INFO]${NC} $1" >&2; }
|
|
print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" >&2; }
|
|
print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" >&2; }
|
|
print_error() { echo -e "${RED}[ERROR]${NC} $1" >&2; }
|
|
|
|
PROFILE="release"
|
|
CARGO_FLAG="--release"
|
|
TARGET_DIR="target/release"
|
|
BUILD_KIND="native"
|
|
|
|
show_usage() {
|
|
echo "signer (Rust) Local Deploy Script"
|
|
echo ""
|
|
echo "USAGE:"
|
|
echo " $0 [OPTIONS]"
|
|
echo ""
|
|
echo "OPTIONS:"
|
|
echo " --musl Build static x86_64 musl binaries in Docker"
|
|
echo " --debug Build native debug profile instead of release"
|
|
echo " -h, --help Show this help message"
|
|
echo ""
|
|
echo "Installs to /usr/local/bin/:"
|
|
echo " signer (the signing daemon)"
|
|
echo " signer-client (the CLI client)"
|
|
}
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
--musl)
|
|
BUILD_KIND="musl"
|
|
PROFILE="release"
|
|
CARGO_FLAG=""
|
|
TARGET_DIR="dist"
|
|
shift
|
|
;;
|
|
--debug)
|
|
if [[ "$BUILD_KIND" == "musl" ]]; then
|
|
print_error "--musl currently supports release builds only"
|
|
exit 1
|
|
fi
|
|
PROFILE="debug"
|
|
CARGO_FLAG=""
|
|
TARGET_DIR="target/debug"
|
|
shift
|
|
;;
|
|
-h|--help)
|
|
show_usage
|
|
exit 0
|
|
;;
|
|
*)
|
|
print_error "Unknown option: $1"
|
|
show_usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Check we're in the project root (Cargo.toml present)
|
|
if [[ ! -f "Cargo.toml" ]]; then
|
|
print_error "Cargo.toml not found. Run this script from the project root."
|
|
exit 1
|
|
fi
|
|
|
|
# Check the binaries we expect are declared
|
|
if ! grep -q 'name = "signer"' Cargo.toml || ! grep -q 'name = "signer-client"' Cargo.toml; then
|
|
print_error "Expected binaries 'signer' and 'signer-client' not found in Cargo.toml"
|
|
exit 1
|
|
fi
|
|
|
|
# Build
|
|
if [[ "$BUILD_KIND" == "musl" ]]; then
|
|
print_status "Building static musl release binaries in Docker..."
|
|
./build_musl.sh
|
|
SIGNER_BIN="${TARGET_DIR}/signer-linux-x86_64-musl"
|
|
CLIENT_BIN="${TARGET_DIR}/signer-client-linux-x86_64-musl"
|
|
else
|
|
print_status "Building ${PROFILE} binaries (cargo build ${CARGO_FLAG})..."
|
|
cargo build ${CARGO_FLAG} 2>&1 | tail -5 || {
|
|
print_error "Build failed"
|
|
exit 1
|
|
}
|
|
SIGNER_BIN="${TARGET_DIR}/signer"
|
|
CLIENT_BIN="${TARGET_DIR}/signer-client"
|
|
fi
|
|
|
|
for bin in "$SIGNER_BIN" "$CLIENT_BIN"; do
|
|
if [[ ! -f "$bin" ]]; then
|
|
print_error "Built binary not found: $bin"
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
print_success "Binaries built: $SIGNER_BIN, $CLIENT_BIN"
|
|
|
|
# Install to /usr/local/bin
|
|
DEST_DIR="/usr/local/bin"
|
|
|
|
if [[ ! -d "$DEST_DIR" ]]; then
|
|
print_status "Creating $DEST_DIR..."
|
|
sudo mkdir -p "$DEST_DIR"
|
|
fi
|
|
|
|
install_binary() {
|
|
local src="$1"
|
|
local name="$2"
|
|
print_status "Installing $name to $DEST_DIR/..."
|
|
sudo install -m 0755 "$src" "$DEST_DIR/$name"
|
|
print_success "Installed: $DEST_DIR/$name"
|
|
}
|
|
|
|
install_binary "$SIGNER_BIN" "signer"
|
|
install_binary "$CLIENT_BIN" "signer-client"
|
|
|
|
# Verify
|
|
print_status "Verification:"
|
|
"$DEST_DIR/signer" --version || true
|
|
"$DEST_DIR/signer-client" --version || true
|
|
|
|
print_success "Local deploy completed (${PROFILE} ${BUILD_KIND} profile)"
|