Skip to content

Commit d71a222

Browse files
committed
[common] Implement WSL2 validation check #34
1 parent 0120c8e commit d71a222

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ detect_user
3434
delete_log
3535
detect_existing_instance
3636
get_os_information
37+
wsl2_requirements
3738
detect_cpu_instructions
3839
is_raspeberrypi_soc
3940
detect_sound

tests/bats/os.bats

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ function setup() {
77
load ../../utils/common.sh
88
LOG_FILE=/tmp/ovos-installer.log
99
OS_RELEASE=/tmp/os-release
10+
WSL_FILE=/tmp/wsl.conf
1011
cat <<EOF >"$OS_RELEASE"
1112
VERSION="39 (Workstation Edition)"
1213
ID=fedora
14+
EOF
15+
cat <<EOF >"$WSL_FILE"
16+
[boot]
17+
systemd=true
1318
EOF
1419
}
1520

@@ -54,6 +59,20 @@ EOF
5459
unset uname
5560
}
5661

62+
@test "function_wsl2_requirements_valid" {
63+
WSL_FILE=/tmp/wsl.conf
64+
KERNEL="5.15.133.1-microsoft-standard-WSL2"
65+
run wsl2_requirements
66+
assert_success
67+
}
68+
69+
@test "function_wsl2_requirements_no_valid" {
70+
truncate -s 0 "$WSL_FILE"
71+
KERNEL="5.15.133.1-microsoft-standard-WSL2"
72+
run wsl2_requirements
73+
assert_failure
74+
}
75+
5776
function teardown() {
58-
rm -f "$OS_RELEASE" "$LOG_FILE"
77+
rm -f "$OS_RELEASE" "$LOG_FILE" "$WSL_FILE"
5978
}

utils/common.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,16 @@ function in_array() {
298298
echo "$needle is an unsupported option" &>>"$LOG_FILE"
299299
on_error
300300
}
301+
302+
# This function validates basic requirements for Windows WSL2 such as systemd
303+
# handles the boot process, etc...
304+
function wsl2_requirements() {
305+
if [[ "$KERNEL" == *"microsoft"* ]]; then
306+
echo -ne "➤ Validating WSL2 requirements... "
307+
if ! grep -q "systemd=true" "$WSL_FILE" &>>"$LOG_FILE"; then
308+
echo "systemd=boot must be added to $WSL_FILE" &>>"$LOG_FILE"
309+
return 1
310+
fi
311+
echo -e "[$done_format]"
312+
fi
313+
}

utils/constants.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ export SCENARIO_ALLOWED_HIVEMIND_OPTIONS
3939
export SCENARIO_NAME="scenario.yaml"
4040
export SCENARIO_PATH=""
4141
export USER_ID="$EUID"
42+
export WSL_FILE=/etc/wsl.conf
4243
export YQ_BINARY_PATH=/tmp/yq
4344
export YQ_URL="https://github.com/mikefarah/yq/releases/download/v4.40.3"

0 commit comments

Comments
 (0)