install.sh 870 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. while [ -n "$1" ]; do
  8. case "$1" in
  9. -n|--name ) server_name=$2 ; shift 2;;
  10. -u|--user ) server_user=$2 ; shift 2;;
  11. -e|--exec ) server_exec=$2 ; shift 2;;
  12. * ) echo $show_usage; exit 1 ;;
  13. esac
  14. done
  15. echo "Received: server_name: $server_name, server_user: $server_user, server_exec: $server_exec"
  16. if [[ "" == $server_name ]]; then
  17. echo "Invalid name"
  18. exit 1
  19. elif [[ "" == $server_exec ]]; then
  20. echo "Invalid exec"
  21. exit 1
  22. elif [[ "" == $server_user ]]; then
  23. echo "Invalid user"
  24. exit 1
  25. fi
  26. serverd=/etc/init.d/${server_name}d
  27. cp -f server.sh $serverd
  28. sed -i "s!SERVER_NAME!$server_name!" $serverd
  29. sed -i "s!SERVER_USER!$server_user!" $serverd
  30. sed -i "s!SERVER_DAEMON!$server_exec!" $serverd
  31. echo "Install success!!!"