60 lines
3.4 KiB
PowerShell
60 lines
3.4 KiB
PowerShell
# bootstrap_autologon_juanjo.ps1
|
|
# Migra la infraestructura a la cuenta local de autologon (juanjo).
|
|
# Se ejecuta UNA sola vez, en el primer inicio de sesion de juanjo (via RunOnce HKLM).
|
|
# No requiere administrador (registra tareas del usuario actual + config git de usuario).
|
|
|
|
$ErrorActionPreference = 'Continue'
|
|
$log = Join-Path $env:USERPROFILE 'bootstrap_autologon.log'
|
|
Start-Transcript -Path $log -Force | Out-Null
|
|
Write-Output "=== BOOTSTRAP AUTOLOGON $(Get-Date -Format s) ==="
|
|
Write-Output "Usuario: $env:USERDOMAIN\$env:USERNAME"
|
|
|
|
$infra = Join-Path $env:USERPROFILE 'Documents\Github\INFRAESTRUCTURA'
|
|
$bib = Join-Path $env:USERPROFILE 'Documents\Github\biblioteca_negocio_prolongo'
|
|
$pwsh = Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe'
|
|
|
|
# 1) Git: identidad + safe.directory (los repos son de otro usuario) + helper
|
|
git config --global user.name "Juanjo Minguez"
|
|
git config --global user.email "desarrollo@faccsa.es"
|
|
git config --global --add safe.directory '*'
|
|
git config --global credential.helper manager
|
|
|
|
# 2) Credenciales de Gitea reutilizando el token del remote de INFRAESTRUCTURA (sin mostrarlo)
|
|
try {
|
|
$remote = git -C $infra remote get-url origin 2>$null
|
|
if ($remote -match 'https://([^:]+):([^@]+)@([^/]+)/') {
|
|
$u = $matches[1]; $tok = $matches[2]; $hostname = $matches[3]
|
|
$credPath = Join-Path $env:USERPROFILE '.git-credentials'
|
|
"https://${u}:${tok}@${hostname}" | Set-Content -Path $credPath -Encoding ascii
|
|
git config --global credential.helper store
|
|
Write-Output "[OK] Credenciales git (store) configuradas."
|
|
} else {
|
|
Write-Output "[WARN] No se pudo extraer token del remote; se usara Git Credential Manager."
|
|
}
|
|
} catch { Write-Output "[WARN] credenciales git: $_" }
|
|
|
|
# 3) Instalar/registrar OmniRoute Watchdog + Monitor Estado + watchers para este usuario
|
|
try {
|
|
& (Join-Path $infra 'scripts\instalar_global.ps1')
|
|
Write-Output "[OK] instalar_global.ps1 ejecutado."
|
|
} catch { Write-Output "[ERROR] instalar_global.ps1: $_" }
|
|
|
|
# 4) MorningRoutine Prolongo para este usuario (abre apps al iniciar sesion)
|
|
try {
|
|
if (Get-ScheduledTask -TaskName 'MorningRoutine Prolongo' -ErrorAction SilentlyContinue) {
|
|
Unregister-ScheduledTask -TaskName 'MorningRoutine Prolongo' -Confirm:$false
|
|
}
|
|
$action = New-ScheduledTaskAction -Execute $pwsh -Argument "-WindowStyle Hidden -ExecutionPolicy Bypass -File `"$infra\scripts\morning_routine\arranque_apps.ps1`""
|
|
$trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME
|
|
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -MultipleInstances IgnoreNew
|
|
$principal = New-ScheduledTaskPrincipal -UserId "$env:USERDOMAIN\$env:USERNAME" -LogonType Interactive -RunLevel Limited
|
|
Register-ScheduledTask -TaskName 'MorningRoutine Prolongo' -Action $action -Trigger $trigger -Settings $settings -Principal $principal -Description 'Abre apps al iniciar sesion (migrado a cuenta autologon).' -Force | Out-Null
|
|
Write-Output "[OK] MorningRoutine Prolongo registrada."
|
|
} catch { Write-Output "[ERROR] MorningRoutine: $_" }
|
|
|
|
Write-Output "--- TAREAS REGISTRADAS ---"
|
|
Get-ScheduledTask | Where-Object { $_.TaskName -match 'OmniRoute|Monitor Estado|Telegram Watcher|Recordatorios|Shutdown Listener|MorningRoutine' } | Select-Object TaskName,State | Format-Table -AutoSize
|
|
|
|
Write-Output "=== FIN BOOTSTRAP $(Get-Date -Format s) ==="
|
|
Stop-Transcript | Out-Null
|