From f5cc18c973fd8107af2a3d70da023caee165ca55 Mon Sep 17 00:00:00 2001 From: sandrews Date: Sun, 21 Sep 2025 14:49:33 -0500 Subject: [PATCH] Remove self update --- 1_Install.ps1 | 212 ------------------------------------- 2_ConfigUpdate.ps1 | 212 ------------------------------------- 3_ConfigAfterNextcloud.ps1 | 212 ------------------------------------- 3 files changed, 636 deletions(-) diff --git a/1_Install.ps1 b/1_Install.ps1 index 34e184f..2576ba8 100644 --- a/1_Install.ps1 +++ b/1_Install.ps1 @@ -22,218 +22,6 @@ if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdent Write-Host "Running with administrator privileges." -ForegroundColor Green -# Self-update function for the script -function Update-Scripts { - Write-Host "Checking for updates..." -ForegroundColor Cyan - $updateScriptDir = $PSScriptRoot - $lastUpdateCheck = $null - $updateCheckFile = Join-Path -Path $updateScriptDir -ChildPath "last_update_check.txt" - $zipUrl = "https://gitea.andrewspolytechnic.com/public/windows-install/archive/master.zip" - - try { - # Check if we've checked for updates in the last 24 hours - if (Test-Path $updateCheckFile) { - $lastUpdateCheck = Get-Content $updateCheckFile | Get-Date - $timeSinceLastCheck = (Get-Date) - $lastUpdateCheck - if ($timeSinceLastCheck.TotalHours -lt 24) { - Write-Host "Last update check was less than 24 hours ago. Skipping update check." -ForegroundColor DarkGray - return $false # No update performed - } - } - - # Create a temporary directory in the script folder (will be ignored by git) - $tempDir = Join-Path -Path $updateScriptDir -ChildPath "temp" - if (Test-Path $tempDir) { Remove-Item $tempDir -Recurse -Force } - New-Item -ItemType Directory -Path $tempDir -Force | Out-Null - - $zipPath = Join-Path -Path $tempDir -ChildPath "update.zip" - $ProgressPreference = 'SilentlyContinue' # Hide progress bar to speed up download - - Write-Host "Downloading updates from $zipUrl..." -ForegroundColor Cyan - - try { - Invoke-WebRequest -Uri $zipUrl -OutFile $zipPath -UseBasicParsing -TimeoutSec 30 - } catch { - Write-Host "Failed to download from URL: $_" -ForegroundColor DarkGray - return $false # Failed to download - } - - # Check if the download was successful (file exists and is not empty) - if ((Test-Path $zipPath) -and ((Get-Item $zipPath).Length -gt 0)) { - Write-Host "Download successful!" -ForegroundColor Green - - try { - # Extract the zip file - Write-Host "Extracting update package..." -ForegroundColor Cyan - Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force - - # Based on our analysis, the zip extracts to a "windows-install" directory - $extractedDir = Get-ChildItem -Path $tempDir -Directory | Where-Object { $_.Name -eq "windows-install" } | Select-Object -First 1 - - if (($extractedDir) -and ((Test-Path $extractedDir.FullName))) { - Write-Host "Comparing update files with current installation..." -ForegroundColor Cyan - - # Function to get file hash that normalizes line endings - function Get-FileHashQuick($filePath) { - if (Test-Path $filePath -PathType Leaf) { - $fileExt = [System.IO.Path]::GetExtension($filePath).ToLower() - - # List of text file extensions that might have line ending differences - $textExtensions = @(".ps1", ".txt", ".json", ".js", ".py", ".csv", ".md", ".ini", ".sh") - - if ($textExtensions -contains $fileExt) { - # For text files, normalize line endings before computing hash - $content = Get-Content -Path $filePath -Raw - if ($content) { - # Normalize to LF - $normalizedContent = $content.Replace("`r`n", "`n") - $stream = [System.IO.MemoryStream]::new([System.Text.Encoding]::UTF8.GetBytes($normalizedContent)) - return (Get-FileHash -InputStream $stream -Algorithm MD5).Hash - } - } - - # For binary files or if normalization failed - return (Get-FileHash -Path $filePath -Algorithm MD5).Hash - } - return $null - } - - $differentFiles = @() - $newFiles = @() - $unchangedFiles = @() - - # Compare files from the extracted directory with existing files - Get-ChildItem -Path $extractedDir.FullName -Recurse | Where-Object { !$_.PSIsContainer -and $_.Name -ne ".git" } | ForEach-Object { - $relativePath = $_.FullName.Substring($extractedDir.FullName.Length + 1) - $currentFilePath = Join-Path -Path $updateScriptDir -ChildPath $relativePath - - if (Test-Path $currentFilePath) { - $newHash = Get-FileHashQuick $_.FullName - $currentHash = Get-FileHashQuick $currentFilePath - - if ($newHash -ne $currentHash) { - $differentFiles += $relativePath - } else { - $unchangedFiles += $relativePath - } - } else { - $newFiles += $relativePath - } - } - - # Display the results - Write-Host "`nUpdate analysis complete!" -ForegroundColor Green - - if ($differentFiles.Count -gt 0) { - Write-Host "`nFiles with changes ($($differentFiles.Count)):" -ForegroundColor Yellow - foreach ($file in $differentFiles) { - Write-Host " - $file" -ForegroundColor Yellow - } - } - - if ($newFiles.Count -gt 0) { - Write-Host "`nNew files ($($newFiles.Count)):" -ForegroundColor Cyan - foreach ($file in $newFiles) { - Write-Host " - $file" -ForegroundColor Cyan - } - } - - if ($unchangedFiles.Count -gt 0) { - Write-Host "`nUnchanged files: $($unchangedFiles.Count)" -ForegroundColor DarkGray - } - - # Record the update check time - Get-Date -Format "yyyy-MM-dd HH:mm:ss" | Out-File -FilePath $updateCheckFile -Force - - # Only ask to apply changes if there are differences - if ($differentFiles.Count -gt 0 -or $newFiles.Count -gt 0) { - $applyChoice = Read-Host "`nWould you like to apply these changes? (Y/N)" - if ($applyChoice -eq "Y" -or $applyChoice -eq "y") { - Write-Host "Installing updates..." -ForegroundColor Cyan - - # Copy all content from extracted directory to the root, preserving structure - Write-Host "Copying files from $($extractedDir.FullName) to $updateScriptDir..." -ForegroundColor Cyan - - # First, copy all individual files at the root level - Get-ChildItem -Path $extractedDir.FullName -File | Where-Object { $_.Name -ne ".gitignore" -and $_.Name -ne ".gitattributes" } | ForEach-Object { - $destPath = Join-Path -Path $updateScriptDir -ChildPath $_.Name - Copy-Item -Path $_.FullName -Destination $destPath -Force - Write-Host " Copied file: $($_.Name)" -ForegroundColor DarkGray - } - - # Then, copy all directories (but not .git) - Get-ChildItem -Path $extractedDir.FullName -Directory | Where-Object { $_.Name -ne ".git" } | ForEach-Object { - $dirName = $_.Name - $destDirPath = Join-Path -Path $updateScriptDir -ChildPath $dirName - - # Create destination directory if it doesn't exist - if (-not (Test-Path $destDirPath -PathType Container)) { - New-Item -Path $destDirPath -ItemType Directory -Force | Out-Null - } - - # Copy all files from this subdirectory - Get-ChildItem -Path $_.FullName -Recurse -File | ForEach-Object { - $relPath = $_.FullName.Substring($extractedDir.FullName.Length + 1) - $destFilePath = Join-Path -Path $updateScriptDir -ChildPath $relPath - $destFileDir = Split-Path -Parent $destFilePath - - # Ensure directory exists - if (-not (Test-Path $destFileDir -PathType Container)) { - New-Item -Path $destFileDir -ItemType Directory -Force | Out-Null - } - - Copy-Item -Path $_.FullName -Destination $destFilePath -Force - Write-Host " Copied: $relPath" -ForegroundColor DarkGray - } - } - - Write-Host "Update completed successfully!" -ForegroundColor Green - - # Suggest restarting the script with the updated version - $restartChoice = Read-Host "The script has been updated. Would you like to restart the script to use the updated version? (Y/N)" - if ($restartChoice -eq "Y" -or $restartChoice -eq "y") { - Write-Host "Restarting script..." -ForegroundColor Cyan - Start-Process PowerShell -Verb RunAs -ArgumentList "-ExecutionPolicy Bypass -File `"$PSCommandPath`"" - exit - } - return $true # Update performed successfully - } else { - Write-Host "Update cancelled. No changes were made." -ForegroundColor Yellow - return $false - } - } else { - Write-Host "`nNo changes detected. Your installation is up to date!" -ForegroundColor Green - return $false # No changes to apply - } - } else { - Write-Host "Could not find extracted update directory." -ForegroundColor Yellow - } - } catch { - Write-Host "Error extracting or installing updates: $_" -ForegroundColor Yellow - } - } else { - Write-Host "Could not download updates. Please check your internet connection." -ForegroundColor Yellow - } - - # Clean up - if (Test-Path $tempDir) { - try { - Remove-Item $tempDir -Recurse -Force -ErrorAction SilentlyContinue - } catch { - Write-Host "Could not clean up temp directory: $_" -ForegroundColor DarkGray - } - } - return $false # Update failed - } catch { - Write-Host "Error checking for updates: $_" -ForegroundColor Yellow - Write-Host "Continuing with current version..." -ForegroundColor Yellow - return $false # Update failed - } -} - -# Call the update function at the beginning -$scriptUpdated = Update-Scripts - [Environment]::UserName $uid = $Env:UserName # Get current username for use in paths diff --git a/2_ConfigUpdate.ps1 b/2_ConfigUpdate.ps1 index 0fb787d..84740e3 100644 --- a/2_ConfigUpdate.ps1 +++ b/2_ConfigUpdate.ps1 @@ -22,218 +22,6 @@ if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdent Write-Host "Running with administrator privileges." -ForegroundColor Green -# Self-update function for the script -function Update-Scripts { - Write-Host "Checking for updates..." -ForegroundColor Cyan - $updateScriptDir = $PSScriptRoot - $lastUpdateCheck = $null - $updateCheckFile = Join-Path -Path $updateScriptDir -ChildPath "last_update_check.txt" - $zipUrl = "https://gitea.andrewspolytechnic.com/public/windows-install/archive/master.zip" - - try { - # Check if we've checked for updates in the last 24 hours - if (Test-Path $updateCheckFile) { - $lastUpdateCheck = Get-Content $updateCheckFile | Get-Date - $timeSinceLastCheck = (Get-Date) - $lastUpdateCheck - if ($timeSinceLastCheck.TotalHours -lt 24) { - Write-Host "Last update check was less than 24 hours ago. Skipping update check." -ForegroundColor DarkGray - return $false # No update performed - } - } - - # Create a temporary directory in the script folder (will be ignored by git) - $tempDir = Join-Path -Path $updateScriptDir -ChildPath "temp" - if (Test-Path $tempDir) { Remove-Item $tempDir -Recurse -Force } - New-Item -ItemType Directory -Path $tempDir -Force | Out-Null - - $zipPath = Join-Path -Path $tempDir -ChildPath "update.zip" - $ProgressPreference = 'SilentlyContinue' # Hide progress bar to speed up download - - Write-Host "Downloading updates from $zipUrl..." -ForegroundColor Cyan - - try { - Invoke-WebRequest -Uri $zipUrl -OutFile $zipPath -UseBasicParsing -TimeoutSec 30 - } catch { - Write-Host "Failed to download from URL: $_" -ForegroundColor DarkGray - return $false # Failed to download - } - - # Check if the download was successful (file exists and is not empty) - if ((Test-Path $zipPath) -and ((Get-Item $zipPath).Length -gt 0)) { - Write-Host "Download successful!" -ForegroundColor Green - - try { - # Extract the zip file - Write-Host "Extracting update package..." -ForegroundColor Cyan - Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force - - # Based on our analysis, the zip extracts to a "windows-install" directory - $extractedDir = Get-ChildItem -Path $tempDir -Directory | Where-Object { $_.Name -eq "windows-install" } | Select-Object -First 1 - - if (($extractedDir) -and ((Test-Path $extractedDir.FullName))) { - Write-Host "Comparing update files with current installation..." -ForegroundColor Cyan - - # Function to get file hash that normalizes line endings - function Get-FileHashQuick($filePath) { - if (Test-Path $filePath -PathType Leaf) { - $fileExt = [System.IO.Path]::GetExtension($filePath).ToLower() - - # List of text file extensions that might have line ending differences - $textExtensions = @(".ps1", ".txt", ".json", ".js", ".py", ".csv", ".md", ".ini", ".sh") - - if ($textExtensions -contains $fileExt) { - # For text files, normalize line endings before computing hash - $content = Get-Content -Path $filePath -Raw - if ($content) { - # Normalize to LF - $normalizedContent = $content.Replace("`r`n", "`n") - $stream = [System.IO.MemoryStream]::new([System.Text.Encoding]::UTF8.GetBytes($normalizedContent)) - return (Get-FileHash -InputStream $stream -Algorithm MD5).Hash - } - } - - # For binary files or if normalization failed - return (Get-FileHash -Path $filePath -Algorithm MD5).Hash - } - return $null - } - - $differentFiles = @() - $newFiles = @() - $unchangedFiles = @() - - # Compare files from the extracted directory with existing files - Get-ChildItem -Path $extractedDir.FullName -Recurse | Where-Object { !$_.PSIsContainer -and $_.Name -ne ".git" } | ForEach-Object { - $relativePath = $_.FullName.Substring($extractedDir.FullName.Length + 1) - $currentFilePath = Join-Path -Path $updateScriptDir -ChildPath $relativePath - - if (Test-Path $currentFilePath) { - $newHash = Get-FileHashQuick $_.FullName - $currentHash = Get-FileHashQuick $currentFilePath - - if ($newHash -ne $currentHash) { - $differentFiles += $relativePath - } else { - $unchangedFiles += $relativePath - } - } else { - $newFiles += $relativePath - } - } - - # Display the results - Write-Host "`nUpdate analysis complete!" -ForegroundColor Green - - if ($differentFiles.Count -gt 0) { - Write-Host "`nFiles with changes ($($differentFiles.Count)):" -ForegroundColor Yellow - foreach ($file in $differentFiles) { - Write-Host " - $file" -ForegroundColor Yellow - } - } - - if ($newFiles.Count -gt 0) { - Write-Host "`nNew files ($($newFiles.Count)):" -ForegroundColor Cyan - foreach ($file in $newFiles) { - Write-Host " - $file" -ForegroundColor Cyan - } - } - - if ($unchangedFiles.Count -gt 0) { - Write-Host "`nUnchanged files: $($unchangedFiles.Count)" -ForegroundColor DarkGray - } - - # Record the update check time - Get-Date -Format "yyyy-MM-dd HH:mm:ss" | Out-File -FilePath $updateCheckFile -Force - - # Only ask to apply changes if there are differences - if ($differentFiles.Count -gt 0 -or $newFiles.Count -gt 0) { - $applyChoice = Read-Host "`nWould you like to apply these changes? (Y/N)" - if ($applyChoice -eq "Y" -or $applyChoice -eq "y") { - Write-Host "Installing updates..." -ForegroundColor Cyan - - # Copy all content from extracted directory to the root, preserving structure - Write-Host "Copying files from $($extractedDir.FullName) to $updateScriptDir..." -ForegroundColor Cyan - - # First, copy all individual files at the root level - Get-ChildItem -Path $extractedDir.FullName -File | Where-Object { $_.Name -ne ".gitignore" -and $_.Name -ne ".gitattributes" } | ForEach-Object { - $destPath = Join-Path -Path $updateScriptDir -ChildPath $_.Name - Copy-Item -Path $_.FullName -Destination $destPath -Force - Write-Host " Copied file: $($_.Name)" -ForegroundColor DarkGray - } - - # Then, copy all directories (but not .git) - Get-ChildItem -Path $extractedDir.FullName -Directory | Where-Object { $_.Name -ne ".git" } | ForEach-Object { - $dirName = $_.Name - $destDirPath = Join-Path -Path $updateScriptDir -ChildPath $dirName - - # Create destination directory if it doesn't exist - if (-not (Test-Path $destDirPath -PathType Container)) { - New-Item -Path $destDirPath -ItemType Directory -Force | Out-Null - } - - # Copy all files from this subdirectory - Get-ChildItem -Path $_.FullName -Recurse -File | ForEach-Object { - $relPath = $_.FullName.Substring($extractedDir.FullName.Length + 1) - $destFilePath = Join-Path -Path $updateScriptDir -ChildPath $relPath - $destFileDir = Split-Path -Parent $destFilePath - - # Ensure directory exists - if (-not (Test-Path $destFileDir -PathType Container)) { - New-Item -Path $destFileDir -ItemType Directory -Force | Out-Null - } - - Copy-Item -Path $_.FullName -Destination $destFilePath -Force - Write-Host " Copied: $relPath" -ForegroundColor DarkGray - } - } - - Write-Host "Update completed successfully!" -ForegroundColor Green - - # Suggest restarting the script with the updated version - $restartChoice = Read-Host "The script has been updated. Would you like to restart the script to use the updated version? (Y/N)" - if ($restartChoice -eq "Y" -or $restartChoice -eq "y") { - Write-Host "Restarting script..." -ForegroundColor Cyan - Start-Process PowerShell -Verb RunAs -ArgumentList "-ExecutionPolicy Bypass -File `"$PSCommandPath`"" - exit - } - return $true # Update performed successfully - } else { - Write-Host "Update cancelled. No changes were made." -ForegroundColor Yellow - return $false - } - } else { - Write-Host "`nNo changes detected. Your installation is up to date!" -ForegroundColor Green - return $false # No changes to apply - } - } else { - Write-Host "Could not find extracted update directory." -ForegroundColor Yellow - } - } catch { - Write-Host "Error extracting or installing updates: $_" -ForegroundColor Yellow - } - } else { - Write-Host "Could not download updates. Please check your internet connection." -ForegroundColor Yellow - } - - # Clean up - if (Test-Path $tempDir) { - try { - Remove-Item $tempDir -Recurse -Force -ErrorAction SilentlyContinue - } catch { - Write-Host "Could not clean up temp directory: $_" -ForegroundColor DarkGray - } - } - return $false # Update failed - } catch { - Write-Host "Error checking for updates: $_" -ForegroundColor Yellow - Write-Host "Continuing with current version..." -ForegroundColor Yellow - return $false # Update failed - } -} - -# Call the update function at the beginning -$scriptUpdated = Update-Scripts - $uid = $Env:UserName # Get the directory where this script is located diff --git a/3_ConfigAfterNextcloud.ps1 b/3_ConfigAfterNextcloud.ps1 index 85b233c..fffe4a2 100644 --- a/3_ConfigAfterNextcloud.ps1 +++ b/3_ConfigAfterNextcloud.ps1 @@ -22,218 +22,6 @@ if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdent Write-Host "Running with administrator privileges." -ForegroundColor Green -# Self-update function for the script -function Update-Scripts { - Write-Host "Checking for updates..." -ForegroundColor Cyan - $updateScriptDir = $PSScriptRoot - $lastUpdateCheck = $null - $updateCheckFile = Join-Path -Path $updateScriptDir -ChildPath "last_update_check.txt" - $zipUrl = "https://gitea.andrewspolytechnic.com/public/windows-install/archive/master.zip" - - try { - # Check if we've checked for updates in the last 24 hours - if (Test-Path $updateCheckFile) { - $lastUpdateCheck = Get-Content $updateCheckFile | Get-Date - $timeSinceLastCheck = (Get-Date) - $lastUpdateCheck - if ($timeSinceLastCheck.TotalHours -lt 24) { - Write-Host "Last update check was less than 24 hours ago. Skipping update check." -ForegroundColor DarkGray - return $false # No update performed - } - } - - # Create a temporary directory in the script folder (will be ignored by git) - $tempDir = Join-Path -Path $updateScriptDir -ChildPath "temp" - if (Test-Path $tempDir) { Remove-Item $tempDir -Recurse -Force } - New-Item -ItemType Directory -Path $tempDir -Force | Out-Null - - $zipPath = Join-Path -Path $tempDir -ChildPath "update.zip" - $ProgressPreference = 'SilentlyContinue' # Hide progress bar to speed up download - - Write-Host "Downloading updates from $zipUrl..." -ForegroundColor Cyan - - try { - Invoke-WebRequest -Uri $zipUrl -OutFile $zipPath -UseBasicParsing -TimeoutSec 30 - } catch { - Write-Host "Failed to download from URL: $_" -ForegroundColor DarkGray - return $false # Failed to download - } - - # Check if the download was successful (file exists and is not empty) - if ((Test-Path $zipPath) -and ((Get-Item $zipPath).Length -gt 0)) { - Write-Host "Download successful!" -ForegroundColor Green - - try { - # Extract the zip file - Write-Host "Extracting update package..." -ForegroundColor Cyan - Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force - - # Based on our analysis, the zip extracts to a "windows-install" directory - $extractedDir = Get-ChildItem -Path $tempDir -Directory | Where-Object { $_.Name -eq "windows-install" } | Select-Object -First 1 - - if (($extractedDir) -and ((Test-Path $extractedDir.FullName))) { - Write-Host "Comparing update files with current installation..." -ForegroundColor Cyan - - # Function to get file hash that normalizes line endings - function Get-FileHashQuick($filePath) { - if (Test-Path $filePath -PathType Leaf) { - $fileExt = [System.IO.Path]::GetExtension($filePath).ToLower() - - # List of text file extensions that might have line ending differences - $textExtensions = @(".ps1", ".txt", ".json", ".js", ".py", ".csv", ".md", ".ini", ".sh") - - if ($textExtensions -contains $fileExt) { - # For text files, normalize line endings before computing hash - $content = Get-Content -Path $filePath -Raw - if ($content) { - # Normalize to LF - $normalizedContent = $content.Replace("`r`n", "`n") - $stream = [System.IO.MemoryStream]::new([System.Text.Encoding]::UTF8.GetBytes($normalizedContent)) - return (Get-FileHash -InputStream $stream -Algorithm MD5).Hash - } - } - - # For binary files or if normalization failed - return (Get-FileHash -Path $filePath -Algorithm MD5).Hash - } - return $null - } - - $differentFiles = @() - $newFiles = @() - $unchangedFiles = @() - - # Compare files from the extracted directory with existing files - Get-ChildItem -Path $extractedDir.FullName -Recurse | Where-Object { !$_.PSIsContainer -and $_.Name -ne ".git" } | ForEach-Object { - $relativePath = $_.FullName.Substring($extractedDir.FullName.Length + 1) - $currentFilePath = Join-Path -Path $updateScriptDir -ChildPath $relativePath - - if (Test-Path $currentFilePath) { - $newHash = Get-FileHashQuick $_.FullName - $currentHash = Get-FileHashQuick $currentFilePath - - if ($newHash -ne $currentHash) { - $differentFiles += $relativePath - } else { - $unchangedFiles += $relativePath - } - } else { - $newFiles += $relativePath - } - } - - # Display the results - Write-Host "`nUpdate analysis complete!" -ForegroundColor Green - - if ($differentFiles.Count -gt 0) { - Write-Host "`nFiles with changes ($($differentFiles.Count)):" -ForegroundColor Yellow - foreach ($file in $differentFiles) { - Write-Host " - $file" -ForegroundColor Yellow - } - } - - if ($newFiles.Count -gt 0) { - Write-Host "`nNew files ($($newFiles.Count)):" -ForegroundColor Cyan - foreach ($file in $newFiles) { - Write-Host " - $file" -ForegroundColor Cyan - } - } - - if ($unchangedFiles.Count -gt 0) { - Write-Host "`nUnchanged files: $($unchangedFiles.Count)" -ForegroundColor DarkGray - } - - # Record the update check time - Get-Date -Format "yyyy-MM-dd HH:mm:ss" | Out-File -FilePath $updateCheckFile -Force - - # Only ask to apply changes if there are differences - if ($differentFiles.Count -gt 0 -or $newFiles.Count -gt 0) { - $applyChoice = Read-Host "`nWould you like to apply these changes? (Y/N)" - if ($applyChoice -eq "Y" -or $applyChoice -eq "y") { - Write-Host "Installing updates..." -ForegroundColor Cyan - - # Copy all content from extracted directory to the root, preserving structure - Write-Host "Copying files from $($extractedDir.FullName) to $updateScriptDir..." -ForegroundColor Cyan - - # First, copy all individual files at the root level - Get-ChildItem -Path $extractedDir.FullName -File | Where-Object { $_.Name -ne ".gitignore" -and $_.Name -ne ".gitattributes" } | ForEach-Object { - $destPath = Join-Path -Path $updateScriptDir -ChildPath $_.Name - Copy-Item -Path $_.FullName -Destination $destPath -Force - Write-Host " Copied file: $($_.Name)" -ForegroundColor DarkGray - } - - # Then, copy all directories (but not .git) - Get-ChildItem -Path $extractedDir.FullName -Directory | Where-Object { $_.Name -ne ".git" } | ForEach-Object { - $dirName = $_.Name - $destDirPath = Join-Path -Path $updateScriptDir -ChildPath $dirName - - # Create destination directory if it doesn't exist - if (-not (Test-Path $destDirPath -PathType Container)) { - New-Item -Path $destDirPath -ItemType Directory -Force | Out-Null - } - - # Copy all files from this subdirectory - Get-ChildItem -Path $_.FullName -Recurse -File | ForEach-Object { - $relPath = $_.FullName.Substring($extractedDir.FullName.Length + 1) - $destFilePath = Join-Path -Path $updateScriptDir -ChildPath $relPath - $destFileDir = Split-Path -Parent $destFilePath - - # Ensure directory exists - if (-not (Test-Path $destFileDir -PathType Container)) { - New-Item -Path $destFileDir -ItemType Directory -Force | Out-Null - } - - Copy-Item -Path $_.FullName -Destination $destFilePath -Force - Write-Host " Copied: $relPath" -ForegroundColor DarkGray - } - } - - Write-Host "Update completed successfully!" -ForegroundColor Green - - # Suggest restarting the script with the updated version - $restartChoice = Read-Host "The script has been updated. Would you like to restart the script to use the updated version? (Y/N)" - if ($restartChoice -eq "Y" -or $restartChoice -eq "y") { - Write-Host "Restarting script..." -ForegroundColor Cyan - Start-Process PowerShell -Verb RunAs -ArgumentList "-ExecutionPolicy Bypass -File `"$PSCommandPath`"" - exit - } - return $true # Update performed successfully - } else { - Write-Host "Update cancelled. No changes were made." -ForegroundColor Yellow - return $false - } - } else { - Write-Host "`nNo changes detected. Your installation is up to date!" -ForegroundColor Green - return $false # No changes to apply - } - } else { - Write-Host "Could not find extracted update directory." -ForegroundColor Yellow - } - } catch { - Write-Host "Error extracting or installing updates: $_" -ForegroundColor Yellow - } - } else { - Write-Host "Could not download updates. Please check your internet connection." -ForegroundColor Yellow - } - - # Clean up - if (Test-Path $tempDir) { - try { - Remove-Item $tempDir -Recurse -Force -ErrorAction SilentlyContinue - } catch { - Write-Host "Could not clean up temp directory: $_" -ForegroundColor DarkGray - } - } - return $false # Update failed - } catch { - Write-Host "Error checking for updates: $_" -ForegroundColor Yellow - Write-Host "Continuing with current version..." -ForegroundColor Yellow - return $false # Update failed - } -} - -# Call the update function at the beginning -$scriptUpdated = Update-Scripts - $uid = $Env:UserName # Get the directory where this script is located $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path