-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
137 lines (94 loc) · 3.53 KB
/
Copy pathinstall.ps1
File metadata and controls
137 lines (94 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Clock Overlays Advanced Bootstrapper
$RepoOwner = "deepdeyiitgn"
$RepoName = "Clock-Overlays"
$ApiUrl = "https://api.github.com/repos/$RepoOwner/$RepoName/releases/latest"
$DownloadsFolder = Join-Path $env:USERPROFILE "Downloads"
$LogFolder = Join-Path $DownloadsFolder "ClockOverlays-Logs"
New-Item -ItemType Directory -Force -Path $LogFolder | Out-Null
$Timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$LogFile = Join-Path $LogFolder "InstallLog_$Timestamp.txt"
function Write-Log {
param([string]$Message)
$Time = Get-Date -Format "yyyy-MM-dd HH:mm:ss.fff"
$Line = "[$Time] $Message"
Write-Host $Line
Add-Content -Path $LogFile -Value $Line
}
Write-Log "=================================================="
Write-Log "Clock Overlays Bootstrapper Started"
Write-Log "Computer: $env:COMPUTERNAME"
Write-Log "User: $env:USERNAME"
Write-Log "OS: $([Environment]::OSVersion.VersionString)"
Write-Log "PowerShell: $($PSVersionTable.PSVersion)"
Write-Log "=================================================="
try {
Write-Log "Fetching latest release..."
$Release = Invoke-RestMethod -Uri $ApiUrl
Write-Log "Release Name : $($Release.name)"
Write-Log "Tag Version : $($Release.tag_name)"
Write-Log "Published At : $($Release.published_at)"
$ExeAsset = $Release.assets |
Where-Object { $_.name -like "*.exe" } |
Select-Object -First 1
if (-not $ExeAsset) {
throw "No EXE asset found."
}
Write-Log "Asset Name : $($ExeAsset.name)"
Write-Log "Asset Size : $([Math]::Round($ExeAsset.size / 1MB, 2)) MB"
$InstallerPath = Join-Path $DownloadsFolder $ExeAsset.name
Write-Log "Download URL:"
Write-Log $ExeAsset.browser_download_url
Write-Log "Download Destination:"
Write-Log $InstallerPath
$ProgressPreference = 'Continue'
Write-Progress `
-Activity "Clock Overlays" `
-Status "Downloading installer..." `
-PercentComplete 0
Invoke-WebRequest `
-Uri $ExeAsset.browser_download_url `
-OutFile $InstallerPath
Write-Progress `
-Activity "Clock Overlays" `
-Status "Download Complete" `
-PercentComplete 100
Write-Log "Download completed successfully."
if (-not (Test-Path $InstallerPath)) {
throw "Downloaded file not found."
}
$FileInfo = Get-Item $InstallerPath
Write-Log "Downloaded File Size:"
Write-Log "$([Math]::Round($FileInfo.Length / 1MB, 2)) MB"
Write-Log "Launching installer..."
# If using Inno Setup in future:
# $InstallerArgs = "/LOG=`"$LogFolder\Installer_$Timestamp.log`""
$Process = Start-Process `
-FilePath $InstallerPath `
-PassThru
Write-Log "Installer PID: $($Process.Id)"
while (-not $Process.HasExited) {
Write-Progress `
-Activity "Installer Running" `
-Status "Waiting for installer to finish..." `
-PercentComplete 50
Start-Sleep -Seconds 2
$Process.Refresh()
Write-Log "Installer still running..."
}
Write-Progress `
-Activity "Installer Running" `
-Status "Installer Finished" `
-PercentComplete 100
Write-Log "Installer Exit Code: $($Process.ExitCode)"
Write-Log "Installer finished."
}
catch {
Write-Log "ERROR OCCURRED"
Write-Log $_.Exception.Message
Write-Log $_
}
Write-Log "=================================================="
Write-Log "Bootstrapper Finished"
Write-Log "Log Saved To:"
Write-Log $LogFile
Write-Log "=================================================="