init windowshost
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
$scriptFolder = "\\host.lan\Data"
|
||||
$pythonScriptFile = "$scriptFolder\server\main.py"
|
||||
$pythonServerPort = 5000
|
||||
|
||||
# Start the flask computer use server
|
||||
Write-Host "Running the server on port $pythonServerPort"
|
||||
python $pythonScriptFile --port $pythonServerPort
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
@@ -0,0 +1,81 @@
|
||||
import os
|
||||
import logging
|
||||
import argparse
|
||||
import shlex
|
||||
import subprocess
|
||||
from flask import Flask, request, jsonify, send_file
|
||||
import threading
|
||||
import traceback
|
||||
import pyautogui
|
||||
from PIL import Image
|
||||
from io import BytesIO
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--log_file", help="log file path", type=str,
|
||||
default=os.path.join(os.path.dirname(__file__), "server.log"))
|
||||
parser.add_argument("--port", help="port", type=int, default=5000)
|
||||
args = parser.parse_args()
|
||||
|
||||
logging.basicConfig(filename=args.log_file,level=logging.DEBUG, filemode='w' )
|
||||
logger = logging.getLogger('werkzeug')
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
computer_control_lock = threading.Lock()
|
||||
|
||||
@app.route('/probe', methods=['GET'])
|
||||
def probe_endpoint():
|
||||
return jsonify({"status": "Probe successful", "message": "Service is operational"}), 200
|
||||
|
||||
@app.route('/execute', methods=['POST'])
|
||||
def execute_command():
|
||||
# Only execute one command at a time
|
||||
with computer_control_lock:
|
||||
data = request.json
|
||||
# The 'command' key in the JSON request should contain the command to be executed.
|
||||
shell = data.get('shell', False)
|
||||
command = data.get('command', "" if shell else [])
|
||||
|
||||
if isinstance(command, str) and not shell:
|
||||
command = shlex.split(command)
|
||||
|
||||
# Expand user directory
|
||||
for i, arg in enumerate(command):
|
||||
if arg.startswith("~/"):
|
||||
command[i] = os.path.expanduser(arg)
|
||||
|
||||
# Execute the command without any safety checks.
|
||||
try:
|
||||
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=shell, text=True, timeout=120)
|
||||
return jsonify({
|
||||
'status': 'success',
|
||||
'output': result.stdout,
|
||||
'error': result.stderr,
|
||||
'returncode': result.returncode
|
||||
})
|
||||
except Exception as e:
|
||||
logger.error("\n" + traceback.format_exc() + "\n")
|
||||
return jsonify({
|
||||
'status': 'error',
|
||||
'message': str(e)
|
||||
}), 500
|
||||
|
||||
@app.route('/screenshot', methods=['GET'])
|
||||
def capture_screen_with_cursor():
|
||||
cursor_path = os.path.join(os.path.dirname(__file__), "cursor.png")
|
||||
screenshot = pyautogui.screenshot()
|
||||
cursor_x, cursor_y = pyautogui.position()
|
||||
cursor = Image.open(cursor_path)
|
||||
# make the cursor smaller
|
||||
cursor = cursor.resize((int(cursor.width / 1.5), int(cursor.height / 1.5)))
|
||||
screenshot.paste(cursor, (cursor_x, cursor_y), cursor)
|
||||
|
||||
|
||||
# Convert PIL Image to bytes and send
|
||||
img_io = BytesIO()
|
||||
screenshot.save(img_io, 'PNG')
|
||||
img_io.seek(0)
|
||||
return send_file(img_io, mimetype='image/png')
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host="0.0.0.0", port=args.port)
|
||||
@@ -0,0 +1,2 @@
|
||||
flask
|
||||
PyAutoGUI
|
||||
@@ -0,0 +1,197 @@
|
||||
function Get-Tools {
|
||||
param(
|
||||
[string]$toolsConfigJson
|
||||
)
|
||||
|
||||
# Convert the JSON string to a PowerShell object
|
||||
$toolsList = $toolsConfigJson | ConvertFrom-Json
|
||||
|
||||
return $toolsList
|
||||
}
|
||||
|
||||
function Get-ToolDetails {
|
||||
param(
|
||||
$toolsList,
|
||||
[string]$toolName
|
||||
)
|
||||
|
||||
# Check if the program exists in the JSON data
|
||||
if ($toolsList.PSObject.Properties.Name -contains $toolName) {
|
||||
# Return the program details as a PowerShell object
|
||||
return $toolsList.$toolName
|
||||
} else {
|
||||
# Handle the case where the program is not found
|
||||
Write-Host "Program '$toolName' not found in the list."
|
||||
return $null
|
||||
}
|
||||
}
|
||||
|
||||
function Invoke-DownloadFileFromAvailableMirrors {
|
||||
param (
|
||||
[string[]]$mirrorUrls,
|
||||
[string]$outfile
|
||||
)
|
||||
foreach ($url in $mirrorUrls) {
|
||||
try {
|
||||
$result = Invoke-DownloadFile -url $url -outfile $outfile
|
||||
if ($result -eq $true) {
|
||||
Write-Host "Downloaded using $url"
|
||||
return $true
|
||||
}
|
||||
} catch {
|
||||
Write-Host "Error downloading from $url. Please check and update the mirrors."
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Downloading from the provided mirrors failed. Please check and update the mirrors."
|
||||
return $false
|
||||
}
|
||||
|
||||
function Invoke-DownloadFile {
|
||||
param (
|
||||
[string]$url,
|
||||
[string]$outfile
|
||||
)
|
||||
# Makes download faster by disabling progress bar
|
||||
$ProgressPreference = "SilentlyContinue"
|
||||
|
||||
$retryCount = 0
|
||||
$maxRetries = 3
|
||||
$sleepSeconds = 2
|
||||
$maxSleepSeconds = 10
|
||||
$userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
|
||||
|
||||
# Ensure directory exists
|
||||
$directory = Split-Path -Path $outfile -Parent
|
||||
if (-Not (Test-Path -Path $directory)) {
|
||||
Write-Host "Creating directory $directory..."
|
||||
New-Item -Path $directory -ItemType Directory -Force | Out-Null
|
||||
}
|
||||
|
||||
while ($retryCount -lt $maxRetries) {
|
||||
try {
|
||||
Invoke-RestMethod -Uri $url -OutFile $outfile -Headers @{"User-Agent" = $userAgent}
|
||||
Write-Host "Download successful, file saved to: $outfile"
|
||||
break
|
||||
} catch {
|
||||
$retryCount++
|
||||
Write-Host "Attempt $retryCount of $maxRetries failed. Error: $($_.Exception.Message)"
|
||||
Start-Sleep -Seconds $sleepSeconds
|
||||
$sleepSeconds = [Math]::Min($sleepSeconds * 2, $maxSleepSeconds) # Exponential backoff with a cap
|
||||
}
|
||||
}
|
||||
|
||||
if ($retryCount -eq $maxRetries) {
|
||||
Write-Host "Failed to download the file after $maxRetries attempts."
|
||||
return $false
|
||||
}
|
||||
|
||||
return $true
|
||||
}
|
||||
|
||||
function Add-ToEnvPath {
|
||||
param (
|
||||
[string]$NewPath
|
||||
)
|
||||
|
||||
# Get the current PATH environment variable
|
||||
$envPath = [Environment]::GetEnvironmentVariable("PATH", "Machine")
|
||||
|
||||
# Append the new path to the existing PATH
|
||||
$newPath = "$envPath;$NewPath"
|
||||
|
||||
# Set the updated PATH environment variable
|
||||
[Environment]::SetEnvironmentVariable("PATH", $newPath, "Machine")
|
||||
|
||||
# Fetch updates from the shell
|
||||
$env:PATH += ";${newPath}"
|
||||
}
|
||||
|
||||
function Register-LogonTask {
|
||||
param(
|
||||
|
||||
[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Name of the scheduled task")]
|
||||
[string]
|
||||
$TaskName,
|
||||
|
||||
[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Path to the .py script")]
|
||||
[string]
|
||||
$ScriptPath,
|
||||
|
||||
[parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Arguments to the .py script")]
|
||||
[string]
|
||||
$Arguments = "",
|
||||
|
||||
[parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Local Account username")]
|
||||
[string]
|
||||
$LocalUser,
|
||||
|
||||
[parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Local Account password")]
|
||||
[string]
|
||||
$LocalPassword,
|
||||
|
||||
[parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Whether to execute the command as SYSTEM")]
|
||||
[switch]
|
||||
$AsSystem = $false,
|
||||
|
||||
[parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "logging file")]
|
||||
[string]
|
||||
$LogFilePath
|
||||
)
|
||||
|
||||
$scriptDirectory = Split-Path $ScriptPath
|
||||
|
||||
$taskActionArgument = "-ExecutionPolicy Bypass -windowstyle hidden -Command `"try { . '$ScriptPath' $Arguments } catch { Write `$_.Exception.Message | Out-File $($TaskName)_Log.txt } finally { } `""
|
||||
$taskAction = New-ScheduledTaskAction -Execute "$PSHome\powershell.exe" -Argument $taskActionArgument -WorkingDirectory $scriptDirectory
|
||||
|
||||
$params = @{
|
||||
Force = $True
|
||||
Action = $taskAction
|
||||
RunLevel = "Highest"
|
||||
TaskName = $TaskName
|
||||
}
|
||||
|
||||
$taskTrigger = New-ScheduledTaskTrigger -AtLogOn
|
||||
$params.Add("Trigger", $taskTrigger)
|
||||
|
||||
if ($AsSystem) {
|
||||
$params.Add("User", "NT AUTHORITY\SYSTEM")
|
||||
}
|
||||
else {
|
||||
$params.Add("User", $LocalUser)
|
||||
if ($LocalPassword) {
|
||||
$params.Add("Password", $LocalPassword)
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Registering scheduled task '$TaskName' to run 'powershell.exe $taskActionArgument'..."
|
||||
Register-ScheduledTask @params
|
||||
}
|
||||
|
||||
# Function to attempt pip install and handle failures
|
||||
function Install-PythonPackages {
|
||||
param (
|
||||
[string]$Package = "",
|
||||
[string]$Arguments = "",
|
||||
[string]$RequirementsPath = ""
|
||||
)
|
||||
$RetryCount = 3
|
||||
$currentAttempt = 0
|
||||
while ($currentAttempt -lt $RetryCount) {
|
||||
if (-not [string]::IsNullOrWhiteSpace($RequirementsPath)) {
|
||||
& python -m pip install --no-cache-dir -r $RequirementsPath $Arguments
|
||||
} else {
|
||||
& python -m pip install --no-cache-dir $Package $Arguments
|
||||
}
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host "Installation successful."
|
||||
return
|
||||
} else {
|
||||
Write-Host "Attempt $($currentAttempt + 1) failed. Retrying..."
|
||||
Start-Sleep -Seconds 10
|
||||
$currentAttempt++
|
||||
}
|
||||
}
|
||||
Write-Error "Failed to install after $RetryCount attempts."
|
||||
exit
|
||||
}
|
||||
@@ -0,0 +1,392 @@
|
||||
$ErrorActionPreference = "Continue" # until downloading from mirrors is more stable
|
||||
|
||||
# Section - General Setup
|
||||
$scriptFolder = "\\host.lan\Data"
|
||||
$toolsFolder = "C:\Users\$env:USERNAME\Tools"
|
||||
|
||||
# Load the shared setup-tools module
|
||||
Import-Module (Join-Path $scriptFolder -ChildPath "setup-tools.psm1")
|
||||
|
||||
# Check if profile exists
|
||||
if (-not (Test-Path $PROFILE)) {
|
||||
New-Item -ItemType File -Path $PROFILE -Force
|
||||
}
|
||||
|
||||
# Create a folder where we store all the standalone executables
|
||||
if (-not (Test-Path $toolsFolder)) {
|
||||
New-Item -ItemType Directory -Path $toolsFolder -Force
|
||||
$envPath = [Environment]::GetEnvironmentVariable("PATH", "Machine")
|
||||
$newPath = "$envPath;$toolsFolder"
|
||||
[Environment]::SetEnvironmentVariable("PATH", $newPath, "Machine")
|
||||
}
|
||||
|
||||
# Section - Tools Installation
|
||||
|
||||
# Set TLS version to 1.2 or higher
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13
|
||||
|
||||
# Load the tools config json listing mirrors and aliases used for installing tools
|
||||
$toolsConfigJsonPath = Join-Path $scriptFolder -ChildPath "tools_config.json"
|
||||
$toolsConfigJson = Get-Content -Path $toolsConfigJsonPath -Raw
|
||||
$toolsList = Get-Tools -toolsConfigJson $toolsConfigJson
|
||||
|
||||
## - Python
|
||||
$pythonToolName = "Python"
|
||||
$userPythonPath = "$env:LOCALAPPDATA\Programs\Python"
|
||||
$pythonDetails = Get-ToolDetails -toolsList $toolsList -toolName $pythonToolName
|
||||
$pythonAlias = $pythonDetails.alias
|
||||
|
||||
# Check for Python installation
|
||||
$pythonExecutablePath = Get-ChildItem -Path $userPythonPath -Filter python.exe -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
|
||||
|
||||
# Force to install Python 3.10 as the pre-installed version on Windows may not work sometimes
|
||||
Write-Host "Downloading Python $pythonVersion..."
|
||||
$pythonInstallerFilePath = "$env:TEMP\python_installer.exe"
|
||||
$downloadResult = Invoke-DownloadFileFromAvailableMirrors -mirrorUrls $pythonDetails.mirrors -outfile $pythonInstallerFilePath
|
||||
if (-not $downloadResult) {
|
||||
Write-Host "Failed to download Python. Please try again later or install manually."
|
||||
} else {
|
||||
Write-Host "Installing Python for current user..."
|
||||
Start-Process -FilePath $pythonInstallerFilePath -Args "/quiet InstallAllUsers=0 PrependPath=0" -NoNewWindow -Wait
|
||||
$pythonExecutablePath = "$userPythonPath\Python310\python.exe"
|
||||
$setAliasExpression = "Set-Alias -Name $pythonAlias -Value `"$pythonExecutablePath`""
|
||||
Add-Content -Path $PROFILE -Value $setAliasExpression
|
||||
Invoke-Expression $setAliasExpression
|
||||
}
|
||||
|
||||
## - Git
|
||||
$gitToolName = "git"
|
||||
$gitToolDetails = Get-ToolDetails -toolsList $toolsList -toolName $gitToolName
|
||||
|
||||
# Check for Git installation
|
||||
try {
|
||||
git --version | Out-Null
|
||||
Write-Host "Git is already installed."
|
||||
} catch {
|
||||
Write-Host "Git is not installed. Downloading and installing Git..."
|
||||
$gitInstallerFilePath = "$env:TEMP\git_installer.exe"
|
||||
$downloadResult = Invoke-DownloadFileFromAvailableMirrors -mirrorUrls $gitToolDetails.mirrors -outfile $gitInstallerFilePath
|
||||
if (-not $downloadResult) {
|
||||
Write-Host "Failed to download Git. Please try again later or install manually."
|
||||
} else {
|
||||
Start-Process -FilePath $gitInstallerFilePath -Args "/VERYSILENT /NORESTART /NOCANCEL /SP-" -Wait
|
||||
Add-ToEnvPath -NewPath "C:\Program Files\Git\bin"
|
||||
|
||||
Write-Host "Git has been installed."
|
||||
}
|
||||
}
|
||||
|
||||
# - 7zip
|
||||
$7ZipToolName = "7zip"
|
||||
$7ZipToolDetails = Get-ToolDetails -toolsList $toolsList -toolName $7ZipToolName
|
||||
Write-Host "$7ZipToolDetails"
|
||||
|
||||
if (Get-Command 7z -ErrorAction SilentlyContinue) {
|
||||
Write-Host "7-Zip is already installed."
|
||||
}
|
||||
else {
|
||||
Write-Host "Installing 7-Zip..."
|
||||
|
||||
$7ZipInstallerFilePath = "$env:TEMP\7_zip.exe"
|
||||
Write-Host "$($7ZipToolDetails.mirrors)"
|
||||
$downloadResult = Invoke-DownloadFileFromAvailableMirrors -mirrorUrls $7ZipToolDetails.mirrors -outfile $7ZipInstallerFilePath
|
||||
if (-not $downloadResult) {
|
||||
Write-Host "Failed to download 7-Zip. Please try again later or install manually."
|
||||
} else {
|
||||
Start-Process -FilePath $7ZipInstallerFilePath -Args "/S" -Verb RunAs -Wait
|
||||
Remove-Item $7ZipInstallerFilePath
|
||||
|
||||
# add 7z to PATH
|
||||
Add-ToEnvPath -NewPath "${env:ProgramFiles}\7-Zip"
|
||||
}
|
||||
}
|
||||
|
||||
# - ffpmeg
|
||||
$ffpmegToolName = "ffmpeg"
|
||||
$ffpmegToolDetails = Get-ToolDetails -toolsList $toolsList -toolName $ffpmegToolName
|
||||
|
||||
if (Get-Command ffmpeg -ErrorAction SilentlyContinue) {
|
||||
Write-Host "ffmpeg is already installed."
|
||||
} else {
|
||||
Write-Host "ffmpeg is not installed. Installing it."
|
||||
$ffpmegInstallerFilePath = "C:\ffmpeg.7z"
|
||||
$downloadResult = Invoke-DownloadFileFromAvailableMirrors -mirrorUrls $ffpmegToolDetails.mirrors -outfile $ffpmegInstallerFilePath
|
||||
if (-not $downloadResult) {
|
||||
Write-Host "Failed to download ffmpeg. Please try again later or install manually."
|
||||
} else {
|
||||
Write-Host "Extracting $ffpmegInstallerFilePath..."
|
||||
7z x -y -o"C:\" "C:\ffmpeg.7z"
|
||||
|
||||
$ffmpegFolder = Get-ChildItem -Path "C:\" -Filter "ffmpeg-*" -Directory
|
||||
$ffmpegFolder = -join ("C:\", $ffmpegFolder)
|
||||
#remove ffmpeg folder if exists
|
||||
if (Test-Path "C:\ffmpeg") {
|
||||
Remove-Item -Path "C:\ffmpeg" -Recurse -Force
|
||||
}
|
||||
Rename-Item -Path "$ffmpegFolder" -NewName "ffmpeg"
|
||||
|
||||
Write-Host "Adding ffmpeg to PATH..."
|
||||
Add-ToEnvPath -NewPath "C:\ffmpeg\bin"
|
||||
|
||||
Write-Host "ffmpeg is installed"
|
||||
}
|
||||
}
|
||||
|
||||
# Disable Edge Auto Updates
|
||||
Stop-Process -Name "MicrosoftEdgeUpdate" -Force -ErrorAction SilentlyContinue
|
||||
$edgeUpdatePath = "${env:ProgramFiles(x86)}\Microsoft\EdgeUpdate"
|
||||
Remove-Item -Path $edgeUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
|
||||
Write-Host "Edge Update processes terminated and directory removed."
|
||||
|
||||
# - Google Chrome
|
||||
$chromeToolName = "Google Chrome"
|
||||
$chromeToolDetails = Get-ToolDetails -toolsList $toolsList -toolName $chromeToolName
|
||||
$chromeExePath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
|
||||
$chromeAlias = $chromeToolDetails.alias
|
||||
|
||||
# Check if Google Chrome is already installed by its alias
|
||||
if (Get-Command $chromeAlias -ErrorAction SilentlyContinue) {
|
||||
Write-Host "Google Chrome is already installed."
|
||||
} else {
|
||||
# Download the installer to the Temp directory
|
||||
$chromeInstallerFilePath = "$env:TEMP\chrome_installer.exe"
|
||||
$downloadResult = Invoke-DownloadFileFromAvailableMirrors -mirrorUrls $chromeToolDetails.mirrors -outfile $chromeInstallerFilePath
|
||||
if (-not $downloadResult) {
|
||||
Write-Host "Failed to download Google Chrome. Please try again later or install manually."
|
||||
} else {
|
||||
# Execute the installer silently with elevated permissions
|
||||
Start-Process -FilePath $chromeInstallerFilePath -ArgumentList "/silent", "/install" -Verb RunAs -Wait
|
||||
|
||||
# Remove the installer file after installation
|
||||
Remove-Item -Path $chromeInstallerFilePath
|
||||
|
||||
# Set alias
|
||||
$setAliasExpression = "Set-Alias -Name $chromeAlias -Value `"$chromeExePath`""
|
||||
Add-Content -Path $PROFILE -Value $setAliasExpression
|
||||
Invoke-Expression $setAliasExpression
|
||||
|
||||
# Add Chrome to the system PATH environment variable
|
||||
Add-ToEnvPath -NewPath "${env:ProgramFiles}\Google\Chrome\Application"
|
||||
|
||||
# Disable Google Chrome Auto Updates
|
||||
$chromeRegPath = "HKLM:\SOFTWARE\Policies\Google\Update"
|
||||
if (-not (Test-Path $chromeRegPath)) {
|
||||
New-Item -Path $chromeRegPath -Force
|
||||
}
|
||||
Set-ItemProperty -Path $chromeRegPath -Name "AutoUpdateCheckPeriodMinutes" -Value 0
|
||||
Set-ItemProperty -Path $chromeRegPath -Name "UpdateDefault" -Value 0
|
||||
}
|
||||
}
|
||||
|
||||
# - LibreOffice
|
||||
$libreOfficeToolName = "LibreOffice"
|
||||
$libreOfficeToolDetails = Get-ToolDetails -toolsList $toolsList -toolName $libreOfficeToolName
|
||||
|
||||
# Check for LibreOffice installation
|
||||
$installedVersion = (Get-WmiObject -Query "SELECT * FROM Win32_Product WHERE Name like 'LibreOffice%'").Version
|
||||
if (-not [string]::IsNullOrWhiteSpace($installedVersion)) {
|
||||
Write-Host "LibreOffice $version is already installed."
|
||||
} else {
|
||||
Write-Host "LibreOffice is not installed. Downloading and installing LibreOffice..."
|
||||
$libreOfficeInstallerFilePath = "$env:TEMP\libreOffice_installer.exe"
|
||||
|
||||
$downloadResult = Invoke-DownloadFileFromAvailableMirrors -mirrorUrls $libreOfficeToolDetails.mirrors -outfile $libreOfficeInstallerFilePath
|
||||
if (-not $downloadResult) {
|
||||
Write-Host "Failed to download LibreOffice. Please try again later or install manually."
|
||||
} else {
|
||||
Start-Process "msiexec.exe" -ArgumentList "/i `"$libreOfficeInstallerFilePath`" /quiet" -Wait -NoNewWindow
|
||||
Write-Host "LibreOffice has been installed."
|
||||
|
||||
# Add LibreOffice to the system PATH environment variable
|
||||
Add-ToEnvPath -NewPath "C:\Program Files\LibreOffice\program"
|
||||
}
|
||||
}
|
||||
|
||||
# - VLC
|
||||
$vlcToolName = "VLC"
|
||||
$vlcToolDetails = Get-ToolDetails -toolsList $toolsList -toolName $vlcToolName
|
||||
$vlcAlias = $vlcToolDetails.alias
|
||||
$vlcExecutableFilePath = "C:\Program Files\VideoLAN\VLC\vlc.exe"
|
||||
|
||||
# Check if VLC is already installed by checking the VLC command
|
||||
if (Test-Path $vlcExecutableFilePath) {
|
||||
Write-Host "VLC is already installed."
|
||||
} else {
|
||||
# Download the installer to the Temp directory
|
||||
$vlcInstallerFilePath = "$env:TEMP\vlc_installer.exe"
|
||||
$downloadResult = Invoke-DownloadFileFromAvailableMirrors -mirrorUrls $vlcToolDetails.mirrors -outfile $vlcInstallerFilePath
|
||||
if (-not $downloadResult) {
|
||||
Write-Host "Failed to download VLC. Please try again later or install manually."
|
||||
} else {
|
||||
# Execute the installer silently with elevated permissions
|
||||
Start-Process -FilePath $vlcInstallerFilePath -ArgumentList "/S" -Verb RunAs -Wait
|
||||
|
||||
# Remove the installer file after installation
|
||||
Remove-Item -Path $vlcInstallerFilePath
|
||||
|
||||
# Set alias
|
||||
$setAliasExpression = "Set-Alias -Name $vlcAlias -Value `"$vlcExecutableFilePath`""
|
||||
Add-Content -Path $PROFILE -Value $setAliasExpression
|
||||
Invoke-Expression $setAliasExpression
|
||||
|
||||
# Add VLC to the system PATH environment variable
|
||||
Add-ToEnvPath -NewPath "C:\Program Files\VideoLAN\VLC"
|
||||
}
|
||||
}
|
||||
|
||||
# - GIMP
|
||||
$gimpToolName = "GIMP"
|
||||
$gimpToolDetails = Get-ToolDetails -toolsList $toolsList -toolName $gimpToolName
|
||||
$gimpAlias = $gimpToolDetails.alias
|
||||
$gimpExecutablePath = "C:\Program Files\GIMP 2\bin\gimp-2.10.exe"
|
||||
|
||||
# Check if GIMP is already installed by checking the GIMP executable path
|
||||
if (Test-Path $gimpExecutablePath) {
|
||||
Write-Host "GIMP is already installed."
|
||||
} else {
|
||||
# Download the installer to the Temp directory
|
||||
$gimpInstallerFilePath = "$env:TEMP\gimp_installer.exe"
|
||||
$downloadResult = Invoke-DownloadFileFromAvailableMirrors -mirrorUrls $gimpToolDetails.mirrors -outfile $gimpInstallerFilePath
|
||||
if (-not $downloadResult) {
|
||||
Write-Host "Failed to download GIMP. Please try again later or install manually."
|
||||
} else {
|
||||
# Execute the installer silently with elevated permissions
|
||||
Start-Process -FilePath $gimpInstallerFilePath -ArgumentList "/VERYSILENT /ALLUSERS" -Verb RunAs -Wait
|
||||
|
||||
# Remove the installer file after installation
|
||||
Remove-Item -Path $gimpInstallerFilePath
|
||||
|
||||
# Set alias
|
||||
$setAliasExpression = "Set-Alias -Name $gimpAlias -Value `"$gimpExecutablePath`""
|
||||
Add-Content -Path $PROFILE -Value $setAliasExpression
|
||||
Invoke-Expression $setAliasExpression
|
||||
|
||||
# Add GIMP to the system PATH environment variable
|
||||
Add-ToEnvPath -NewPath "C:\Program Files\GIMP 2\bin"
|
||||
}
|
||||
}
|
||||
|
||||
# - VS Code
|
||||
$vsCodeToolName = "VS Code"
|
||||
$vsCodeToolDetails = Get-ToolDetails -toolsList $toolsList -toolName $vsCodeToolName
|
||||
$vsCodeAlias = $gimpToolDetails.alias
|
||||
$vsCodeExecutablePath = "C:\Users\$env:USERNAME\AppData\Local\Programs\Microsoft VS Code\Code.exe"
|
||||
|
||||
# Check if VS Code is already installed by checking the VS Code executable path
|
||||
if (Test-Path $vsCodeExecutablePath) {
|
||||
Write-Host "VS Code is already installed."
|
||||
} else {
|
||||
# Download the installer to the Temp directory
|
||||
$vsCodeInstallerFilePath = "$env:TEMP\VSCodeSetup.exe"
|
||||
$downloadResult = Invoke-DownloadFileFromAvailableMirrors -mirrorUrls $vsCodeToolDetails.mirrors -outfile $vsCodeInstallerFilePath
|
||||
if (-not $downloadResult) {
|
||||
Write-Host "Failed to download VS Code. Please try again later or install manually."
|
||||
} else {
|
||||
# Execute the installer silently with elevated permissions
|
||||
Start-Process -FilePath $vsCodeInstallerFilePath -ArgumentList "/VERYSILENT", "/mergetasks=!runcode" -Verb RunAs -Wait
|
||||
|
||||
# Remove the installer file after installation
|
||||
Remove-Item -Path $vsCodeInstallerFilePath
|
||||
|
||||
# Set alias
|
||||
$setAliasExpression = "Set-Alias -Name $vsCodeAlias -Value `"$vsCodeExecutablePath`""
|
||||
Add-Content -Path $PROFILE -Value $setAliasExpression
|
||||
Invoke-Expression $setAliasExpression
|
||||
|
||||
# Add VS Code to the system PATH environment variable
|
||||
Add-ToEnvPath -NewPath "C:\Users\$env:USERNAME\AppData\Local\Programs\Microsoft VS Code\bin"
|
||||
|
||||
# Disable Visual Studio Code Auto Updates
|
||||
$vsCodeSettingsPath = "${env:APPDATA}\Code\User\settings.json"
|
||||
if (-not (Test-Path $vsCodeSettingsPath)) {
|
||||
# Create the directory if it doesn't exist
|
||||
$dirPath = Split-Path -Path $vsCodeSettingsPath -Parent
|
||||
if (-not (Test-Path $dirPath)) {
|
||||
New-Item -ItemType Directory -Path $dirPath -Force
|
||||
}
|
||||
# Initialize an empty hashtable to act as the JSON object
|
||||
$settingsObj = @{}
|
||||
$settingsObj["update.mode"] = "none" # Set update mode to none
|
||||
$settingsObj | ConvertTo-Json | Set-Content $vsCodeSettingsPath
|
||||
} else {
|
||||
# If the file exists, modify it
|
||||
$settingsObj = Get-Content $vsCodeSettingsPath | ConvertFrom-Json
|
||||
$settingsObj["update.mode"] = "none"
|
||||
$settingsObj | ConvertTo-Json | Set-Content $vsCodeSettingsPath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# - Thunderbird
|
||||
$thunderbirdToolName = "Thunderbird"
|
||||
$thunderbirdToolDetails = Get-ToolDetails -toolsList $toolsList -toolName $thunderbirdToolName
|
||||
$thunderbirdAlias = $thunderbirdToolDetails.alias
|
||||
$thunderbirdExecutablePath = "C:\Program Files\Mozilla Thunderbird\thunderbird.exe"
|
||||
|
||||
# Check if Thunderbird is already installed by checking the Thunderbird executable path
|
||||
if (Test-Path $thunderbirdExecutablePath) {
|
||||
Write-Host "Thunderbird is already installed."
|
||||
} else {
|
||||
# Download the installer to the Temp directory
|
||||
$thunderbirdInstallerFilePath = "$env:TEMP\ThunderbirdSetup.exe"
|
||||
$downloadResult = Invoke-DownloadFileFromAvailableMirrors -mirrorUrls $thunderbirdToolDetails.mirrors -outfile $thunderbirdInstallerFilePath
|
||||
if (-not $downloadResult) {
|
||||
Write-Host "Failed to download Thunderbird. Please try again later or install manually."
|
||||
} else {
|
||||
# Execute the installer silently with elevated permissions
|
||||
Start-Process -FilePath $thunderbirdInstallerFilePath -ArgumentList "/S" -Verb RunAs -Wait
|
||||
|
||||
# Remove the installer file after installation
|
||||
Remove-Item -Path $thunderbirdInstallerFilePath
|
||||
|
||||
# Set alias
|
||||
$setAliasExpression = "Set-Alias -Name $thunderbirdAlias -Value `"$thunderbirdExecutablePath`""
|
||||
Add-Content -Path $PROFILE -Value $setAliasExpression
|
||||
Invoke-Expression $setAliasExpression
|
||||
|
||||
# Add Thunderbird to the system PATH environment variable
|
||||
Add-ToEnvPath -NewPath "C:\Program Files\Mozilla Thunderbird"
|
||||
}
|
||||
}
|
||||
|
||||
# - Server Setup
|
||||
|
||||
$pythonServerPort = 5000
|
||||
$onLogonTaskName = "Server_OnLogon"
|
||||
$requirementsFile = "$scriptFolder\server\requirements.txt"
|
||||
|
||||
# Ensure pip is updated to the latest version
|
||||
Install-PythonPackages -Package "pip" -Arguments "--upgrade"
|
||||
|
||||
Install-PythonPackages -Package "wheel"
|
||||
Install-PythonPackages -Package "pywinauto"
|
||||
|
||||
# Install Python packages from requirements.txt using Python's pip module
|
||||
if (Test-Path $requirementsFile) {
|
||||
Write-Host "Installing required Python packages using pip from requirements file..."
|
||||
Install-PythonPackages -RequirementsPath $requirementsFile
|
||||
} else {
|
||||
Write-Error "Requirements file not found: $requirementsFile"
|
||||
exit
|
||||
}
|
||||
|
||||
# Add a firewall rule to allow incoming connections on the specified port for the Python executable
|
||||
$pythonServerRuleName = "PythonHTTPServer-$pythonServerPort"
|
||||
if (-not (Get-NetFirewallRule -Name $pythonServerRuleName -ErrorAction SilentlyContinue)) {
|
||||
New-NetFirewallRule -DisplayName $pythonServerRuleName -Direction Inbound -Program $pythonExecutablePath -Protocol TCP -LocalPort $pythonServerPort -Action Allow -Profile Any
|
||||
Write-Host "Firewall rule added to allow traffic on port $pythonServerPort for Python"
|
||||
} else {
|
||||
Write-Host "Firewall rule already exists. $pythonServerRuleName "
|
||||
}
|
||||
|
||||
$onLogonScriptPath = "$scriptFolder\on-logon.ps1"
|
||||
# Check if the scheduled task exists before unregistering it
|
||||
if (Get-ScheduledTask -TaskName $onLogonTaskName -ErrorAction SilentlyContinue) {
|
||||
Write-Host "Scheduled task $onLogonTaskName already exists."
|
||||
} else {
|
||||
Write-Host "Registering new task $onLogonTaskName..."
|
||||
Register-LogonTask -TaskName $onLogonTaskName -ScriptPath $onLogonScriptPath -LocalUser "Docker"
|
||||
}
|
||||
|
||||
Start-Sleep -Seconds 10
|
||||
Start-ScheduledTask -TaskName $onLogonTaskName
|
||||
@@ -0,0 +1,71 @@
|
||||
{
|
||||
"Python": {
|
||||
"mirrors": [
|
||||
"https://www.python.org/ftp/python/3.10.0/python-3.10.0-amd64.exe"
|
||||
],
|
||||
"alias": "python"
|
||||
},
|
||||
"git": {
|
||||
"mirrors": [
|
||||
"https://github.com/git-for-windows/git/releases/download/v2.37.1.windows.1/Git-2.37.1-64-bit.exe"
|
||||
]
|
||||
},
|
||||
"7zip": {
|
||||
"mirrors": [
|
||||
"https://www.7-zip.org/a/7z2407-x64.exe"
|
||||
]
|
||||
},
|
||||
"ffmpeg": {
|
||||
"mirrors": [
|
||||
"https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.7z"
|
||||
]
|
||||
},
|
||||
"Google Chrome": {
|
||||
"mirrors": [
|
||||
"https://dl.google.com/chrome/install/latest/chrome_installer.exe"
|
||||
],
|
||||
"alias": "google-chrome"
|
||||
},
|
||||
"LibreOffice": {
|
||||
"mirrors": [
|
||||
"https://mirror.raiolanetworks.com/tdf/libreoffice/stable/24.8.4/win/x86_64/LibreOffice_24.8.4_Win_x86-64.msi",
|
||||
"https://mirrors.iu13.net/tdf/libreoffice/stable/24.8.4/win/x86_64/LibreOffice_24.8.4_Win_x86-64.msi",
|
||||
"https://download.documentfoundation.org/libreoffice/stable/24.8.4/win/x86_64/LibreOffice_24.8.4_Win_x86-64.msi"
|
||||
]
|
||||
},
|
||||
"VLC": {
|
||||
"mirrors": [
|
||||
"https://ftp.free.org/mirrors/videolan/vlc/3.0.21/win64/vlc-3.0.21-win64.exe",
|
||||
"https://mirror.fcix.net/videolan-ftp/vlc/3.0.21/win64/vlc-3.0.21-win64.exe",
|
||||
"https://mirror.raiolanetworks.com/videolan/vlc/3.0.21/win64/vlc-3.0.21-win64.exe"
|
||||
],
|
||||
"alias": "vlc"
|
||||
},
|
||||
"GIMP": {
|
||||
"mirrors": [
|
||||
"https://www-ftp.lip6.fr/pub/gimp/gimp/v2.10/windows/gimp-2.10.38-setup.exe",
|
||||
"https://download.gimp.org/gimp/v2.10/windows/gimp-2.10.38-setup.exe",
|
||||
"https://www-ftp.lip6.fr/pub/gimp/gimp/v2.10/windows/gimp-2.10.0-setup.exe"
|
||||
],
|
||||
"alias": "gimp"
|
||||
},
|
||||
"VS Code": {
|
||||
"mirrors": [
|
||||
"https://update.code.visualstudio.com/latest/win32-x64-user/stable"
|
||||
],
|
||||
"alias": "code"
|
||||
},
|
||||
"Thunderbird": {
|
||||
"mirrors": [
|
||||
"https://download-installer.cdn.mozilla.net/pub/thunderbird/releases/115.12.1/win64/en-US/Thunderbird%20Setup%20115.12.1.exe",
|
||||
"https://archive.mozilla.org/pub/thunderbird/releases/115.12.1/win64/en-US/Thunderbird%20Setup%20115.12.1.exe"
|
||||
],
|
||||
"alias": "thunderbird"
|
||||
},
|
||||
"Caddy Proxy": {
|
||||
"mirrors": [
|
||||
"https://caddyserver.com/api/download?os=windows&arch=amd64"
|
||||
],
|
||||
"alias": "caddy"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user