diff --git a/make-eda-ready.sh b/make-eda-ready.sh index 81f9e8e..7d21679 100755 --- a/make-eda-ready.sh +++ b/make-eda-ready.sh @@ -19,7 +19,7 @@ WIN_USERPROFILE=$(powershell.exe -NoProfile -Command 'echo $env:USERPROFILE' | t if [ -z "$WIN_USERPROFILE" ]; then echo "Failed to detect Windows user profile directory." - echo "Please set the kernel path manually in /etc/wsl.conf." + echo "Please set the kernel path manually in .wslconfig." exit 1 fi @@ -27,17 +27,21 @@ WIN_USERNAME=$(echo "$WIN_USERPROFILE" | sed 's|^C:\\Users\\||') WSL_KERNELS_DIR="/mnt/c/Users/${WIN_USERNAME}/.wsl-kernels" mkdir -p "$WSL_KERNELS_DIR" -mv "$TMP_BZIMAGE" "${WSL_KERNELS_DIR}/bzImage" +cp "$TMP_BZIMAGE" "${WSL_KERNELS_DIR}/bzImage" +rm "$TMP_BZIMAGE" -if ! grep -q '^\[wsl2\]' /etc/wsl.conf; then - echo "[wsl2]" | sudo tee -a /etc/wsl.conf > /dev/null +WSL_CONFIG_PATH="/mnt/c/Users/${WIN_USERNAME}/.wslconfig" + +# Update or create the .wslconfig file +if [ ! -f "$WSL_CONFIG_PATH" ]; then + echo "[wsl2]" | sudo tee "$WSL_CONFIG_PATH" > /dev/null fi -if grep -q '^kernel=' /etc/wsl.conf; then - sudo sed -i "s|^kernel=.*|kernel=c:\\\\\\\\Users\\\\\\\\${WIN_USERNAME}\\\\\\\\.wsl-kernels\\\\\\\\bzImage|g" /etc/wsl.conf +if grep -q '^kernel=' "$WSL_CONFIG_PATH"; then + sudo sed -i "s|^kernel=.*|kernel=c:\\\\\\\\Users\\\\\\\\${WIN_USERNAME}\\\\\\\\.wsl-kernels\\\\\\\\bzImage|g" "$WSL_CONFIG_PATH" else - sudo sed -i "/^\[wsl2\]/a kernel=c:\\\\\\\\Users\\\\\\\\${WIN_USERNAME}\\\\\\\\.wsl-kernels\\\\\\\\bzImage" /etc/wsl.conf + sudo sed -i "/^\[wsl2\]/a kernel=c:\\\\\\\\Users\\\\\\\\${WIN_USERNAME}\\\\\\\\.wsl-kernels\\\\\\\\bzImage" "$WSL_CONFIG_PATH" fi -echo "make-eda-ready: Kernel moved to ${WSL_KERNELS_DIR}/bzImage and wsl.conf updated." +echo "make-eda-ready: Kernel moved to ${WSL_KERNELS_DIR}/bzImage and .wslconfig updated." echo "Stop the WSL (wsl --shutdown Containerlab) for the new kernel to take effect."