Skip to content
Snippets Groups Projects
Commit 28a7dc92 authored by Saad Chaaban's avatar Saad Chaaban
Browse files

package_auto_updater_RStudio.ps1 hochgeladen.

parent 13d8316d
No related branches found
No related tags found
1 merge request!7Scripte aktualisiert
$SOURCE_FILE = '\\husowi28c.user.hu-berlin.de\sowiabteilungen\edv\chocolatey-packages\R.Studio\tools\chocolateyInstall.ps1'
$Online_Url = 'https://posit.co/download/rstudio-desktop/#download'
$Date = Get-Date -Format "yyyy-MM-dd"
$BACKUP_FILE = '\\husowi28c.user.hu-berlin.de\sowiabteilungen\edv\chocolatey-packages\R.Studio\tools\'+$Date+'_BAK_chocolateyInstall.ps1'
$NUSPEC = '\\husowi28c.user.hu-berlin.de\sowiabteilungen\edv\chocolatey-packages\R.Studio\R.Studio.nuspec'
$NUSPEC_BACKUP = '\\husowi28c.user.hu-berlin.de\sowiabteilungen\edv\chocolatey-packages\R.Studio\R.Studio.nuspec.BAK'
<#
Schritt 1
Alte Chocolatey Dateien Auslesen und String der URL sichern!
#>
$OLD_URL = Get-Content $SOURCE_FILE | Select -Index 4
<#
Entferne Nicht gewünschte Zeichen aus dem String.
Kurze regex Erklärung
Alles vor https://
Mögliche Sonderzeichen im Code
Entferne alle (falls vorhanden) Leerzeichen vor dem https
#>
$OLD_URL = $OLD_URL -replace '.*(?=https://)' `
-replace '[<>'']' `
-replace '\s'
<#
Schritt 2
WebRequest auf die R.Studio Seite.
Alle Links Filtern.
Nur den Link der Exe File kopieren.
#>
$Updated_URL = (Invoke-WebRequest $Online_URL -UseBasicParsing).Links | Select-Object -Property href | where href -like 'https://download1.rstudio.org/electron/windows/*.exe'
$case = 0
while ( $case -ne 999 ) {
switch ( $case ) {
0 {
<#
Ist unser Script up to Date?
Vergleiche die alte URL mit der neuen IRL
#>
$match = $Updated_URL.href[-1] -eq $OLD_URL
If(-Not $match) {
Write-Output "Neue Version verfügbar!";
$case = 1
}
else {
$case = 999
Write-Host "Everything is Fine!";
}
}
1 {
$match= Get-Item $BACKUP_FILE
If(-Not $match) {
Write-Output "Erstelle Backup!";
Copy-Item $SOURCE_FILE -Destination $BACKUP_FILE -Force -Recurse
$case = 2
}
else {
$case = 2
}
}
2 {
<# CASE2
Dateien bearbeiten
#>
# Hashwerte aus alter Datei lesen
$OLD_SHA = Get-Content $SOURCE_FILE | Select -Index 6
$OLD_SHA = $OLD_SHA -replace "'"
$wc = [System.Net.WebClient]::new()
$NEW_SHA = Get-FileHash -InputStream ($wc.OpenRead($Updated_URL.href[-1]))
Write-Host -NoNewline "URL Online: "
$Updated_URL.href[-1]
Write-Host -NoNewline "Hashwert Online: ";
$NEW_SHA.Hash.ToLower()
<#
ERSETZE SHA UND URL IN FILE
#>
(Get-Content $SOURCE_FILE).Replace($OLD_URL,$Updated_URL.href[-1]) | Set-Content $SOURCE_FILE
(Get-Content $SOURCE_FILE).Replace($OLD_SHA.substring(13),$NEW_SHA.Hash.ToLower()) | Set-Content $SOURCE_FILE
<#
Updaten der Nuspec File!
#>
Copy-Item $NUSPEC -Destination $NUSPEC_BACKUP -Force -Recurse
# Lese die Version aus der URL heraus
$Version = $Updated_URL.href[-1]
$Version = $Version.substring($Version.length - 17, 9)
$Version = " <version>$Version</version>"
$content = Get-Content $NUSPEC
$content[19] = $Version
# Schreibe neu Version in die Datei!
$content| Out-File $NUSPEC
$case = 3
}
3 {
<#
Pushen des aktualisierten Pakets
Noch nicht aktiv da dies mit einer Chocolatey Abfrage gekoppelt werden sollte!
$nupkg = choco pack $NUSPEC
$nupkg = $nupkg -replace "'" | Select -index 2
choco push $nupkg.Substring(29) --source=https://push.chocolatey.org/
Remove-Item $nupkg.Substring(29)
#>
$case = 999
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment