-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun
More file actions
executable file
·47 lines (36 loc) · 1.11 KB
/
run
File metadata and controls
executable file
·47 lines (36 loc) · 1.11 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
#!/bin/bash
set -e # Exit on error
# Set the target directory for cargo build
CARGO_TARGET_DIR=/app/target
# Define IP address and interface
IP_ADDRESS="192.168.0.1/24"
INTERFACE="tun0"
# Build the Rust project in release mode
cargo b --release
ext=$?
# Check if the build was successful
if [[ $ext -ne 0 ]]; then
exit $ext
fi
# Set capabilities for trust binary
echo "setting cap net admin"
setcap cap_net_admin=eip $CARGO_TARGET_DIR/release/trust
# Run the trust binary in the background and capture its process ID
$CARGO_TARGET_DIR/release/trust &
pid=$!
# Check if the IP address is not already added to the specified interface
# if ! ip addr show dev $INTERFACE | grep -q $IP_ADDRESS; then
echo "adding $IP_ADDRESS to $INTERFACE"
ip addr add $IP_ADDRESS dev $INTERFACE
# fi
# Check if the tun0 interface does not exist
if ! ip link show tun0 &> /dev/null; then
echo "adding tun0 interface"
ip tuntap add dev tun0 mode tun
fi
echo "setting up tun0"
ip link set tun0 up
# Set up a trap to kill the trust process on INT or TERM signals
trap "kill $pid" INT TERM
# Wait for the trust process to finish
wait $pid