Skip to content

Instantly share code, notes, and snippets.

Last active April 20, 2024 11:21
Show Gist options
  • Save mattetti/9807e2a1e654a7c00bb9c13f340fc39f to your computer and use it in GitHub Desktop.
Save mattetti/9807e2a1e654a7c00bb9c13f340fc39f to your computer and use it in GitHub Desktop.
bash script to run from WSL to setup Windows and Linux from the linux side. To run: `wget -O` and then `bash`
export WINHOME=$(wslpath "$(wslvar USERPROFILE)")
# github username is needed to pull down the dot files
export GITHUBUSERNAME="mattetti"
# wininstall does an install using winget and checks that it went well
function wininstall {
echo "Installing $1";
cmd.exe /C winget.exe install -e $1;
if [ $? -eq 0 ]; then
echo $?
echo "$1 failed to install"
function ifPathNotAvail {
if [[ ! -f $1 ]]
if [ ! -z "$2" ]
function ifPathNotAvailWinInstall {
if [[ ! -f $1 ]]
if [ ! -z "$2" ]
wininstall $2
# ifCMDNotAvail checks if the command passed as the first argument is
# available and calls $2 if it is not, $3 if it is.
function ifCMDNotAvail {
if ! command -v $1 &> /dev/null
if [ ! -z "$3" ]
# vscode calls the vscode binary on the windows side
function vscode { cmd.exe /c "code $1 $2 $3"; }
function askSetup {
while true; do
read -p "Do you wish to setup $1? " yn
case $yn in
[Yy]* ) $2; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
function windowsDeviceManagement {
winDriversPath="$(wslvar USERPROFILE)\Downloads\drivers"
mkdir -p $driversPath
echo "downloading Focusrite Control"
wget -v -O "$driversPath/FocusriteControl.exe" 2>&1
cmd.exe /C "$winDriversPath\FocusriteControl.exe" /SILENT
# TODO: eos webdriver
echo "downloading eos webdrivers"
wget -v -O "$driversPath/" 2>&1
unzip "$driversPath/" -d $driversPath
msiexec.exe /i "$winDriversPath\EOS-Webcam-Utility-Beta.msi" /quiet
function installVSCode {
wininstall Microsoft.VisualStudioCode
# I use this extension to sync all my settings across machines
vscode --install-extension Shan.code-settings-sync
# open vscode to setup
echo "opening VSCode so you can link your GH account"
echo "Once you linked the account, launch the command panel and invoke Sync: Download Settings"
code .
function setupSSHKey {
echo "Setting up Git"
ssh-keygen -t rsa -b 4096 -C ""
echo "new SSH key generated"
ssh-add ~/.ssh/id_rsa
cat ~/.ssh/ | clip.exe
cmd.exe /C start
echo "Your new ssh key was added to your clipboard, add it to GitHub (and consider turning on SSO)"
echo "Press any key when your key was added to GitHub"
while true; do
read -t 3 -n 1
if [ $? = 0 ] ; then
echo "waiting for the keypress"
function setupChezMoi {
curl -sfL | sh
chezmoi init "$GITHUBUSERNAME/dotfiles.git"
chezmoi apply
function setupNPM {
wget -qO- | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/" ] && \. "$NVM_DIR/" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
nvm install node stable
npm install -g npm@latest
function setupGo {
wget "$linuxpkg"
tar -xvf $linuxpkg
sudo chown -R root:root ./go
sudo mv go /usr/local
source ~/.bash_profile
rm $linuxpkg
## Windows
function windowsSetup {
wingetAlert() {
echo "winget could not be found"
echo "make sure you are at least on Windows 2004 and winget is installed and available and restart this script -"
echo "You might need to install a preview version from"
cmd.exe /c start ""
# checking that winget is installed on the windows side
ifPathNotAvail "$WINHOME/AppData/Local/Microsoft/WindowsApps/winget.exe" wingetAlert
ifPathNotAvailWinInstall "/mnt/c/Program Files/PowerToys/PowerToys.exe" Microsoft.Powertoys
## TODO: install config from gist.
ifPathNotAvailWinInstall wt.exe Microsoft.WindowsTerminal
ifPathNotAvailWinInstall "$WINHOME/AppData/Local/1Password/app/7/1Password.exe" AgileBits.1Password
ifPathNotAvailWinInstall "/mnt/c/Program Files/VideoLAN/VLC/vlc.exe" VideoLAN.VLC
ifPathNotAvailWinInstall "/mnt/c/Program Files/7-Zip/7z.exe" 7zip
ifPathNotAvailWinInstall "/mnt/c/Program Files (x86)/Adobe/Acrobat Reader DC/Reader/AcroRd32.exe" Adobe.AdobeAcrobatReaderDC
ifCMDNotAvail code installVSCode
askSetup "Windows drivers" windowsDeviceManagement;
## Linux
function linuxSetup {
cd "$HOME"
export PATH=$PATH:"$HOME/bin"
# ssh key
ifPathNotAvail "$HOME/.ssh/id_rsa" setupSSHKey
# .dot files
ifPathNotAvail "$HOME/bin/chezmoi" setupChezMoi
chezmoi update
# nvm/node/npm
source ~/.bashrc
ifCMDNotAvail npm setupNPM
# go
ifCMDNotAvail go setupGo
# python
# rust
echo "Updating linux, sudo password is required"
sudo apt-get update;
sudo apt-get install unzip
askSetup "Windows env" windowsSetup
askSetup "Linux env" linuxSetup
echo 'All done! You might need to source ~/.bashrc and source ~/.bash_profile or start a new terminal'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment