99-validate 941 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/bash
  2. success() {
  3. echo "[ OK ] $1"
  4. }
  5. info() {
  6. echo "[INFO] $1"
  7. }
  8. warn() {
  9. echo "[WARN] $1" >&2
  10. }
  11. error() {
  12. echo "[FAIL] $1" >&2
  13. }
  14. critical() {
  15. echo "[CRIT] $1" >&2
  16. exit 1
  17. }
  18. echo "[INFO] Validating that VPN is up and the server is connected to internet..."
  19. ipv4=$(ping -w3 -c1 ip.yunohost.org >/dev/null 2>&1 && curl --max-time 5 https://ip.yunohost.org --silent)
  20. ipv6=$(ping -w3 -c1 ip6.yunohost.org >/dev/null 2>&1 && curl --max-time 5 https://ip6.yunohost.org --silent)
  21. if ip route get 1.2.3.4 | grep -q tun0; then
  22. if ping -c1 -w5 debian.org >/dev/null; then
  23. echo "[ OK ] YunoHost VPN client started!"
  24. echo "[INFO] IPv4 address is $ipv4"
  25. echo "[INFO] IPv6 address is $ipv6"
  26. else
  27. echo "[CRIT] The VPN is up but debian.org cannot be reached, indicating that something is probably misconfigured/blocked." >&2
  28. exit 1
  29. fi
  30. else
  31. echo "[CRIT] IPv4 routes are misconfigured !?" >&2
  32. exit 1
  33. fi