You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.3 KiB

  1. #! /bin/bash
  2. IMAGE_NAME="leesah/shadowsocks-libev"
  3. PORTNUMBER="8338"
  4. SHADOWSOCKS="/usr/local/bin/ss-server"
  5. HOST="-s 0.0.0.0"
  6. PORT="-p $PORTNUMBER"
  7. JSON=""
  8. function print_usage {
  9. echo
  10. echo "Usage:"
  11. echo " docker run $IMAGE_NAME [OPTIONS]"
  12. echo
  13. echo "OPTIONS"
  14. echo " -k <password> password of your remote server"
  15. echo
  16. echo " [-m <encrypt_method>] encrypt method: table, rc4, rc4-md5"
  17. echo " aes-128-cfb, aes-192-cfb, aes-256-cfb,"
  18. echo " bf-cfb, camellia-128-cfb, camellia-192-cfb,"
  19. echo " camellia-256-cfb, cast5-cfb, des-cfb, idea-cfb,"
  20. echo " rc2-cfb, seed-cfb, salsa20 and chacha20"
  21. echo " [-t <timeout>] socket timeout in seconds"
  22. echo " [-c <config_file>] config file in json"
  23. echo " [-u] enable udprelay mode"
  24. echo " [-v] verbose mode"
  25. echo
  26. echo " [--fast-open] enable TCP fast open"
  27. echo " [--acl <acl_file>] config file of ACL \(Access Control List\)"
  28. echo
  29. echo " [-h] print this"
  30. echo
  31. }
  32. function print_usage_configfile {
  33. echo "Config file is currently not supported by this image."
  34. echo
  35. echo "See https://github.com/leesah/shadowsocks-libev/issues/1 for current progress."
  36. echo
  37. }
  38. function print_usage_host {
  39. echo "To specify the host on which ss-server should listen, please use"
  40. echo " docker run -p $1::$PORTNUMBER ..."
  41. echo "or"
  42. echo " docker run -p $1:<HOST-PORT>:$PORTNUMBER ..."
  43. echo
  44. echo "See manpage of docker-run for more details:"
  45. echo " man docker-run"
  46. echo
  47. }
  48. function print_usage_port {
  49. echo "To specify the port on which ss-server should listen, please use"
  50. echo " docker run -p $1:$PORTNUMBER ..."
  51. echo
  52. }
  53. OPTIONS=`getopt -o s:p:k:m:t:c:uvh --long server:,key:,password:,encrypt-method:,timeout:,acl:,server-port:,config-file:,fast-open,help -n "$IMAGE_NAME" -- "$@"`
  54. if [ $? -ne 0 ]; then
  55. print_usage
  56. exit 1
  57. fi
  58. eval set -- "$OPTIONS"
  59. while true; do
  60. case "$1" in
  61. -k|--key|--password) PASSWORD="-k $2"; shift 2;;
  62. -m|--encrypt-method) ENCRYPTION="-m $2"; shift 2;;
  63. -t|--timeout) TIMEOUT="-t $2"; shift 2;;
  64. --acl) ACL="--acl $2"; shift 2;;
  65. --fast-open) FAST_OPEN="--fast-open"; shift;;
  66. -u) UDP_RELAY="-u"; shift;;
  67. -v) VERBOSE="-v"; shift;;
  68. --) shift; break;;
  69. -c|--config-file) print_usage_configfile; exit 128;;
  70. -s|--server) print_usage_host "$2"; exit 128;;
  71. -p|--server-port) print_usage_port "$2"; exit 128;;
  72. -h|--help) print_usage; exit 0;;
  73. *)
  74. echo "$IMAGE_NAME: unexpected argument: $1"
  75. print_usage
  76. exit 1;;
  77. esac
  78. done
  79. if [ -z "$HOST" -o -z "$PORT" -o -z "$PASSWORD" ]; then
  80. echo "$IMAGE_NAME: insufficient arguments."
  81. print_usage
  82. exit 1
  83. fi
  84. echo "Launching Shadowsocks server..."
  85. echo "To watch the output, run"
  86. echo " docker ps -ql | xargs docker logs -f"
  87. $SHADOWSOCKS $HOST $PORT $PASSWORD $ENCRYPTION $TIMEOUT $UDP_RELAY $VERBOSE $FAST_OPEN $ACL $JSON