Skip to content

Instantly share code, notes, and snippets.

@augustohp
Last active November 23, 2024 17:34
Show Gist options
  • Save augustohp/15183d64bcba18a9a773b7402ea63801 to your computer and use it in GitHub Desktop.
Save augustohp/15183d64bcba18a9a773b7402ea63801 to your computer and use it in GitHub Desktop.
Bootstraps a new environment on WSL (Windows Subsystem for Linux) with my configuration
#!/usr/bin/env bash
# vim: noet ft=sh sw=4 ts=4:
#
# Author: Augusto Pascutti <[email protected]>
#
# This will help you bootstrap a Windows machine with WSL with Docker
# and some other utilities. This is heavily customized for my own use.
#
# Requirements (or things that should already be installed):
# - WSL (with Debian or Ubuntu): `Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux`
# - Docker for Windows
EXTRA_APT_PACKAGES_TO_INSTALL="git vim curl jq gnupg2 tmux lsof htop par tree bash bash-completion wget"
indent()
{
sed 's/^/ /'
}
# https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly
install_docker()
{
sudo apt-get update
sudo apt-get remove -y docker docker-engine docker.io containerd runc
sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - 2>&1
sudo apt-key fingerprint 0EBFCD88 2>&1
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install -y \
docker-ce docker-ce-cli containerd.io
sudo usermod -aG docker $USER
echo "export DOCKER_HOST=tcp://localhost:2375" >> ~/.bashrc && source ~/.bashrc
sudo cat <<-EOF > /tmp/wsl.conf
[automount]
root = /
options = "metadata"
EOF
sudo mv /tmp/wsl.conf /etc/wsl.conf
cat <<-EOT
>>> Restart the terminal and run "docker run hellow-world" to test Docker installation.
EOT
}
install_extra()
{
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install -y \
${EXTRA_APT_PACKAGES_TO_INSTALL}
}
install_updates()
{
sudo apt-get update
sudo apt-get upgrade -y
}
# https://gist.github.com/augustohp/0b0f96249e399d4ec731830280fbe776
install_castles()
{
assert_1password_integration
bash <(curl --silent -L https://git.io/fNMTH)
}
assert_1password_integration()
{
if ! ssh-add.exe -l > /dev/null 2>&1
then
echo "SSH Agent (from 1password) is not running, start it."
exit 2
fi
echo "Setting 'ssh.exe' as the default SSH command for Git"
git config --global core.sshCommand ssh.exe
}
main()
{
echo "Updating installed packages..."
install_updates | indent
if ! docker run hello-world > /dev/null 2>&1
then
echo "Do you wish to install Docker?"
read -p "[y/N]: " -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Installing Docker (removing old one) which will connect to Docker-CE for Windows..."
install_docker | indent
fi
fi
echo "Install extra packages ($EXTRA_APT_PACKAGES_TO_INSTALL):"
read -p "[y/N]: " -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Installing extra packages..."
install_extra | indent
fi
echo "Would you like to install my dotfiles?"
read -p "[y/N]: " -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Installing dotfiles..."
install_castles
fi
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment