Skip to content

Commit

Permalink
use .wslconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
FloSch62 committed Dec 16, 2024
1 parent cfcfbbc commit 3798fcf
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions make-eda-ready.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,29 @@ 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

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."

0 comments on commit 3798fcf

Please sign in to comment.