diff --git a/setup/setup_px4_sitl.sh b/setup/setup_px4_sitl.sh index e2d4862..b8abd96 100644 --- a/setup/setup_px4_sitl.sh +++ b/setup/setup_px4_sitl.sh @@ -4,28 +4,18 @@ REPO_URL="https://github.com/alireza787b/PX4-Autopilot-Me.git" BRANCH_NAME="px4xplane-sitl" UPSTREAM_URL="https://github.com/PX4/PX4-Autopilot.git" -DEFAULT_CLONE_PATH="$HOME/testpx4" # Default path is set here, but it can be customized by the user +DEFAULT_CLONE_PATH="$HOME/testpx4" DEFAULT_CONFIG_FILE="$HOME/.px4sitl_config" -DEFAULT_FALLBACK_IP="127.0.0.1" # Fallback IP if no IP is detected or entered -SCRIPT_NAME="px4xplane_script.sh" # Name of the script - -# === Airframe Options for SITL === +DEFAULT_FALLBACK_IP="127.0.0.1" +SCRIPT_NAME="px4xplane_script.sh" PLATFORM_CHOICES=("xplane_ehang184" "xplane_alia250" "xplane_cessna172" "xplane_tb2") +REPAIR_MODE_FLAG="--repair" -# === Check if Uninstall Option is Passed === -if [[ "$1" == "--uninstall" ]]; then - echo "Uninstalling global access for px4xplane..." - if [ -L "$HOME/bin/px4xplane" ]; then - rm "$HOME/bin/px4xplane" - echo "Removed global command from $HOME/bin." - elif [ -L "$HOME/.local/bin/px4xplane" ]; then - rm "$HOME/.local/bin/px4xplane" - echo "Removed global command from $HOME/.local/bin." - else - echo "Global command not found." - fi - echo "Uninstallation complete." - exit 0 +# === Flags and Arguments === +REPAIR_MODE=false # Default: Skip repair if not explicitly asked +if [[ "$1" == "$REPAIR_MODE_FLAG" ]]; then + REPAIR_MODE=true + shift fi # === Check for Custom Installation Directory Parameter === @@ -39,13 +29,13 @@ else CONFIG_FILE="$DEFAULT_CONFIG_FILE" fi -# === Create the Parent Directory if it Doesn't Exist === +# === Create Parent Directory if Needed === if [ ! -d "$INSTALL_PATH" ]; then echo "Directory $INSTALL_PATH does not exist. Creating it..." mkdir -p "$INSTALL_PATH" fi -# === Ensure the Script is Copied to the Parent Directory (Not Inside the Repo) === +# === Copy Script to Parent Directory === SCRIPT_PATH="$INSTALL_PATH/$SCRIPT_NAME" if [ "$(basename "$0")" != "$SCRIPT_NAME" ]; then echo "Copying script to $SCRIPT_PATH..." @@ -53,73 +43,85 @@ if [ "$(basename "$0")" != "$SCRIPT_NAME" ]; then chmod +x "$SCRIPT_PATH" fi +# === Distinguish Important Prompts === +highlight() { + echo -e "\n\033[1;33m$1\033[0m\n" # Yellow bold text +} + # === Introductory Information === -echo "----------------------------------------------------------" -echo "PX4 X-Plane SITL Setup Script" -echo "Author: Alireza Ghaderi" -echo "GitHub Repo: alireza787b/px4xplane" -echo "LinkedIn: alireza787b" -echo "Date: August 2024" -echo "----------------------------------------------------------" -echo "This script helps you set up PX4 SITL with X-Plane integration." -echo "It will clone the repository, install dependencies, and build SITL." -echo "You will need to download the PX4 X-Plane plugin from the release" -echo "section of this repository: https://github.com/alireza787b/px4xplane" -echo "Please ensure to follow the README instructions and video tutorials." -echo "This is a temporary setup until the integration is merged officially with PX4." -echo "----------------------------------------------------------" -echo "Press Enter to start the process (default: continue in 5 seconds)..." +highlight "----------------------------------------------------------" +highlight "PX4 X-Plane SITL Setup Script" +highlight "Author: Alireza Ghaderi" +highlight "GitHub Repo: alireza787b/px4xplane" +highlight "LinkedIn: alireza787b" +highlight "Date: August 2024" +highlight "----------------------------------------------------------" +highlight "This script helps you set up PX4 SITL with X-Plane integration." +highlight "You will need to download the PX4 X-Plane plugin from the release section of this repository: https://github.com/alireza787b/px4xplane" +highlight "This is a temporary setup until the integration is merged officially with PX4." +highlight "----------------------------------------------------------" +highlight "Press Enter to start the process (default: continue in 5 seconds)..." read -t 5 -r # === Prerequisites Check === -echo "Checking for required tools..." +highlight "Checking for required tools..." if ! command -v git &> /dev/null; then echo "Git is not installed. Please install Git and run the script again." exit 1 fi -# === Clone the Repository === -if [ ! -d "$CLONE_PATH/.git" ]; then - echo "Cloning the repository from $REPO_URL into $CLONE_PATH..." - git clone --recursive "$REPO_URL" "$CLONE_PATH" +# === Simplified Process for Subsequent Runs === +if [ -d "$CLONE_PATH" ] && [ -f "$CONFIG_FILE" ] && [ "$REPAIR_MODE" = false ]; then + highlight "Detected existing configuration. Skipping setup and proceeding to build..." else - echo "Repository already cloned at $CLONE_PATH." -fi + # === Full Repair Mode (If Flag is Set) === + if [ "$REPAIR_MODE" = true ]; then + highlight "Repair mode enabled. Running full setup and pulling the latest code..." + fi -cd "$CLONE_PATH" || exit -git checkout "$BRANCH_NAME" + # === Clone the Repository === + if [ ! -d "$CLONE_PATH/.git" ]; then + highlight "Cloning the repository from $REPO_URL into $CLONE_PATH..." + git clone --recursive "$REPO_URL" "$CLONE_PATH" + else + echo "Repository already cloned at $CLONE_PATH." + fi -# === Add Upstream and Fetch Tags === -echo "Adding upstream repository and fetching tags..." -git remote add upstream "$UPSTREAM_URL" -git fetch upstream -git fetch upstream --tags + cd "$CLONE_PATH" || exit + git checkout "$BRANCH_NAME" -# If tag issue persists, create a missing tag manually -if ! git tag | grep -q "v1.14.0-dev"; then - echo "Creating missing tag v1.14.0-dev..." - git tag v1.14.0-dev -fi + # === Add Upstream and Fetch Tags === + highlight "Adding upstream repository and fetching tags..." + git remote add upstream "$UPSTREAM_URL" + git fetch upstream + git fetch upstream --tags -# === Run the ubuntu.sh Script === -echo "Running setup script to install dependencies..." -bash Tools/setup/ubuntu.sh -echo "Setup complete. For WSL users, it's recommended to exit WSL, restart it, and rerun the script." + # If tag issue persists, create a missing tag manually + if ! git tag | grep -q "v1.14.0-dev"; then + echo "Creating missing tag v1.14.0-dev..." + git tag v1.14.0-dev + fi + + # === Run the ubuntu.sh Script === + highlight "Running setup script to install dependencies..." + bash Tools/setup/ubuntu.sh + echo "Setup complete. For WSL users, it's recommended to exit WSL, restart it, and rerun the script." -# === Fetch Latest Changes === -echo "Fetching the latest changes from the remote repository..." -git fetch --all -git pull origin "$BRANCH_NAME" + # === Fetch Latest Changes === + highlight "Fetching the latest changes from the remote repository..." + git fetch --all + git pull origin "$BRANCH_NAME" -# === Initialize and Update Submodules === -echo "Updating submodules..." -git submodule update --init --recursive + # === Initialize and Update Submodules === + highlight "Updating submodules..." + git submodule update --init --recursive +fi # === Clean Build Options === -echo "Do you want to run 'make clean' to clean the build directory? Press Enter to skip (default) or type 'y' to clean: " +highlight "Do you want to run 'make clean' to clean the build directory? Press Enter to skip (default) or type 'y' to clean: " read -t 5 -r CLEAN_BUILD -echo "Do you want to run 'make distclean' to reset the build directory? Press Enter to skip (default) or type 'y' to reset: " +highlight "Do you want to run 'make distclean' to reset the build directory? Press Enter to skip (default) or type 'y' to reset: " read -t 5 -r DISTCLEAN_BUILD if [[ "$CLEAN_BUILD" =~ ^[Yy]$ ]]; then @@ -137,14 +139,14 @@ if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null; then if [ -f "$CONFIG_FILE" ]; then source "$CONFIG_FILE" - echo "Detected previous configuration. Use stored Windows IP ($PX4_SIM_HOSTNAME) or enter a new one (press Enter to keep default: $PX4_SIM_HOSTNAME in 10 seconds):" + highlight "Detected previous configuration. Use stored Windows IP ($PX4_SIM_HOSTNAME) or enter a new one (press Enter to keep default: $PX4_SIM_HOSTNAME in 10 seconds):" else - echo "Auto-detected Windows IP: $AUTO_DETECTED_IP" + highlight "Auto-detected Windows IP: $AUTO_DETECTED_IP" PX4_SIM_HOSTNAME="$AUTO_DETECTED_IP" fi echo "Tip: You can find your Windows IP by opening PowerShell and typing 'ipconfig'. Look for the IP address under the section titled 'Ethernet adapter vEthernet (WSL)' or something similar." - echo "Please enter the IP address if you want to change the detected one (press Enter to accept detected IP or enter a new one):" + highlight "Please enter the IP address if you want to change the detected one (press Enter to accept detected IP or enter a new one):" read -t 10 -r NEW_IP if [ -n "$NEW_IP" ]; then @@ -153,7 +155,7 @@ if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null; then # If no IP is set, default to the predefined fallback IP (localhost or any other) if [ -z "$PX4_SIM_HOSTNAME" ]; then - echo "No IP detected. Falling back to predefined IP: $DEFAULT_FALLBACK_IP (this only works if X-Plane is also running on Linux)." + highlight "No IP detected. Falling back to predefined IP: $DEFAULT_FALLBACK_IP (this only works if X-Plane is also running on Linux)." PX4_SIM_HOSTNAME="$DEFAULT_FALLBACK_IP" fi @@ -171,7 +173,7 @@ fi # === Global Access Setup (Optional) === if ! command -v px4xplane &> /dev/null; then - echo "Do you want to set up global access to the 'px4xplane' command so you can run this script from anywhere?" + highlight "Do you want to set up global access to the 'px4xplane' command so you can run this script from anywhere?" echo "Press Enter to confirm (default: yes) or type 'n' to skip." read -t 10 -r GLOBAL_SETUP if [[ -z "$GLOBAL_SETUP" || "$GLOBAL_SETUP" =~ ^[Yy]$ ]]; then @@ -186,7 +188,7 @@ if ! command -v px4xplane &> /dev/null; then source "$HOME/.bashrc" fi chmod +x "$SCRIPT_PATH" - echo "Global access to 'px4xplane' command set up successfully." + highlight "Global access to 'px4xplane' command set up successfully." echo "You can now run 'px4xplane' from anywhere to execute this script." else echo "Global access setup skipped." @@ -194,28 +196,28 @@ if ! command -v px4xplane &> /dev/null; then fi # === Platform Selection and Build === -echo "Please select the platform to build:" +highlight "Please select the platform to build:" select PLATFORM in "${PLATFORM_CHOICES[@]}"; do if [[ " ${PLATFORM_CHOICES[@]} " =~ " ${PLATFORM} " ]]; then - echo "You have selected $PLATFORM. Building..." + highlight "You have selected $PLATFORM. Building..." LAST_PLATFORM="$PLATFORM" echo "LAST_PLATFORM=$LAST_PLATFORM" >> "$CONFIG_FILE" make px4_sitl_default "$PLATFORM" break else - echo "Invalid selection. Please choose a valid platform." + highlight "Invalid selection. Please choose a valid platform." fi done -echo "Make sure that the selected airframe is defined and selected inside X-Plane's menu and loaded." -echo "Follow the video tutorials and instructions for more guidance." +highlight "Make sure that the selected airframe is defined and selected inside X-Plane's menu and loaded." +highlight "Follow the video tutorials and instructions for more guidance." # === Final Completion Message === -echo "Script completed. Summary:" -echo "- Repository cloned: $CLONE_PATH" -echo "- Dependencies installed" -echo "- Submodules updated" -echo "- Platform built: $PLATFORM" -echo "You can now proceed with running the SITL simulation." +highlight "Script completed. Summary:" +highlight "- Repository cloned: $CLONE_PATH" +highlight "- Dependencies installed" +highlight "- Submodules updated" +highlight "- Platform built: $PLATFORM" +highlight "You can now proceed with running the SITL simulation." # === End of Script ===