59 lines
1.8 KiB
Bash
59 lines
1.8 KiB
Bash
|
#!/bin/bash
|
||
|
#
|
||
|
# Usage: eg. ./test-run.sh -p /dev/ttyUSB0 -s 192.168.10.1 -d 192.168.10.2
|
||
|
#
|
||
|
|
||
|
# Function to display usage instructions
|
||
|
usage() {
|
||
|
echo "Usage: $0 -p xbee_port -s xbee_net_src_ip -d xbee_net_dst_ip"
|
||
|
echo " -p xbee_port The serial port where the XBee is connected (e.g., /dev/ttyUSB0)"
|
||
|
echo " -s xbee_net_src_ip The source IP address for the XBee network (e.g., 192.168.10.1)"
|
||
|
echo " -d xbee_net_dst_ip The destination IP address to ping (e.g., 192.168.10.2)"
|
||
|
exit 1
|
||
|
}
|
||
|
|
||
|
# Parse command-line arguments
|
||
|
while getopts "p:s:d:" opt; do
|
||
|
case "$opt" in
|
||
|
p) xbee_port=$OPTARG ;;
|
||
|
s) xbee_net_src_ip=$OPTARG ;;
|
||
|
d) xbee_net_dst_ip=$OPTARG ;;
|
||
|
*) usage ;;
|
||
|
esac
|
||
|
done
|
||
|
|
||
|
# Check if all required arguments are provided
|
||
|
if [ -z "$xbee_port" ] || [ -z "$xbee_net_src_ip" ] || [ -z "$xbee_net_dst_ip" ]; then
|
||
|
usage
|
||
|
fi
|
||
|
|
||
|
# Update package list and install necessary packages
|
||
|
echo "Installing necessary packages..."
|
||
|
sudo apt-get update
|
||
|
sudo apt-get install -y git build-essential libudev-dev iproute2 iputils-ping cargo
|
||
|
|
||
|
# Clone the xbnet repository
|
||
|
echo "Cloning xbnet repository..."
|
||
|
git clone https://github.com/jgoerzen/xbnet.git /usr/src/xbnet
|
||
|
|
||
|
# Build xbnet
|
||
|
echo "Building xbnet..."
|
||
|
cd /usr/src/xbnet
|
||
|
cargo build --release
|
||
|
|
||
|
# Copy the built binary to /usr/local/bin
|
||
|
echo "Installing xbnet..."
|
||
|
sudo cp target/release/xbnet /usr/local/bin/xbnet
|
||
|
|
||
|
# Configure the XBee network interface
|
||
|
echo "Configuring XBee network interface..."
|
||
|
sudo xbnet $xbee_port tun
|
||
|
sudo ip addr add $xbee_net_src_ip/24 dev xbnet0
|
||
|
sudo ip link set dev xbnet0 up
|
||
|
|
||
|
# Ping the destination IP to verify connectivity
|
||
|
echo "Pinging destination IP $xbee_net_dst_ip..."
|
||
|
ping -c 4 $xbee_net_dst_ip
|
||
|
|
||
|
echo "Setup complete. The XBee network interface is configured and tested."
|