Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable passing hostnames instead of IPs #45

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function show_help {
echo ""
echo "Usage: ${0} [-h | -v VEHICLE | -w WORLD] [IP_API | IP_QGC IP_API]"
echo "Usage: ${0} [-h | -v VEHICLE | -w WORLD] [HOST_API | HOST_QGC HOST_API]"
echo ""
echo "Run a headless px4-gazebo simulation in a docker container. The"
echo "available vehicles and worlds are the ones available in PX4"
Expand All @@ -12,12 +12,24 @@ function show_help {
echo " -v Set the vehicle (default: iris)"
echo " -w Set the world (default: empty)"
echo ""
echo " <IP_API> is the IP to which PX4 will send MAVLink on UDP port 14540"
echo " <IP_QGC> is the IP to which PX4 will send MAVLink on UDP port 14550"
echo " <HOST_API> is the host or IP to which PX4 will send MAVLink on UDP port 14540"
echo " <HOST_QGC> is the host or IP to which PX4 will send MAVLink on UDP port 14550"
echo ""
echo "By default, MAVLink is sent to the host."
}

function get_ip {
output=$(getent hosts "$1" | awk '{print $1}')
if [ -z $output ];
then
# No output, assume IP
echo $1
else
# Got IP, use it
echo $output
fi
}

OPTIND=1 # Reset in case getopts has been used previously in the shell.

vehicle=iris
Expand All @@ -38,22 +50,12 @@ done

shift $((OPTIND-1))

# All the leftover arguments are supposed to be IPs
for arg in "$@"
do
if ! [[ ${arg} =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: invalid IP: ${arg}!"
echo ""
show_help
exit 1
fi
done

if [ "$#" -eq 1 ]; then
IP_QGC="$1"
IP_QGC=$(get_ip "$1")
elif [ "$#" -eq 2 ]; then
IP_API="$1"
IP_QGC="$2"
IP_API=$(get_ip "$1")
IP_QGC=$(get_ip "$2")
elif [ "$#" -gt 2 ]; then
show_help
exit 1;
Expand Down
Loading