install.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. PREFIX="${1:-/opt/mynetspeeder}"
  4. BIN_PATH="/usr/local/bin/mynetspeeder"
  5. PYTHON_BIN="${PYTHON_BIN:-$(command -v python3 || true)}"
  6. PACKAGE_PARENT="$(dirname "$PREFIX")"
  7. PACKAGE_NAME="$(basename "$PREFIX")"
  8. if [[ $EUID -ne 0 ]]; then
  9. echo "need root"
  10. exit 1
  11. fi
  12. if [[ -z "$PYTHON_BIN" ]]; then
  13. echo "python3 not found"
  14. exit 1
  15. fi
  16. if ! command -v rsync >/dev/null 2>&1; then
  17. echo "rsync not found"
  18. exit 1
  19. fi
  20. mkdir -p "$PREFIX"
  21. rsync -a --delete /home/mynetspeeder/ "$PREFIX/"
  22. find "$PREFIX" -name '__pycache__' -type d -prune -exec rm -rf {} +
  23. cat > "$BIN_PATH" <<EOF
  24. #!/usr/bin/env bash
  25. set -euo pipefail
  26. export PYTHONPATH="$PACKAGE_PARENT\${PYTHONPATH:+:\$PYTHONPATH}"
  27. cd "$PACKAGE_PARENT"
  28. exec "$PYTHON_BIN" -m "$PACKAGE_NAME" "\$@"
  29. EOF
  30. chmod +x "$BIN_PATH"
  31. chmod +x \
  32. "$PREFIX/scripts/install.sh" \
  33. "$PREFIX/scripts/start-main.sh" \
  34. "$PREFIX/scripts/stop-main.sh" \
  35. "$PREFIX/scripts/start-relay-main.sh" \
  36. "$PREFIX/scripts/stop-relay-main.sh" \
  37. "$PREFIX/scripts/commands/tcp_only_start.sh" \
  38. "$PREFIX/scripts/commands/tcp_only_stop.sh" \
  39. "$PREFIX/scripts/commands/udp_only_start.sh" \
  40. "$PREFIX/scripts/commands/udp_only_stop.sh" \
  41. "$PREFIX/scripts/commands/start-relay-tcp.sh" \
  42. "$PREFIX/scripts/commands/stop-relay-tcp.sh" \
  43. "$PREFIX/scripts/commands/start-relay-udp.sh" \
  44. "$PREFIX/scripts/commands/stop-relay-udp.sh"
  45. echo "installed to $PREFIX"
  46. echo "package parent: $PACKAGE_PARENT"
  47. echo "command: $BIN_PATH"
  48. echo "test: mynetspeeder --help"