Skip to content

Commit

Permalink
path to scrit
Browse files Browse the repository at this point in the history
  • Loading branch information
alireza787b committed Aug 25, 2024
1 parent 8b28eff commit ec4ae00
Showing 1 changed file with 55 additions and 33 deletions.
88 changes: 55 additions & 33 deletions setup/setup_px4_sitl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
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/PX4-Autopilot-Me"
DEFAULT_CLONE_PATH="$HOME/testpx4" # Default path is set here, but it can be customized by the user
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" # The new script name for global access
SCRIPT_NAME="px4xplane_script.sh" # Name of the script

# === Airframe Options for SITL ===
PLATFORM_CHOICES=("xplane_ehang184" "xplane_alia250" "xplane_cessna172" "xplane_tb2")
Expand All @@ -30,42 +30,64 @@ fi

# === Check for Custom Installation Directory Parameter ===
if [ -n "$1" ]; then
CLONE_PATH="$1/PX4-Autopilot-Me"
CONFIG_FILE="$1/.px4sitl_config"
INSTALL_PATH="$1"
CLONE_PATH="$INSTALL_PATH/PX4-Autopilot-Me"
CONFIG_FILE="$INSTALL_PATH/.px4sitl_config"
else
CLONE_PATH="$DEFAULT_CLONE_PATH"
INSTALL_PATH="$DEFAULT_CLONE_PATH"
CLONE_PATH="$INSTALL_PATH/PX4-Autopilot-Me"
CONFIG_FILE="$DEFAULT_CONFIG_FILE"
fi

# === Check if the Directory Exists and Handle Appropriately ===
if [ -d "$CLONE_PATH" ]; then
if [ ! -d "$CLONE_PATH/.git" ]; then
echo "Directory $CLONE_PATH exists but is not a git repository."
echo "Would you like to delete the directory and clone a fresh repository? (y/n)"
read -r DELETE_DIR
if [[ "$DELETE_DIR" =~ ^[Yy]$ ]]; then
rm -rf "$CLONE_PATH"
echo "Directory deleted. Cloning fresh repository..."
git clone --recursive "$REPO_URL" "$CLONE_PATH"
else
echo "Please provide a different directory or ensure $CLONE_PATH is a valid git repository."
exit 1
fi
else
echo "Directory $CLONE_PATH exists and is a valid git repository. Pulling the latest changes..."
cd "$CLONE_PATH" || exit
git checkout "$BRANCH_NAME"
git pull origin "$BRANCH_NAME"
fi
else
# Directory does not exist, so we can clone the repository
# === Create the Parent Directory if it Doesn't Exist ===
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) ===
SCRIPT_PATH="$INSTALL_PATH/$SCRIPT_NAME"
if [ "$(basename "$0")" != "$SCRIPT_NAME" ]; then
echo "Copying script to $SCRIPT_PATH..."
cp "$0" "$SCRIPT_PATH"
chmod +x "$SCRIPT_PATH"
fi

# === 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)..."
read -t 5 -r

# === Prerequisites Check ===
echo "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"
else
echo "Repository already cloned at $CLONE_PATH."
fi

# === Proceed with the Rest of the Script ===

cd "$CLONE_PATH" || exit
git checkout "$BRANCH_NAME"

# === Add Upstream and Fetch Tags ===
echo "Adding upstream repository and fetching tags..."
Expand Down Expand Up @@ -154,16 +176,16 @@ if ! command -v px4xplane &> /dev/null; then
read -t 10 -r GLOBAL_SETUP
if [[ -z "$GLOBAL_SETUP" || "$GLOBAL_SETUP" =~ ^[Yy]$ ]]; then
if [ -d "$HOME/bin" ]; then
ln -sf "$CLONE_PATH/$SCRIPT_NAME" "$HOME/bin/px4xplane"
ln -sf "$SCRIPT_PATH" "$HOME/bin/px4xplane"
elif [ -d "$HOME/.local/bin" ]; then
ln -sf "$CLONE_PATH/$SCRIPT_NAME" "$HOME/.local/bin/px4xplane"
ln -sf "$SCRIPT_PATH" "$HOME/.local/bin/px4xplane"
else
mkdir -p "$HOME/.local/bin"
ln -sf "$CLONE_PATH/$SCRIPT_NAME" "$HOME/.local/bin/px4xplane"
ln -sf "$SCRIPT_PATH" "$HOME/.local/bin/px4xplane"
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$HOME/.bashrc"
source "$HOME/.bashrc"
fi
chmod +x "$CLONE_PATH/$SCRIPT_NAME"
chmod +x "$SCRIPT_PATH"
echo "Global access to 'px4xplane' command set up successfully."
echo "You can now run 'px4xplane' from anywhere to execute this script."
else
Expand Down

0 comments on commit ec4ae00

Please sign in to comment.