Skip to content

Commit

Permalink
Merge pull request #138 from szymonos/dev
Browse files Browse the repository at this point in the history
Merge dev to main
  • Loading branch information
szymonos authored Oct 14, 2023
2 parents c7a4658 + 8b836c2 commit b906552
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .assets/provision/autoexec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sh
# :script executed on WSL startup via [boot] command defined in wsl.conf
14 changes: 7 additions & 7 deletions wsl/wsl_network_fix.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ begin {
}

# instantiate string builder
$builder = [System.Text.StringBuilder]::new("# Generated by wsl_network_fix.ps1 on $((Get-Date).ToString('s'))")
$builder = [System.Text.StringBuilder]::new("# Generated by wsl_network_fix.ps1 on $((Get-Date).ToString('s'))`n")
}

process {
Expand Down Expand Up @@ -113,20 +113,20 @@ process {
$idx = -1
$selection = Read-Host -Prompt "Please select the interface for propagating DNS Servers:`n$($list | Format-Table | Out-String)"
[bool]$returnedInt = [int]::TryParse($selection, [ref]$idx)
} until ($returnedInt -and $idx -ge 0 -and $idx -lt $netAdapters.Count)
} until ($returnedInt -and $idx -ge 0 -and $idx -lt $ipConfig.Count)
$dnsServers = $ipConfig[$idx].DNSServer
$dnsServers.ForEach({ $builder.AppendLine("nameserver $_") | Out-Null })
}
# get DNS suffix search list
$searchSuffix = (Get-DnsClientGlobalSetting).SuffixSearchList -join ','
if ($searchSuffix) {
$builder.AppendLine("search $searchSuffix") | Out-Null
}
# get distro default gateway
$def_gtw = (wsl.exe -d $Distro -u root --exec sh -c 'ip route show default' | Select-String '(?<=via )[\d\.]+(?= dev)').Matches.Value
if ($def_gtw) {
$builder.AppendLine("nameserver $def_gtw") | Out-Null
}
# get DNS suffix search list
$searchSuffix = (Get-DnsClientGlobalSetting).SuffixSearchList -join ','
if ($searchSuffix) {
$builder.AppendLine("search $searchSuffix") | Out-Null
}
$builder.AppendLine('options timeout:1 retries:1') | Out-Null
$resolvConf = $builder.ToString().Replace("`r`n", "`n")
# save resolv.conf file
Expand Down
10 changes: 8 additions & 2 deletions wsl/wsl_setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,15 @@ process {
'[ -d $HOME/miniconda3 ] && python="true" || python="false";',
'[ -f $HOME/.ssh/id_ed25519 ] && ssh_key="true" || ssh_key="false";',
'[ -d /mnt/wslg ] && wslg="true" || wslg="false";',
'[ -x /etc/autoexec.sh ] && wsl_boot="true" || wsl_boot="false";',
'git_user_name="$(git config --global --get user.name 2>/dev/null)";',
'[ -n "$git_user_name" ] && git_user="true" || git_user="false";',
'git_user_email="$(git config --global --get user.email 2>/dev/null)";',
'[ -n "$git_user_email" ] && git_email="true" || git_email="false";',
'grep -qw "systemd.*true" /etc/wsl.conf 2>/dev/null && systemd="true" || systemd="false";',
'grep -Fqw "dark" /etc/profile.d/gtk_theme.sh 2>/dev/null && gtkd="true" || gtkd="false";',
'printf "{\"user\":\"$(id -un)\",\"shell\":$shell,\"k8s_base\":$k8s_base,\"k8s_ext\":$k8s_ext,',
'\"omp\":$omp,\"az\":$az,\"wslg\":$wslg,\"python\":$python,\"systemd\":$systemd,\"gtkd\":$gtkd,',
'printf "{\"user\":\"$(id -un)\",\"shell\":$shell,\"k8s_base\":$k8s_base,\"k8s_ext\":$k8s_ext,\"omp\":$omp,',
'\"az\":$az,\"wslg\":$wslg,\"wsl_boot\":$wsl_boot,\"python\":$python,\"systemd\":$systemd,\"gtkd\":$gtkd,',
'\"pwsh\":$pwsh,\"zsh\":$zsh,\"git_user\":$git_user,\"git_email\":$git_email,\"ssh_key\":$ssh_key}"'
)
# check existing distro setup
Expand Down Expand Up @@ -287,6 +288,11 @@ process {
Write-Warning 'SSL certificate problem: self-signed certificate in certificate chain. Script execution halted.'
exit
}
# *boot setup
if (-not $chk.wsl_boot) {
wsl.exe --distribution $Distro --user root install -m 0755 .assets/provision/autoexec.sh /etc
Set-WslConf -Distro $Distro -ConfDict ([ordered]@{ boot = @{ command = '"[ -x /etc/autoexec.sh ] && /etc/autoexec.sh || true"' } })
}
switch ($scopes) {
distrobox {
Write-Host 'installing distrobox...' -ForegroundColor Cyan
Expand Down
14 changes: 7 additions & 7 deletions wsl/wsl_wslg.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ Enable/disable WSLg.
Specify the value to true or false to enable/disable WSLg.
.EXAMPLE
wsl/wsl_wslg.ps1 -WSLg 'true'
wsl/wsl_wslg.ps1 -WSLg 'false'
wsl/wsl_wslg.ps1 -GuiApplications 'true'
wsl/wsl_wslg.ps1 -GuiApplications 'false'
#>
[CmdletBinding()]
param (
[Parameter(Mandatory, Position = 0)]
[ValidateSet('true', 'false')]
[string]$WSLg
[string]$GuiApplications
)

begin {
Expand All @@ -36,14 +36,14 @@ process {
if (Test-Path "$HOME/.wslconfig") {
$wslConfig = Get-Content -Path "$HOME/.wslconfig" | ConvertFrom-Cfg
if ($wslConfig.wsl2) {
$wslConfig.wsl2.guiApplications = $WSLg
$wslConfig.wsl2.guiApplications = $GuiApplications
} else {
$wslConfig.wsl2 = @{ guiApplications = $WSLg }
$wslConfig.wsl2 = @{ guiApplications = $GuiApplications }
}
} else {
$wslConfig = [ordered]@{
wsl2 = @{
guiApplications = $WSLg
guiApplications = $GuiApplications
}
}
}
Expand All @@ -54,5 +54,5 @@ process {
}

end {
Write-Host "WSLg $($WSLg -eq 'true' ? 'enabled': 'disabled')."
Write-Host "WSLg $($GuiApplications -eq 'true' ? 'enabled': 'disabled')."
}

0 comments on commit b906552

Please sign in to comment.