Skip to content

Instantly share code, notes, and snippets.

@larsemil
Created March 26, 2024 09:35
Show Gist options
  • Save larsemil/d97d005f513d0aa48980cd524e87da16 to your computer and use it in GitHub Desktop.
Save larsemil/d97d005f513d0aa48980cd524e87da16 to your computer and use it in GitHub Desktop.
# Konfiguration
$OWNER = "2047-Science-Center"
$REPO = ""
$FILE_PATH = [System.Environment]::GetFolderPath("MyDocuments") # Använder användarens Dokument-mapp
$TOKEN = "" # Ersätt med din faktiska GitHub token
$VERSION_FILE = Join-Path $FILE_PATH "latestVersion.txt"
$API_URL = "https://api.github.com/repos/$OWNER/$REPO"
# Hämta den senaste releasen med Invoke-RestMethod
$headers = @{
Authorization = "token $TOKEN"
}
$LATEST_RELEASE_JSON = Invoke-RestMethod -Uri "$API_URL/releases/latest" -Method Get -Headers $headers
# Kontrollera om vi redan har laddat ner denna version
$DOWNLOAD = $true
if (Test-Path $VERSION_FILE) {
$STORED_VERSION = Get-Content $VERSION_FILE
if ($LATEST_RELEASE_JSON.tag_name -eq $STORED_VERSION) {
Write-Host "Senaste versionen ($($LATEST_RELEASE_JSON.tag_name)) är redan nedladdad."
$DOWNLOAD = $false
}
}
if ($DOWNLOAD) {
# Extrahera asset_id
$ASSET_ID = $LATEST_RELEASE_JSON.assets[0].id
# Ladda ner filen med API och asset ID
$DOWNLOAD_URL = "$API_URL/releases/assets/$ASSET_ID"
Write-Host "Laddar ner asset med ID $ASSET_ID från $DOWNLOAD_URL..."
Invoke-RestMethod -Uri $DOWNLOAD_URL -Headers @{Authorization="token $TOKEN"; Accept="application/octet-stream"} -OutFile "$FILE_PATH\latest.zip"
# Kontrollera om filen laddades ner och uppdatera versionsfilen
if (Test-Path "$FILE_PATH\latest.zip") {
Write-Host "Filen laddades ner till $FILE_PATH\latest.zip. Uppdaterar version till $($LATEST_RELEASE_JSON.tag_name)."
Set-Content $VERSION_FILE $LATEST_RELEASE_JSON.tag_name
Expand-Archive -Path "$FILE_PATH\latest.zip" -DestinationPath $FILE_PATH -Force
& "$FILE_PATH\Linux\Eco_Loco.sh"
} else {
Write-Host "Det gick inte att ladda ner filen."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment