Advertisement
Guest User

Untitled

a guest
Jan 31st, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. ## Show the usage for NGXDIS
  4. function show_usage {
  5. cat <<EOF
  6.  
  7. NGXDIS:
  8. Disable an nginx server block (Ubuntu Server).
  9. Assumes /etc/nginx/sites-available and /etc/nginx/sites-enabled setup used.
  10.  
  11. -q "quiet", do not reload nginx server after operation
  12. -h Help - Show this menu.
  13.  
  14. EOF
  15. }
  16.  
  17. if [[ $EUID -ne 0 ]]; then
  18. echo "!!! Please use \"sudo ngxdis [Your_Server_Block]\""
  19. exit 1
  20. fi
  21.  
  22. # parse options
  23. NoReload=0
  24. while getopts "qh" OPTION; do
  25. case $OPTION in
  26. q)
  27. NoReload=1
  28. ;;
  29. h)
  30. show_usage
  31. exit 0
  32. ;;
  33. *)
  34. show_usage
  35. exit 1
  36. ;;
  37. esac
  38. done
  39.  
  40. shift $(( OPTIND - 1 ))
  41.  
  42. # -z str: Returns True if the length of str is equal to zero.
  43. if [[ -z $1 ]]; then
  44. echo "!!! Please choose a Server Block"
  45. exit 1
  46. else
  47. # -h filename: True if file exists and is a symbolic link.
  48. # -f filename: Returns True if file, filename is an ordinary file.
  49. if [[ ! -h /etc/nginx/sites-enabled/$1 && ! -f /etc/nginx/sites-enabled/$1 ]]; then
  50. echo "!!! Server Block \"$1\" is not enabled"
  51. exit 1
  52. else
  53. rm /etc/nginx/sites-enabled/$1
  54. echo ">>> Disabled Server Block \"$1\""
  55.  
  56. # Reload nginx configuration
  57. # Reload nginx configuration
  58. if [[ $NoReload -eq 0 ]]; then
  59. service nginx reload
  60. fi
  61.  
  62. exit 0
  63. fi
  64. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement