98 lines
3.7 KiB
Bash
Executable File
98 lines
3.7 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
TMP_DIR="$(mktemp -d)"
|
|
trap 'rm -rf "$TMP_DIR"' EXIT INT TERM
|
|
|
|
export HOME="$TMP_DIR/home"
|
|
export LEMANA_VPN_BIN_DIR="$HOME/bin"
|
|
export LEMANA_VPN_CONFIG_DIR="$HOME/.config/lemana-vpn"
|
|
export OPENCONNECT_LITE_CONFIG_DIR="$HOME/.config/openconnect-lite"
|
|
mkdir -p "$HOME"
|
|
|
|
output="$(cd "$ROOT" && sh install.sh --dry-run --non-interactive --minimal)"
|
|
|
|
printf '%s\n' "$output" | grep -q 'Detected state:'
|
|
printf '%s\n' "$output" | grep -q 'Interactive prompts: off'
|
|
printf '%s\n' "$output" | grep -q 'Modules: bitwarden=0 touchid=0 sudoers=1 shell=1 app=1 autostart=1'
|
|
printf '%s\n' "$output" | grep -q 'Проверяю Homebrew-зависимости'
|
|
printf '%s\n' "$output" | grep -q 'Swift build может занять минуту'
|
|
printf '%s\n' "$output" | grep -q 'sudo install -d -m 755 -o root -g wheel /usr/local/sbin'
|
|
printf '%s\n' "$output" | grep -q 'swift build -c release --package-path'
|
|
printf '%s\n' "$output" | grep -q 'launchctl load'
|
|
printf '%s\n' "$output" | grep -q 'restart LemanaVPN.app if running'
|
|
|
|
esc="$(printf '\033')"
|
|
if printf '%s\n' "$output" | grep -q "$esc"; then
|
|
echo "non-tty dry-run output contains ANSI color codes" >&2
|
|
exit 1
|
|
fi
|
|
|
|
status_json="$(bash "$ROOT/bin/vpn-lemanapro.sh" --status --json)"
|
|
printf '%s\n' "$status_json" | grep -q '"modules":'
|
|
printf '%s\n' "$status_json" | grep -q '"app":'
|
|
|
|
status_text="$(bash "$ROOT/bin/vpn-lemanapro.sh" --status)"
|
|
printf '%s\n' "$status_text" | grep -q 'Modules:'
|
|
printf '%s\n' "$status_text" | grep -q 'core='
|
|
printf '%s\n' "$status_text" | grep -q 'app='
|
|
printf '%s\n' "$status_text" | grep -q 'autostart='
|
|
|
|
uninstall_home="$TMP_DIR/uninstall-home"
|
|
mkdir -p "$uninstall_home"
|
|
uninstall_output="$(
|
|
HOME="$uninstall_home" \
|
|
LEMANA_VPN_BIN_DIR="$uninstall_home/bin" \
|
|
LEMANA_VPN_CONFIG_DIR="$uninstall_home/.config/lemana-vpn" \
|
|
OPENCONNECT_LITE_CONFIG_DIR="$uninstall_home/.config/openconnect-lite" \
|
|
sh "$ROOT/uninstall.sh" --dry-run --remove-keychain --remove-touchid-helper --remove-openconnect-lite
|
|
)"
|
|
|
|
printf '%s\n' "$uninstall_output" | grep -q 'Начинаю удаление Lemana VPN'
|
|
printf '%s\n' "$uninstall_output" | grep -q 'Проверяю runtime-патчи openconnect-lite'
|
|
printf '%s\n' "$uninstall_output" | grep -q 'Удаляю sudoers и DNS cleanup wrapper'
|
|
printf '%s\n' "$uninstall_output" | grep -q 'killall LemanaVPN # if running'
|
|
printf '%s\n' "$uninstall_output" | grep -q 'Удаляю VPN-записи из macOS Keychain'
|
|
|
|
if printf '%s\n' "$uninstall_output" | grep -q "$esc"; then
|
|
echo "non-tty uninstall dry-run output contains ANSI color codes" >&2
|
|
exit 1
|
|
fi
|
|
|
|
missing_user="lemana-smoke-missing-$$"
|
|
set +e
|
|
manual_output="$(
|
|
HOME="$HOME" \
|
|
LEMANA_VPN_USERNAME="$missing_user" \
|
|
LEMANA_VPN_USE_BITWARDEN=0 \
|
|
bash "$ROOT/bin/vpn-lemanapro.sh" --json 2>&1
|
|
)"
|
|
manual_code=$?
|
|
set -e
|
|
|
|
[ "$manual_code" -ne 0 ]
|
|
printf '%s\n' "$manual_output" | grep -q '"event":"keychain_required"'
|
|
printf '%s\n' "$manual_output" | grep -q 'vpn --configure-keychain'
|
|
if printf '%s\n' "$manual_output" | grep -q 'Cleaning up VPN DNS'; then
|
|
echo "missing manual credentials should fail before VPN cleanup trap is installed" >&2
|
|
exit 1
|
|
fi
|
|
|
|
fake_pwd="$TMP_DIR/fake-pwd"
|
|
mkdir -p "$fake_pwd/bin"
|
|
printf 'stale local cli\n' > "$fake_pwd/bin/vpn-lemanapro.sh"
|
|
|
|
piped_output="$(
|
|
cd "$fake_pwd" &&
|
|
LEMANA_VPN_RAW_BASE_URL="file://$ROOT" sh -s -- --dry-run --non-interactive --minimal --without-app < "$ROOT/install.sh"
|
|
)"
|
|
|
|
printf '%s\n' "$piped_output" | grep -q "curl -fsSL file://$ROOT/bin/vpn-lemanapro.sh"
|
|
if printf '%s\n' "$piped_output" | grep -q "$fake_pwd/bin/vpn-lemanapro.sh"; then
|
|
echo "piped install used stale PWD/bin/vpn-lemanapro.sh" >&2
|
|
exit 1
|
|
fi
|
|
|
|
printf 'smoke ok\n'
|