forked from ImageOptim/ImageOptim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_appcast.php
More file actions
93 lines (69 loc) · 2.8 KB
/
update_appcast.php
File metadata and controls
93 lines (69 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
$bundleName = "ImageOptim";
$baseURL = dirname(readKey('SUFeedURL'));
$minOSVersion = "10.8";
$exactVersion = readKey('CFBundleVersion');
$niceVersion = readKey('CFBundleShortVersionString');
if (!$niceVersion) $niceVersion = $exactVersion;
$download_url = "$baseURL/$bundleName$niceVersion.tar.bz2";
$archivepath = exec('xcodebuild -project ImageOptim.xcodeproj/ -showBuildSettings 2>/dev/null | fgrep TARGET_BUILD_DIR | awk \'{print $3}\'') . "/$bundleName.tar.bz2";
$pempath = getenv("HOME")."/.ssh/dsa_priv_imageoptim.pem";
$appcastpath = rawurldecode(basename(readKey('SUFeedURL')));
const SPARKLE_NS = "http://www.andymatuschak.org/xml-namespaces/sparkle";
if (!file_exists($archivepath)) throw new Exception("Can't find $archivepath");
$feed = new DOMDocument;
if (!$feed->load($appcastpath)) {
throw new Exception("can't load $appcastpath");
}
$xp = new DOMXPath($feed);
$xp->registerNamespace("sparkle",SPARKLE_NS);
$item = $xp->query("//item[enclosure/@sparkle:version='$exactVersion']")->item(0);
if (!$item)
{
$item = getElement($feed->getElementsByTagName('channel')->item(0),"item");
newline($item);
}
setText(getElement($item, "title"), "Version $niceVersion");
setText(getElement($item, "pubDate"), date(DATE_RSS));
setText(getElement($item, "sparkle:minimumSystemVersion", SPARKLE_NS), $minOSVersion);
getElement($item, "description");
$enc = getElement($item, "enclosure");
$enc->setAttributeNS(SPARKLE_NS, "sparkle:version", $exactVersion);
$enc->setAttribute("url", $download_url);
$enc->setAttribute("length", filesize($archivepath));
$enc->setAttributeNS(SPARKLE_NS, "sparkle:dsaSignature", signUpdate($archivepath, $pempath));
file_put_contents($appcastpath, $feed->saveXML());
function readKey($name)
{
$plistpath = realpath('Info.plist');
$domain = preg_replace('/\.plist$/','',$plistpath);
return system("defaults read ".escapeshellarg($domain)." ".escapeshellarg($name));
}
function getElement(DOMElement $parent, $tagname, $ns = NULL)
{
if ($ns !== NULL) $el = $parent->getElementsByTagNameNS($ns, preg_replace('/^.*:/','',$tagname))->item(0);
else $el = $parent->getElementsByTagName($tagname)->item(0);
if (!$el)
{
$el = $parent->ownerDocument->createElementNS($ns, $tagname);
$parent->appendChild($el);
newline($parent);
}
return $el;
}
function newline(DOMElement $parent)
{
$parent->appendChild($parent->ownerDocument->createTextNode("\n"));
}
function setText(DOMElement $el, $textcontent)
{
while($el->firstChild) $el->removeChild($el->firstChild);
if (strlen($textcontent))
{
$el->appendChild($el->ownerDocument->createTextNode($textcontent));
}
}
function signUpdate($archivepath, $pempath)
{
return system("ruby sign_update.rb ".escapeshellarg($archivepath)." ".escapeshellarg($pempath));
}