summarylogtreecommitdiffstats
path: root/wg-bench.sh
blob: a4e895d64a45d475eb6c8882a0f3197daae19945 (plain)
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
#!/bin/sh

# Check if running as root
if [ "$(id -u)" -ne 0 ]; then
    echo "Error: This script must be run as root." >&2
    exit 1
fi

# Define help message
print_help() {
    cat <<EOF
Usage: ${0##*/} [command]

Available commands:
    setup-netns    Set up network namespaces
    benchmark      Run the benchmark
    clean-up       Clean up resources
    config         Edit the configuration file

Please run as root.
EOF
}

# Validate arguments
if [ $# -ne 1 ]; then
    print_help >&2
    exit 1
fi

COMMAND="$1"
WG_BENCH_DIR="/opt/wg-bench"

case "$COMMAND" in
    setup-netns|benchmark|clean-up)
        # Execute corresponding script
        SCRIPT_PATH="${WG_BENCH_DIR}/${COMMAND}.sh"
        if [ ! -f "$SCRIPT_PATH" ]; then
            echo "Error: Required script $SCRIPT_PATH not found." >&2
            exit 1
        fi
        cd "$WG_BENCH_DIR" || {
            echo "Error: Could not access directory $WG_BENCH_DIR" >&2
            exit 1
        }
        $SCRIPT_PATH
        ;;
    config)
        # Edit config with $EDITOR or fallback to vi
        CONFIG_PATH="${WG_BENCH_DIR}/config.sh"
        EDITOR="${EDITOR:-vi}"
        if ! command -v "$EDITOR" >/dev/null 2>&1; then
            echo "Error: Editor '$EDITOR' not found." >&2
            exit 1
        fi
        "$EDITOR" "$CONFIG_PATH"
        ;;
    *)
        print_help >&2
        exit 1
        ;;
esac