install.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. set -e
  3. show_usage() {
  4. printf "./install.sh -u tangs -e /tmp/process -n process\n\
  5. -u|--user%-8schange to user before starting process\n\
  6. -n|--name%-8sprocess name\n\
  7. -e|--exec%-8sexecutable file path\n\
  8. -d|--chdir%-7sthe boot path of a program\n"
  9. }
  10. server_name=""
  11. server_user=""
  12. server_exec=""
  13. server_path=""
  14. while [ -n "$1" ]; do
  15. case "$1" in
  16. -n|--name ) server_name=$2 ; shift 2;;
  17. -u|--user ) server_user=$2 ; shift 2;;
  18. -e|--exec ) server_exec=$2 ; shift 2;;
  19. -d|--chdir ) server_path=$2 ; shift 2;;
  20. * ) echo show_usage; exit 1 ;;
  21. esac
  22. done
  23. echo "Received: server_name: $server_name, server_user: $server_user, server_exec: $server_exec"
  24. if [[ "" == $server_name ]]; then
  25. echo "Invalid name"
  26. exit 1
  27. elif [[ "" == $server_exec ]]; then
  28. echo "Invalid exec"
  29. exit 1
  30. elif [[ "" == $server_user ]]; then
  31. echo "Invalid user"
  32. exit 1
  33. fi
  34. if [ "" == $server_path ]; then
  35. server_path=`pwd`
  36. fi
  37. serverd=/etc/init.d/${server_name}d
  38. cp -f server.sh $serverd
  39. sed -i "s!SERVER_NAME!$server_name!" $serverd
  40. sed -i "s!SERVER_USER!$server_user!" $serverd
  41. sed -i "s!SERVER_DAEMON!$server_exec!" $serverd
  42. sed -i "s!SERVER_PATH!$server_path!" $serverd
  43. echo "Install success!!!"