|
# Definir diretório para armazenar o arquivo packages.config, logs e downloads |
|
$basePath = "C:/temp/Setup-WindowsDevEnvironment" |
|
$logPath = "$basePath/logs" |
|
$downloadsPath = "$basePath/downloads" |
|
$packagesConfigPath = "$basePath/packages.config" |
|
$logFile = "$logPath/install_log.txt" |
|
|
|
# Criar diretórios caso não existam |
|
if (!(Test-Path -Path $basePath)) { |
|
New-Item -ItemType Directory -Path $basePath |
|
} |
|
if (!(Test-Path -Path $logPath)) { |
|
New-Item -ItemType Directory -Path $logPath |
|
} |
|
if (!(Test-Path -Path $downloadsPath)) { |
|
New-Item -ItemType Directory -Path $downloadsPath |
|
} |
|
if (Test-Path $logFile) { |
|
Remove-Item -Path $logFile -Force |
|
} |
|
|
|
# Baixar o arquivo packages.config da URL fornecida |
|
$packagesUrl = "https://gist.githubusercontent.com/ganobrega/95d330fe1232c387f76084510257811e/raw/packages.config" |
|
Write-Host "Baixando o arquivo packages.config..." -ForegroundColor Yellow |
|
Invoke-WebRequest -Uri $packagesUrl -OutFile $packagesConfigPath |
|
|
|
# Verifica se o Chocolatey está instalado |
|
if (!(Get-Command choco -ErrorAction SilentlyContinue)) { |
|
Write-Host "Chocolatey não está instalado. Instalando agora..." -ForegroundColor Yellow |
|
|
|
# Configura a política de execução para permitir scripts remotos temporariamente |
|
Set-ExecutionPolicy Bypass -Scope Process -Force |
|
|
|
# Baixa e instala o Chocolatey |
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 |
|
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) |
|
|
|
# Verifica novamente se o Chocolatey foi instalado com sucesso |
|
if (Get-Command choco -ErrorAction SilentlyContinue) { |
|
Write-Host "Chocolatey foi instalado com sucesso!" -ForegroundColor Green |
|
} else { |
|
Write-Host "Falha ao instalar o Chocolatey. Verifique a conexão com a internet ou permissões administrativas." -ForegroundColor Red |
|
exit 1 |
|
} |
|
} else { |
|
Write-Host "Chocolatey já está instalado no sistema." -ForegroundColor Green |
|
} |
|
|
|
# Instalar pacotes usando o comando choco install com o arquivo packages.config |
|
Write-Host "Iniciando a instalação dos pacotes..." -ForegroundColor Yellow |
|
try { |
|
choco install $packagesConfigPath -y |
|
Write-Host "Instalação concluída com sucesso!" -ForegroundColor Green |
|
} catch { |
|
Write-Host "Falha ao instalar os pacotes. Verifique o arquivo packages.config." -ForegroundColor Red |
|
Add-Content -Path $logFile -Value "Falha ao instalar pacotes: $($_.Exception.Message)" |
|
} |
|
|
|
# Instalar o Windows Terminal usando o winget |
|
Write-Host "Instalando o Windows Terminal..." -ForegroundColor Yellow |
|
try { |
|
winget install --id Microsoft.WindowsTerminal -e --source msstore |
|
Write-Host "Windows Terminal instalado com sucesso!" -ForegroundColor Green |
|
} catch { |
|
Write-Host "Falha ao instalar o Windows Terminal. Verifique o winget." -ForegroundColor Red |
|
Add-Content -Path $logFile -Value "Falha ao instalar o Windows Terminal: $($_.Exception.Message)" |
|
} |
|
|
|
# Verifica se o WSL está instalado |
|
Write-Host "Verificando instalação do WSL..." -ForegroundColor Yellow |
|
$wslFeature = Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -eq "Microsoft-Windows-Subsystem-Linux" } |
|
|
|
if ($wslFeature.State -eq "Enabled") { |
|
Write-Host "WSL já está instalado no sistema." -ForegroundColor Green |
|
} else { |
|
Write-Host "WSL não está instalado. Instalando agora..." -ForegroundColor Yellow |
|
|
|
# Ativa o WSL |
|
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart -ErrorAction Stop |
|
|
|
# Instala o WSL 2 e o kernel necessário |
|
wsl --install |
|
|
|
Write-Host "WSL foi instalado com sucesso!" -ForegroundColor Green |
|
} |
|
|
|
# Configura o Git Bash como o perfil padrão no Windows Terminal |
|
Write-Host "Configurando o Git Bash como perfil padrão no Windows Terminal..." -ForegroundColor Yellow |
|
|
|
$settingsPath = "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json" |
|
|
|
# Verifica se o arquivo settings.json existe |
|
if (Test-Path $settingsPath) { |
|
# Lê o conteúdo do arquivo settings.json |
|
$settingsJson = Get-Content -Path $settingsPath -Raw | ConvertFrom-Json |
|
|
|
# Encontra o perfil do Git Bash e altera o valor de defaultProfile |
|
$gitBashProfile = $settingsJson.profiles.list | Where-Object { $_.name -eq "Git Bash" } |
|
if ($gitBashProfile) { |
|
$settingsJson.defaults.profile = $gitBashProfile.guid |
|
# Salva as alterações no arquivo settings.json |
|
$settingsJson | ConvertTo-Json -Depth 10 | Set-Content -Path $settingsPath -Force |
|
Write-Host "Git Bash configurado como perfil padrão no Windows Terminal." -ForegroundColor Green |
|
} else { |
|
Write-Host "Não foi encontrado o perfil 'Git Bash' no Windows Terminal." -ForegroundColor Red |
|
} |
|
} else { |
|
Write-Host "Arquivo settings.json do Windows Terminal não encontrado." -ForegroundColor Red |
|
} |
|
|
|
# Instalar o Raindrop.io através do winget (Windows Store) |
|
Write-Host "Instalando o Raindrop.io da Windows Store..." -ForegroundColor Yellow |
|
try { |
|
winget install --id Raindrop.Raindrop -e --source msstore |
|
Write-Host "Raindrop.io instalado com sucesso!" -ForegroundColor Green |
|
} catch { |
|
Write-Host "Falha ao instalar o Raindrop.io. Verifique o winget." -ForegroundColor Red |
|
Add-Content -Path $logFile -Value "Falha ao instalar o Raindrop.io: $($_.Exception.Message)" |
|
} |
|
|
|
# Baixar e abrir o Lightshot |
|
try { |
|
Write-Host "Baixando o Lightshot..." -ForegroundColor Yellow |
|
$lightshotUrl = "https://app.prntscr.com/build/setup-lightshot.exe" |
|
$lightshotFile = "$downloadsPath\LightshotSetup.exe" |
|
Invoke-WebRequest -Uri $lightshotUrl -OutFile $lightshotFile |
|
Start-Process $lightshotFile |
|
Write-Host "Lightshot instalado e aberto." -ForegroundColor Green |
|
} catch { |
|
Write-Host "Falha ao instalar o Lightshot." -ForegroundColor Red |
|
Add-Content -Path $logFile -Value "Falha ao instalar o Lightshot: $($_.Exception.Message)" |
|
} |
|
|
|
|
|
# Instalar o Chris Titus Tech's Windows Utility |
|
try { |
|
# Executar o comando final solicitado |
|
Write-Host "Executando o comando solicitado..." -ForegroundColor Yellow |
|
irm "https://christitus.com/win" | iex |
|
} catch { |
|
Write-Host "Falha ao instalar o ChristitusWin." -ForegroundColor Red |
|
Add-Content -Path $logFile -Value "Falha ao instalar o ChristitusWin: $($_.Exception.Message)" |
|
} |
|
|
|
# Criar um ponto de restauração no Windows |
|
Write-Host "Criando um ponto de restauração do sistema..." -ForegroundColor Yellow |
|
$restorePointName = "Ponto de Restauração - $((Get-Date).ToString('yyyy-MM-dd_HH-mm-ss'))" |
|
try { |
|
Checkpoint-Computer -Description $restorePointName -RestorePointType "MODIFY_SETTINGS" |
|
Write-Host "Ponto de restauração criado com sucesso!" -ForegroundColor Green |
|
} catch { |
|
Write-Host "Falha ao criar ponto de restauração: $($_.Exception.Message)" -ForegroundColor Red |
|
Add-Content -Path $logFile -Value "Falha ao criar ponto de restauração: $($_.Exception.Message)" |
|
} |
|
|
|
Write-Host "Processo concluído!" -ForegroundColor Green |
|
|
|
# Exibe mensagem com caminho do log em caso de falha |
|
if (Test-Path $logFile) { |
|
Write-Host "Alguns erros ocorreram durante a execução. Consulte o log em: $logFile" -ForegroundColor Yellow |
|
} |