mirror of
https://github.com/ScoopInstaller/Scoop.git
synced 2026-09-23 22:06:07 +00:00
Merge branch 'release/2019-05-15'
This commit is contained in:
+29
-1
@@ -112,6 +112,7 @@ $Queue | ForEach-Object {
|
||||
}
|
||||
$regex = ''
|
||||
$jsonpath = ''
|
||||
$xpath = ''
|
||||
$replace = ''
|
||||
|
||||
if ($json.checkver -eq 'github') {
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -159,6 +163,7 @@ $Queue | ForEach-Object {
|
||||
regex = $regex;
|
||||
json = $json;
|
||||
jsonpath = $jsonpath;
|
||||
xpath = $xpath;
|
||||
reverse = $reverse;
|
||||
replace = $replace;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
+27
-16
@@ -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) {
|
||||
@@ -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")) {
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -43,11 +43,15 @@
|
||||
"pattern": "^\\$[.[].*$",
|
||||
"type": "string"
|
||||
},
|
||||
"xpath": {
|
||||
"type": "string"
|
||||
},
|
||||
"mode": {
|
||||
"enum": [
|
||||
"download",
|
||||
"extract",
|
||||
"json",
|
||||
"xpath",
|
||||
"rdf",
|
||||
"metalink",
|
||||
"fosshub",
|
||||
@@ -237,6 +241,9 @@
|
||||
"pattern": "^\\$[.[].*$",
|
||||
"type": "string"
|
||||
},
|
||||
"xpath": {
|
||||
"type": "string"
|
||||
},
|
||||
"reverse": {
|
||||
"description": "Reverse the order of regex matches",
|
||||
"type": "boolean"
|
||||
|
||||
Reference in New Issue
Block a user