169 lines
4.6 KiB
Bash
Executable File
169 lines
4.6 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"
|
|
|
|
# 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 ""
|
|
}
|
|
|
|
# Build the application in debug mode
|
|
function build_debug {
|
|
echo -e "${GREEN}Building in debug mode...${NC}"
|
|
cargo build
|
|
}
|
|
|
|
# Build the application in release mode
|
|
function build_release {
|
|
echo -e "${GREEN}Building in release mode...${NC}"
|
|
cargo build --release
|
|
}
|
|
|
|
# Run the application
|
|
function run_app {
|
|
echo -e "${GREEN}Running application...${NC}"
|
|
cargo run
|
|
}
|
|
|
|
# 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
|
|
}
|
|
|
|
# Install development dependencies
|
|
function setup {
|
|
echo -e "${GREEN}Installing development dependencies...${NC}"
|
|
|
|
# Check if running on Raspberry Pi
|
|
if [ -f /etc/os-release ]; then
|
|
. /etc/os-release
|
|
if [[ "$ID" == "raspbian" ]]; then
|
|
echo -e "${YELLOW}Detected Raspberry Pi OS${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
|
|
# 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"
|
|
else
|
|
echo -e "${YELLOW}Not running on Raspberry Pi OS, skipping system dependencies${NC}"
|
|
fi
|
|
fi
|
|
|
|
# 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
|