install.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 the program\n\
  9. -h|--help%-8sfor help\n"
  10. }
  11. server_name=""
  12. server_user=""
  13. server_exec=""
  14. server_path=""
  15. while [ -n "$1" ]; do
  16. case "$1" in
  17. -n|--name ) server_name=$2 ; shift 2;;
  18. -u|--user ) server_user=$2 ; shift 2;;
  19. -e|--exec ) server_exec=$2 ; shift 2;;
  20. -d|--chdir ) server_path=$2 ; shift 2;;
  21. -h|--help ) show_usage ; exit 0;;
  22. * ) echo show_usage; exit 1 ;;
  23. esac
  24. done
  25. echo "Received: server_name: $server_name, server_user: $server_user, server_exec: $server_exec"
  26. if [[ "" == $server_name ]]; then
  27. echo "Invalid name"
  28. exit 1
  29. elif [[ "" == $server_exec ]]; then
  30. echo "Invalid exec"
  31. exit 1
  32. elif [[ "" == $server_user ]]; then
  33. echo "Invalid user"
  34. exit 1
  35. fi
  36. if [ "" == $server_path ]; then
  37. server_path=`pwd`
  38. fi
  39. serverd=/etc/init.d/${server_name}
  40. cp -f server.sh $serverd
  41. sed -i "s!SERVER_NAME!$server_name!" $serverd
  42. sed -i "s!SERVER_USER!$server_user!" $serverd
  43. sed -i "s!SERVER_DAEMON!$server_exec!" $serverd
  44. sed -i "s!SERVER_PATH!$server_path!" $serverd
  45. echo "Install successfully!!!"