install.sh 1021 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. set -e
  3. show_usage="./install.sh -u(--user) user -n(--name) name -e(--exec) exec"
  4. server_name=""
  5. server_user=""
  6. server_exec=""
  7. server_path=""
  8. while [ -n "$1" ]; do
  9. case "$1" in
  10. -n|--name ) server_name=$2 ; shift 2;;
  11. -u|--user ) server_user=$2 ; shift 2;;
  12. -e|--exec ) server_exec=$2 ; shift 2;;
  13. -d|--chdir ) server_path=$2 ; shift 2;;
  14. * ) echo $show_usage; exit 1 ;;
  15. esac
  16. done
  17. echo "Received: server_name: $server_name, server_user: $server_user, server_exec: $server_exec"
  18. if [[ "" == $server_name ]]; then
  19. echo "Invalid name"
  20. exit 1
  21. elif [[ "" == $server_exec ]]; then
  22. echo "Invalid exec"
  23. exit 1
  24. elif [[ "" == $server_user ]]; then
  25. echo "Invalid user"
  26. exit 1
  27. fi
  28. test "" -ne $server_path || server_path=`pwd`
  29. serverd=/etc/init.d/${server_name}d
  30. cp -f server.sh $serverd
  31. sed -i "s!SERVER_NAME!$server_name!" $serverd
  32. sed -i "s!SERVER_USER!$server_user!" $serverd
  33. sed -i "s!SERVER_DAEMON!$server_exec!" $serverd
  34. sed -i "s!SERVER_PATH!$server_path!" $serverd
  35. echo "Install success!!!"