diff --git a/App/AppInfo/appinfo.ini b/App/AppInfo/appinfo.ini index 5561441..4ac3089 100644 Binary files a/App/AppInfo/appinfo.ini and b/App/AppInfo/appinfo.ini differ diff --git a/App/AppInfo/update.ini b/App/AppInfo/update.ini new file mode 100644 index 0000000..52284e8 --- /dev/null +++ b/App/AppInfo/update.ini @@ -0,0 +1,13 @@ +[Version] +Package = 1.8.3.0 +Display = 1.8.3-beta1-uroesch + +[Archive] +URL1 = https://netcologne.dl.sourceforge.net/project/ldapadmin/ldapadmin/1.8.3/LdapAdminExe-w64-1.8.3.zip +Checksum1 = SHA256:E2E9A3603150D14E2F7AE2CD85878CE187D953FF8FA01FCAA5B73949E573A4DE +TargetDir1 = LdapAdmin64.exe +ExtractDir1 = LdapAdmin.exe +URL2 = https://netcologne.dl.sourceforge.net/project/ldapadmin/ldapadmin/1.8.3/LdapAdminExe-w32-1.8.3.zip +Checksum2 = SHA256:20343E6B2F85E51FFB9CEEB88804CF1E24DA1B1055A48A4AD0ECD170BDDA7BDC +TargetDir2 = LdapAdmin.exe +ExtractDir2 = LdapAdmin.exe diff --git a/Other/Update/Update.ps1 b/Other/Update/Update.ps1 new file mode 100644 index 0000000..40c08fb --- /dev/null +++ b/Other/Update/Update.ps1 @@ -0,0 +1,225 @@ +# ----------------------------------------------------------------------------- +# Description: Generic Update Script for PortableApps +# Author: Urs Roesch +# ----------------------------------------------------------------------------- + +# ----------------------------------------------------------------------------- +# Globals +# ----------------------------------------------------------------------------- +$AppRoot = "$PSScriptRoot\..\.." +$AppInfoDir = "$AppRoot\App\AppInfo" +$AppInfoIni = "$AppInfoDir\appinfo.ini" +$UpdateIni = "$AppInfoDir\update.ini" +$Debug = $True + +# ----------------------------------------------------------------------------- +# Functions +# ----------------------------------------------------------------------------- +Function Debug () { + param( [string] $Message ) + If (-Not($Debug)) { return } + Write-Host $Message +} + +# ----------------------------------------------------------------------------- +Function Parse-Ini { + param ( + $IniFile + ) + + $IniContent = Get-Content $IniFile + + $resulttable=@() + foreach ($line in $IniContent) { + Debug "Processing $line" + if ($line[0] -eq ";") { + Debug "Skip comment line" + } + + elseif ($line[0] -eq "[") { + $Section = $line.replace("[","").replace("]","") + Debug "Found new section: $Section" + } + elseif ($line -like "*=*") { + Debug "Found Keyline" + $resulttable += @{ + Section = $Section + Key = $line.split("=")[0].Trim() + Value = $line.split("=")[1].Trim() + } + } + else { + Debug "Skip line" + } + } + return $resulttable +} + +# ----------------------------------------------------------------------------- +Function Fetch-Section() { + param( [string] $Key ) + $Section = @{} + Foreach ($Item in $Config) { + If ($Item["Section"] -eq $Key) { + $Section += @{ $Item["Key"] = $Item["Value"] } + } + } + return $Section +} + +# ----------------------------------------------------------------------------- +Function Url-Basename { + param( + [string] $URL + ) + $Elements = $URL.split('/') + $Basename = $Elements[$($Elements.Length-1)] + return $Basename +} + +# ----------------------------------------------------------------------------- +Function Check-Sum { + param( + [string] $Checksum, + [string] $File + ) + ($Algorithm, $Sum) = $Checksum.Split(':') + $Result = (Get-FileHash -Path $File -Algorithm $Algorithm).Hash + Debug "Checksum of INI ($Sum) and downloaded file ($Result)" + return ($Sum -eq $Result) +} + +# ----------------------------------------------------------------------------- +Function Download-ZIP { + param( + [string] $URL, + [string] $Checksum + ) + $PathZip = "$PSScriptRoot\$(Url-Basename -URL $URL)" + If (!(Test-Path $PathZip)) { + Debug "Downloading file from '$URL'" + Invoke-WebRequest -Uri $URL -OutFile $PathZip + } + If (!(Check-Sum -Checksum $Checksum -File $PathZip)) { + Debug "Checksum of File $PathZip does not match with '$Checksum'" + Exit 1 + } + Debug "Downloaded ZIP file '$PathZip'" + return $PathZip +} + +# ----------------------------------------------------------------------------- +Function Update-Zip { + param( + [string] $URL, + [string] $TargetDir, + [string] $ExtractDir, + [string] $Checksum + ) + $ZipFile = $(Download-ZIP -URL $URL -Checksum $Checksum) + $TargetPath = "$AppRoot\App\$TargetDir" + Expand-Archive -LiteralPath $ZipFile -DestinationPath $PSScriptRoot -Force + If (Test-Path $TargetPath) { + Write-Output "Removing $TargetPath" + Remove-Item -Path $TargetPath -Force -Recurse + } + Debug "Move $ExtractDir to $TargetPath" + Move-Item -Path $PSScriptRoot\$ExtractDir -Destination $TargetPath -Force + Debug "Cleanup $ZipFile" + Remove-Item $ZipFile +} + +# ----------------------------------------------------------------------------- +Function Update-Appinfo-Item() { + param( + [string] $IniFile, + [string] $Match, + [string] $Replace + ) + If (Test-Path $IniFile) { + $Content = (Get-Content $IniFile) + $Content -replace $Match, $Replace | Out-File -FilePath $IniFile + } +} + +# ----------------------------------------------------------------------------- +Function Update-Appinfo() { + $Version = (Fetch-Section "Version") + Update-Appinfo-Item ` + -IniFile $AppInfoIni ` + -Match '^PackageVersion\s*=.*' ` + -Replace "PackageVersion=$($Version['Package'])" + Update-Appinfo-Item ` + -IniFile $AppInfoIni ` + -Match '^DisplayVersion\s*=.*' ` + -Replace "DisplayVersion=$($Version['Display'])" +} + +# ----------------------------------------------------------------------------- +Function Update-Application() { + $Archive = (Fetch-Section 'Archive') + $Position = 1 + While ($True) { + If (-Not ($Archive.ContainsKey("URL$Position"))) { + Break + } + Update-ZIP ` + -URL $Archive["URL$Position"] ` + -TargetDir $Archive["TargetDir$Position"] ` + -ExtractDir $Archive["ExtractDir$Position"] ` + -Checksum $Archive["Checksum$Position"] + $Position += 1 + } +} + +# ----------------------------------------------------------------------------- +Function Windows-Path() { + param( [string] $Path ) + $Path = $Path -replace ".*drive_(.)", '$1:' + $Path = $Path.Replace("/", "\") + return $Path +} + +# ----------------------------------------------------------------------------- +Function Create-Launcher() { + Set-Location $AppRoot + $AppPath = (Get-Location) + $Launcher = "..\PortableApps.comLauncher\PortableApps.comLauncherGenerator.exe" + If ($AppPath[0] -eq '/') { + Debug "Running Launcher: wine $Launcher $(Windows-Path AppPath)" + Invoke-Expression "wine $Launcher /s $(Windows-Path $AppPath)" + } + Else { + Debug "Running Launcher: wine $Launcher AppPath" + Invoke-Expression "$Launcher $AppPath" + } + Write-FileSystemCache $AppPath.Drive.Name +} + +# ----------------------------------------------------------------------------- +Function Create-Installer() { + Set-Location $AppRoot + $AppPath = (Get-Location) + $Installer = "..\PortableApps.comInstaller\PortableApps.comInstaller.exe" + If ($AppPath[0] -eq '/') { + Debug "Running Installer: wine $Installer $(Windows-Path AppPath)" + Invoke-Expression "wine $Installer $(Windows-Path $AppPath)" + } + Else { + # Windows seems to need a bit of break before + # writing the file completely to disk + Debug "Sleeping ..." + Sleep 5 + Debug "Running Installer: $Installer $AppPath" + Invoke-Expression "$Installer $AppPath" + } +} + +# ----------------------------------------------------------------------------- +# Main +# ----------------------------------------------------------------------------- +$Config = (Parse-Ini $UpdateIni) +Update-Application +Update-Appinfo +Create-Launcher +Create-Installer diff --git a/Other/Update/UpdateLdapAdmin.ps1 b/Other/Update/UpdateLdapAdmin.ps1 deleted file mode 100644 index e8fbdc1..0000000 --- a/Other/Update/UpdateLdapAdmin.ps1 +++ /dev/null @@ -1,65 +0,0 @@ -$AppRoot = "$PSScriptRoot\..\.." -$AppInfoIni = "$AppRoot\App\AppInfo\appinfo.ini" -$PackageVersion = '1.8.3.0' -$DisplayVersion = '1.8.3-beta0-uroesch' -$ZipVersion = '1.8.3' -$Archive64URL = "https://netcologne.dl.sourceforge.net/project/ldapadmin/ldapadmin/$ZipVersion/LdapAdminExe-w32-$ZipVersion.zip" -$TargetDir64 = 'LdapAdmin64.exe' -$ExtractDir64 = 'LdapAdmin.exe' -$Archive32URL = "https://netcologne.dl.sourceforge.net/project/ldapadmin/ldapadmin/$ZipVersion/LdapAdminExe-w32-$ZipVersion.zip" -$TargetDir32 = 'LdapAdmin32.exe' -$ExtractDir32 = 'LdapAdmin.exe' - -Function Url-Basename { - param( - [string] $URL - ) - $Elements = $URL.split('/') - $Basename = $Elements[$($Elements.Length-1)] - return $Basename -} - -Function Download-ZIP { - param( - [string] $URL - ) - $PathZip = "$PSScriptRoot\$(Url-Basename -URL $URL)" - If (!(Test-Path $PathZip)) { - Invoke-WebRequest -Uri $URL -OutFile $PathZip - } - return $PathZip -} - -Function Update-Zip { - param( - [string] $URL, - [string] $TargetDir, - [string] $ExtractDir - ) - $ZipFile = $(Download-ZIP -URL $URL) - $TargetPath = "$AppRoot\App\$TargetDir" - Expand-Archive -LiteralPath $ZipFile -DestinationPath $PSScriptRoot -Force - If (Test-Path $TargetPath) { - Write-Output "Removing $TargetPath" - Remove-Item -Path $TargetPath -Force -Recurse - } - Move-Item -Path $PSScriptRoot\$ExtractDir -Destination $TargetPath -Force - Remove-Item $ZipFile -} - -Function Update-Appinfo() { - param( - [string] $IniFile, - [string] $Match, - [string] $Replace - ) - If (Test-Path $IniFile) { - $Content = (Get-Content $IniFile) - $Content -replace $Match,$Replace | Out-File -FilePath $IniFile - } -} - -Update-ZIP -URL $Archive64URL -TargetDir $TargetDir64 -ExtractDir $ExtractDir64 -Update-ZIP -URL $Archive32URL -TargetDir $TargetDir32 -ExtractDir $ExtractDir32 -Update-Appinfo -IniFile $AppInfoIni -Match '^PackageVersion\s*=.*' -Replace "PackageVersion=$PackageVersion" -Update-Appinfo -IniFile $AppInfoIni -Match '^DisplayVersion\s*=.*' -Replace "DisplayVersion=$DisplayVersion" \ No newline at end of file