bash script to run from WSL to setup Windows and Linux from the linux side. To run: `wget https://gist.githubusercontent.com/mattetti/9807e2a1e654a7c00bb9c13f340fc39f/raw/ -O newMachineSetup.sh` and then `bash newMachineSetup.sh`
#!/bin/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 $? | |
else | |
echo "$1 failed to install" | |
fi | |
} | |
function ifPathNotAvail { | |
if [[ ! -f $1 ]] | |
then | |
if [ ! -z "$2" ] | |
then | |
$2 | |
fi | |
fi | |
} | |
function ifPathNotAvailWinInstall { | |
if [[ ! -f $1 ]] | |
then | |
if [ ! -z "$2" ] | |
then | |
wininstall $2 | |
fi | |
fi | |
} | |
# 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 | |
then | |
$2 | |
else | |
if [ ! -z "$3" ] | |
then | |
$3 | |
fi | |
fi | |
} | |
# vscode calls the vscode binary on the windows side | |
# https://code.visualstudio.com/docs/editor/command-line | |
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.";; | |
esac | |
done | |
} | |
function windowsDeviceManagement { | |
driversPath=$WINHOME/Downloads/drivers | |
winDriversPath="$(wslvar USERPROFILE)\Downloads\drivers" | |
mkdir -p $driversPath | |
echo "downloading Focusrite Control" | |
wget https://fael-downloads-prod.focusrite.com/customer/prod/s3fs-public/downloads/Focusrite%20Control%20-%203.6.0.1822.exe -v -O "$driversPath/FocusriteControl.exe" 2>&1 | |
cmd.exe /C "$winDriversPath\FocusriteControl.exe" /SILENT | |
# TODO: eos webdriver | |
echo "downloading eos webdrivers" | |
wget http://downloads.canon.com/webcam/EOSWebcamUtilityBeta-WIN0.9.0.zip -v -O "$driversPath/EOSWebcam.zip" 2>&1 | |
unzip "$driversPath/EOSWebcam.zip" -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 "mattai@microsoft.com" | |
echo "new SSH key generated" | |
ssh-agent | |
ssh-add ~/.ssh/id_rsa | |
cat ~/.ssh/id_rsa.pub | clip.exe | |
cmd.exe /C start https://github.com/settings/ssh/new | |
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 | |
break; | |
else | |
echo "waiting for the keypress" | |
fi | |
done | |
} | |
function setupChezMoi { | |
# https://github.com/twpayne/chezmoi | |
curl -sfL https://git.io/chezmoi | sh | |
chezmoi init "https://github.com/$GITHUBUSERNAME/dotfiles.git" | |
chezmoi apply | |
} | |
function setupNPM { | |
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash | |
export NVM_DIR="$HOME/.nvm" | |
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # 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 { | |
linuxpkg=$(curl https://golang.org/VERSION?m=text).linux-amd64.tar.gz | |
wget "https://dl.google.com/go/$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 - https://www.microsoft.com/en-us/p/app-installer/9nblggh4nns1" | |
echo "You might need to install a preview version from https://github.com/microsoft/winget-cli/releases" | |
cmd.exe /c start "https://www.microsoft.com/en-us/p/app-installer/9nblggh4nns1" | |
exit | |
} | |
# 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