Compare commits
3
Commits
618b2b9483
...
d34ec2d974
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d34ec2d974 | ||
|
|
266eb7fb75 | ||
|
|
b240b07f3a |
@@ -0,0 +1,380 @@
|
||||
```powershell
|
||||
#!/usr/bin/env pwsh
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
Write-Host "Welcome to logofclient!"
|
||||
Write-Host "(c)2026 - MyPapertown, MyPaperCloud, Elias Fierke"
|
||||
Write-Host "Version 1.0"
|
||||
Write-Host ""
|
||||
Write-Host "Note: Windows (Un)Installer has been implemented with AI and is untested. Please report to fierke@mypapertown.de"
|
||||
Write-Host ""
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Configuration
|
||||
# ------------------------------------------------------------
|
||||
|
||||
$GiteaUrl = if ($env:GITEA_URL) { $env:GITEA_URL } else { "https://git.mypapercloud.de" }
|
||||
$Owner = if ($env:OWNER) { $env:OWNER } else { "fierke" }
|
||||
$Repo = if ($env:REPO) { $env:REPO } else { "logofclient" }
|
||||
|
||||
$InstallDir = Join-Path $env:ProgramFiles "logofclient"
|
||||
$VersionFile = Join-Path $InstallDir ".version"
|
||||
|
||||
$StartMenuDir = Join-Path `
|
||||
$env:ProgramData `
|
||||
"Microsoft\Windows\Start Menu\Programs"
|
||||
|
||||
$ShortcutPath = Join-Path `
|
||||
$StartMenuDir `
|
||||
"logofclient.lnk"
|
||||
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Administrator privileges
|
||||
# ------------------------------------------------------------
|
||||
|
||||
function Test-IsAdministrator {
|
||||
$Identity = [Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$Principal = New-Object Security.Principal.WindowsPrincipal($Identity)
|
||||
|
||||
return $Principal.IsInRole(
|
||||
[Security.Principal.WindowsBuiltInRole]::Administrator
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
function Ensure-Administrator {
|
||||
if (Test-IsAdministrator) {
|
||||
return
|
||||
}
|
||||
|
||||
Write-Host "Administrator privileges are required."
|
||||
Write-Host "Requesting elevation..."
|
||||
|
||||
# Reconstruct the original arguments
|
||||
$ArgumentList = @(
|
||||
"-NoProfile"
|
||||
"-ExecutionPolicy"
|
||||
"Bypass"
|
||||
"-File"
|
||||
"`"$PSCommandPath`""
|
||||
)
|
||||
|
||||
foreach ($Arg in $args) {
|
||||
$ArgumentList += "`"$Arg`""
|
||||
}
|
||||
|
||||
Start-Process `
|
||||
-FilePath "powershell.exe" `
|
||||
-ArgumentList $ArgumentList `
|
||||
-Verb RunAs
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Help
|
||||
# ------------------------------------------------------------
|
||||
|
||||
function Show-Help {
|
||||
Write-Host "-- HELP --"
|
||||
Write-Host " -v | Print the current application version"
|
||||
Write-Host " -h | Show this help text"
|
||||
Write-Host " -y | Answer all questions with yes"
|
||||
Write-Host ""
|
||||
Write-Host "-- COMMANDS --"
|
||||
Write-Host " install | install logofclient to your Windows-system"
|
||||
Write-Host " update | update logofclient to the newest version"
|
||||
Write-Host " uninstall | remove logofclient from your system"
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Gitea
|
||||
# ------------------------------------------------------------
|
||||
|
||||
function Get-LatestRelease {
|
||||
$Api = "$($GiteaUrl.TrimEnd('/'))/api/v1"
|
||||
|
||||
Write-Host "Fetching version..."
|
||||
|
||||
return Invoke-RestMethod `
|
||||
-Uri "$Api/repos/$Owner/$Repo/releases/latest" `
|
||||
-Method Get
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Install
|
||||
# ------------------------------------------------------------
|
||||
|
||||
function Install {
|
||||
Ensure-Administrator
|
||||
|
||||
$Release = Get-LatestRelease
|
||||
$Tag = $Release.tag_name
|
||||
|
||||
Write-Host "Installing logofclient $Tag..."
|
||||
|
||||
$AssetName = "logofclient-$Tag-win.zip"
|
||||
|
||||
$Asset = $Release.assets |
|
||||
Where-Object { $_.name -eq $AssetName } |
|
||||
Select-Object -First 1
|
||||
|
||||
if (-not $Asset) {
|
||||
throw "Could not find release asset '$AssetName'."
|
||||
}
|
||||
|
||||
$AssetUrl = $Asset.browser_download_url
|
||||
|
||||
Write-Host "Downloading package: $AssetUrl"
|
||||
|
||||
$TempDir = Join-Path `
|
||||
$env:TEMP `
|
||||
"logofclient-install"
|
||||
|
||||
$Archive = Join-Path `
|
||||
$TempDir `
|
||||
$AssetName
|
||||
|
||||
if (Test-Path $TempDir) {
|
||||
Remove-Item `
|
||||
$TempDir `
|
||||
-Recurse `
|
||||
-Force
|
||||
}
|
||||
|
||||
New-Item `
|
||||
-ItemType Directory `
|
||||
-Path $TempDir | Out-Null
|
||||
|
||||
Invoke-WebRequest `
|
||||
-Uri $AssetUrl `
|
||||
-OutFile $Archive
|
||||
|
||||
Write-Host "Installing to: $InstallDir"
|
||||
|
||||
# Remove previous installation
|
||||
if (Test-Path $InstallDir) {
|
||||
Remove-Item `
|
||||
$InstallDir `
|
||||
-Recurse `
|
||||
-Force
|
||||
}
|
||||
|
||||
New-Item `
|
||||
-ItemType Directory `
|
||||
-Path $InstallDir | Out-Null
|
||||
|
||||
# Extract ZIP
|
||||
Expand-Archive `
|
||||
-Path $Archive `
|
||||
-DestinationPath $InstallDir `
|
||||
-Force
|
||||
|
||||
# Save installed version
|
||||
Set-Content `
|
||||
-Path $VersionFile `
|
||||
-Value $Tag `
|
||||
-Encoding UTF8
|
||||
|
||||
# Find executable
|
||||
$Executable = Join-Path `
|
||||
$InstallDir `
|
||||
"Logof Client.exe"
|
||||
|
||||
if (-not (Test-Path $Executable)) {
|
||||
throw "Executable '$Executable' was not found after installation."
|
||||
}
|
||||
|
||||
# --------------------------------------------------------
|
||||
# Start Menu shortcut
|
||||
# --------------------------------------------------------
|
||||
|
||||
Write-Host "Creating Start Menu shortcut..."
|
||||
|
||||
New-Item `
|
||||
-ItemType Directory `
|
||||
-Path $StartMenuDir `
|
||||
-Force | Out-Null
|
||||
|
||||
$Shell = New-Object -ComObject WScript.Shell
|
||||
|
||||
$Shortcut = $Shell.CreateShortcut($ShortcutPath)
|
||||
|
||||
$Shortcut.TargetPath = $Executable
|
||||
$Shortcut.WorkingDirectory = $InstallDir
|
||||
$Shortcut.Description = "logofclient"
|
||||
|
||||
$IconPath = Join-Path `
|
||||
$InstallDir `
|
||||
"assets\icon.ico"
|
||||
|
||||
if (Test-Path $IconPath) {
|
||||
$Shortcut.IconLocation = $IconPath
|
||||
}
|
||||
|
||||
$Shortcut.Save()
|
||||
|
||||
# Clean up downloaded archive
|
||||
Remove-Item `
|
||||
$TempDir `
|
||||
-Recurse `
|
||||
-Force
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Installed logofclient $Tag successfully."
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Uninstall
|
||||
# ------------------------------------------------------------
|
||||
|
||||
function Uninstall {
|
||||
Ensure-Administrator
|
||||
|
||||
Write-Host "Uninstalling logofclient..."
|
||||
|
||||
if (Test-Path $InstallDir) {
|
||||
Remove-Item `
|
||||
$InstallDir `
|
||||
-Recurse `
|
||||
-Force
|
||||
}
|
||||
|
||||
if (Test-Path $ShortcutPath) {
|
||||
Remove-Item `
|
||||
$ShortcutPath `
|
||||
-Force
|
||||
}
|
||||
|
||||
Write-Host "logofclient has been uninstalled."
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Update
|
||||
# ------------------------------------------------------------
|
||||
|
||||
function Update {
|
||||
Ensure-Administrator
|
||||
|
||||
Write-Host "Checking for updates..."
|
||||
|
||||
$InstalledTag = ""
|
||||
|
||||
if (Test-Path $VersionFile) {
|
||||
$InstalledTag = (
|
||||
Get-Content `
|
||||
$VersionFile `
|
||||
-Raw
|
||||
).Trim()
|
||||
}
|
||||
|
||||
$Release = Get-LatestRelease
|
||||
$LatestTag = $Release.tag_name
|
||||
|
||||
Write-Host "Installed version: $InstalledTag"
|
||||
Write-Host "Latest version: $LatestTag"
|
||||
|
||||
if ($InstalledTag -eq $LatestTag) {
|
||||
Write-Host "Already up to date."
|
||||
return
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Updating logofclient: $InstalledTag -> $LatestTag"
|
||||
|
||||
if ($InstalledTag) {
|
||||
Uninstall
|
||||
}
|
||||
|
||||
Install
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Argument parsing
|
||||
# ------------------------------------------------------------
|
||||
|
||||
$AlwaysYes = $false
|
||||
$Command = $null
|
||||
|
||||
foreach ($Arg in $args) {
|
||||
switch ($Arg) {
|
||||
|
||||
"-y" {
|
||||
$AlwaysYes = $true
|
||||
}
|
||||
|
||||
"-h" {
|
||||
Show-Help
|
||||
exit 0
|
||||
}
|
||||
|
||||
"--help" {
|
||||
Show-Help
|
||||
exit 0
|
||||
}
|
||||
|
||||
"-v" {
|
||||
Write-Host "Version 1.0"
|
||||
exit 0
|
||||
}
|
||||
|
||||
"install" {
|
||||
$Command = "install"
|
||||
}
|
||||
|
||||
"update" {
|
||||
$Command = "update"
|
||||
}
|
||||
|
||||
"uninstall" {
|
||||
$Command = "uninstall"
|
||||
}
|
||||
|
||||
default {
|
||||
if ($Arg.StartsWith("-")) {
|
||||
Write-Error "Unknown option: $Arg"
|
||||
}
|
||||
else {
|
||||
Write-Error "Unknown command: $Arg"
|
||||
}
|
||||
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (-not $Command) {
|
||||
Show-Help
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Execute command
|
||||
# ------------------------------------------------------------
|
||||
|
||||
switch ($Command) {
|
||||
|
||||
"install" {
|
||||
Install
|
||||
}
|
||||
|
||||
"update" {
|
||||
Update
|
||||
}
|
||||
|
||||
"uninstall" {
|
||||
Uninstall
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user