meteor_detect/build.sh

203 lines
6.3 KiB
Bash
Executable File

#!/bin/bash
set -e
# Meteor Detection System build script
# Define colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Default configuration
CONFIG_DIR="$HOME/.config/meteor_detect"
# Detect OS platform
PLATFORM=$(uname)
if [[ "$PLATFORM" == "Linux" ]]; then
IS_RASPBERRY_PI=false
# Check if we're on a Raspberry Pi
if [ -f /proc/device-tree/model ]; then
MODEL=$(tr -d '\0' < /proc/device-tree/model)
if [[ "$MODEL" == *"Raspberry Pi"* ]]; then
IS_RASPBERRY_PI=true
fi
fi
PLATFORM_FEATURE="--features gpio,gstreamer-display"
echo -e "${GREEN}Detected Linux platform. Enabling GPIO and GStreamer support.${NC}"
else
PLATFORM_FEATURE="--features gstreamer-display"
echo -e "${YELLOW}Detected non-Linux platform ($PLATFORM). GPIO support disabled, GStreamer enabled.${NC}"
fi
# Print help message
function print_help {
echo -e "${YELLOW}Meteor Detection System Build Script${NC}"
echo ""
echo "Usage: $0 [command]"
echo ""
echo "Commands:"
echo " build Build the application in debug mode"
echo " build-release Build the application in release mode"
echo " run Run the application"
echo " clean Clean build artifacts"
echo " setup Install development dependencies"
echo " test Run tests"
echo " create-config Create a default configuration file"
echo " help Show this help message"
echo ""
if [[ "$PLATFORM" != "Linux" ]]; then
echo -e "${YELLOW}Note: Running on non-Linux platform. GPIO support is disabled.${NC}"
echo -e "${YELLOW} Only video processing and meteor detection will be available.${NC}"
fi
}
# Build the application in debug mode
function build_debug {
echo -e "${GREEN}Building in debug mode...${NC}"
cargo build $PLATFORM_FEATURE
}
# Build the application in release mode
function build_release {
echo -e "${GREEN}Building in release mode...${NC}"
cargo build --release $PLATFORM_FEATURE
}
# Run the application
function run_app {
echo -e "${GREEN}Running application...${NC}"
cargo run $PLATFORM_FEATURE
}
# Clean build artifacts
function clean {
echo -e "${GREEN}Cleaning build artifacts...${NC}"
cargo clean
}
# Run tests
function run_tests {
echo -e "${GREEN}Running tests...${NC}"
cargo test $PLATFORM_FEATURE
}
# Install development dependencies
function setup {
echo -e "${GREEN}Installing development dependencies...${NC}"
# Check if running on Raspberry Pi
if [[ "$IS_RASPBERRY_PI" == "true" ]]; then
echo -e "${YELLOW}Detected Raspberry Pi hardware${NC}"
# Install system dependencies
echo -e "${GREEN}Installing system dependencies...${NC}"
sudo apt update
sudo apt install -y git curl build-essential pkg-config \
libssl-dev libv4l-dev v4l-utils \
libopencv-dev libsqlite3-dev libglib2.0-dev \
libudev-dev libgstrtspserver-1.0-dev \
gcc g++ cmake clang libclang-dev llvm-dev \
sudo apt-get install libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev \
gstreamer1.0-plugins-base gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly \
gstreamer1.0-libav gstreamer1.0-tools \
gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl \
gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio
elif [[ "$PLATFORM" == "Darwin" ]]; then
echo -e "${YELLOW}Detected macOS platform${NC}"
# Check for Homebrew and install dependencies
if command -v brew &> /dev/null; then
echo -e "${GREEN}Installing macOS dependencies via Homebrew...${NC}"
brew install opencv gstreamer sqlite3 pkg-config
brew install gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly
else
echo -e "${RED}Homebrew not found. Please install it from https://brew.sh/${NC}"
echo -e "${YELLOW}Then install the required dependencies:${NC}"
echo "brew install opencv gstreamer sqlite3 pkg-config"
echo "brew install gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly"
fi
else
echo -e "${YELLOW}Platform-specific setup not implemented for $PLATFORM${NC}"
echo -e "${YELLOW}You may need to manually install dependencies like OpenCV and GStreamer${NC}"
fi
# Install Rust if not already installed
if ! command -v rustc &> /dev/null; then
echo -e "${GREEN}Installing Rust...${NC}"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
fi
# Create configuration directory
mkdir -p "$CONFIG_DIR"
# Check for Rust installation
if ! command -v rustc &> /dev/null; then
echo -e "${RED}Rust is not installed. Please install Rust from https://rustup.rs/${NC}"
exit 1
fi
# Update Rust toolchain
echo -e "${GREEN}Updating Rust toolchain...${NC}"
rustup update
echo -e "${GREEN}Setup complete!${NC}"
}
# Create default configuration
function create_config {
echo -e "${GREEN}Creating default configuration...${NC}"
mkdir -p "$CONFIG_DIR"
if [ -f "$CONFIG_DIR/config.toml" ]; then
echo -e "${YELLOW}Configuration file already exists at $CONFIG_DIR/config.toml${NC}"
read -p "Overwrite? (y/N) " confirm
if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
echo "Aborted"
return 0
fi
fi
cp config-example.toml "$CONFIG_DIR/config.toml"
echo -e "${GREEN}Default configuration created at $CONFIG_DIR/config.toml${NC}"
}
# Main script entry point
case "$1" in
"build")
build_debug
;;
"build-release")
build_release
;;
"run")
run_app
;;
"clean")
clean
;;
"setup")
setup
;;
"test")
run_tests
;;
"create-config")
create_config
;;
"help"|"")
print_help
;;
*)
echo -e "${RED}Unknown command: $1${NC}"
print_help
exit 1
;;
esac
exit 0