|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +main() { |
| 4 | + if is_linux; then |
| 5 | + echo 'Configuring Linux...' |
| 6 | + |
| 7 | + configure_warp_with_doh_and_ipv6_exclusion_on_linux # [WORKS] Resolves the issue when run independently on GitHub runners lacking IPv6 support. |
| 8 | + prefer_ipv4_on_linux # [DOES NOT WORK] It does not resolve the issue when run independently on GitHub runners without IPv6 support. |
| 9 | + |
| 10 | + # Considered alternatives: |
| 11 | + # - `sysctl` commands, and direct changes to `/proc/sys/net/` and `/etc/sysctl.conf` led to silent |
| 12 | + # Node 18 exits (code: 13) when using `fetch`. |
| 13 | + elif is_macos; then |
| 14 | + echo 'Configuring macOS...' |
| 15 | + |
| 16 | + configure_warp_with_doh_and_ipv6_exclusion_on_macos # [WORKS] Resolves the issue when run independently on GitHub runners lacking IPv6 support. |
| 17 | + disable_ipv6_on_macos # [WORKS INCONSISTENTLY] Resolves the issue inconsistently when run independently on GitHub runners without IPv6 support. |
| 18 | + fi |
| 19 | + echo "IPv4: $(curl --ipv4 --silent --max-time 15 --retry 3 --user-agent Mozilla https://api.ip.sb/geoip)" |
| 20 | + echo "IPv6: $(curl --ipv6 --silent --max-time 15 --retry 3 --user-agent Mozilla https://api.ip.sb/geoip)" |
| 21 | +} |
| 22 | + |
| 23 | +is_linux() { |
| 24 | + [[ "$(uname -s)" == "Linux" ]] |
| 25 | +} |
| 26 | + |
| 27 | +is_macos() { |
| 28 | + [[ "$(uname -s)" == "Darwin" ]] |
| 29 | +} |
| 30 | + |
| 31 | +configure_warp_with_doh_and_ipv6_exclusion_on_linux() { |
| 32 | + install_warp_on_debian |
| 33 | + configure_warp_doh_and_exclude_ipv6 |
| 34 | +} |
| 35 | + |
| 36 | +configure_warp_with_doh_and_ipv6_exclusion_on_macos() { |
| 37 | + brew install cloudflare-warp |
| 38 | + configure_warp_doh_and_exclude_ipv6 |
| 39 | +} |
| 40 | + |
| 41 | +configure_warp_doh_and_exclude_ipv6() { |
| 42 | + echo 'Beginning configuration of the Cloudflare WARP client with DNS-over-HTTPS and IPv6 exclusion...' |
| 43 | + echo 'Initiating client registration with Cloudflare...' |
| 44 | + warp-cli --accept-tos registration new |
| 45 | + echo 'Configuring WARP to operate in DNS-over-HTTPS mode (warp+doh)...' |
| 46 | + warp-cli --accept-tos mode warp+doh |
| 47 | + echo 'Excluding IPv6 traffic from WARP by configuring it as a split tunnel...' |
| 48 | + warp-cli --accept-tos add-excluded-route '::/0' # Exclude IPv6, forcing IPv4 resolution |
| 49 | + # `tunnel ip add` does not work with IP ranges, see https://community.cloudflare.com/t/cant-cidr-for-split-tunnling/630834 |
| 50 | + echo 'Establishing WARP connection...' |
| 51 | + warp-cli --accept-tos connect |
| 52 | +} |
| 53 | + |
| 54 | +install_warp_on_debian() { |
| 55 | + curl -fsSL https://pkg.cloudflareclient.com/pubkey.gpg | sudo gpg --yes --dearmor --output /usr/share/keyrings/cloudflare-warp-archive-keyring.gpg |
| 56 | + echo "deb [arch=amd64 signed-by=/usr/share/keyrings/cloudflare-warp-archive-keyring.gpg] https://pkg.cloudflareclient.com/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cloudflare-client.list |
| 57 | + sudo apt-get update |
| 58 | + sudo apt-get install -y cloudflare-warp |
| 59 | +} |
| 60 | + |
| 61 | +disable_ipv6_on_macos() { |
| 62 | + networksetup -listallnetworkservices \ |
| 63 | + | tail -n +2 \ |
| 64 | + | while IFS= read -r interface; do |
| 65 | + echo "Disabling IPv6 on: $interface..." |
| 66 | + networksetup -setv6off "$interface" |
| 67 | + done |
| 68 | +} |
| 69 | + |
| 70 | +prefer_ipv4_on_linux() { |
| 71 | + local -r gai_config_file_path='/etc/gai.conf' |
| 72 | + if [ ! -f "$gai_config_file_path" ]; then |
| 73 | + echo "Creating $gai_config_file_path since it doesn't exist..." |
| 74 | + touch "$gai_config_file_path" |
| 75 | + fi |
| 76 | + echo "precedence ::ffff:0:0/96 100" | sudo tee -a "$gai_config_file_path" > /dev/null |
| 77 | + echo "Configuration complete." |
| 78 | +} |
| 79 | + |
| 80 | +main |
0 commit comments