provision.awk 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. ###
  2. # Modifying Yii2's files for Vagrant VM
  3. #
  4. # @author HA3IK <golubha3ik@gmail.com>
  5. # @version 1.0.0
  6. BEGIN {
  7. print "AWK BEGINs its work:"
  8. IGNORECASE = 1
  9. # Correct IP - wildcard last octet
  10. match(ip, /(([0-9]+\.)+)/, arr)
  11. ip = arr[1] "*"
  12. }
  13. # BODY
  14. {
  15. # Check if it's the same file
  16. if (FILENAME != isFile["same"]){
  17. msg = "- Work with: " FILENAME
  18. # Close a previous file
  19. close(isFile["same"])
  20. # Delete previous data
  21. delete isFile
  22. # Save current file
  23. isFile["same"] = FILENAME
  24. # Define array index for the file
  25. switch (FILENAME){
  26. case /config\/web\.php$/:
  27. isFile["IsConfWeb"] = 1
  28. msg = msg " - add allowed IP: " ip
  29. break
  30. }
  31. # Print the concatenated message for the file
  32. print msg
  33. }
  34. # IF config/web.php
  35. if (isFile["IsConfWeb"]){
  36. # IF line has "allowedIPs" and doesn't has our IP
  37. if (match($0, "allowedIPs") && !match($0, ip)){
  38. match($0, /([^\]]+)(.+)/, arr)
  39. $0 = sprintf("%s, '%s'%s", arr[1], ip, arr[2])
  40. }
  41. # Rewrite the file
  42. print $0 > FILENAME
  43. }
  44. }
  45. END {
  46. print "AWK ENDs its work."
  47. }