Skip to content

Commit

Permalink
[common] Implement WSL2 validation check #34
Browse files Browse the repository at this point in the history
  • Loading branch information
goldyfruit committed Dec 12, 2023
1 parent 0120c8e commit d71a222
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ detect_user
delete_log
detect_existing_instance
get_os_information
wsl2_requirements
detect_cpu_instructions
is_raspeberrypi_soc
detect_sound
Expand Down
21 changes: 20 additions & 1 deletion tests/bats/os.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF >"$OS_RELEASE"
VERSION="39 (Workstation Edition)"
ID=fedora
EOF
cat <<EOF >"$WSL_FILE"
[boot]
systemd=true
EOF
}

Expand Down Expand Up @@ -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"
}
13 changes: 13 additions & 0 deletions utils/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions utils/constants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit d71a222

Please sign in to comment.