Last active
July 5, 2024 14:46
-
-
Save cartolari/8ba26f9cc0da46194a9812cdbcb4d5b0 to your computer and use it in GitHub Desktop.
Windows workstation setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $switchName = "VM-Internal-Switch" | |
| $ipAddressString = "10.100.100.1" | |
| $prefixLength = 24 | |
| $netNatName = "VM-NAT-Network" | |
| Write-Output "Creating new VM Switch" | |
| if ($null -eq (Get-VMSwitch -Name $switchName -ErrorAction SilentlyContinue)) { | |
| New-VMSwitch -Name $switchName -SwitchType Internal | |
| } | |
| $netAdapter = Get-NetAdapter -Name "vEthernet ($switchName)" | |
| Write-Output "Assigning IP Address" | |
| $ipAddressParams = @{ | |
| IPAddress = $ipAddressString | |
| PrefixLength = $prefixLength | |
| InterfaceIndex = $netAdapter.InterfaceIndex | |
| } | |
| New-NetIPAddress @ipAddressParams -ErrorAction SilentlyContinue | |
| $netNat = Get-NetNat -Name $netNatName -ErrorAction SilentlyContinue | |
| if ($null -eq $netNat) { | |
| New-NetNat -Name $netNatName -InternalIPInterfaceAddressPrefix "$ipAddressString/$prefixLength" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- mode: ruby -*- | |
| # vi: set ft=ruby : | |
| Vagrant.configure("2") do |config| | |
| config.vm.box = "generic/arch" | |
| config.vm.provider "hyperv" do |hv| | |
| hv.cpus = 6 | |
| hv.maxmemory = 8192 | |
| hv.memory = 1024 | |
| hv.vmname = "Arch" | |
| hv.vm_integration_services = { | |
| guest_service_interface: true, | |
| heartbeat: true, | |
| key_value_pair_exchange: true, | |
| shutdown: true, | |
| time_synchronization: true, | |
| vss: true, | |
| } | |
| end | |
| config.ssh.username = "vagrant" | |
| config.vm.provision "shell", args: "vagrant", inline: %( | |
| set -xeuo pipefail | |
| vm_user=$1 | |
| # Setup Pacman and upgrade | |
| curl -SsL 'https://www.archlinux.org/mirrorlist/?country=BR&ip_version=4&use_mirror_status=on' | \ | |
| sed 's/^#Server/Server/' > \ | |
| /etc/pacman.d/mirrorlist | |
| pacman -Syyu --noconfirm --needed base-devel | |
| # Setup Yay | |
| if ! hash yay; then | |
| mkdir -p /tmp/yay-bin | |
| chown $vm_user:$vm_user /tmp/yay-bin | |
| curl -SsL https://aur.archlinux.org/cgit/aur.git/snapshot/yay-bin.tar.gz | tar xzf - -C /tmp/yay-bin --strip-components=1 | |
| cd /tmp/yay-bin | |
| su $vm_user -c 'makepkg -f' | |
| pacman -U --noconfirm yay-bin-*.tar.xz | |
| fi | |
| # Enable SystemD NetworkD, disable dhcpcd | |
| mkdir -p /etc/systemd/network | |
| cat <<EOF > /etc/systemd/network/eth0.network | |
| [Match] | |
| Name=eth0 | |
| [Network] | |
| DHCP=ipv4 | |
| EOF | |
| cat <<EOF > /etc/systemd/network/eth1.network | |
| [Match] | |
| Name=eth1 | |
| [Network] | |
| Address=10.100.100.10/24 | |
| Gateway=10.100.100.1 | |
| DNS=1.1.1.1 | |
| DNS=8.8.8.8 | |
| EOF | |
| cat <<EOF > /etc/resolv.conf.head | |
| nameserver 1.1.1.1 | |
| nameserver 8.8.8.8 | |
| EOF | |
| sudo systemctl enable systemd-networkd | |
| sudo systemctl disable dhcpcd | |
| # Rename user | |
| if ! grep PasswordAuthentication /etc/ssh/sshd_config; then | |
| echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config | |
| fi | |
| sudo -u $vm_user -- yay -S --needed --noconfirm \ | |
| aspell-en \ | |
| aspell-pt \ | |
| autojump \ | |
| aws-cli \ | |
| bat \ | |
| cloc \ | |
| clustergit-git \ | |
| clustergit-git \ | |
| cmake \ | |
| docker-compose \ | |
| ebtables \ | |
| emacs \ | |
| fish \ | |
| fslint \ | |
| fzf \ | |
| git-lfs \ | |
| global \ | |
| go \ | |
| grml-zsh-config \ | |
| gvim \ | |
| imagemagick \ | |
| jdk-openjdk \ | |
| linux-headers \ | |
| moreutils \ | |
| neovim \ | |
| net-tools \ | |
| nodejs \ | |
| npm \ | |
| oath-toolkit \ | |
| openconnect \ | |
| packer \ | |
| postgresql-libs \ | |
| pygmentize \ | |
| python \ | |
| python-boto \ | |
| python-neovim \ | |
| python-pip \ | |
| python-psutil \ | |
| rclone \ | |
| ripgrep \ | |
| rmlint \ | |
| ruby \ | |
| s3cmd \ | |
| sbt \ | |
| scala \ | |
| shellcheck-bin \ | |
| sqlite \ | |
| sysdig \ | |
| sysstat \ | |
| terraform \ | |
| the_silver_searcher \ | |
| tig \ | |
| tigervnc \ | |
| tree \ | |
| ufw \ | |
| units \ | |
| unzip \ | |
| xclip \ | |
| yarn \ | |
| zsh-autosuggestions \ | |
| zsh-completions \ | |
| zsh-syntax-highlighting | |
| usermod -aG docker $vm_user || 0 | |
| ) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Install packages with Scoop | |
| if (!(Get-Command scoop -ErrorAction SilentlyContinue)) { | |
| Set-ExecutionPolicy RemoteSigned -Scope CurrentUser | |
| Invoke-WebRequest -useb get.scoop.sh | Invoke-Expression | |
| } | |
| Set-Alias -Name scoop -Value scoop.cmd | |
| function Install-Package-If-Missing([String]$packageName) { | |
| if (scoop list | Select-String -Pattern "^\s+\b$packageName\b" -Quiet) { | |
| Write-Output "Package $packageName already installed" | |
| return | |
| } | |
| Write-Output "Installing package $packageName" | |
| scoop install $packageName | |
| } | |
| Install-Package-If-Missing git | |
| scoop bucket add extras | |
| scoop bucket add java | |
| scoop bucket add nonportable | |
| Install-Package-If-Missing sudo | |
| Install-Package-If-Missing 7zip | |
| Install-Package-If-Missing autohotkey | |
| Install-Package-If-Missing curl | |
| Install-Package-If-Missing dotnet-sdk | |
| Install-Package-If-Missing fiddler | |
| Install-Package-If-Missing firefox | |
| Install-Package-If-Missing googlechrome | |
| Install-Package-If-Missing jetbrains-toolbox | |
| Install-Package-If-Missing kitty | |
| Install-Package-If-Missing libreoffice-fresh | |
| Install-Package-If-Missing microsoft-edge-beta-np | |
| Install-Package-If-Missing nodejs | |
| Install-Package-If-Missing notepadplusplus | |
| Install-Package-If-Missing nssm | |
| Install-Package-If-Missing openjdk | |
| Install-Package-If-Missing powertoys | |
| Install-Package-If-Missing processhacker | |
| Install-Package-If-Missing putty | |
| Install-Package-If-Missing slack | |
| Install-Package-If-Missing vagrant | |
| Install-Package-If-Missing vim | |
| Install-Package-If-Missing virtualbox-np | |
| Install-Package-If-Missing vlc | |
| Install-Package-If-Missing vscode | |
| Install-Package-If-Missing wget | |
| Install-Package-If-Missing windows-terminal | |
| Install-Package-If-Missing winscp | |
| Install-Package-If-Missing wireshark | |
| Install-Package-If-Missing wiztree | |
| # PowerShell settings | |
| if (!(Test-Path -Path C:\Users\Bruno\Documents\WindowsPowerShell\Microsoft.Powershell_profile.ps1)) { | |
| $powershellProfile = @' | |
| Import-Module PSReadline | |
| Set-PSReadlineOption -EditMode Emacs | |
| '@ | |
| New-Item -ItemType Directory -Force -Path C:\Users\Bruno\Documents\WindowsPowershell | |
| Write-Output $powershellProfile > C:\Users\Bruno\Documents\WindowsPowerShell\Microsoft.Powershell_profile.ps1 | |
| } | |
| # Admin Commands | |
| $adminCommands = @' | |
| # Set Caps Lock to Ctrl | |
| $Remap = New-Object -TypeName byte[] -ArgumentList 20 | |
| $Remap[8] = 0x02 | |
| $Remap[12] = 0x1d | |
| $Remap[14] = 0x3a | |
| Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Keyboard Layout' -Name 'Scancode Map' -Value $Remap -Force | |
| # Show Hidden Files and Extensions in Explorer | |
| Set-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced' -Name 'HideFileExt' -Value '0' -Type DWORD -Force | |
| Set-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced' -Name 'Hidden' -Value '1' -Type DWORD -Force | |
| # Enable Hyper-V if available | |
| $hyperv = Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V | |
| if ($hyperv -ne $null -And $hyperv.State -ne "Enabled") { | |
| Enable-WindowsOptionalFeature -Online -NoRestart -FeatureName Microsoft-Hyper-V -All -ErrorAction Continue | |
| } | |
| # Enable Virtual Machine Platform if Available | |
| $vmPlatform = Get-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform | |
| if ($vmPlatform -ne $null -And $vmPlatform.State -ne "Enabled") { | |
| Enable-WindowsOptionalFeature -Online -NoRestart -FeatureName VirtualMachinePlatform -All -ErrorAction Continue | |
| } | |
| # Enable WSL | |
| $wsl = Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux | |
| if ($wsl.State -ne "Enabled") { | |
| Enable-WindowsOptionalFeature -Online -NoRestart -FeatureName Microsoft-Windows-Subsystem-Linux | |
| } | |
| Write-Output "To complete the setup, after rebooting run: 'wsl --set-default-version 2'" | |
| '@ | |
| $tempFile = New-TemporaryFile | |
| $adminCommandsFile = $tempFile.FullName + ".ps1" | |
| $adminCommandsOutFile = $adminCommandsFile + ".out" | |
| Rename-Item -Path $tempFile.FullName -NewName $adminCommandsFile | |
| Set-Content -Path $adminCommandsFile -Value $adminCommands | |
| Write-Output "Running commands that require administrative privileges" | |
| Start-Process -FilePath powershell -Verb RunAs -Wait -WindowStyle Hidden -ArgumentList "-Command &`"${adminCommandsFile}`" *> $adminCommandsOutFile" | |
| Get-Content $adminCommandsOutFile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment