autoupdate: add Sparkle framework

This commits brings optionnal linking against Sparkle framework.
This framework is used to autoupdate apps not present in the Mac app store

Refs #75349

Change-Id: I82b14757c106f1282d91e631927057d00989feb7
diff --git a/sparkle/LICENSE b/sparkle/LICENSE
new file mode 100644
index 0000000..f4020f8
--- /dev/null
+++ b/sparkle/LICENSE
@@ -0,0 +1,60 @@
+Copyright (c) 2006-2013 Andy Matuschak.
+Copyright (c) 2009-2013 Elgato Systems GmbH.
+Copyright (c) 2011-2014 Kornel LesiƄski.
+Copyright (c) 2014 C.W. Betts.
+Copyright (c) 2014 Petroules Corporation.
+Copyright (c) 2014 Big Nerd Ranch.
+All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+=================
+EXTERNAL LICENSES
+=================
+
+bspatch.c and bsdiff.c, from bsdiff 4.3 <http://www.daemonology.net/bsdiff/>:
+    Copyright (c) 2003-2005 Colin Percival.
+
+sais.c and sais.c, from sais-lite (2010/08/07) <https://sites.google.com/site/yuta256/sais>:
+    Copyright (c) 2008-2010 Yuta Mori.
+
+SUDSAVerifier.m:
+    Copyright (c) 2011 Mark Hamlin.
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted providing that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
diff --git a/sparkle/Sparkle b/sparkle/Sparkle
new file mode 160000
index 0000000..d0cc3b6
--- /dev/null
+++ b/sparkle/Sparkle
@@ -0,0 +1 @@
+Subproject commit d0cc3b63b4da6b952fa7b96607cd80fb75a9b48f
diff --git a/sparkle/dsa_pub.pem b/sparkle/dsa_pub.pem
new file mode 100644
index 0000000..97455e2
--- /dev/null
+++ b/sparkle/dsa_pub.pem
@@ -0,0 +1,36 @@
+-----BEGIN PUBLIC KEY-----
+MIIGRzCCBDoGByqGSM44BAEwggQtAoICAQCp4+JqCDyIMIMGtvpMvEPsQJ2SLJrt
+y16KsLNmcUXLM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4xQYBryQCMu6JC5ibWzP
+-----END PUBLIC KEY-----
diff --git a/sparkle/sign_update.sh b/sparkle/sign_update.sh
new file mode 100644
index 0000000..d15c3cd
--- /dev/null
+++ b/sparkle/sign_update.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+set -e
+set -o pipefail
+if [ "$#" -ne 2 ]; then
+  echo "Usage: $0 update_archive private_key"
+  exit 1
+fi
+openssl=/usr/bin/openssl
+$openssl dgst -sha1 -binary < "$1" | $openssl dgst -dss1 -sign "$2" | base64 --wrap=0
+
diff --git a/sparkle/sparkle-xml-updater.sh b/sparkle/sparkle-xml-updater.sh
new file mode 100644
index 0000000..d0dc91b
--- /dev/null
+++ b/sparkle/sparkle-xml-updater.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+# Take the package to add as argument ./sparkle-xml-updater.sh ring.dmg
+
+REPO_FOLDER=<dir>
+SPARKLE_FILE=<xml_filename>
+REPO_URL=<url>
+PACKAGE=$1
+DSA_KEY=<path_to_key_file>
+
+if [ ! -f ${PACKAGE} -o ! -f ${DSA_KEY} ]; then
+    echo "Can't find package or dsa key, aborting..."
+    exit 1
+fi
+
+if [ -f ${REPO_FOLDER}/${SPARKLE_FILE} ]; then
+    ITEMS=$(sed -n "/<item>/,/<\/item>/p" ${REPO_FOLDER}/${SPARKLE_FILE}) 
+fi
+
+cat << EOFILE > ${REPO_FOLDER}/${SPARKLE_FILE}
+<?xml version="1.0" encoding="utf-8"?>
+<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/">
+    <channel>
+        <title>Ring - nightly</title>
+        <link>${REPO_URL}/${SPARKLE_FILE}</link>
+        <description>Most recent changes with links to updates.</description>
+        <language>en</language>
+        <item>
+            <title>Ring nightly $(date "+%Y/%m/%d %H:%M")</title>
+            <pubDate>$(date -R)</pubDate>
+            <enclosure url="${REPO_URL}/$(basename ${PACKAGE})" sparkle:version="$(date +%Y%m%d%H%M)" sparkle:shortVersionString="nightly-$(date "+%Y%m%d")" length="$(stat -c %s ${PACKAGE})" type="application/octet-stream" sparkle:dsaSignature="$(/opt/joulupukki/mac_keys/sign_update.sh ${PACKAGE} ${DSA_KEY})" />
+            <sparkle:minimumSystemVersion>10.7</sparkle:minimumSystemVersion>
+        </item>
+$(echo -e "${ITEMS}")
+    </channel>
+</rss>
+EOFILE
+