Skip to content

Commit

Permalink
fix: cleanup previous commits
Browse files Browse the repository at this point in the history
  • Loading branch information
he3als committed Aug 11, 2024
1 parent 682c0fd commit 6fc9483
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 105 deletions.
9 changes: 6 additions & 3 deletions src/playbook/Configuration/custom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ actions:
- !task: {path: 'tweaks\scripts\script-ngen.yml'}
- !task: {path: 'tweaks\qol\config-powershell.yml'}

# Cleanup script takes longer to finish so it has its own status
# It's ran here as you can't check when cleanmgr is finished
# Disk Cleanup is run first so it can run in the background
- !writeStatus: {status: 'Cleaning up'}
- !task: {path: 'tweaks\scripts\script-cleanup.yml'}
- !powerShell:
command: '.\CLEANUP.ps1'
exeDir: true
wait: true
runas: currentUserElevated

# Set hidden Settings pages
# Done before everything else as scripts will overwrite it
Expand Down
2 changes: 1 addition & 1 deletion src/playbook/Configuration/tweaks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ actions:
# with modifying the graphical user interface (GUI).
# -----------------------------------------------------
- !writeStatus: {status: 'Running QoL tweaks'}
- !task: {path: 'tweaks\performance\system\bcdedit-tweaks.yml'}
- !task: {path: 'tweaks\qol\bcdedit-tweaks.yml'}
- !task: {path: 'tweaks\qol\best-wallpaper-quality.yml'}
- !task: {path: 'tweaks\qol\config-start-menu.yml'}
- !task: {path: 'tweaks\qol\config-windows-ink-workspace.yml'}
Expand Down
9 changes: 0 additions & 9 deletions src/playbook/Configuration/tweaks/scripts/script-cleanup.yml

This file was deleted.

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ function New-Shortcut {
[switch]$IfExist
)

if (!(Test-Path $Source -PathType Leaf)) {
if (!(Test-Path $Source)) {
throw "Source '$source' not found."
}

if ($IfExist -and !(Test-Path $Destination)) {
return
}

if (!$WorkingDir) {
$WorkingDir = Split-Path $Source
}

$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($Destination)
$Shortcut.TargetPath = $Source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,42 +43,24 @@ public class KnownFolder
}
}

function Get-Accounts {
$accounts = Get-CimInstance Win32_UserAccount -Filter "Disabled=False"
$userProfiles = Get-CimInstance Win32_UserProfile

$profileLookup = @{}
foreach ($profile in $userProfiles) {
$profileLookup[$profile.SID] = $profile.LocalPath
}

$data = $accounts | ForEach-Object {
$account = $_
$profilePath = $profileLookup[$account.SID]

[PSCustomObject]@{
Name = $account.Name
Caption = $account.Caption
Path = $profilePath
SID = $account.SID
}
}

return $data
}

