Guest User

Untitled

a guest
Mar 2nd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. wordpress() {
  2. local drt="$1"
  3. local domain="$2"
  4. local dbpass="$3"
  5.  
  6. # should do more checking here, this is the bare minimum.
  7. # it avoids running `rm -rf /` if both $drt and $domain
  8. # are empty, and running `rm -rf "$drt/"` if $domain is empty.
  9. [ -z "$drt" ] && error 1 '$drt is empty. aborting!'
  10. [ -z "$domain" ] && error 1 '$domain is empty. aborting!'
  11. [ -z "$dbpass" ] && error 1 '$dbpass is empty. aborting!'
  12.  
  13. # should check exit status of each command run here and take
  14. # appropriate action on any failures. Figure out what you want
  15. # to happen if any of the following fail and implement it.
  16. rm -rf "$drt"/"$domain"/ 2>/dev/null
  17. wp core download --path="$drt"/"$domain"/ --allow-root
  18. wp config create --path="$drt"/"$domain"/ --dbname="$domain"
  19. --dbuser="$domain" --dbpass="$dbpass" --dbhost=localhost
  20. --allow-root
  21. }
  22.  
  23. error() {
  24. local ec msg
  25.  
  26. ec="$1" ; shift
  27. msg="$*"
  28.  
  29. [ -n "$msg" ] && echo "$msg" >&2
  30. # don't exit if $ec==0 - just return after printing a warning to stderr
  31. [ "$ec" != 0 ] && exit "$ec"
  32. }
  33.  
  34. function1 () { ... ; }
  35. function2 () { ... ; }
  36. function3 () { ... ; }
  37. function4 () { ... ; }
  38.  
  39. main () {
  40. function1
  41. function2
  42. function3
  43. function4
  44. }
  45.  
  46. main
  47.  
  48. case "$var" in
  49. 1) function1 ;;
  50. 2) function2 ;;
  51. 3) function3 ;;
  52. 4) function4 ;;
  53. *) error 1 'Unknown case' ;;
  54. esac
Add Comment
Please, Sign In to add comment