Skip to content

Instantly share code, notes, and snippets.

@isaacrlevin
Last active September 24, 2024 17:54
Show Gist options
  • Save isaacrlevin/41edcac085cc164ed698fedcab6b0fa8 to your computer and use it in GitHub Desktop.
Save isaacrlevin/41edcac085cc164ed698fedcab6b0fa8 to your computer and use it in GitHub Desktop.
WSL Dev Box Customization
[wsl2]
networkingMode=mirrored
# From https://github.com/microsoft/devcenter-examples
$schema: 1.0
############ Project related Softwares in Dev Box Windows OS ############
tasks:
- name: default-devcenter-catalog/choco
parameters:
package: vscode
userTasks:
- name: default-devcenter-catalog/powershell
description: Admin cannot access wsl, so put the task to user level
parameters:
command: |
############ Install WSL related extensions for VS Code ############
code --install-extension ms-vscode-remote.remote-wsl
$Ubuntu = 'Ubuntu-22.04'
$defaultUser = 'isaac'
########################### 1-Install Ubuntu ###############################
Write-host "Install WSL distro Ubuntu 22.04"
wsl --install -d $Ubuntu -n
ubuntu2204 install --root
wsl -s $Ubuntu
########################### 2-Init User ###############################
Write-host "Setup the inittial envionrment for WSL distro"
$tempDirectory = 'C:\Temp'
New-Item -Path $tempDirectory -ItemType Directory -Force
$installPath = Join-Path $tempDirectory 'init-distro.sh'
(new-object net.webclient).DownloadFile('https://gist.githubusercontent.com/isaacrlevin/41edcac085cc164ed698fedcab6b0fa8/raw/62d9f35349466403db0b82971611c8e523de7579/init-distro.sh', $installPath)
Set-Location $tempDirectory
wsl -- /bin/bash -c "./init-distro.sh $defaultUser"
Write-host "Set default user"
wsl --shutdown
ubuntu2204 config --default-user $defaultUser
########################### 3-Install Common Software in Linux ###############################
$installPath = Join-Path $tempDirectory 'install-software.sh'
(new-object net.webclient).DownloadFile('https://gist.githubusercontent.com/isaacrlevin/41edcac085cc164ed698fedcab6b0fa8/raw/62d9f35349466403db0b82971611c8e523de7579/install-software.sh', $installPath)
Set-Location $tempDirectory
wsl -- /bin/bash -c "./install-software.sh $defaultUser"
########################### 4-Set Networking mode in WSL ###############################
$wslConfigPath = Join-Path $env:USERPROFILE '.wslconfig'
(new-object net.webclient).DownloadFile('https://gist.githubusercontent.com/isaacrlevin/41edcac085cc164ed698fedcab6b0fa8/raw/62d9f35349466403db0b82971611c8e523de7579/.wslconfig', $wslConfigPath)
wsl --shutdown
- name: default-devcenter-catalog/choco
parameters:
package: docker-desktop
#!/usr/bin/env bash
if [[ $# -ne 1 ]]; then
echo "Illegal number of parameters. Parameters should equal or greater than 1" >&2
exit 1
fi
# this will create WSL using root login.
# the following create a new user and set it as default user
username=$1
if ! grep -q $username /etc/passwd; then
NEWUSER=$username
sudo useradd --create-home --shell /usr/bin/bash --user-group --groups adm,dialout,cdrom,floppy,sudo,audio,dip,video,plugdev,netdev --password $(echo '' | openssl passwd -1 -stdin) $NEWUSER
cat <<EOF | sudo tee -a /etc/wsl.conf
[user]
default=$username
EOF
fi
cat <<EOF | sudo tee -a /etc/wsl.conf
[interop]
appendWindowsPath = false
EOF
# no password for sudo
cat <<EOF | sudo tee -a /etc/sudoers.d/$username
$username ALL=(ALL) NOPASSWD:ALL
EOF
#!/usr/bin/env bash
if [[ $# -ne 1 ]]; then
echo "Illegal number of parameters. Parameters should equal or greater than 1" >&2
exit 1
fi
defaultUser=$1
# install dev dependencies
sudo apt update
sudo apt install -y zsh \
build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev \
libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev \
unzip language-pack-en openjdk-21-jdk-headless firefox
# install nvm for Node.js
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# install node
nvm install node
# install pyenv for Python
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
cd ~/.pyenv && src/configure && make -C src
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment