handle-ipv6-setting 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. # This command reads the `DISABLE_IPV6` env var and will either enable
  3. # or disable ipv6 in all nginx configs based on this setting.
  4. # Lowercase
  5. DISABLE_IPV6=$(echo "${DISABLE_IPV6:-}" | tr '[:upper:]' '[:lower:]')
  6. CYAN='\E[1;36m'
  7. BLUE='\E[1;34m'
  8. YELLOW='\E[1;33m'
  9. RED='\E[1;31m'
  10. RESET='\E[0m'
  11. FOLDER=$1
  12. if [ "$FOLDER" == "" ]; then
  13. echo -e "${RED}❯ $0 requires a absolute folder path as the first argument!${RESET}"
  14. echo -e "${YELLOW} ie: $0 /data/nginx${RESET}"
  15. exit 1
  16. fi
  17. FILES=$(find "$FOLDER" -type f -name "*.conf")
  18. if [ "$DISABLE_IPV6" == "true" ] || [ "$DISABLE_IPV6" == "on" ] || [ "$DISABLE_IPV6" == "1" ] || [ "$DISABLE_IPV6" == "yes" ]; then
  19. # IPV6 is disabled
  20. echo "Disabling IPV6 in hosts"
  21. echo -e "${BLUE}❯ ${CYAN}Disabling IPV6 in hosts: ${YELLOW}${FOLDER}${RESET}"
  22. # Iterate over configs and run the regex
  23. for FILE in $FILES
  24. do
  25. echo -e " ${BLUE}❯ ${YELLOW}${FILE}${RESET}"
  26. sed -E -i 's/^([^#]*)listen \[::\]/\1#listen [::]/g' "$FILE"
  27. done
  28. else
  29. # IPV6 is enabled
  30. echo -e "${BLUE}❯ ${CYAN}Enabling IPV6 in hosts: ${YELLOW}${FOLDER}${RESET}"
  31. # Iterate over configs and run the regex
  32. for FILE in $FILES
  33. do
  34. echo -e " ${BLUE}❯ ${YELLOW}${FILE}${RESET}"
  35. sed -E -i 's/^(\s*)#listen \[::\]/\1listen [::]/g' "$FILE"
  36. done
  37. fi