From d71a222f7631520bf138f2a6dc436f7b528ece04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Trellu?= Date: Tue, 12 Dec 2023 09:48:18 -0500 Subject: [PATCH] [common] Implement WSL2 validation check #34 --- setup.sh | 1 + tests/bats/os.bats | 21 ++++++++++++++++++++- utils/common.sh | 13 +++++++++++++ utils/constants.sh | 1 + 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index 25468765..5de59932 100644 --- a/setup.sh +++ b/setup.sh @@ -34,6 +34,7 @@ detect_user delete_log detect_existing_instance get_os_information +wsl2_requirements detect_cpu_instructions is_raspeberrypi_soc detect_sound diff --git a/tests/bats/os.bats b/tests/bats/os.bats index 09cfdc04..d96cc550 100644 --- a/tests/bats/os.bats +++ b/tests/bats/os.bats @@ -7,9 +7,14 @@ function setup() { load ../../utils/common.sh LOG_FILE=/tmp/ovos-installer.log OS_RELEASE=/tmp/os-release + WSL_FILE=/tmp/wsl.conf cat <"$OS_RELEASE" VERSION="39 (Workstation Edition)" ID=fedora +EOF + cat <"$WSL_FILE" +[boot] +systemd=true EOF } @@ -54,6 +59,20 @@ EOF unset uname } +@test "function_wsl2_requirements_valid" { + WSL_FILE=/tmp/wsl.conf + KERNEL="5.15.133.1-microsoft-standard-WSL2" + run wsl2_requirements + assert_success +} + +@test "function_wsl2_requirements_no_valid" { + truncate -s 0 "$WSL_FILE" + KERNEL="5.15.133.1-microsoft-standard-WSL2" + run wsl2_requirements + assert_failure +} + function teardown() { - rm -f "$OS_RELEASE" "$LOG_FILE" + rm -f "$OS_RELEASE" "$LOG_FILE" "$WSL_FILE" } diff --git a/utils/common.sh b/utils/common.sh index 0bf12d2a..ff4b41a1 100644 --- a/utils/common.sh +++ b/utils/common.sh @@ -298,3 +298,16 @@ function in_array() { echo "$needle is an unsupported option" &>>"$LOG_FILE" on_error } + +# This function validates basic requirements for Windows WSL2 such as systemd +# handles the boot process, etc... +function wsl2_requirements() { + if [[ "$KERNEL" == *"microsoft"* ]]; then + echo -ne "➤ Validating WSL2 requirements... " + if ! grep -q "systemd=true" "$WSL_FILE" &>>"$LOG_FILE"; then + echo "systemd=boot must be added to $WSL_FILE" &>>"$LOG_FILE" + return 1 + fi + echo -e "[$done_format]" + fi +} diff --git a/utils/constants.sh b/utils/constants.sh index ae777c3f..11d8d8db 100644 --- a/utils/constants.sh +++ b/utils/constants.sh @@ -39,5 +39,6 @@ export SCENARIO_ALLOWED_HIVEMIND_OPTIONS export SCENARIO_NAME="scenario.yaml" export SCENARIO_PATH="" export USER_ID="$EUID" +export WSL_FILE=/etc/wsl.conf export YQ_BINARY_PATH=/tmp/yq export YQ_URL="https://github.com/mikefarah/yq/releases/download/v4.40.3"