function Get-SystemDrive {
@(
$drive = $null
foreach ($letter in @(
$env:SystemDrive,
(Get-CimInstance -ClassName Win32_OperatingSystem).SystemDrive,
"C:"
) | ForEach-Object {
if (($_.Length -eq 2) -and (Test-Path $_ -ItemType Container)) {
return $_
)) {
if ($letter -and ($letter.Length -eq 2) -and (Test-Path $letter -PathType Container)) {
$drive = $letter
break
}
}

throw "Failed to find the system drive!"
if ($drive) {
return $drive
} else {
throw "Failed to find the system drive!"
}
}

Export-ModuleMember -Function Get-UserPath, Get-Accounts
Export-ModuleMember -Function Get-UserPath, Get-SystemDrive

This file was deleted.

36 changes: 20 additions & 16 deletions src/playbook/Executables/CLEANUP.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
$env:PSModulePath += ";$PWD\AtlasModules\Scripts\Modules"
function Invoke-AtlasDiskCleanup {
# Kill running cleanmgr instances, as they will prevent new cleanmgr from starting
Get-Process -Name cleanmgr -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
Expand Down Expand Up @@ -48,40 +49,43 @@ function Invoke-AtlasDiskCleanup {
# If so, don't cleanup as it will also cleanup other drives, which will be slow, and we don't want to touch other data
$drives = (Get-PSDrive -PSProvider FileSystem).Root | Where-Object { $_ -notmatch $(Get-SystemDrive) }
foreach ($drive in $drives) {
if (!(Test-Path -Path $(Join-Path -Path $drive.Root -ChildPath 'Windows') -PathType Container)) {
Invoke-AtlasDiskCleanup
}
if (!(Test-Path -Path $(Join-Path -Path $drive -ChildPath 'Windows') -PathType Container)) {
Write-Output "No other Windows drives found, running Disk Cleanup."
Invoke-AtlasDiskCleanup
}
}

# Clear the user temp folder
$env:temp, $env:tmp, "$env:localappdata\Temp" | ForEach-Object {
if (Test-Path $_ -PathType Container) {
$userTemp = $_
foreach ($path in @($env:temp, $env:tmp, "$env:localappdata\Temp")) {
if (Test-Path $path -PathType Container) {
$userTemp = $path
break
}
}
if (!$userTemp) {
Write-Error "User temp folder not found!"
} else {
if ($path) {
Write-Output "Cleaning user TEMP folder..."
Get-ChildItem -Path $userTemp | Where-Object { $_.Name -ne 'AME' } | Remove-Item -Force -Recurse -EA 0
} else {
Write-Error "User temp folder not found!"
}

# Clear the system temp folder
$machine = [System.EnvironmentVariableTarget]::Machine
@(
foreach ($path in @(
[System.Environment]::GetEnvironmentVariable("Temp", $machine),
[System.Environment]::GetEnvironmentVariable("Tmp", $machine),
"$([Environment]::GetFolderPath('Windows'))\Temp"
) | ForEach-Object {
if (Test-Path $_ -PathType Container) {
$sysTemp = $_
)) {
if (Test-Path $path -PathType Container) {
$sysTemp = $path
break
}
}
if (!$sysTemp) {
Write-Error "System temp folder not found!"
} else {
if ($sysTemp) {
Write-Output "Cleaning system TEMP folder..."
Remove-Item -Path "$sysTemp\*" -Force -Recurse -EA 0
} else {
Write-Error "System temp folder not found!"
}

# Delete all system restore points
Expand Down
32 changes: 16 additions & 16 deletions src/playbook/Executables/LIBREWOLF.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
$env:PSModulePath += ";$PWD\AtlasModules\Scripts\Modules"
$ProgressPreference = "SilentlyContinue"
$ErrorActionPreference = "Stop"

# Initial variables
$drive = Get-SystemDrive
$env:PSModulePath += ";$PWD\AtlasModules\Scripts\Modules"
$desktop = [Environment]::GetFolderPath("Desktop")
$startMenu = [Environment]::GetFolderPath("CommonPrograms")
$programs = [Environment]::GetFolderPath("ProgramFiles")
Expand All @@ -19,17 +19,8 @@ if ([string]::IsNullOrEmpty($librewolfVersion)) {
$librewolfFileName = "librewolf-$librewolfVersion-windows-x86_64-setup.exe"
$librewolfDownload = "https://gitlab.com/api/v4/projects/$gitLabId/packages/generic/librewolf/$librewolfVersion/$librewolfFileName"

Write-Output "Getting the latest LibreWolf-WinUpdater download link"
$librewolfUpdaterURI = "https://codeberg.org/api/v1/repos/ltguillaume/librewolf-winupdater/releases?draft=false&pre-release=false&page=1&limit=1"
$librewolfUpdaterDownload = (Invoke-RestMethod -Uri "$librewolfUpdaterURI").Assets |
Where-Object { $_.name -like "*.zip" } |
Select-Object -ExpandProperty browser_download_url

# Output paths
$outputLibrewolf = "$drive\$librewolfFileName"
$outputLibrewolfUpdater = "$drive\librewolf-winupdater.zip"

Write-Output "Downloading the latest LibreWolf setup"
$outputLibrewolf = "$drive\$librewolfFileName"
curl.exe -LSs "$librewolfDownload" -o "$outputLibrewolf"

Write-Output "Installing LibreWolf silently"
Expand All @@ -39,15 +30,23 @@ if (!(Test-Path $librewolfPath)) {
}

Write-Output "Creating LibreWolf Desktop shortcut"
New-Shortcut -Source "$librewolfPath\librewolf.exe" -ShortcutPath "$desktop\LibreWolf.lnk" -WorkingDir $librewolfPath
New-Shortcut -Source "$librewolfPath\librewolf.exe" -Destination "$desktop\LibreWolf.lnk" -WorkingDir $librewolfPath


Write-Title "Installing LibreWolf-WinUpdater..."
Write-Output "Getting the latest LibreWolf-WinUpdater download link"
$librewolfUpdaterURI = "https://codeberg.org/api/v1/repos/ltguillaume/librewolf-winupdater/releases?draft=false&pre-release=false&page=1&limit=1"
$librewolfUpdaterDownload = (Invoke-RestMethod -Uri "$librewolfUpdaterURI").Assets |
Where-Object { $_.name -like "*.zip" } |
Select-Object -ExpandProperty browser_download_url

Write-Output "Downloading the latest LibreWolf WinUpdater ZIP"
$outputLibrewolfUpdater = "$drive\librewolf-winupdater.zip"
curl.exe -LSs "$librewolfUpdaterDownload" -o "$outputLibrewolfUpdater"

Write-Output "Installing/extracting Librewolf-WinUpdater"
Write-Output "Extracting Librewolf-WinUpdater"
Expand-Archive -Path $outputLibrewolfUpdater -DestinationPath "$programs\LibreWolf\librewolf-winupdater" -Force

# Automatic updater
Write-Output "Adding automatic updater task"
foreach ($User in (Get-CimInstance -ClassName Win32_UserAccount -Filter "Disabled=False").Name) {
$Action = New-ScheduledTaskAction -Execute "$updaterPath\LibreWolf-WinUpdater.exe" -Argument "/Scheduled"
Expand All @@ -59,8 +58,9 @@ foreach ($User in (Get-CimInstance -ClassName Win32_UserAccount -Filter "Disable
}

Write-Output "Adding LibreWolf WinUpdater shortcut"
New-Shortcut -Source "$updaterPath\Librewolf-WinUpdater.exe" -ShortcutPath "$startMenu\LibreWolf\LibreWolf WinUpdater.lnk" -WorkingDir $librewolfPath
New-Shortcut -Source "$updaterPath\Librewolf-WinUpdater.exe" -Destination "$startMenu\LibreWolf\LibreWolf WinUpdater.lnk" -WorkingDir $librewolfPath

Write-Output "Removing temp files"
# Finish
Write-Title "Removing temp files"
Remove-Item "$outputLibrewolf" -Force
Remove-Item "$outputLibrewolfUpdater" -Force
14 changes: 9 additions & 5 deletions src/playbook/Executables/SOFTWARE.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ $msiArgs = "/qn /quiet /norestart ALLUSERS=1 REBOOT=ReallySuppress"
$arm = ((Get-CimInstance -Class Win32_ComputerSystem).SystemType -match 'ARM64') -or ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64')

# Create temporary directory
function Remove-TempDirectory { Pop-Location; Remove-Item -Path $tempDir -Force -Recurse -EA 0 }
$tempDir = Join-Path -Path $(Get-SystemDrive) -ChildPath $([System.Guid]::NewGuid())
New-Item $tempDir -ItemType Directory -Force | Out-Null
Push-Location $tempDir
Expand All @@ -36,11 +37,11 @@ if ($Brave) {
Write-Output "Still running BraveSetup."
Start-Sleep -Seconds 2
} else {
Remove-Item "$tempDir" -ErrorAction SilentlyContinue -Force -Recurse
Remove-TempDirectory
}
} until (!$processesFound)

Stop-Process -Name "brave" -Force -ErrorAction SilentlyContinue
Stop-Process -Name "brave" -Force -EA 0
exit
}

Expand All @@ -52,6 +53,8 @@ if ($Firefox) {
& curl.exe -LSs "https://download.mozilla.org/?product=firefox-latest-ssl&os=$firefoxArch&lang=en-US" -o "$tempDir\firefox.exe"
Write-Output "Installing Firefox..."
Start-Process -FilePath "$tempDir\firefox.exe" -WindowStyle Hidden -ArgumentList '/S /ALLUSERS=1' -Wait

Remove-TempDirectory
exit
}

Expand All @@ -62,6 +65,8 @@ if ($Chrome) {
& curl.exe -LSs "https://dl.google.com/dl/chrome/install/googlechromestandaloneenterprise$chromeArch.msi" -o "$tempDir\chrome.msi"
Write-Output "Installing Google Chrome..."
Start-Process -FilePath "$tempDir\chrome.msi" -WindowStyle Hidden -ArgumentList '/qn' -Wait

Remove-TempDirectory
exit
}

Expand Down Expand Up @@ -136,7 +141,7 @@ $githubApi = Invoke-RestMethod "https://api.github.com/repos/M2Team/NanaZip/rele
$assets = $githubApi.Assets.browser_download_url | Select-String ".xml", ".msixbundle" | Select-Object -Unique -First 2
function InstallNanaZip {
Write-Output "Downloading NanaZip..."
$path = New-Item "$tempDir\nanazip-$(New-Guid)" -ItemType Directory
$path = New-Item "$tempDir\nanazip" -ItemType Directory
$assets | ForEach-Object {
$filename = $_ -split '/' | Select-Object -Last 1
Write-Output "Downloading '$filename'..."
Expand Down Expand Up @@ -189,5 +194,4 @@ Write-Output "Installing legacy DirectX runtimes..."
Start-Process -FilePath "$tempDir\directx\dxsetup.exe" -WindowStyle Hidden -ArgumentList '/silent' -Wait

# Remove temporary directory
Pop-Location
Remove-Item -Path $tempDir -Force -Recurse -EA 0
Remove-TempDirectory
18 changes: 3 additions & 15 deletions src/playbook/Executables/TASKBARPINS.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,13 @@ if ($Browser) {

# Init shortcuts
$tmp = New-Item (Join-Path -Path $([System.IO.Path]::GetTempPath()) -ChildPath $([System.Guid]::NewGuid())) -ItemType Directory -Force
function Add-Shortcut {
param (
[string]$Temp = $tmp,
[string]$Path,
[string]$Destination
)

$Shortcut = (New-Object -ComObject WScript.Shell).CreateShortcut("$Temp\$Destination.lnk")
$Shortcut.TargetPath = $Path
$Shortcut.WorkingDirectory = Split-Path $Path
$Shortcut.Save()
}
Add-Shortcut -Path $($shortcuts.$explorer.Path) -Destination $explorer
New-Shortcut -Source $($shortcuts.$explorer.Path) -Destination "$tmp\$explorer.lnk"

# Decide Registry Favorites
if ([string]::IsNullOrEmpty($Browser)) { # If Edge exists, pin it, otherwise, pin only File Explorer
$edgePath = $shortcuts.$edge.Path
if (Test-Path $edgePath) {
Add-Shortcut -Path $edgePath -Destination $edge
New-Shortcut -Source $edgePath -Destination "$tmp\$edge.lnk"
$Browser = $edge
$regTaskbar = $shortcuts.$edge
} else {
Expand All @@ -80,7 +68,7 @@ if ([string]::IsNullOrEmpty($Browser)) { # If Edge exists, pin it, otherwise, pi
$regTaskbar = $shortcuts.$explorer
}
} else { # Browser options
Add-Shortcut -Path $($shortcuts.$Browser.Path) -Destination $Browser
New-Shortcut -Source $($shortcuts.$Browser.Path) -Destination "$tmp\$Browser.lnk"
$regTaskbar = $shortcuts.$Browser
}

Expand Down

0 comments on commit 6fc9483

Please sign in to comment.