2009-03-21, 17:51
Is there an script or plugin that can automatically update my XBMC with the new revs so I don't have to keep downloading the latest building and reinstalling them, Thanks.
###################################################################################
# Script: Update-XBMC.ps1 #
# Purpose: Update script for Jester Windows XBMC SVN builds. #
# Author: mpw222, get-webfile function by Joel Bennett (http://poshcode.org/417) #
###################################################################################
# Paramaters
param(
[switch]$force, # Forces installation of newest build
[switch]$norestart, # Does not restart xbmc
[switch]$check, # Performs version check only
[switch]$help # Prints usage
)
# User Defined
$xbmcurl="http://ocs.nl/xbmc/"
# Usage
if ($help) {
"Update-XBMC.ps1 - An update script for Jester Windows XBMC SVN builds.`n"
"Switches:"
"-force Forces installation of newest build"
"-norestart Does not restart xbmc"
"-check Performs version check only"
"-help Prints usage"
exit 0
}
# Functions
###################################################
# Function: Get-WebFile #
# Purpose: wget for PowerShell #
# Author: Joel Bennett http://poshcode.org/417 #
###################################################
function Get-WebFile {
param(
$url = (Read-Host "The URL to download"),
$fileName = $null,
[switch]$Passthru,
[switch]$quiet
)
$req = [System.Net.HttpWebRequest]::Create($url);
$res = $req.GetResponse();
if($fileName -and !(Split-Path $fileName)) {
$fileName = Join-Path (Get-Location -PSProvider "FileSystem") $fileName
}
elseif((!$Passthru -and ($fileName -eq $null)) -or (($fileName -ne $null) -and (Test-Path -PathType "Container" $fileName)))
{
[string]$fileName = ([regex]'(?i)filename=(.*)$').Match( $res.Headers["Content-Disposition"] ).Groups[1].Value
$fileName = $fileName.trim("\/""'")
if(!$fileName) {
$fileName = $res.ResponseUri.Segments[-1]
$fileName = $fileName.trim("\/")
if(!$fileName) {
$fileName = Read-Host "Please provide a file name"
}
$fileName = $fileName.trim("\/")
if(!([IO.FileInfo]$fileName).Extension) {
$fileName = $fileName + "." + $res.ContentType.Split(";")[0].Split("/")[1]
}
}
$fileName = Join-Path (Get-Location -PSProvider "FileSystem") $fileName
}
if($Passthru) {
$encoding = [System.Text.Encoding]::GetEncoding( $res.CharacterSet )
[string]$output = ""
}
if($res.StatusCode -eq 200) {
[int]$goal = $res.ContentLength
$reader = $res.GetResponseStream()
if($fileName) {
$writer = new-object System.IO.FileStream $fileName, "Create"
}
[byte[]]$buffer = new-object byte[] 4096
[int]$total = [int]$count = 0
do
{
$count = $reader.Read($buffer, 0, $buffer.Length);
if($fileName) {
$writer.Write($buffer, 0, $count);
}
if($Passthru){
$output += $encoding.GetString($buffer,0,$count)
} elseif(!$quiet) {
$total += $count
if($goal -gt 0) {
Write-Progress "Downloading $url" "Saving $total of $goal" -id 0 -percentComplete (($total/$goal)*100)
} else {
Write-Progress "Downloading $url" "Saving $total bytes..." -id 0
}
}
} while ($count -gt 0)
$reader.Close()
if($fileName) {
$writer.Flush()
$writer.Close()
}
if($Passthru){
$output
}
}
$res.Close();
}
#######################################################
# Function: Get-PFx86 #
# Purpose: Returns the 32-bit Program Files directory #
#######################################################
function Get-PFx86 {
if ($env:processor_architecture -match "x86") {
$pf=$env:programfiles
} else {
$pf=${env:ProgramFiles(x86)}
}
return $pf
}
########
# MAIN #
########
$lockfile=join-path $env:temp (($myinvocation.mycommand).tostring() + ".lock")
if (!$force) {
if ((test-path $lockfile) -eq $true) {
$lockage=((get-date) - ((dir $lockfile).lastwritetime)).hours
if ($lockage -lt 1) {
"Lock file detected, script closing"
exit 1
}
}
}
"lock" > $lockfile
if ((get-host).name -match "ConsoleHost") {"`n`n`n`n"}
$pf=Get-PFx86
$versionfile=Join-Path (Get-PFx86) "XBMC\ver.txt"
if (test-path $versionfile) {
$currentversion=get-content $versionfile
"XBMC SVN-$currentversion currently installed."
} else {
$currentversion="0"
"XBMC not installed or no version file."
}
$htmlfile=join-path $env:temp "xbmc.html"
Get-WebFile $xbmcurl $htmlfile
$link=get-content $htmlfile | select-string "XBMCSetup-Rev\d+-jester.exe" | sort-object -descending | select-object -first 1
$newversion = ($link.tostring() -replace ".*href=`"XBMCSetup-Rev","") -replace "-jester`.exe.*",""
"XBMC SVN-$newversion available online."
if ($newversion -le $currentversion) {
"Latest version already installed."
if ($force) {
"Force switch detected, installing anyway."
} else {
"Script closing."
remove-item $htmlfile
Remove-Item $lockfile
exit 0
}
}
if ($check) {
"Check switch enabled, script closing."
Remove-Item $lockfile
exit 0
}
$installerfile= ($link.tostring() -replace ".*XBMC","XBMC") -replace "`.exe.*","`.exe"
$installerlink=$xbmcurl + $installerfile
$installerpath=join-path $env:temp $installerfile
"Downloading XBMC SVN-$newversion."
Get-WebFile $installerlink $installerpath
$imdbfile=join-path $pf "XBMC\system\scrapers\video\imdb.xml"
if (test-path $imdbfile) {$imdbxml=get-content $imdbfile}
Get-Process | ? {$_.ProcessName -match "xbmc"} | Stop-Process
"Installing XBMC SVN-$newversion."
Start-Process $installerpath -wait -ArgumentList "/S"
"Installation complete, removing installer."
remove-item $installerpath
$newversion > $versionfile
if ($xbmcxml) {$imdbxml > $imdbfile}
if (!$norestart) {Start-Process (join-path $pf "XBMC\xbmc.exe") -ArgumentList "-fs"}
remove-item $htmlfile
remove-item $lockfile
exit 0
xexe Wrote:Something worth considering in this excellent project is that each build exe should identify more than the vanilla build number.That's IF the build contains anything other than a straight SVN build. When that does happen I think we have always identified them as such.
Jesters format of:
XBMCSetup-Rev17788-jester-ext.exe
Is a good model to build upon. The main thing would be that if someone wanted say "the new Ikons with smoothvideo and HD tagging" if such a thing existed the filename contained that info.
xexe Wrote:Perhaps we can take this logic further and have community "SVN Stables". These could be releases tagged as working really well. Then if there is a problem in SVN we could provide a means for users that have ticked "only use stable svns" to not end up with a broken version. This helps users stay up to date without having to follow TRAC so closely and reduces bandwidth usage etcIs someone going to beta test our SVN builds? I doubt that. I don't even always have time to run the build after I make it.
xexe Wrote:The main thing the downloading tool needs to accommodate is the diverse user inputs people control XBMC with. What we do not want is every single user having to manually alter their setup to run it. In a perfect world it should be runable from within XBMC.