i have XML file and i am trying to get the URL ends with RosettaUpdateAuto.pkg compared with BuildVersion if equals and fetch the url for the RosettaUpdateAuto.pkg.
BuildVersion 20A5374g is equals and get the URL : https://swcdn.apple.com/content/downloads/04/39/001-50263-A_LEF5A7Q02Z/s4d18996ppu4gczumkptqmljgay795qmvl/RosettaUpdateAuto.pkg
<dict>
<key>CatalogVersion</key>
<integer>2</integer>
<key>ApplePostURL</key>
<string></string>
<key>IndexDate</key>
<date>2023-01-13T00:35:44Z</date>
<key>Products</key>
<dict>
<key>001-50263</key>
<dict>
<key>ServerMetadataURL</key>
<string>https://swcdn.apple.com/content/downloads/04/39/001-50263-A_LEF5A7Q02Z/s4d18996ppu4gczumkptqmljgay795qmvl/RosettaUpdateAuto.smd</string>
<key>Packages</key>
<array>
<dict>
<key>Digest</key>
<string>f3a58e780d28ecbdbad32c66049abdb235352245</string>
<key>Size</key>
<integer>392574</integer>
<key>MetadataURL</key>
<string>https://swdist.apple.com/content/downloads/04/39/001-50263-A_LEF5A7Q02Z/s4d18996ppu4gczumkptqmljgay795qmvl/RosettaUpdateAuto.pkm</string>
<key>URL</key>
<string>https://swcdn.apple.com/content/downloads/04/39/001-50263-A_LEF5A7Q02Z/s4d18996ppu4gczumkptqmljgay795qmvl/RosettaUpdateAuto.pkg</string>
</dict>
</array>
<key>ExtendedMetaInfo</key>
<dict>
<key>ProductType</key>
<string>otherArchitectureHandlerOS</string>
<key>BuildVersion</key>
<string>20A5374g</string>
</dict>
<key>PostDate</key>
<date>2020-09-18T01:24:13Z</date>
<key>Distributions</key>
</dict>
</dict>
</dict>
CodePudding user response:
Like this:
url=$(xmllint --xpath '//key[text()="ExtendedMetaInfo"]/following-sibling::dict/string[2][text() = "20A5374g"]/../../array/dict/string[contains(., "pkg")]/text()' file.xml)
[[ $url ]] && wget "$url"