Initial commit: Living Room PC setup scripts
This commit is contained in:
parent
9c1e897bdc
commit
fe187a5b92
17 changed files with 466 additions and 36 deletions
55
.gitignore
vendored
Normal file
55
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
/bginfo/mac
|
||||||
|
|
||||||
|
# BGInfo files
|
||||||
|
**/mac
|
||||||
|
|
||||||
|
# Windows system files
|
||||||
|
Thumbs.db
|
||||||
|
ehthumbs.db
|
||||||
|
Desktop.ini
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# PowerShell files
|
||||||
|
*.ps1xml
|
||||||
|
*.psc1
|
||||||
|
*.psd1
|
||||||
|
*.psm1
|
||||||
|
*.pssc
|
||||||
|
*.psrc
|
||||||
|
*.ps1.config
|
||||||
|
|
||||||
|
# Visual Studio files
|
||||||
|
.vs/
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
x64/
|
||||||
|
x86/
|
||||||
|
build/
|
||||||
|
bld/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
[Oo]ut/
|
||||||
|
msbuild.log
|
||||||
|
msbuild.err
|
||||||
|
msbuild.wrn
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
*.log
|
||||||
|
logs/
|
||||||
|
log/
|
||||||
|
|
||||||
|
# Temporary files
|
||||||
|
*.tmp
|
||||||
|
*.temp
|
||||||
|
*.swp
|
||||||
|
*.*~
|
||||||
|
~*.*
|
||||||
|
|
||||||
30
README.md
30
README.md
|
|
@ -254,6 +254,36 @@ You can now connect to your PC remotely using ssh.
|
||||||
``` powershell
|
``` powershell
|
||||||
ssh username@your-pc-ip-address
|
ssh username@your-pc-ip-address
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Text Editors
|
||||||
|
When working with text files remotely, you'll need a text editor. While traditional CLI editors like vim and nano are powerful, they can be challenging for users not familiar with command-line interfaces. Here are your options:
|
||||||
|
|
||||||
|
#### Microsoft Edit (Recommended for Most Users)
|
||||||
|
Microsoft Edit is a modern, user-friendly text editor that provides a familiar Windows interface. It's perfect for users who:
|
||||||
|
- Are more comfortable with GUI applications
|
||||||
|
- Don't have extensive CLI experience
|
||||||
|
- Need a simple, straightforward editing experience
|
||||||
|
|
||||||
|
Install Microsoft Edit:
|
||||||
|
```powershell
|
||||||
|
winget install Microsoft.Edit
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Alternative CLI Editors
|
||||||
|
For users who prefer command-line editors:
|
||||||
|
|
||||||
|
1. **vim** (via Chocolatey):
|
||||||
|
```powershell
|
||||||
|
choco install vim
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **nano** (via Chocolatey):
|
||||||
|
```powershell
|
||||||
|
choco install nano
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note:** While vim and nano are excellent choices for experienced users, Microsoft Edit was chosen as the default editor in this setup because it provides the most accessible experience for users who may not be familiar with command-line interfaces. This aligns with the goal of making the living room PC setup as user-friendly as possible.
|
||||||
|
|
||||||
You can install applications like btop kill process, etc.
|
You can install applications like btop kill process, etc.
|
||||||
```powershell
|
```powershell
|
||||||
winget install Microsoft.VCRedist.2015+.x86
|
winget install Microsoft.VCRedist.2015+.x86
|
||||||
|
|
|
||||||
4
Steps.md
4
Steps.md
|
|
@ -1,6 +1,8 @@
|
||||||
This file contains the steps to optimize and install the necessary software for a living room PC with a target of running Steam Big Picture Mode. The goal is to make it as close to a console experience as possible. Requiring minimal input from a user that requires more than a game controller.
|
This file contains the steps to optimize and install the necessary software for a living room PC with a target of running Steam Big Picture Mode. The goal is to make it as close to a console experience as possible. Requiring minimal input from a user that requires more than a game controller.
|
||||||
|
|
||||||
Install apps using Winget for script simplicity.
|
1. Install apps using Winget for script simplicity. Use chocolatey as a fall back.
|
||||||
|
a. Make sure Winget is working and up to date.
|
||||||
|
b. Setup chocolatey
|
||||||
|
|
||||||
1. Optimize Windows
|
1. Optimize Windows
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ $vbsFiles = @(
|
||||||
"sshstatus.vbs"
|
"sshstatus.vbs"
|
||||||
)
|
)
|
||||||
|
|
||||||
$baseUrl = "https://raw.githubusercontent.com/robojerk/ConfigureWindowsSteamPC/main/bginfo/scripts"
|
$baseUrl = "https://raw.githubusercontent.com/robojerk/Leanback_11/main/bginfo/scripts"
|
||||||
foreach ($file in $vbsFiles) {
|
foreach ($file in $vbsFiles) {
|
||||||
$url = "$baseUrl/$file"
|
$url = "$baseUrl/$file"
|
||||||
$output = "$vbsDir\$file"
|
$output = "$vbsDir\$file"
|
||||||
|
|
@ -38,7 +38,7 @@ foreach ($file in $vbsFiles) {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Download config.bgi from GitHub
|
# Download config.bgi from GitHub
|
||||||
$configUrl = "https://raw.githubusercontent.com/robojerk/ConfigureWindowsSteamPC/main/bginfo/config.bgi"
|
$configUrl = "https://raw.githubusercontent.com/robojerk/Leanback_11/main/bginfo/config.bgi"
|
||||||
Invoke-WebRequest -Uri $configUrl -OutFile "$bginfoDir\config.bgi"
|
Invoke-WebRequest -Uri $configUrl -OutFile "$bginfoDir\config.bgi"
|
||||||
|
|
||||||
# Create scheduled task to run BGInfo at startup
|
# Create scheduled task to run BGInfo at startup
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
D8:9E:F3:36:81:A3
|
|
||||||
188
install.ps1
188
install.ps1
|
|
@ -1,9 +1,111 @@
|
||||||
# This script will install the components to make a Living Room PC
|
# This script will install the components to make a Living Room PC
|
||||||
# Main focus is for gaming, primarily on Steam
|
# Main focus is for gaming, primarily on Steam
|
||||||
|
|
||||||
|
# Apps to be installed:
|
||||||
|
# - Steam (winget: Valve.Steam, choco: steam)
|
||||||
|
# - PowerShell 7 (winget: Microsoft.PowerShell, choco: powershell-core)
|
||||||
|
# - BGInfo (winget: Sysinternals.BGInfo, choco: bginfo)
|
||||||
|
# - VCRedist (winget: Microsoft.VCRedist.2015+.x64, choco: vcredist140)
|
||||||
|
# - btop4win (winget: not available, choco: btop4win)
|
||||||
|
# - Microsoft Edit (winget: Microsoft.Edit, choco: not available)
|
||||||
|
|
||||||
# Requires running as administrator
|
# Requires running as administrator
|
||||||
#Requires -RunAsAdministrator
|
#Requires -RunAsAdministrator
|
||||||
|
|
||||||
|
### Package Manager Setup ###
|
||||||
|
Write-Host "Setting up package managers..." -ForegroundColor Green
|
||||||
|
|
||||||
|
# Check and setup Winget
|
||||||
|
Write-Host "Checking Winget..." -ForegroundColor Yellow
|
||||||
|
$wingetPath = Get-Command winget -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
if (-not $wingetPath) {
|
||||||
|
Write-Host "Winget is not installed. Installing via Microsoft Store..." -ForegroundColor Yellow
|
||||||
|
Start-Process "ms-windows-store://pdp/?ProductId=9NBLGGH4NNS1"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check Winget version
|
||||||
|
$wingetVersion = (winget --version)
|
||||||
|
Write-Host "Current Winget version: $wingetVersion" -ForegroundColor Green
|
||||||
|
|
||||||
|
# Update Winget
|
||||||
|
Write-Host "Updating Winget..." -ForegroundColor Yellow
|
||||||
|
winget upgrade --all --include-unknown
|
||||||
|
|
||||||
|
# Setup Chocolatey
|
||||||
|
Write-Host "Setting up Chocolatey..." -ForegroundColor Yellow
|
||||||
|
|
||||||
|
# Set TLS 1.2 for security
|
||||||
|
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
|
||||||
|
|
||||||
|
# Check if Chocolatey is already installed
|
||||||
|
if (-not (Get-Command choco -ErrorAction SilentlyContinue)) {
|
||||||
|
Write-Host "Installing Chocolatey..." -ForegroundColor Yellow
|
||||||
|
|
||||||
|
# Create the installation directory if it doesn't exist
|
||||||
|
$chocoPath = "$env:ProgramData\chocolatey"
|
||||||
|
if (-not (Test-Path $chocoPath)) {
|
||||||
|
New-Item -ItemType Directory -Path $chocoPath -Force | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
# Download and run the Chocolatey installation script
|
||||||
|
$installScript = "https://community.chocolatey.org/install.ps1"
|
||||||
|
$tempFile = [System.IO.Path]::GetTempFileName()
|
||||||
|
|
||||||
|
try {
|
||||||
|
Invoke-WebRequest -Uri $installScript -OutFile $tempFile
|
||||||
|
& $tempFile
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Error "Failed to install Chocolatey: $_"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (Test-Path $tempFile) {
|
||||||
|
Remove-Item $tempFile -Force
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Host "Chocolatey is already installed." -ForegroundColor Green
|
||||||
|
}
|
||||||
|
|
||||||
|
# Verify Chocolatey installation
|
||||||
|
$chocoVersion = (choco --version)
|
||||||
|
Write-Host "Chocolatey version: $chocoVersion" -ForegroundColor Green
|
||||||
|
|
||||||
|
# Update Chocolatey
|
||||||
|
Write-Host "Updating Chocolatey..." -ForegroundColor Yellow
|
||||||
|
choco upgrade chocolatey -y
|
||||||
|
|
||||||
|
### Function to Install Apps ###
|
||||||
|
function Install-App {
|
||||||
|
param (
|
||||||
|
[string]$AppName,
|
||||||
|
[string]$WingetId,
|
||||||
|
[string]$ChocoId,
|
||||||
|
[switch]$UseChocoOnly
|
||||||
|
)
|
||||||
|
|
||||||
|
Write-Host "Installing $AppName..." -ForegroundColor Yellow
|
||||||
|
|
||||||
|
if ($UseChocoOnly) {
|
||||||
|
Write-Host "Using Chocolatey for $AppName..." -ForegroundColor Yellow
|
||||||
|
choco install $ChocoId -y
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Write-Host "Attempting to install $AppName via Winget..." -ForegroundColor Yellow
|
||||||
|
winget install -e --id $WingetId --accept-source-agreements --accept-package-agreements
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "Winget installation failed, falling back to Chocolatey..." -ForegroundColor Yellow
|
||||||
|
choco install $ChocoId -y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
### Remove Bloatware
|
### Remove Bloatware
|
||||||
Write-Host "Starting debloating process..." -ForegroundColor Green
|
Write-Host "Starting debloating process..." -ForegroundColor Green
|
||||||
|
|
||||||
|
|
@ -26,7 +128,7 @@ Remove-Item -Path "$env:SYSTEMDRIVE\OneDriveTemp" -Force -Recurse -ErrorAction S
|
||||||
|
|
||||||
# Install PowerShell 7 and set as default
|
# Install PowerShell 7 and set as default
|
||||||
Write-Host "Installing PowerShell 7..." -ForegroundColor Yellow
|
Write-Host "Installing PowerShell 7..." -ForegroundColor Yellow
|
||||||
winget install -e --id Microsoft.PowerShell --accept-source-agreements --accept-package-agreements
|
Install-App -AppName "PowerShell 7" -WingetId "Microsoft.PowerShell" -ChocoId "powershell-core"
|
||||||
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "DontUsePowerShellOnWinX" -Value 0 -Type DWord
|
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "DontUsePowerShellOnWinX" -Value 0 -Type DWord
|
||||||
|
|
||||||
# Debloat Edge
|
# Debloat Edge
|
||||||
|
|
@ -90,36 +192,77 @@ cleanmgr /sagerun:1
|
||||||
### Steam
|
### Steam
|
||||||
# Install Steam using winget
|
# Install Steam using winget
|
||||||
Write-Host "Installing Steam..." -ForegroundColor Green
|
Write-Host "Installing Steam..." -ForegroundColor Green
|
||||||
winget install -e --id Valve.Steam --accept-source-agreements --accept-package-agreements
|
Install-App -AppName "Steam" -WingetId "Valve.Steam" -ChocoId "steam"
|
||||||
|
|
||||||
### BGInfo
|
### Install Required Components
|
||||||
# Script variables
|
Write-Host "Installing required components..." -ForegroundColor Green
|
||||||
$bgInfoPath = "$env:USERPROFILE\.bginfo"
|
|
||||||
|
|
||||||
# Function to ensure a directory exists
|
# Install VCRedist
|
||||||
function EnsureDirectory {
|
Install-App -AppName "Visual C++ Redistributable" -WingetId "Microsoft.VCRedist.2015+.x64" -ChocoId "vcredist140"
|
||||||
param([string]$path)
|
|
||||||
if (-not (Test-Path $path)) {
|
# Install OpenSSH using PowerShell method
|
||||||
New-Item -ItemType Directory -Path $path -Force | Out-Null
|
Write-Host "Installing OpenSSH..." -ForegroundColor Yellow
|
||||||
|
|
||||||
|
# Check if OpenSSH is available
|
||||||
|
$sshCapabilities = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
|
||||||
|
Write-Host "Available OpenSSH capabilities:" -ForegroundColor Yellow
|
||||||
|
$sshCapabilities | Format-Table Name, State
|
||||||
|
|
||||||
|
# Install OpenSSH Client and Server
|
||||||
|
Write-Host "Installing OpenSSH components..." -ForegroundColor Yellow
|
||||||
|
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
|
||||||
|
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
|
||||||
|
|
||||||
|
# Start and configure OpenSSH Server
|
||||||
|
Write-Host "Configuring OpenSSH Server..." -ForegroundColor Yellow
|
||||||
|
Start-Service sshd
|
||||||
|
Set-Service -Name sshd -StartupType 'Automatic'
|
||||||
|
|
||||||
|
# Configure Windows Firewall for SSH
|
||||||
|
Write-Host "Configuring Windows Firewall for SSH..." -ForegroundColor Yellow
|
||||||
|
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue | Select-Object Name, Enabled)) {
|
||||||
|
Write-Host "Creating firewall rule for SSH..." -ForegroundColor Yellow
|
||||||
|
New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
|
||||||
|
} else {
|
||||||
|
Write-Host "Firewall rule for SSH already exists." -ForegroundColor Green
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Install btop4win (Chocolatey only)
|
||||||
|
# Note: btop4win requires Visual C++ Redistributable 2015-2022 (x86) to be installed first
|
||||||
|
Write-Host "Installing Visual C++ Redistributable 2015-2022 (x86)..." -ForegroundColor Yellow
|
||||||
|
Install-App -AppName "Visual C++ Redistributable 2015-2022 (x86)" -WingetId "Microsoft.VCRedist.2015+.x86" -ChocoId "vcredist140"
|
||||||
|
|
||||||
|
Write-Host "Installing btop4win..." -ForegroundColor Yellow
|
||||||
|
Install-App -AppName "btop4win" -ChocoId "btop4win" -UseChocoOnly
|
||||||
|
|
||||||
|
# Install Microsoft Edit
|
||||||
|
Install-App -AppName "Microsoft Edit" -WingetId "Microsoft.Edit" -ChocoId ""
|
||||||
|
|
||||||
|
### Function to Setup BGInfo ###
|
||||||
|
function Setup-BGInfo {
|
||||||
|
param (
|
||||||
|
[string]$ConfigPath = "$env:USERPROFILE\.bginfo\config.bgi"
|
||||||
|
)
|
||||||
|
|
||||||
|
Write-Host "Setting up BGInfo..." -ForegroundColor Yellow
|
||||||
|
|
||||||
|
# Create BGInfo directory
|
||||||
|
$bginfoPath = "$env:USERPROFILE\.bginfo"
|
||||||
|
if (-not (Test-Path $bginfoPath)) {
|
||||||
|
New-Item -ItemType Directory -Path $bginfoPath -Force | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
# Install BGInfo using winget
|
# Install BGInfo using winget
|
||||||
Write-Host "Installing BGInfo..." -ForegroundColor Green
|
Install-App -AppName "BGInfo" -WingetId "Sysinternals.BGInfo" -ChocoId "bginfo"
|
||||||
winget install -e --id Sysinternals.BGInfo --accept-source-agreements --accept-package-agreements
|
|
||||||
|
|
||||||
# Create .bginfo directory
|
|
||||||
Write-Host "Setting up BGInfo..." -ForegroundColor Green
|
|
||||||
EnsureDirectory $bgInfoPath
|
|
||||||
|
|
||||||
# Copy BGInfo scripts
|
# Copy BGInfo scripts
|
||||||
Write-Host "Copying BGInfo scripts..." -ForegroundColor Yellow
|
Write-Host "Copying BGInfo scripts..." -ForegroundColor Yellow
|
||||||
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
|
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
Copy-Item "$scriptPath\bginfo\*" $bgInfoPath -Force
|
Copy-Item "$scriptPath\bginfo\*" $bginfoPath -Force
|
||||||
|
|
||||||
# Create scheduled task to run BGInfo at logon
|
# Create scheduled task to run BGInfo at logon
|
||||||
$bgInfoExe = "$env:ProgramFiles\sysinternals\bginfo.exe"
|
$bgInfoExe = "$env:ProgramFiles\sysinternals\bginfo.exe"
|
||||||
$action = New-ScheduledTaskAction -Execute $bgInfoExe -Argument "$bgInfoPath\config.bgi /timer:0"
|
$action = New-ScheduledTaskAction -Execute $bgInfoExe -Argument "$ConfigPath /timer:0"
|
||||||
$trigger = New-ScheduledTaskTrigger -AtLogOn
|
$trigger = New-ScheduledTaskTrigger -AtLogOn
|
||||||
$principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest
|
$principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest
|
||||||
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
|
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
|
||||||
|
|
@ -127,6 +270,15 @@ $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoi
|
||||||
Write-Host "Creating BGInfo startup task..." -ForegroundColor Yellow
|
Write-Host "Creating BGInfo startup task..." -ForegroundColor Yellow
|
||||||
Register-ScheduledTask -TaskName "BGInfo" -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force
|
Register-ScheduledTask -TaskName "BGInfo" -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force
|
||||||
|
|
||||||
|
# Run BGInfo immediately
|
||||||
|
Write-Host "Running BGInfo..." -ForegroundColor Yellow
|
||||||
|
Start-Process $bgInfoExe -ArgumentList "$ConfigPath /timer:0" -NoNewWindow -Wait
|
||||||
|
}
|
||||||
|
|
||||||
|
### BGInfo Setup ###
|
||||||
|
Write-Host "Setting up BGInfo..." -ForegroundColor Green
|
||||||
|
Setup-BGInfo
|
||||||
|
|
||||||
### Auto-Login Setup ###
|
### Auto-Login Setup ###
|
||||||
Write-Host "Configuring Auto-Login..." -ForegroundColor Green
|
Write-Host "Configuring Auto-Login..." -ForegroundColor Green
|
||||||
|
|
||||||
|
|
|
||||||
121
run_file_remote.ps1
Normal file
121
run_file_remote.ps1
Normal file
|
|
@ -0,0 +1,121 @@
|
||||||
|
# Connect to remote PC and list files
|
||||||
|
$remoteHost = "192.168.1.191"
|
||||||
|
$remoteUser = "rob"
|
||||||
|
$remoteDir = "C:\Users\rob\Documents\Projects\Leanback_11"
|
||||||
|
$remoteTestDir = "C:\Users\rob\Documents\Projects\Leanback_11\test"
|
||||||
|
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
|
|
||||||
|
# Check if OpenSSH is installed locally
|
||||||
|
Write-Host "Checking OpenSSH installation..." -ForegroundColor Yellow
|
||||||
|
if (-not (Get-WindowsCapability -Online -Name 'OpenSSH.Client~~~~0.0.1.0').State -eq 'Installed') {
|
||||||
|
Write-Host "Installing OpenSSH Client..." -ForegroundColor Yellow
|
||||||
|
Add-WindowsCapability -Online -Name 'OpenSSH.Client~~~~0.0.1.0'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test SSH connection first
|
||||||
|
Write-Host "Testing SSH connection..." -ForegroundColor Yellow
|
||||||
|
try {
|
||||||
|
$testConnection = ssh -o BatchMode=no -o ConnectTimeout=5 "$remoteUser@$remoteHost" "powershell -ExecutionPolicy Bypass -Command `"echo 'Connection successful'`""
|
||||||
|
if ($testConnection -eq 'Connection successful') {
|
||||||
|
Write-Host "SSH connection test successful" -ForegroundColor Green
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
Write-Host "SSH connection test failed. Please check:" -ForegroundColor Red
|
||||||
|
Write-Host "1. OpenSSH Server is installed on the remote machine" -ForegroundColor Red
|
||||||
|
Write-Host "2. SSH service is running on the remote machine" -ForegroundColor Red
|
||||||
|
Write-Host "3. Firewall allows SSH connections (port 22)" -ForegroundColor Red
|
||||||
|
Write-Host "4. Your credentials are correct" -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# First, check if the directories exist and create them if they don't
|
||||||
|
Write-Host "Checking remote directories..." -ForegroundColor Yellow
|
||||||
|
$checkDirCommand = "powershell -ExecutionPolicy Bypass -Command `"if (-not (Test-Path '$remoteDir')) { New-Item -ItemType Directory -Path '$remoteDir' -Force }; if (-not (Test-Path '$remoteTestDir')) { New-Item -ItemType Directory -Path '$remoteTestDir' -Force }`""
|
||||||
|
ssh "$remoteUser@$remoteHost" $checkDirCommand
|
||||||
|
|
||||||
|
# Copy bginfo.ps1 to remote test directory
|
||||||
|
Write-Host "Copying bginfo.ps1 to remote test directory..." -ForegroundColor Yellow
|
||||||
|
$bginfoPath = Join-Path $scriptPath "test\bginfo.ps1"
|
||||||
|
if (Test-Path $bginfoPath) {
|
||||||
|
$bginfoContent = Get-Content -Path $bginfoPath -Raw
|
||||||
|
$bginfoContent = $bginfoContent -replace '"', '\"'
|
||||||
|
$copyCommand = "powershell -ExecutionPolicy Bypass -Command `"Set-Content -Path '$remoteTestDir\bginfo.ps1' -Value '$bginfoContent'`""
|
||||||
|
ssh "$remoteUser@$remoteHost" $copyCommand
|
||||||
|
} else {
|
||||||
|
Write-Host "Warning: Could not find bginfo.ps1 at $bginfoPath" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
|
||||||
|
# List files in the remote test directory
|
||||||
|
Write-Host "`nAvailable scripts in ${remoteTestDir}:" -ForegroundColor Green
|
||||||
|
try {
|
||||||
|
$command = "powershell -ExecutionPolicy Bypass -Command `"Get-ChildItem -Path '$remoteTestDir' -Filter '*.ps1' | Select-Object Name, LastWriteTime | Format-Table -AutoSize`""
|
||||||
|
$files = ssh "$remoteUser@$remoteHost" $command
|
||||||
|
Write-Host $files
|
||||||
|
} catch {
|
||||||
|
Write-Host "Failed to list files. Error: $_" -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get user selection
|
||||||
|
$selection = Read-Host "`nEnter the number of the script you want to run (or 'q' to quit)"
|
||||||
|
|
||||||
|
if ($selection -eq 'q') {
|
||||||
|
Write-Host "Exiting..." -ForegroundColor Yellow
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get the selected file
|
||||||
|
try {
|
||||||
|
$command = "powershell -ExecutionPolicy Bypass -Command `"`$files = Get-ChildItem -Path '$remoteTestDir' -Filter '*.ps1'; `$files[$selection - 1].FullName`""
|
||||||
|
$selectedFile = ssh "$remoteUser@$remoteHost" $command
|
||||||
|
} catch {
|
||||||
|
Write-Host "Failed to get selected file. Error: $_" -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($selectedFile) {
|
||||||
|
$scriptName = Split-Path $selectedFile -Leaf
|
||||||
|
$date = Get-Date -Format "yyyy-MM-dd"
|
||||||
|
$logFileName = "$date-$scriptName.log"
|
||||||
|
$logPath = Join-Path $remoteTestDir $logFileName
|
||||||
|
|
||||||
|
Write-Host "`nRunning ${selectedFile}..." -ForegroundColor Green
|
||||||
|
Write-Host "Logging to ${logPath}" -ForegroundColor Yellow
|
||||||
|
|
||||||
|
# Run the script and capture output
|
||||||
|
try {
|
||||||
|
$command = @"
|
||||||
|
powershell -ExecutionPolicy Bypass -Command "
|
||||||
|
Start-Transcript -Path '$logPath' -Force
|
||||||
|
try {
|
||||||
|
`$process = Start-Process powershell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File \"$selectedFile\"' -Verb RunAs -PassThru -Wait
|
||||||
|
Write-Output \"`nProcess Exit Code: `$(`$process.ExitCode)\"
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Output \"Error running script: `$_\"
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
Stop-Transcript
|
||||||
|
}
|
||||||
|
"
|
||||||
|
"@
|
||||||
|
ssh "$remoteUser@$remoteHost" $command
|
||||||
|
} catch {
|
||||||
|
Write-Host "Failed to run script. Error: $_" -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Display the log contents
|
||||||
|
Write-Host "`nLog contents:" -ForegroundColor Green
|
||||||
|
try {
|
||||||
|
$command = "powershell -ExecutionPolicy Bypass -Command `"Get-Content '$logPath'`""
|
||||||
|
$logContents = ssh "$remoteUser@$remoteHost" $command
|
||||||
|
Write-Host $logContents
|
||||||
|
} catch {
|
||||||
|
Write-Host "Failed to read log file. Error: $_" -ForegroundColor Red
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "`nLog file saved to: ${logPath}" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host "Invalid selection" -ForegroundColor Red
|
||||||
|
}
|
||||||
71
test/bginfo.ps1
Normal file
71
test/bginfo.ps1
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
#This script is used to install and configure bginfo for the current user.
|
||||||
|
|
||||||
|
#Requires -RunAsAdministrator
|
||||||
|
|
||||||
|
### Function to Install Apps ###
|
||||||
|
function Install-App {
|
||||||
|
param (
|
||||||
|
[string]$AppName,
|
||||||
|
[string]$WingetId,
|
||||||
|
[string]$ChocoId,
|
||||||
|
[switch]$UseChocoOnly
|
||||||
|
)
|
||||||
|
|
||||||
|
Write-Host "Installing $AppName..." -ForegroundColor Yellow
|
||||||
|
|
||||||
|
if ($UseChocoOnly) {
|
||||||
|
Write-Host "Using Chocolatey for $AppName..." -ForegroundColor Yellow
|
||||||
|
choco install $ChocoId -y
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Write-Host "Attempting to install $AppName via Winget..." -ForegroundColor Yellow
|
||||||
|
winget install -e --id $WingetId --accept-source-agreements --accept-package-agreements
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "Winget installation failed, falling back to Chocolatey..." -ForegroundColor Yellow
|
||||||
|
choco install $ChocoId -y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
### Function to Setup BGInfo ###
|
||||||
|
function Setup-BGInfo {
|
||||||
|
param (
|
||||||
|
[string]$ConfigPath = "$env:USERPROFILE\.bginfo\config.bgi"
|
||||||
|
)
|
||||||
|
|
||||||
|
Write-Host "Setting up BGInfo..." -ForegroundColor Yellow
|
||||||
|
|
||||||
|
# Create BGInfo directory
|
||||||
|
$bginfoPath = "$env:USERPROFILE\.bginfo"
|
||||||
|
if (-not (Test-Path $bginfoPath)) {
|
||||||
|
New-Item -ItemType Directory -Path $bginfoPath -Force | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
# Install BGInfo using winget
|
||||||
|
Install-App -AppName "BGInfo" -WingetId "Sysinternals.BGInfo" -ChocoId "bginfo"
|
||||||
|
|
||||||
|
# Copy BGInfo scripts
|
||||||
|
Write-Host "Copying BGInfo scripts..." -ForegroundColor Yellow
|
||||||
|
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
|
Copy-Item "$scriptPath\bginfo\*" $bginfoPath -Force
|
||||||
|
|
||||||
|
# Create scheduled task to run BGInfo at logon
|
||||||
|
$bgInfoExe = "$env:ProgramFiles\sysinternals\bginfo.exe"
|
||||||
|
$action = New-ScheduledTaskAction -Execute $bgInfoExe -Argument "$ConfigPath /timer:0"
|
||||||
|
$trigger = New-ScheduledTaskTrigger -AtLogOn
|
||||||
|
$principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest
|
||||||
|
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
|
||||||
|
|
||||||
|
Write-Host "Creating BGInfo startup task..." -ForegroundColor Yellow
|
||||||
|
Register-ScheduledTask -TaskName "BGInfo" -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force
|
||||||
|
|
||||||
|
# Run BGInfo immediately
|
||||||
|
Write-Host "Running BGInfo..." -ForegroundColor Yellow
|
||||||
|
Start-Process $bgInfoExe -ArgumentList "$ConfigPath /timer:0" -NoNewWindow -Wait
|
||||||
|
}
|
||||||
|
|
||||||
|
### Main Execution ###
|
||||||
|
Write-Host "Setting up BGInfo..." -ForegroundColor Green
|
||||||
|
Setup-BGInfo
|
||||||
Loading…
Add table
Add a link
Reference in a new issue