@@ -230,25 +230,75 @@ install_wireguard() {
230230 fi
231231
232232 if command -v go & > /dev/null; then
233- print_step " Building wireguard-go from source (takes 1-2 minutes)..."
233+ GO_VERSION=$( go version 2> /dev/null | grep -oP ' go\K[0-9]+\.[0-9]+' || echo " 0.0" )
234+ print_step " Building wireguard-go from source (Go $GO_VERSION , takes 1-2 minutes)..."
234235 TMPDIR_WG=$( mktemp -d)
236+ WG_BUILT=false
237+
235238 if git clone --depth 1 https://git.zx2c4.com/wireguard-go " $TMPDIR_WG /wireguard-go" 2> /dev/null; then
236239 cd " $TMPDIR_WG /wireguard-go"
237- if make 2> /dev/null; then
240+ # Try make first (uses Makefile), fall back to direct go build
241+ if make 2>&1 ; then
242+ sudo cp wireguard-go /usr/local/bin/
243+ sudo chmod +x /usr/local/bin/wireguard-go
244+ WG_BUILT=true
245+ elif go build -o wireguard-go 2>&1 ; then
238246 sudo cp wireguard-go /usr/local/bin/
239247 sudo chmod +x /usr/local/bin/wireguard-go
240- print_ok " wireguard-go built and installed"
241- WG_MODE=" userspace"
248+ WG_BUILT=true
242249 else
243- print_warn " wireguard-go build failed"
250+ print_warn " wireguard-go source build failed (Go version may be too old, need 1.20+) "
244251 fi
245252 cd " $HOME "
246- else
247- print_warn " Failed to clone wireguard-go repository"
248253 fi
249254 rm -rf " $TMPDIR_WG "
255+
256+ # If source build failed, try upgrading Go and retrying
257+ if [ " $WG_BUILT " = false ]; then
258+ print_step " Trying newer Go version via snap..."
259+ if sudo snap install go --classic 2> /dev/null; then
260+ export PATH=" /snap/bin:$PATH "
261+ TMPDIR_WG2=$( mktemp -d)
262+ if git clone --depth 1 https://git.zx2c4.com/wireguard-go " $TMPDIR_WG2 /wireguard-go" 2> /dev/null; then
263+ cd " $TMPDIR_WG2 /wireguard-go"
264+ if make 2>&1 || go build -o wireguard-go 2>&1 ; then
265+ sudo cp wireguard-go /usr/local/bin/
266+ sudo chmod +x /usr/local/bin/wireguard-go
267+ WG_BUILT=true
268+ fi
269+ cd " $HOME "
270+ fi
271+ rm -rf " $TMPDIR_WG2 "
272+ fi
273+ fi
274+
275+ if [ " $WG_BUILT " = true ]; then
276+ print_ok " wireguard-go built and installed"
277+ WG_MODE=" userspace"
278+ else
279+ print_warn " Could not build wireguard-go -- will fall back to Boson relay"
280+ fi
250281 else
251282 print_warn " Go compiler not available, cannot build wireguard-go"
283+ print_step " Installing Go compiler..."
284+ sudo apt-get install -y -qq golang-go 2> /dev/null || sudo snap install go --classic 2> /dev/null || true
285+ if command -v go & > /dev/null; then
286+ print_step " Retrying wireguard-go build..."
287+ TMPDIR_WG=$( mktemp -d)
288+ if git clone --depth 1 https://git.zx2c4.com/wireguard-go " $TMPDIR_WG /wireguard-go" 2> /dev/null; then
289+ cd " $TMPDIR_WG /wireguard-go"
290+ if make 2>&1 || go build -o wireguard-go 2>&1 ; then
291+ sudo cp wireguard-go /usr/local/bin/
292+ sudo chmod +x /usr/local/bin/wireguard-go
293+ print_ok " wireguard-go built and installed"
294+ WG_MODE=" userspace"
295+ else
296+ print_warn " wireguard-go build failed even with fresh Go"
297+ fi
298+ cd " $HOME "
299+ fi
300+ rm -rf " $TMPDIR_WG "
301+ fi
252302 fi
253303 fi
254304 fi
0 commit comments