bodeting.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/bash
  2. # This file serves as as an example of how I launch the debug server and client in a tmux session for what I call "Bodeting" (Bodet Alarm and Gong) testing
  3. # Parse command line arguments
  4. SUDO_PASSWORD="mlol-no"
  5. while getopts "p:" opt; do
  6. case $opt in
  7. p) SUDO_PASSWORD="$OPTARG" ;;
  8. *) echo "Usage: $0 [-p sudo_password]" >&2; exit 1 ;;
  9. esac
  10. done
  11. # Create directory for client configs if it doesn't exist
  12. mkdir -p configs
  13. # Create server config with multicast groups
  14. cat > configs/server_config.toml << EOF
  15. secret = "bodeting-secret-key-so-much-secure"
  16. listen_ip = "0.0.0.0"
  17. listen_port = 8989
  18. simple_auth = true
  19. [multicast_groups]
  20. # Bodet Alarm group for 239.192.55.2
  21. [multicast_groups.bodetalarm]
  22. address = "239.192.55.2"
  23. port = 1681
  24. # Bodet Gong group for 239.192.55.1
  25. [multicast_groups.bodetgong]
  26. address = "239.192.55.1"
  27. port = 1681
  28. # Test client authorizations
  29. [[authorized_clients]]
  30. name = "localhost"
  31. ip_address = "127.0.0.1"
  32. group_ids = [] # Empty means all groups
  33. EOF
  34. # Create debug agent config
  35. cat > configs/debug_agent_config.toml << EOF
  36. secret = "bodeting-secret-key-so-much-secure"
  37. server = "127.0.0.1"
  38. port = 8989
  39. multicast_group_ids = []
  40. # Set to true for debug mode
  41. test_mode = true
  42. EOF
  43. # Check if tmux is already running
  44. if [ -z "$TMUX" ]; then
  45. # Start a new tmux session
  46. tmux new-session -d -s debug_server
  47. # Split the window horizontally (side by side)
  48. tmux split-window -h -t debug_server:0.0
  49. # Configure the left pane for the server
  50. if [ -n "$SUDO_PASSWORD" ]; then
  51. tmux send-keys -t debug_server:0.0 "cd $(pwd) && clear && echo 'Starting server...' && echo '$SUDO_PASSWORD' | sudo -S RUST_LOG=debug ./target/release/castrepeat-server --config configs/server_config.toml" C-m
  52. else
  53. tmux send-keys -t debug_server:0.0 "cd $(pwd) && clear && echo 'Starting server...' && sudo RUST_LOG=debug ./target/release/castrepeat-server --config configs/server_config.toml" C-m
  54. fi
  55. # Give the server a moment to start up
  56. sleep 2
  57. # Configure the right pane for the debug agent
  58. tmux send-keys -t debug_server:0.1 "cd $(pwd) && clear && echo 'Starting debug agent...' && RUST_LOG=debug ./target/release/castrepeat-client --config configs/debug_agent_config.toml" C-m
  59. # If you need to test multicast traffic generation, you can add:
  60. # tmux split-window -v -t debug_server:0.1
  61. # tmux send-keys -t debug_server:0.2 "cd $(pwd) && clear && echo 'Starting multicast generator...' && RUST_LOG=debug ./target/release/castrepeat-mcast-test" C-m
  62. # Attach to the session
  63. tmux attach-session -t debug_server
  64. else
  65. echo "Already in a tmux session. Please exit current tmux session before running this script."
  66. exit 1
  67. fi