-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·93 lines (76 loc) · 2.25 KB
/
setup.sh
File metadata and controls
executable file
·93 lines (76 loc) · 2.25 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
set -e
# --- Configuration ---
INTERFACE="aether0"
HOST_IP="192.168.1.1/24"
HOST_MAC="00:11:22:33:44:55"
PROJECT_NAME="aether"
# --- Argument Parsing ---
MODE="release"
BUILD_FLAG="--release"
TARGET_DIR="release"
if [[ "$1" == "--debug" ]]; then
MODE="debug"
BUILD_FLAG=""
TARGET_DIR="debug"
fi
BINARY="./target/$TARGET_DIR/$PROJECT_NAME"
echo "========================================"
echo " Project Aether: Environment Setup"
echo " Mode: $MODE"
echo "========================================"
# --- Step 1: Build the Stack (As User) ---
echo "[*] Building binary..."
if cargo build $BUILD_FLAG; then
echo "[✔] Build successful."
else
echo "[✘] Build failed! Aborting."
exit 1
fi
# --- Step 2: Network Configuration (Requires Sudo) ---
cleanup() {
echo ""
echo "[*] Shutting down..."
# Only delete if it exists
if ip link show $INTERFACE > /dev/null 2>&1; then
sudo ip link delete $INTERFACE
echo "[✔] Interface $INTERFACE removed."
fi
}
# Trap Ctrl+C (SIGINT) to ensure cleanup runs
trap cleanup SIGINT
echo "[*] Configuring Network Interface..."
# Check if interface exists and reset it
if ip link show $INTERFACE > /dev/null 2>&1; then
echo " [-] Removing existing $INTERFACE..."
sudo ip link delete $INTERFACE
fi
# Create TAP
sudo ip tuntap add mode tap name $INTERFACE
echo " [+] Created TAP interface: $INTERFACE"
# Assign IP & MAC
sudo ip addr add $HOST_IP dev $INTERFACE
sudo ip link set dev $INTERFACE address $HOST_MAC
echo " [+] Host IP assigned: $HOST_IP"
echo " [+] Host MAC static: $HOST_MAC"
# Bring Up
sudo ip link set dev $INTERFACE up
echo " [+] Interface is UP"
# --- Step 3: Permissions & Launch ---
echo "[*] Setting Capabilities..."
if [ -f "$BINARY" ]; then
# Give the binary permission to use network interfaces without running as full root
sudo setcap cap_net_admin,cap_net_raw+eip "$BINARY"
echo " [+] Capabilities set on $BINARY"
else
echo "[✘] Critical Error: Binary not found at $BINARY"
cleanup
exit 1
fi
echo "========================================"
echo " Aether Stack Launching..."
echo " (Ctrl+C to stop and cleanup)"
echo "========================================"
# Launch the binary
"$BINARY"
cleanup