Copy MSYS2's default files into a recreated home
MSYS2 only copies /etc/skel into a home directory that does not exist yet when the user logs in. The cleanup always creates the home first, so the default files never arrived. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c96357c83a
commit
c498ce1d52
1 changed files with 6 additions and 5 deletions
|
|
@ -59,23 +59,24 @@ function Restore-Keys($target, $source) {
|
|||
[IO.File]::WriteAllText($target, (($keys + $required) -join "`n") + "`n")
|
||||
}
|
||||
|
||||
# The home directory is the one from /etc/passwd, which the user cannot change, but which they can delete. The
|
||||
# directories in it belong to the user, so that they can put their own keys in .ssh.
|
||||
function New-Dir($path) {
|
||||
# The home directory is the one from /etc/passwd, which the user cannot change, but which they can delete. A new one
|
||||
# gets MSYS2's default files from /etc/skel, which MSYS2 itself only copies into a home that does not exist yet.
|
||||
function New-Home($path) {
|
||||
New-Item -ItemType Directory -Path $path | Out-Null
|
||||
# The parent directory gives the users read access only, so the owner gets write access on their own home.
|
||||
if ($sid) {
|
||||
icacls $path /grant "*${sid}:(OI)(CI)F" | Out-Null
|
||||
icacls $path /setowner "*$sid" | Out-Null
|
||||
}
|
||||
Get-ChildItem -LiteralPath 'C:\msys2\etc\skel' -Force | Copy-Item -Destination $path -Recurse -Force
|
||||
}
|
||||
|
||||
if (-not (Test-Path -LiteralPath $HomeDir)) {
|
||||
New-Dir $HomeDir
|
||||
New-Home $HomeDir
|
||||
Write-Log "created $HomeDir"
|
||||
} elseif ((Get-Item -LiteralPath $HomeDir -Force).Attributes -band [IO.FileAttributes]::ReparsePoint) {
|
||||
Remove-Anything $HomeDir
|
||||
New-Dir $HomeDir
|
||||
New-Home $HomeDir
|
||||
Write-Log "replaced the link $HomeDir"
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue