forked from yuk7/AlpineWSL
-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.ps1
71 lines (61 loc) · 4.59 KB
/
install.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
param(
[parameter(Mandatory=$false)][string]$user = $env:UserName.ToLower(),
[parameter(Mandatory=$true)][string]$email = "username@domain.com"
)
Start-Transcript -path C:\TEMP\install-wsl.log -append
# Set distro name
$wslDistro = (Get-ChildItem -Path .\Alpine*.exe).Name
$distroName = $wslDistro.Split('.')[0]
$wslPath = "C:\Users\$user\.wsl\$distroName"
$TargetFile = "$wslPath\$wslDistro"
$ShortcutFile = "C:\Users\$user\Desktop\$distroName WSL.lnk"
# Uninstall previous WSL distro if present
If (Test-Path $wslPath) {
Write-Host -ForegroundColor Yellow ("`nUninstalling previous Windows Subsystem for Linux (WSL), $distroName Linux")
Start-Process $wslPath\$wslDistro -ArgumentList "clean" -NoNewWindow -Wait
Get-ChildItem -Path $wslPath -Recurse | Remove-Item -force -recurse
Remove-Item -Force $wslPath
Remove-Item -Force $ShortcutFile
Write-Host -ForegroundColor Yellow ("`nPrevious Windows Subsystem for Linux (WSL), $distroName Linux FOUND and REMOVED.")
}
Else {
Write-Host -ForegroundColor Yellow ("`nPrevious Windows Subsystem for Linux (WSL), $distroName Linux NOT found.")
}
# Install WSL Distro
Write-Host -ForegroundColor Yellow ("`nInstalling Windows Subsystem for Linux (WSL), $distroName Linux to $wslPath")
Invoke-Command -ScriptBlock { Copy-Item -Recurse -Path .\ -Destination $args[0] -Force } -ArgumentList $wslPath
Start-Process wsl.exe -ArgumentList "--set-default-version 2" -NoNewWindow -Wait
Start-Process $wslPath\$wslDistro -NoNewWindow -Wait
Start-Process $wslPath\$wslDistro -ArgumentList "run cd /usr/share/texmf-dist/tex/latex/acrotex; sudo latex acrotex.ins" -NoNewWindow -Wait # would like to add this to makefile
Start-Process $wslPath\$wslDistro -ArgumentList "run sudo mktexlsr" -NoNewWindow -Wait # would like to add this to makefile
Start-Process $wslPath\$wslDistro -ArgumentList "run sudo git config --system core.autocrlf false" -NoNewWindow -Wait
Start-Process $wslPath\$wslDistro -ArgumentList "run sudo git config --system core.symlinks false" -NoNewWindow -Wait
Start-Process $wslPath\$wslDistro -ArgumentList "run sudo git config --system rebase.autosquash true" -NoNewWindow -Wait
Start-Process $wslPath\$wslDistro -ArgumentList "run sudo git config --system lfs.activitytimeout 0" -NoNewWindow -Wait
Start-Process $wslPath\$wslDistro -ArgumentList "run sudo git config --system credential.helper 'cache --timeout 30000'" -NoNewWindow -Wait
Start-Process $wslPath\$wslDistro -ArgumentList "run git lfs install" -NoNewWindow -Wait
Write-Host -ForegroundColor Green ("`nInstallation of Windows Subsystem for Linux (WSL), $distroName Linux is complete")
# Configure user for WSL Distro
Write-Host -ForegroundColor Yellow ("`nConfiguring user:$user for Windows Subsystem for Linux (WSL), $distroName Linux")
Write-Host -ForegroundColor Yellow ("`nSet password for $user when prompted")
Start-Process $wslPath\$wslDistro -ArgumentList "run adduser $user --shell bash --uid 1000" -NoNewWindow -Wait
Start-Process $wslPath\$wslDistro -ArgumentList "run echo '$user ALL=(ALL) ALL' >> /etc/sudoers" -NoNewWindow -Wait
Start-Process $wslPath\$wslDistro -ArgumentList "config --default-uid 1000" -NoNewWindow -Wait
Start-Process $wslPath\$wslDistro -ArgumentList "config --default-term wt" -NoNewWindow -Wait
Start-Process $wslPath\$wslDistro -ArgumentList "run echo export PLANTUML=/usr/local/plantuml.jar >> ~/.bash_profile" -NoNewWindow -Wait # would like to add this to makefile
Start-Process $wslPath\$wslDistro -ArgumentList "run echo neofetch >> ~/.bash_profile" -NoNewWindow -Wait # would like to add this to makefile
Start-Process $wslPath\$wslDistro -ArgumentList "run echo from pprint import pprint >> ~/.pyrc" -NoNewWindow -Wait # would like to add this to makefile
Start-Process $wslPath\$wslDistro -ArgumentList "run echo export DISPLAY=:1 >> ~/.bash_profile" -NoNewWindow -Wait # would like to add this to makefile
Start-Process $wslPath\$wslDistro -ArgumentList "run git config --global user.name $user" -NoNewWindow -Wait
Start-Process $wslPath\$wslDistro -ArgumentList "run git config --global user.email '$email'" -NoNewWindow -Wait
# Create desktop shortcut for user
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.Save()
# Cleanup
Remove-Item -Force $wslPath\rootfs.tar.gz
Remove-Item -Force $wslPath\addWSLfeature.ps1
Remove-Item -Force $wslPath\install.ps1
Write-Host -ForegroundColor Green ("`nUser Configuration of user:$user for Windows Subsystem for Linux (WSL), $distroName Linux is complete")
Stop-Transcript