-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathgo2_setup.bash
More file actions
executable file
·72 lines (57 loc) · 2.77 KB
/
go2_setup.bash
File metadata and controls
executable file
·72 lines (57 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# === Read network interface from robot_config.yaml ===
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROBOT_CONFIG_PATH="$SCRIPT_DIR/../../robot_config.yaml"
if [ ! -f "$ROBOT_CONFIG_PATH" ]; then
echo "Error: robot_config.yaml not found at $ROBOT_CONFIG_PATH"
return 1 2>/dev/null || exit 1
fi
NETWORK_IFACE=$(python3 -c "import yaml; config = yaml.safe_load(open('$ROBOT_CONFIG_PATH')); print(config['robot_configuration']['network_interface'])" 2>/dev/null)
if [ -z "$NETWORK_IFACE" ]; then
echo "Error: Could not read network_interface from robot_config.yaml"
return 1 2>/dev/null || exit 1
fi
echo "Network interface from config: $NETWORK_IFACE"
# === ROS Environment Variables ===
unset ROS_DOMAIN_ID
unset RMW_IMPLEMENTATION
unset CYCLONEDDS_URI
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
#export ROS_DOMAIN_ID=42
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Export CYCLONEDDS_URI pointing to the XML file in the same directory
export CYCLONEDDS_URI="file://${SCRIPT_DIR}/../../cyclonedds_config.xml"
# === Network Configuration Check ===
if ! command -v nmcli &> /dev/null
then
echo "Info: nmcli command not found. Skipping network configuration."
# The script continues to run without exiting
else
# === Network Configuration Variables ===
IFACE="$NETWORK_IFACE"
echo "Ethernet interface: $IFACE"
IP="192.168.123.170"
NETMASK="255.255.0.0"
GATEWAY="192.168.123.1"
# === Step 1a: Find the active connection name for the specified interface ===
echo "Searching for the active connection on interface $IFACE..."
CONNECTION_NAME=$(nmcli -t -f DEVICE,NAME connection show --active | grep "^$IFACE" | cut -d':' -f2)
if [ -z "$CONNECTION_NAME" ]; then
echo "Error: No active connection found on interface $IFACE. Please ensure the interface is connected and has a profile."
# The script will just finish here, without an error code
else
echo "Found active connection: '$CONNECTION_NAME'"
# === Step 2a: Modify the connection's IPv4 settings ===
echo "Modifying connection '$CONNECTION_NAME' with new IP: $IP..."
# Set the IPv4 method to manual (static IP)
sudo nmcli connection modify "$CONNECTION_NAME" ipv4.method manual
# Set the new IP address and netmask
sudo nmcli connection modify "$CONNECTION_NAME" ipv4.addresses "$IP/16"
# Set the new gateway
sudo nmcli connection modify "$CONNECTION_NAME" ipv4.gateway "$GATEWAY"
# === Step 3a: Reapply the connection to make changes take effect ===
echo "Reapplying connection '$CONNECTION_NAME' to activate the new settings."
sudo nmcli connection up "$CONNECTION_NAME"
echo "Interface $IFACE has been reconfigured successfully."
fi
fi