Skip to content

Commit

Permalink
Merge branch 'release/2019-05-15'
Browse files Browse the repository at this point in the history
  • Loading branch information
r15ch13 committed May 15, 2019
2 parents 87a1e78 + 765706c commit 731d878
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 17 deletions.
30 changes: 29 additions & 1 deletion bin/checkver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ $Queue | ForEach-Object {
}
$regex = ''
$jsonpath = ''
$xpath = ''
$replace = ''

if ($json.checkver -eq 'github') {
Expand Down Expand Up @@ -140,12 +141,15 @@ $Queue | ForEach-Object {
if ($json.checkver.jsonpath) {
$jsonpath = $json.checkver.jsonpath
}
if ($json.checkver.xpath) {
$xpath = $json.checkver.xpath
}

if ($json.checkver.replace -and $json.checkver.replace.GetType() -eq [System.String]) {
$replace = $json.checkver.replace
}

if (!$jsonpath -and !$regex) {
if (!$jsonpath -and !$regex -and !$xpath) {
$regex = $json.checkver
}

Expand All @@ -159,6 +163,7 @@ $Queue | ForEach-Object {
regex = $regex;
json = $json;
jsonpath = $jsonpath;
xpath = $xpath;
reverse = $reverse;
replace = $replace;
}
Expand All @@ -185,6 +190,7 @@ while ($in_progress -gt 0) {
$url = $state.url
$regexp = $state.regex
$jsonpath = $state.jsonpath
$xpath = $state.xpath
$reverse = $state.reverse
$replace = $state.replace
$expected_ver = $json.version
Expand Down Expand Up @@ -214,11 +220,33 @@ while ($in_progress -gt 0) {
}
}

if ($xpath) {
$xml = [xml]$page
# Find all `significant namespace declarations` from the XML file
$nsList = $xml.SelectNodes("//namespace::*[not(. = ../../namespace::*)]")
# Then add them into the NamespaceManager
$nsmgr = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
$nsList | ForEach-Object {
$nsmgr.AddNamespace($_.LocalName, $_.Value)
}
# Getting version from XML, using XPath
$ver = $xml.SelectSingleNode($xpath, $nsmgr).'#text'
if (!$ver) {
next "couldn't find '$xpath' in $url"
continue
}
}

if ($jsonpath -and $regexp) {
$page = $ver
$ver = ''
}

if ($xpath -and $regexp) {
$page = $ver
$ver = ''
}

if ($regexp) {
$regex = New-Object System.Text.RegularExpressions.Regex($regexp)
if ($reverse) {
Expand Down
41 changes: 41 additions & 0 deletions lib/autoupdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,38 @@ function find_hash_in_json([String] $url, [Hashtable] $substitutions, [String] $
return format_hash $hash
}

function find_hash_in_xml([String] $url, [Hashtable] $substitutions, [String] $xpath) {
$xml = $null

try {
$wc = New-Object Net.Webclient
$wc.Headers.Add('Referer', (strip_filename $url))
$wc.Headers.Add('User-Agent', (Get-UserAgent))
$xml = [xml]$wc.downloadstring($url)
} catch [system.net.webexception] {
write-host -f darkred $_
write-host -f darkred "URL $url is not valid"
return
}

# Replace placeholders
if ($substitutions) {
$xpath = substitute $xpath $substitutions
}

# Find all `significant namespace declarations` from the XML file
$nsList = $xml.SelectNodes("//namespace::*[not(. = ../../namespace::*)]")
# Then add them into the NamespaceManager
$nsmgr = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
$nsList | ForEach-Object {
$nsmgr.AddNamespace($_.LocalName, $_.Value)
}

# Getting hash from XML, using XPath
$hash = $xml.SelectSingleNode($xpath, $nsmgr).'#text'
return format_hash $hash
}

function find_hash_in_headers([String] $url) {
$hash = $null

Expand Down Expand Up @@ -178,6 +210,12 @@ function get_hash_for_app([String] $app, $config, [String] $version, [String] $u
$regex = $config.regex
}

$xpath = ''
if ($config.xpath) {
$xpath = $config.xpath
$hashmode = 'xpath'
}

if (!$hashfile_url -and $url -match "^(?:.*fosshub.com\/).*(?:\/|\?dwl=)(?<filename>.*)$") {
$hashmode = 'fosshub'
}
Expand All @@ -193,6 +231,9 @@ function get_hash_for_app([String] $app, $config, [String] $version, [String] $u
'json' {
$hash = find_hash_in_json $hashfile_url $substitutions $jsonpath
}
'xpath' {
$hash = find_hash_in_xml $hashfile_url $substitutions $xpath
}
'rdf' {
$hash = find_hash_in_rdf $hashfile_url $basename
}
Expand Down
43 changes: 27 additions & 16 deletions libexec/scoop-update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ $quiet = $opt.q -or $opt.quiet
$independent = $opt.i -or $opt.independent

# load config
$repo = $(get_config SCOOP_REPO)
if (!$repo) {
$repo = "https://github.com/lukesampson/scoop"
set_config SCOOP_REPO "$repo" | Out-Null
$configRepo = get_config SCOOP_REPO
if (!$configRepo) {
$configRepo = "https://github.com/lukesampson/scoop"
set_config SCOOP_REPO $configRepo | Out-Null
}

# Find current update channel from config
$branch = $(get_config SCOOP_BRANCH)
if (!$branch) {
$branch = "master"
set_config SCOOP_BRANCH "$branch" | Out-Null
$configBranch = get_config SCOOP_BRANCH
if (!$configBranch) {
$configBranch = "master"
set_config SCOOP_BRANCH $configBranch | Out-Null
}

if(($PSVersionTable.PSVersion.Major) -lt 5) {
Expand Down Expand Up @@ -78,7 +78,7 @@ function update_scoop() {
$newdir = fullpath $(versiondir 'scoop' 'new')

# get git scoop
git_clone -q $repo --branch $branch --single-branch "`"$newdir`""
git_clone -q $configRepo --branch $configBranch --single-branch "`"$newdir`""

# check if scoop was successful downloaded
if (!(test-path "$newdir")) {
Expand All @@ -91,16 +91,27 @@ function update_scoop() {
} else {
Push-Location $currentdir

# Change branch if user configured other branch
if (!((git_branch) -match "\*\s+$branch")) {
# reset git fetch refs (GH-3368)
$currentRepo = git_config remote.origin.url
$currentBranch = git_branch

$isRepoChanged = !($currentRepo -match $configRepo)
$isBranchChanged = !($currentBranch -match "\*\s+$configBranch")

# Change remote url if the repo is changed
if ($isRepoChanged) {
git_config remote.origin.url "$configRepo"
}

# Fetch and reset local repo if the repo or the branch is changed
if ($isRepoChanged -or $isBranchChanged) {
# Reset git fetch refs, so that it can fetch all branches (GH-3368)
git_config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
# fetch remote branches
git_fetch --force origin -q
# fetch remote branch
git_fetch --force origin "refs/heads/`"$configBranch`":refs/remotes/origin/$configBranch" -q
# checkout and track the branch
git_checkout -B $branch -t origin/$branch -q
git_checkout -B $configBranch -t origin/$configBranch -q
# reset branch HEAD
git_reset --hard origin/$branch -q
git_reset --hard origin/$configBranch -q
} else {
git_pull -q
}
Expand Down
7 changes: 7 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@
"pattern": "^\\$[.[].*$",
"type": "string"
},
"xpath": {
"type": "string"
},
"mode": {
"enum": [
"download",
"extract",
"json",
"xpath",
"rdf",
"metalink",
"fosshub",
Expand Down Expand Up @@ -237,6 +241,9 @@
"pattern": "^\\$[.[].*$",
"type": "string"
},
"xpath": {
"type": "string"
},
"reverse": {
"description": "Reverse the order of regex matches",
"type": "boolean"
Expand Down

0 comments on commit 731d878

Please sign in to comment.