Files
signer/deploy_local.sh
T

125 lines
3.1 KiB
Bash
Executable File

#!/bin/bash
set -e
# signer (Rust) — Local Deploy Script
#
# Builds release binaries and installs them to /usr/local/bin/.
#
# USAGE:
# ./deploy_local.sh # build release + install
# ./deploy_local.sh --debug # build debug + 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"
show_usage() {
echo "signer (Rust) Local Deploy Script"
echo ""
echo "USAGE:"
echo " $0 [OPTIONS]"
echo ""
echo "OPTIONS:"
echo " --debug Build 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
--debug)
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
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"
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
name=$(basename "$src")
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"
install_binary "$CLIENT_BIN"
# Verify
print_status "Verification:"
"$DEST_DIR/signer" --version || true
"$DEST_DIR/signer-client" --version || true
print_success "Local deploy completed (${PROFILE} profile)"