Each profile without asOutbound is a tunnel service of its own, AmneziaWGTunnel$<interface>, as amneziawg-windows's client installs one: amneziawg-go on Wintun, its routes and DNS, and for one peer that takes everything its firewall blocking what would leave outside the tunnel. It runs awg-tunnel.exe, amneziawg-windows built from its pinned commit with a main of ours (its Run(), its log in a file) instead of its tunnel.dll, beside Wintun's signed DLL (tools/build-amneziawg.sh). The service writes each profile's .conf below its state root, registers the tunnel (unrestricted service SID, which its firewall exempts it by), starts the autostart ones with itself, and removes the tunnels of profiles gone, and all of them on uninstall. proxy-ctl awg list|on|off|log, and the app's AmneziaWG page: profiles (a system-wide one switched on and off, its log), one added from a vpn:// link or a .conf, or removed. tools/lib.sh: clone_commit, and fetch_pinned, which fetches in pieces a download that stalls (some networks cut TLS after about 16 KB, as wintun.net's here). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
105 lines
5.2 KiB
Bash
Executable File
105 lines
5.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# The setup program under Wine: a silent install into Program Files (every file, the
|
|
# components' manifests among them), the entry in Settings > Apps, the service registered and
|
|
# answering over its pipe; the same setup again over the running install (an upgrade); then the
|
|
# entry's quiet uninstall, after which the service, the files and the entry are gone.
|
|
#
|
|
# nix shell nixpkgs#wineWow64Packages.stable -c tools/wine-setup-test.sh dist/ProxySuite-<version>-windows-x64-setup.exe [RELEASE_DIR]
|
|
#
|
|
# RELEASE_DIR (the unpacked release the setup was made of): its files are compared with the
|
|
# installed ones.
|
|
set -euo pipefail
|
|
SETUP=$(realpath "${1:?the setup program}")
|
|
REL=${2:+$(realpath "$2")}
|
|
WORK=$(mktemp -d)
|
|
export WINEPREFIX=${WINEPREFIX:-$WORK/prefix} WINEDEBUG=-all
|
|
trap 'wineserver -k 2>/dev/null || true; rm -rf "$WORK"' EXIT
|
|
wineboot -i >/dev/null 2>&1 || true
|
|
for key in Tcpip Tcpip6; do
|
|
wine reg add "HKLM\\SYSTEM\\CurrentControlSet\\Services\\$key\\Parameters\\Interfaces" /f >/dev/null 2>&1
|
|
done
|
|
PF="$WINEPREFIX/drive_c/Program Files/ProxySuite"
|
|
KEY='HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\ProxySuite'
|
|
fail() { echo "FAIL: $*"; exit 1; }
|
|
|
|
state() { local st; st=$(wine sc query ProxySuite 2>/dev/null || true); st=${st//$'\r'/}; grep STATE <<<"$st" | grep -o '[A-Z_]*$' || echo NONE; }
|
|
# Wine's manager often fails the first start right after a create (wine-install-test.sh says
|
|
# more); a second start works.
|
|
running() {
|
|
local s last=""
|
|
for _ in $(seq 60); do
|
|
s=$(state)
|
|
[ "$s" = "$last" ] || echo " $s"
|
|
last=$s
|
|
[ "$s" = RUNNING ] && return 0
|
|
[ "$s" = STOPPED ] && { wine sc start ProxySuite >/dev/null 2>&1 || true; }
|
|
sleep 3
|
|
done
|
|
return 1
|
|
}
|
|
|
|
echo "== setup /S"
|
|
wine "$SETUP" /S && rc=0 || rc=$?
|
|
echo " exit code $rc"
|
|
[ "$rc" = 0 ] || fail "setup exited with $rc"
|
|
[ -f "$PF/proxy-suite-service.exe" ] || fail "nothing in Program Files"
|
|
ls "$PF" | sed 's/^/ /'
|
|
if [ -n "$REL" ]; then
|
|
# Every file of the release, dotfiles too (the components' .files.json and .version).
|
|
missing=$(cd "$REL" && find . -type f | while read -r f; do [ -f "$PF/$f" ] || echo "$f"; done)
|
|
[ -z "$missing" ] || fail "not installed: $missing"
|
|
echo " every file of the release is there ($(cd "$REL" && find . -type f | wc -l))"
|
|
fi
|
|
ls "$PF"/components/*/.files.json >/dev/null || fail "no component manifests"
|
|
|
|
echo "== Settings > Apps"
|
|
entry=$(wine reg query "$KEY" 2>/dev/null | tr -d '\r') || fail "no uninstall entry"
|
|
sed 's/^/ /' <<<"$entry"
|
|
for v in DisplayName DisplayVersion UninstallString QuietUninstallString InstallLocation EstimatedSize; do
|
|
grep -q "$v" <<<"$entry" || fail "the entry has no $v"
|
|
done
|
|
|
|
echo "== the service"
|
|
running || fail "the service is $(state)"
|
|
for _ in $(seq 30); do wine "$PF/proxy-ctl.exe" status >/dev/null 2>&1 && break; sleep 1; done
|
|
wine "$PF/proxy-ctl.exe" components | tr -d '\r' | sed 's/^/ /' || fail "no answer over the pipe"
|
|
|
|
echo "== an AmneziaWG system-wide profile: its tunnel service registered, then removed"
|
|
CONF='[Interface]\nPrivateKey = yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk=\nAddress = 10.8.0.2/32\nDNS = 1.1.1.1\n\n[Peer]\nPublicKey = bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=\nAllowedIPs = 0.0.0.0/0, ::/0\nEndpoint = 203.0.113.7:51820\n'
|
|
printf '{ "amneziaWg": { "enable": true, "profiles": { "home": { "config": "%s" } } } }' "$CONF" >"$WORK/awg.json"
|
|
wine "$PF/proxy-ctl.exe" config set "Z:$WORK/awg.json" | tr -d '\r' | sed 's/^/ /'
|
|
sleep 3
|
|
qc=$(wine sc qc 'AmneziaWGTunnel$home' 2>/dev/null | tr -d '\r')
|
|
grep -q 'awg-tunnel.exe' <<<"$qc" || fail "no tunnel service registered: $(wine "$PF/proxy-ctl.exe" logs proxy-suite-awg-vpn -n 20 | tr -d '\r')"
|
|
grep -i 'BINARY_PATH_NAME' <<<"$qc" | sed 's/^ */ /'
|
|
wine "$PF/proxy-ctl.exe" awg | tr -d '\r' | sed 's/^/ /'
|
|
# Wine has no Wintun driver: the tunnel itself cannot come up here, only be asked to.
|
|
wine "$PF/proxy-ctl.exe" awg on home 2>&1 | tr -d '\r' | sed 's/^/ on: /' || true
|
|
sleep 3
|
|
wine "$PF/proxy-ctl.exe" awg log home -n 5 2>&1 | tr -d '\r' | sed 's/^/ log: /' || true
|
|
printf '{}' >"$WORK/none.json"
|
|
wine "$PF/proxy-ctl.exe" config set "Z:$WORK/none.json" >/dev/null
|
|
sleep 3
|
|
wine sc query 'AmneziaWGTunnel$home' >/dev/null 2>&1 && fail "the tunnel service outlived its profile"
|
|
echo " registered, and removed with its profile"
|
|
|
|
echo "== setup /S again, over the running install"
|
|
wine "$SETUP" /S && rc=0 || rc=$?
|
|
[ "$rc" = 0 ] || fail "the upgrade exited with $rc"
|
|
running || fail "after the upgrade the service is $(state)"
|
|
for _ in $(seq 30); do wine "$PF/proxy-ctl.exe" status >/dev/null 2>&1 && break; sleep 1; done
|
|
wine "$PF/proxy-ctl.exe" status >/dev/null 2>&1 || fail "no answer after the upgrade"
|
|
echo " upgraded, running, answering"
|
|
|
|
echo "== the entry's quiet uninstall"
|
|
quiet=$(wine reg query "$KEY" /v QuietUninstallString | tr -d '\r' | sed -n 's/.*REG_SZ *//p')
|
|
echo " $quiet"
|
|
# Its command line, as Windows would run it: the quoted program, then its argument.
|
|
prog=${quiet#\"}; prog=${prog%%\"*}
|
|
wine "$prog" uninstall
|
|
sleep 6
|
|
[ "$(state)" = NONE ] || fail "the service is still there: $(state)"
|
|
wine reg query "$KEY" >/dev/null 2>&1 && fail "the entry is still there"
|
|
[ ! -e "$PF" ] || fail "Program Files\\ProxySuite is still there: $(ls "$PF")"
|
|
echo "OK: installed, upgraded and removed by the setup program and its entry"
|