-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
47 lines (36 loc) · 957 Bytes
/
run.sh
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
#!/bin/bash
set -e
if [ -f .env ]; then
export $(grep -v '#' .env | xargs)
else
echo ".env file not found!"
exit 1
fi
cleanup() {
sudo ip link set down dev tun0 || true
sudo ip tuntap del dev tun0 mode tun || true
}
# cleaning up
trap cleanup EXIT
# Build the Rust project
cargo b --release
ext=$?
if [[ $ext -ne 0 ]]; then
echo "$ext"
fi
# Create tun0 interface if it doesn't exist
if ! ip link show tun0 > /dev/null 2>&1; then
sudo ip tuntap add dev tun0 mode tun
fi
# Set capabilities for the binary
sudo setcap cap_net_admin=eip "$CARGO_TARGET_DIR"/release/rfc793
# Run the binary in the background
"$CARGO_TARGET_DIR"/release/rfc793 &
RUST_PROCESS_ID=$!
# Configure the tun0 interface if the IP address is not already assigned
if ! ip addr show tun0 | grep -q "192.168.0.1/24"; then
sudo ip addr add 192.168.0.1/24 dev tun0
fi
sudo ip link set up dev tun0
# Wait for the Rust process to exit
wait $RUST_PROCESS_ID