Skip to content

Instantly share code, notes, and snippets.

@pvoliveira
Created August 23, 2023 10:38
Show Gist options
  • Save pvoliveira/04478d80191bbd36266251d110638a7f to your computer and use it in GitHub Desktop.
Save pvoliveira/04478d80191bbd36266251d110638a7f to your computer and use it in GitHub Desktop.
Setup Ubuntu WSL2
#! /usr/bin/bash
if ! which zsh > /dev/null; then
echo '## setup - zsh'
sudo apt-get update -y && sudo apt-get install -y zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
fi
if ! systemctl list-unit-files | grep 'wsl-vpnkit' > /dev/null; then
echo '## setup wsl-vpnkit'
echo '## setup wsl-vpnkiti - downloading wsl image'
curl -Lo /tmp/wsl-vpnkit.tar.gz 'https://github.com/sakai135/wsl-vpnkit/releases/download/v0.4.1/wsl-vpnkit.tar.gz' \
&& wsl.exe --unregister wsl-vpnkit \
&& wsl.exe --import wsl-vpnkit --version 2 /mnt/c/Users/paulo.oliveira/wsl-vpnkit /tmp/wsl-vpnkit.tar.gz \
&& rm /temp/wsl-vpnkit.tar.gz
echo '## setup wsl-vpnkit - configuring system service'
wsl.exe -d wsl-vpnkit --cd /app cat /app/wsl-vpnkit.service | sudo tee /etc/systemd/system/wsl-vpnkit.service
sudo systemctl enable wsl-vpnkit
echo '## setup wsl-vpnkit - start and check the status of the service'
sudo systemctl start wsl-vpnkit
systemctl status wsl-vpnkit
fi
if ! add-apt-repository --list | grep 'git-core/ppa' > /dev/null; then
echo '## setup - git ppa'
sudo add-apt-repository -y ppa:git-core/ppa
fi
if ! which docker > /dev/null; then
echo '## setup - docker'
sudo apt-get install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update -y &&
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo groupadd docker
sudo usermod -aG docker $USER
echo '## setup - docker - enabling service'
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
fi
if ! [ -f /usr/bin/keychain ]; then
sudo apt-get update -y && sudo apt-get install keychain
echo '/usr/bin/keychain -q --nogui $HOME/.ssh/id_ed25519' >> ~/.bashrc
echo 'source $HOME/.keychain/$HOSTNAME-sh' >> ~/.bashrc
fi
if ! [ -f /usr/local/bin/difft ]; then
echo '## setup - difftastic'
curl -Ls 'https://github.com/Wilfred/difftastic/releases/latest/download/difft-x86_64-unknown-linux-gnu.tar.gz' | sudo tar -zxv -C /usr/local/bin --one-top-level=. difft \
&& sudo chmod +x /usr/local/bin/difft
echo '## setup - difftastic - configuring'
git config --global diff.external difft
fi
if ! [ -f /usr/local/bin/nu ]; then
echo '## setup - nushell'
curl -sL 'https://api.github.com/repos/nushell/nushell/releases/latest' | grep browser_download_url | cut -d '"' -f 4 | grep x86_64-unknown-linux-gnu | xargs -I% curl -L % | sudo tar -zvx -C /usr/local/bin --strip-components=1
fi
if ! [ -f /usr/local/bin/hx ]; then
echo '## setup - helix - compiling'
mkdir -p ~/dev
rm -rf ~/dev/helix
sudo apt-get update -y && sudo apt-get install -y build-essential
git clone --depth=1 git@github.com:helix-editor/helix.git ~/dev/helix
if which docker > /dev/null; then
docker run --rm -v ~/dev/helix:/usr/src/helix -w /usr/src/helix rust:slim /bin/sh -c 'apt-get update -y && apt-get install -y git build-essential && cargo build --release'
fi
if [ -f ~/dev/helix/target/release/hx ]; then
echo '## setup - helix - coping to destination and configuring git editor'
sudo cp ~/dev/helix/target/release/hx /usr/local/bin/ \
&& ln -s ~/dev/helix/runtime ~/.config/helix/runtime \
&& chmod 700 ~/dev/helix/runtime \
&& git config --global core.editor hx
else
echo '## setup - helix - binary not found'
fi
fi
if ! [ -f /usr/local/bin/rg ]; then
echo '## setup - ripgrep - compiling'
mkdir -p ~/dev
sudo rm -rf ~/dev/ripgrep
git clone --depth=1 git@github.com:BurntSushi/ripgrep.git ~/dev/ripgrep
if which docker > /dev/null; then
docker run --rm --user "$(id -u)":"$(id -g)" -v ~/dev/ripgrep:/usr/src/ripgrep -w /usr/src/ripgrep rust:slim cargo build --release
fi
if [ -f ~/dev/ripgrep/target/release/rg ]; then
echo '## setup - ripgrep - coping to destination and configuring git editor'
sudo cp ~/dev/ripgrep/target/release/rg /usr/local/bin/
else
echo '## setup - ripgrep - binary not found'
fi
fi
if ![ -f /usr/local/bin/helm ]; then
echo '## setup - helm'
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment