Kodi Community Forum
[WINDOWS] Plugin or script to update Third-Party SVN builds? - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: General Support (https://forum.kodi.tv/forumdisplay.php?fid=111)
+---- Forum: Windows (https://forum.kodi.tv/forumdisplay.php?fid=59)
+---- Thread: [WINDOWS] Plugin or script to update Third-Party SVN builds? (/showthread.php?tid=47281)

Pages: 1 2 3 4 5


[WINDOWS] Plugin or script to update Third-Party SVN builds? - rimmi2002 - 2009-03-21

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.


- mpw222 - 2009-03-21

I wrote a powershell script that does this for the jester builds. It needs to be run outside xbmc (it will close xbmc if running), and it requires .net 2 and powershell. I just have eventghost launch it. PM me if you're interested.


- febox-pootz - 2009-03-21

i'm interested too... can you send me please? thanks man


- Livin - 2009-03-21

mpw,
maybe you can post it and someone might be able to convert it to an XBMC script?


- kay.one - 2009-03-22

could you please post the script on pastbin or even here so we can all use it,


- mpw222 - 2009-03-22

OK, here it is. I borrowed a wget function from a PowerShell repository, which is why it is written much better than the rest of the script. I'm definitely a scripting novice, so I encourage anyone to improve this or convert it to something that can be launched from inside xbmc.

What it does:
1. Downloads the html listing of jester's builds.
2. If a newer version is found (based on build number), the installer is downloaded. On the first run, it will always download the newest build.
3. The existing imdb scraper is preserved.
4. If xbmc is running, it gets closed.
5. New build installs silently.
6. Previous imdb scraper restored.
7. Build number written to ver.txt in xbmc directory.
8. XBMC starts in fullscreen.

How to run it:
1. Vista and XP only: Download Powershell 2 CTP3 (PowerShell 1.0 might work).
2. XP only: Download .NET 3.5 (2.0 might work)
3. Open a PowerShell prompt. In Vista/7, you'll need to run as an admin.
4. Run "set-executionpolicy remotesigned"
5. From here on, it can be run with powershell.exe <path>\update-xbmc.ps1 by an administrator.

Notes
1. Tested on XP, Vista and 7, x86 and x64. Running from a remote on Vista or 7 pretty much requires turning off UAC.

Code:
###################################################################################
# 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



- kricker - 2009-03-22

If someone gets this working stable in a XBMC plugin like BigBellyBilly's XBMC T3CH updater script, I'll setup a ftp/http site for Ikons and myself to post our builds. Jester to if he likes, but it looks like he already has a good system in place for himself.

I was told once a long time ago by BigBellyBilly that he'd welcome someone to modify his script for such an endeavor.


- kay.one - 2009-03-24

if you could upload your files to a simple html page, that could be parsed easily or even with an rrs feed i could modify this script to pick up any of the builds based on a parameter.


- kricker - 2009-03-24

PM me with directions on how you need it structured and we can start testing.


- xexe - 2009-03-24

Something worth considering in this excellent project is that each build exe should identify more than the vanilla build number.

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.


- kricker - 2009-03-24

xexe Wrote:Something worth considering in this excellent project is that each build exe should identify more than the vanilla build number.

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.
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.


- xexe - 2009-03-24

Thats sounds absolutely true to me... however what hasn't historically been universally identified is the builder which is also very important to ensure that a build problem with one builder is identifiable as such.

I would suggest something simple like (example only):

XBMCSetup-Rev17788-kricker-trunk.exe

which could signify

1. XBMCSetup - Obviously that it is an XBMC setup file
2. Rev17788 - the build number
3. kricker - the builder
4. trunk - some word to signify that it is a "vanilla" build. In general i always find it better to explicitly say something than rely on an implicit implication i.e. the absense of a word shouldnt mean something

These are only ideas for consideration, the details as always should be up for debate and ideas Smile


- kay.one - 2009-03-25

instead of putting everything in the file name we could create a "list.xml" that contains the download url for the build and all the attributes of that build as the elements.

also on a different topic, i was thinking of moving this script to a windows application or form that could run on the background with a GUI to make it simpler for users to install and configure. powershell might not be the most user friendly way, I am in no way a powershell programmer but i write windows services and background applications for living so i could easily start that effort.


- xexe - 2009-03-25

I had thought about a list.xml type solution. The problem I see with it is that people that grab the files directly will have problems identifying what they are after the fact. Perhaps this isnt really a problem in reality if everyone uses the plugin.

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.

The other thing it has to cater for is not grabbing every SVN. What we dont want is a tool that runs all the time and grabs every single release. Multiply this by the XBMC user base and it gets silly traffic wise especially since no one wants to upgrade this often.

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 etc


- kricker - 2009-03-25

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 etc
Is 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.

The biggest thing is, the installer needs to be able to roll back if something is wrong with the new version. Have you all looked at BBB's T3CH upgrader script? We pretty much need something just like it but working on win32.

If in place upgrade is wanted, then there will need to be some sort of application or batch that is run to do it. After all you can't do an in place upgrade if XBMC is currently running.