├── Builds └── App │ └── PLACE_APP_HERE_AND_DELETE_ME ├── Scripts ├── bitly-config-example.json ├── bin │ ├── BinaryDelta │ ├── BinaryDelta.dSYM │ │ └── Contents │ │ │ ├── Resources │ │ │ └── DWARF │ │ │ │ └── BinaryDelta │ │ │ └── Info.plist │ ├── sign_update.sh │ └── generate_keys.sh ├── aws-s3-config-example.json ├── sparkle-builder-config-example.json ├── appcast.py └── sparkle-builder.py ├── requirements.txt ├── .gitignore ├── README.md └── LICENSE /Builds/App/PLACE_APP_HERE_AND_DELETE_ME: -------------------------------------------------------------------------------- 1 | DELETE_ME 2 | -------------------------------------------------------------------------------- /Scripts/bitly-config-example.json: -------------------------------------------------------------------------------- 1 | { 2 | "BITLY_TOKEN" : "token-string" 3 | } 4 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | bitly-api==0.3 2 | boto==2.38.0 3 | Jinja2==2.7.3 4 | MarkupSafe==0.23 5 | -------------------------------------------------------------------------------- /Scripts/bin/BinaryDelta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omgitsu/SparkleBuilder/HEAD/Scripts/bin/BinaryDelta -------------------------------------------------------------------------------- /Scripts/bin/BinaryDelta.dSYM/Contents/Resources/DWARF/BinaryDelta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omgitsu/SparkleBuilder/HEAD/Scripts/bin/BinaryDelta.dSYM/Contents/Resources/DWARF/BinaryDelta -------------------------------------------------------------------------------- /Scripts/aws-s3-config-example.json: -------------------------------------------------------------------------------- 1 | { 2 | "AWS_ACCESS_KEY_ID" : "aws access key", 3 | "AWS_SECRET_ACCESS_KEY" : "aws secret key", 4 | "S3_BUCKET_NAME" : "bucket_name" 5 | } 6 | -------------------------------------------------------------------------------- /Scripts/bin/sign_update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | set -o pipefail 4 | if [ "$#" -ne 2 ]; then 5 | echo "Usage: $0 update_archive private_key" 6 | exit 1 7 | fi 8 | openssl=/usr/bin/openssl 9 | $openssl dgst -sha1 -binary < "$1" | $openssl dgst -dss1 -sign "$2" | $openssl enc -base64 10 | -------------------------------------------------------------------------------- /Scripts/bin/generate_keys.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | for file in "dsaparam.pem" "dsa_priv.pem" "dsa_pub.pem"; do 4 | if [ -e "$file" ]; then 5 | echo "There's already a $file here! Move it aside or be more careful!" 6 | exit 1 7 | fi 8 | done 9 | 10 | openssl="/usr/bin/openssl" 11 | $openssl gendsa <($openssl dsaparam 4096) -out dsa_priv.pem 12 | chmod 0400 dsa_priv.pem 13 | $openssl dsa -in dsa_priv.pem -pubout -out dsa_pub.pem 14 | chmod 0444 dsa_pub.pem 15 | 16 | echo " 17 | Generated private and public keys: dsa_priv.pem and dsa_pub.pem. 18 | BACK UP YOUR PRIVATE KEY AND KEEP IT SAFE! 19 | If you lose it, your users will be unable to upgrade!" 20 | 21 | open -R dsa_priv.pem 22 | -------------------------------------------------------------------------------- /Scripts/bin/BinaryDelta.dSYM/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleIdentifier 8 | com.apple.xcode.dsym.BinaryDelta 9 | CFBundleInfoDictionaryVersion 10 | 6.0 11 | CFBundlePackageType 12 | dSYM 13 | CFBundleSignature 14 | ???? 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleVersion 18 | 1 19 | 20 | 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### OSX ### 2 | .DS_Store 3 | .AppleDouble 4 | .LSOverride 5 | 6 | # Icon must end with two \r 7 | Icon 8 | 9 | 10 | # Thumbnails 11 | ._* 12 | 13 | # Files that might appear in the root of a volume 14 | .DocumentRevisions-V100 15 | .fseventsd 16 | .Spotlight-V100 17 | .TemporaryItems 18 | .Trashes 19 | .VolumeIcon.icns 20 | 21 | # Directories potentially created on remote AFP share 22 | .AppleDB 23 | .AppleDesktop 24 | Network Trash Folder 25 | Temporary Items 26 | .apdisk 27 | 28 | 29 | # Byte-compiled / optimized / DLL files 30 | __pycache__/ 31 | *.py[cod] 32 | *$py.class 33 | 34 | # C extensions 35 | *.so 36 | 37 | # Distribution / packaging 38 | .Python 39 | env/ 40 | build/ 41 | develop-eggs/ 42 | dist/ 43 | downloads/ 44 | eggs/ 45 | .eggs/ 46 | lib/ 47 | lib64/ 48 | parts/ 49 | sdist/ 50 | var/ 51 | *.egg-info/ 52 | .installed.cfg 53 | *.egg 54 | 55 | # PyInstaller 56 | # Usually these files are written by a python script from a template 57 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 58 | *.manifest 59 | *.spec 60 | 61 | # Installer logs 62 | pip-log.txt 63 | pip-delete-this-directory.txt 64 | 65 | # Unit test / coverage reports 66 | htmlcov/ 67 | .tox/ 68 | .coverage 69 | .coverage.* 70 | .cache 71 | nosetests.xml 72 | coverage.xml 73 | *,cover 74 | 75 | # Translations 76 | *.mo 77 | *.pot 78 | 79 | # Django stuff: 80 | *.log 81 | 82 | # Sphinx documentation 83 | docs/_build/ 84 | 85 | # PyBuilder 86 | target/ 87 | 88 | # keys 89 | *.pem 90 | 91 | # private config files 92 | sparkle-builder-config.json 93 | aws-s3-config.json 94 | bitly-config.json 95 | -------------------------------------------------------------------------------- /Scripts/sparkle-builder-config-example.json: -------------------------------------------------------------------------------- 1 | { 2 | "VERBOSE" : true, 3 | "BUILD_DIRECTORY_PATH" : "/Full/Path/To/Your/Builds/", 4 | "PRIVATE_KEY_PATH" : "/Full/Path/To/Your/Private/Keys/dsa_priv.pem", 5 | "SPARKLE_BIN_PATH" : "/Full/Path/To/The/Sparkle/bin/directory/bin/", 6 | "APPCAST_FILE_NAME" : "appcast.xml", 7 | "APPCAST_BASE_URL" : "http://sparklebuilder.dev/", 8 | "APPCAST_TITLE" : "App Changelog", 9 | "APPCAST_DESCRIPTION" : "some description", 10 | "APPCAST_LANGUAGE" : "en", 11 | "APPCAST_LATEST_VERSION_UPDATE_DESCRIPTION" : "Foo", 12 | "APPCAST_RELEASE_NOTES_FILE" : "relative/path/from/appcast/directory/on/your/server", 13 | "CLEAN_DIRECTORIES" : true, 14 | "OVERWRITE_APP_ARCHIVES" : true, 15 | "ARCHIVE_ZIPS" : true, 16 | "ARCHIVE_APPCASTS" : true, 17 | "ARCHIVE_DELTAS" : true, 18 | "PUBLISH" : true, 19 | "PUBLISH_ROOT_PATH" : "/Full/Path/To/Your/Server/Files/", 20 | "PUBLISH_APPCAST_DIR" : "appcast/", 21 | "PUBLISH_DOWNLOADS_DIR" : "downloads/", 22 | "PUBLISH_DELTAS_DIR" : "deltas/", 23 | "USE_S3_FOR_DOWNLOADS" : false, 24 | "USE_BITLY_TO_SHORTEN_LINKS" : false 25 | } 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SparkleBuilder 2 | ### a simple python script to automate [Sparkle](http://sparkle-project.org/) appcast generation and delta creation 3 | 4 | #### basic instructions 5 | * clone the repo 6 | * `pip install requirements.txt` 7 | * configure the settings in `sparkle-builder-config-example.json` 8 | * rename the example to `sparkle-builder-config.json` 9 | * configure the settings in `aws-s3-config-example.json` 10 | * rename the example to `aws-s3-config.json` 11 | * configure the settings in `bitly-config-example.json` 12 | * rename the example to `bitly-config.json` 13 | * delete the file in `Builds/App` 14 | * place your **latest** app in `Builds/App` 15 | * cd into `Scripts` 16 | * run `python sparkle-builder.py` 17 | 18 | #### What it does (and can do) 19 | 20 | * generates an appcast.xml file for use with [Sparkle](http://sparkle-project.org/). 21 | * zips the application and signs with your private dsa key 22 | * archives your app in a zip appending the version number 23 | * archives your app appending the version number 24 | * creates `delta` files for each pervious version of your app 25 | * optionally 26 | * archives appcasts, deltas and zips 27 | * publishes the zips, appcast and deltas to another directory* 28 | 29 | ###### With everything enabled in the .config file your final directory structure will look like this: 30 | 31 | * Builds/ 32 | * App/ 33 | * Appcast/ 34 | * Archives/ 35 | * Appcasts/ 36 | * Apps/ 37 | * Deltas/ 38 | * Zips/ 39 | * Deltas/ 40 | * Zips/ 41 | 42 | ###### The directory that you publish to will look like this: 43 | * appcast/ 44 | * deltas/ 45 | * downloads/ 46 | 47 | ##### Notes 48 | * the appcast uses your build number aka `CFBundleVersion` in your info.plist for updates - make sure that it increments between versions! 49 | 50 | 51 | >If you already have a bunch of builds, the recommendation is to create the `Builds/Archives/Apps/` folder and place each of the previous builds there *before* you run the app for the first time. Each app should be named with the version and build number appended to the file name. So version 1.0.1 of your test.app should be named test-1.0.1.app 52 | 53 | >Alternatively you could run the script for each version of your app starting at the lowest build number and going on from there 54 | -------------------------------------------------------------------------------- /Scripts/appcast.py: -------------------------------------------------------------------------------- 1 | ## 2 | ## appcast.py 3 | ## SparkleBuilder 4 | ## 5 | ## Created by James Baker on 4/29/15. 6 | ## Copyright (c) 2015 WDDG, Inc. All rights reserved. 7 | ## 8 | ## Permission is hereby granted, free of charge, to any person obtaining a copy 9 | ## of this software and associated documentation files (the "Software"), to deal 10 | ## in the Software without restriction, including without limitation the rights 11 | ## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | ## copies of the Software, and to permit persons to whom the Software is 13 | ## furnished to do so, subject to the following conditions: 14 | ## 15 | ## The above copyright notice and this permission notice shall be included in 16 | ## all copies or substantial portions of the Software. 17 | ## 18 | ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | ## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | ## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | ## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | ## THE SOFTWARE. 25 | ## 26 | 27 | 28 | from jinja2 import Template 29 | 30 | class Appcast: 31 | def __init__(self): 32 | self.title = None 33 | self.app_name = None 34 | self.appcast_url = None 35 | self.appcast_description = None 36 | self.language = None 37 | self.latest_version_number = None 38 | self.latest_version_update_description = None 39 | self.pub_date = None 40 | self.latest_version_url = None 41 | self.latest_version_number = None 42 | self.short_version_string = None 43 | self.latest_version_size = None 44 | self.latest_version_dsa_key = None 45 | self.release_notes_file = None 46 | self.deltas = [] 47 | 48 | # appcast main Template 49 | self.__appcast_template = Template(''' 50 | 51 | 52 | {{ title }} 53 | {{ appcast_url }} 54 | {{ appcast_description }} 55 | {{ language }} 56 | 57 | {{ app_name }} version {{ short_version_string }} 58 | {% if release_notes_file %} 59 | {{ release_notes_file }} 60 | {% else %} 61 | {{ latest_version_update_description }} 62 | {% endif %} 63 | {{ pub_date }} 64 | 70 | {% if deltas %} 71 | 72 | {% for delta in deltas %} 73 | {{ delta }} 74 | {% endfor %} 75 | 76 | {% endif %} 77 | 78 | 79 | 80 | ''') 81 | 82 | def append_delta(self, delta): 83 | rendered_delta = delta.render() 84 | self.deltas.append(rendered_delta) 85 | 86 | def render(self): 87 | appcast = self.__appcast_template.render( 88 | title = self.title, 89 | app_name = self.app_name, 90 | appcast_url = self.appcast_url, 91 | appcast_description = self.appcast_description, 92 | release_notes_file = self.release_notes_file, 93 | launguage = self.launguage, 94 | latest_version_number = self.latest_version_number, 95 | short_version_string = self.short_version_string, 96 | latest_version_update_description = self.latest_version_update_description, 97 | pub_date = self.pub_date, 98 | latest_version_url = self.latest_version_url, 99 | latest_version_size = self.latest_version_size, 100 | latest_version_dsa_key = self.latest_version_dsa_key, 101 | deltas = self.deltas, 102 | ) 103 | return appcast 104 | 105 | 106 | class Delta: 107 | 108 | def __init__(self): 109 | self.delta_url = None 110 | self.delta_to_version = None 111 | self.delta_from_version = None 112 | self.short_version_string = None 113 | self.delta_size = None 114 | self.delta_dsa_key = None 115 | 116 | self.__delta_template = Template(''' 117 | 124 | ''') 125 | 126 | def render(self): 127 | delta = self.__delta_template.render( 128 | delta_url = self.delta_url, 129 | delta_to_version = self.delta_to_version, 130 | delta_from_version = self.delta_from_version, 131 | short_version_string = self.short_version_string, 132 | delta_size = self.delta_size, 133 | delta_dsa_key = self.delta_dsa_key, 134 | ) 135 | return delta 136 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /Scripts/sparkle-builder.py: -------------------------------------------------------------------------------- 1 | ## 2 | ## sparkle-builder.py 3 | ## SparkleBuilder 4 | ## 5 | ## Created by James Baker on 4/29/15. 6 | ## Copyright (c) 2015 WDDG, Inc. All rights reserved. 7 | ## 8 | ## Permission is hereby granted, free of charge, to any person obtaining a copy 9 | ## of this software and associated documentation files (the "Software"), to deal 10 | ## in the Software without restriction, including without limitation the rights 11 | ## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | ## copies of the Software, and to permit persons to whom the Software is 13 | ## furnished to do so, subject to the following conditions: 14 | ## 15 | ## The above copyright notice and this permission notice shall be included in 16 | ## all copies or substantial portions of the Software. 17 | ## 18 | ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | ## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | ## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | ## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | ## THE SOFTWARE. 25 | ## 26 | 27 | from __future__ import division 28 | 29 | import os 30 | import sys 31 | import datetime 32 | import time 33 | import json 34 | 35 | from boto.s3.connection import S3Connection 36 | from boto.s3.key import Key 37 | from subprocess import Popen, PIPE 38 | from shutil import move, copy, copytree, rmtree 39 | from plistlib import readPlist 40 | from pprint import pprint 41 | from bitly_api import Connection as BitlyConnection 42 | 43 | from appcast import Appcast, Delta 44 | 45 | # functions 46 | 47 | def log(msg): 48 | if VERBOSE: 49 | print msg 50 | 51 | def create_dir_if_needed(path, name): 52 | if not os.path.isdir(path): 53 | log("create {} directory.".format(name)) 54 | os.makedirs(path) 55 | 56 | def clean_directory(dir): 57 | for f in os.listdir(dir): 58 | fp = os.path.join(dir, f) 59 | try: 60 | if os.path.isfile(fp): 61 | os.unlink(fp) 62 | elif os.path.isdir(fp): 63 | rmtree(fp) 64 | except Exception, e: 65 | print e 66 | 67 | def create_delta(old_source = '', new_source = ''): 68 | log("creating delta from {} to {} ".format(old_source, new_source)) 69 | binary_delta_script = SPARKLE_BIN_PATH + "BinaryDelta" 70 | old_version = get_version_info(old_source) 71 | new_version = get_version_info(new_source) 72 | delta_file = "{}-{}.delta".format(old_version, new_version) 73 | delta_file_path = "{}{}".format(DELTAS_PATH, delta_file) 74 | create_delta_call = [binary_delta_script, "create", old_source, new_source, delta_file_path] 75 | process = Popen(create_delta_call, stdout=PIPE) 76 | (output, err) = process.communicate() 77 | exit_code = process.wait() 78 | log("{} created".format(delta_file)) 79 | return delta_file, delta_file_path 80 | 81 | 82 | def create_zip(file_name, new_name=''): 83 | log("zipping " + file_name) 84 | path = CURRENT_APP_PATH 85 | source_file = path + file_name 86 | if new_name: 87 | file_name = new_name 88 | 89 | ## build the zip and move into place 90 | zip_file = path + file_name + ".zip" 91 | new_zip_file = ZIPS_PATH + file_name + '.zip' 92 | if os.path.exists(new_zip_file): 93 | os.remove(new_zip_file) 94 | ditto_call = ["ditto", "-c", "-k", "--keepParent", "-rsrc", source_file, zip_file] 95 | process = Popen(ditto_call, stdout=PIPE) 96 | (output, err) = process.communicate() 97 | exit_code = process.wait() 98 | move(zip_file, ZIPS_PATH) 99 | 100 | log("{}.zip created".format(file_name)) 101 | if ARCHIVE_ZIPS: 102 | archive_file(new_zip_file, 'Zips/') 103 | # return path to new zip 104 | return new_zip_file 105 | 106 | 107 | def sign_update(zip_file = '', private_key_path = ''): 108 | sign_update_script = SPARKLE_BIN_PATH + "sign_update.sh" 109 | sign_update_call = [sign_update_script, zip_file, private_key_path] 110 | process = Popen(sign_update_call, stdout=PIPE) 111 | (output, err) = process.communicate() 112 | exit_code = process.wait() 113 | return output.rstrip() 114 | 115 | 116 | def get_key_from_bundle(key='', bundle=''): 117 | info_plist = bundle + "/Contents/Info.plist" 118 | with open(info_plist, 'rb') as fp: 119 | pl = readPlist(fp) 120 | return pl[key] 121 | 122 | 123 | def get_version_info(bundle): 124 | info_plist = bundle + "/Contents/Info.plist" 125 | with open(info_plist, 'rb') as fp: 126 | pl = readPlist(fp) 127 | major_version = get_key_from_bundle(key='CFBundleShortVersionString', bundle=bundle) 128 | minor_version = get_key_from_bundle(key='CFBundleVersion', bundle=bundle) #pl['CFBundleVersion'] 129 | return "{}.{}".format(major_version,minor_version) 130 | 131 | 132 | def get_bundle_version(app_file): 133 | return get_key_from_bundle(key='CFBundleVersion', bundle=app_file) 134 | 135 | 136 | def archive_file(filepath, subdirectory): 137 | basename = os.path.basename(filepath) 138 | filename, extension = os.path.splitext(basename) 139 | date = time.strftime("%d%m%Y") 140 | new_filename = "{}{}_{}".format(ARCHIVE_PATH+subdirectory, filename, date) 141 | i = 0 142 | while os.path.exists("{}_{}{}".format(new_filename, str(i), extension)): 143 | i+=1 144 | copy(filepath,"{}_{}{}".format(new_filename, str(i), extension)) 145 | log("archive {}".format(basename)) 146 | 147 | 148 | def copy_files(origin="", destination="", extension=""): 149 | for (dirpath, _, filenames) in os.walk(origin): 150 | for filename in filenames: 151 | _, _extension = os.path.splitext(filename) 152 | if _extension == extension: 153 | log("publish {}".format(filename)) 154 | origin_file = os.path.join(dirpath, filename) 155 | published_file = os.path.join(destination, filename) 156 | copy(origin_file, published_file) 157 | 158 | def s3upload(filepath, directory=""): 159 | filename = os.path.basename(filepath) 160 | log("uploading {} to s3".format(filename)) 161 | conn = S3Connection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) 162 | bucket = conn.get_bucket(S3_BUCKET_NAME) 163 | k = Key(bucket) 164 | k.key = directory + filename 165 | with open(filepath) as file: 166 | k.set_contents_from_file(file) 167 | s3_file_url = AWS_BUCKET_PATH + directory + filename 168 | log("new s3 file at:" + s3_file_url) 169 | return s3_file_url 170 | 171 | 172 | def format_url(url='', title=''): 173 | if USE_BITLY_TO_SHORTEN_LINKS: 174 | url = shorten_url_with_bitly(url, title) 175 | return url 176 | 177 | def shorten_url_with_bitly(url, title): 178 | log("shortening url with bitly") 179 | c = BitlyConnection(access_token=BITLY_TOKEN) 180 | response = c.shorten(url) 181 | c.user_link_edit(response["url"],"title",title=title) 182 | log("new bitly link:"+response["url"]) 183 | return response["url"] 184 | 185 | ############################## 186 | ### configuration setup ### 187 | ############################## 188 | 189 | with open('sparkle-builder-config.json') as data_file: 190 | data = json.load(data_file) 191 | 192 | 193 | VERBOSE = data["VERBOSE"] 194 | 195 | ## AWS S3 configuration 196 | USE_S3_FOR_DOWNLOADS = data["USE_S3_FOR_DOWNLOADS"] 197 | 198 | if USE_S3_FOR_DOWNLOADS: 199 | with open('aws-s3-config.json') as data_file: 200 | s3data = json.load(data_file) 201 | AWS_ACCESS_KEY_ID = s3data["AWS_ACCESS_KEY_ID"] 202 | AWS_SECRET_ACCESS_KEY = s3data["AWS_SECRET_ACCESS_KEY"] 203 | S3_BUCKET_NAME = s3data["S3_BUCKET_NAME"] 204 | AWS_BUCKET_PATH = "https://s3.amazonaws.com/mockulus/" 205 | 206 | ## bitly 207 | USE_BITLY_TO_SHORTEN_LINKS = data["USE_BITLY_TO_SHORTEN_LINKS"] 208 | if USE_BITLY_TO_SHORTEN_LINKS: 209 | with open('bitly-config.json') as data_file: 210 | bitly_data = json.load(data_file) 211 | BITLY_TOKEN = bitly_data["BITLY_TOKEN"] 212 | 213 | # paths 214 | BUILD_PATH = data["BUILD_DIRECTORY_PATH"] 215 | os.chdir(BUILD_PATH) 216 | APPS_PATH = BUILD_PATH + "Apps/" 217 | ZIPS_PATH = BUILD_PATH + "Zips/" 218 | DELTAS_PATH = BUILD_PATH + "Deltas/" 219 | APPCAST_PATH = BUILD_PATH + "Appcast/" 220 | ARCHIVE_PATH = BUILD_PATH + "Archives/" 221 | CURRENT_APP_PATH = BUILD_PATH + "App/" 222 | APP_ARCHIVE_PATH = ARCHIVE_PATH + "Apps/" 223 | 224 | ## get the latest app 225 | ## bark and exit if there is more than one in the directory 226 | 227 | _apps = [] 228 | for (_, dirname, _) in os.walk(CURRENT_APP_PATH): 229 | _apps.extend(dirname) 230 | break 231 | 232 | if not _apps: 233 | print "nothing found at {}, please place latest version of the app there".format(CURRENT_APP_PATH) 234 | sys.exit() 235 | 236 | if len(_apps) > 1: 237 | print "more than one app found at {}. remove all apps, files and directories other the latest version".format(CURRENT_APP_PATH) 238 | sys.exit() 239 | 240 | LATEST_APP = _apps[0] 241 | APP_NAME = get_key_from_bundle(key='CFBundleExecutable', bundle=CURRENT_APP_PATH+LATEST_APP) 242 | BUNDLE_VERSION = get_bundle_version(CURRENT_APP_PATH+LATEST_APP) 243 | CURRENT_VERSION = get_version_info(CURRENT_APP_PATH+LATEST_APP) 244 | LATEST_APP_ARCHIVE = '{}-{}.app'.format(APP_NAME, CURRENT_VERSION) 245 | 246 | log(APP_NAME) 247 | log("current-version: {}".format(CURRENT_VERSION)) 248 | log("bundle-version: {}".format(BUNDLE_VERSION)) 249 | 250 | PRIVATE_KEY_PATH = data["PRIVATE_KEY_PATH"] 251 | SPARKLE_BIN_PATH = data["SPARKLE_BIN_PATH"] 252 | 253 | # options 254 | CLEAN_DIRECTORIES = data["CLEAN_DIRECTORIES"] 255 | OVERWRITE_APP_ARCHIVES = data["OVERWRITE_APP_ARCHIVES"] 256 | ARCHIVE_ZIPS = data["ARCHIVE_ZIPS"] 257 | ARCHIVE_APPCASTS = data["ARCHIVE_APPCASTS"] 258 | ARCHIVE_DELTAS = data["ARCHIVE_DELTAS"] 259 | 260 | # Appcast setup 261 | APPCAST_FILE_NAME = data["APPCAST_FILE_NAME"] 262 | APPCAST_BASE_URL = data["APPCAST_BASE_URL"] 263 | APPCAST_TITLE = data["APPCAST_TITLE"] 264 | APPCAST_DESCRIPTION = data["APPCAST_DESCRIPTION"] 265 | APPCAST_LANGUAGE = data["APPCAST_LANGUAGE"] 266 | APPCAST_LATEST_VERSION_UPDATE_DESCRIPTION = data["APPCAST_LATEST_VERSION_UPDATE_DESCRIPTION"] 267 | APPCAST_RELEASE_NOTES_FILE = data["APPCAST_RELEASE_NOTES_FILE"] 268 | 269 | if APPCAST_RELEASE_NOTES_FILE: 270 | APPCAST_RELEASE_NOTES_FILE = "{}appcast/{}".format(APPCAST_BASE_URL, APPCAST_RELEASE_NOTES_FILE) 271 | 272 | ## publish configuration 273 | PUBLISH = data["PUBLISH"] 274 | PUBLISH_ROOT_PATH = data["PUBLISH_ROOT_PATH"] 275 | PUBLISH_APPCAST_DIR = data["PUBLISH_APPCAST_DIR"] 276 | PUBLISH_DOWNLOADS_DIR = data["PUBLISH_DOWNLOADS_DIR"] 277 | PUBLISH_DELTAS_DIR = data["PUBLISH_DELTAS_DIR"] 278 | 279 | ## app derived 280 | # LATEST_APP = '{}-{}.app'.format(APP_NAME, CURRENT_VERSION) 281 | 282 | ## appcast derived 283 | APPCAST_URL = APPCAST_BASE_URL + "appcast/" + APPCAST_FILE_NAME 284 | APPCAST_PUBDATE = time.strftime("%a, %d %b %G %T %z") 285 | APPCAST_LATEST_VERSION_NUMBER = CURRENT_VERSION 286 | APPCAST_LATEST_VERSION_URL = APPCAST_BASE_URL + "downloads/" + LATEST_APP_ARCHIVE + ".zip" 287 | APPCAST_DELTA_URL = APPCAST_BASE_URL + 'deltas/' 288 | 289 | APPCAST_FILE = APPCAST_PATH + APPCAST_FILE_NAME 290 | 291 | 292 | 293 | 294 | ############################## 295 | ### appcast genreration ### 296 | ############################## 297 | 298 | # load old apps from Apps 299 | 300 | apps = [] 301 | if os.path.isdir(APP_ARCHIVE_PATH): 302 | for (_, dirname, _) in os.walk(APP_ARCHIVE_PATH): 303 | apps.extend(dirname) 304 | break 305 | 306 | if not apps: 307 | print "no apps found in {}. no deltas will be produced".format(APP_ARCHIVE_PATH) 308 | 309 | ## check for directories, if Zips or Deltas don't exist create them 310 | 311 | create_dir_if_needed(ZIPS_PATH, 'Zips') 312 | create_dir_if_needed(APPCAST_PATH, 'Appcast') 313 | create_dir_if_needed(DELTAS_PATH, 'Deltas') 314 | 315 | if CLEAN_DIRECTORIES: 316 | clean_directory(DELTAS_PATH) 317 | clean_directory(APPCAST_PATH) 318 | clean_directory(ZIPS_PATH) 319 | 320 | create_dir_if_needed(ARCHIVE_PATH, 'Archive') 321 | create_dir_if_needed(ARCHIVE_PATH+'Apps/', 'Archive/Apps') 322 | 323 | if ARCHIVE_APPCASTS: 324 | create_dir_if_needed(ARCHIVE_PATH+'Appcasts/', 'Archive/Appcasts') 325 | 326 | if ARCHIVE_DELTAS: 327 | create_dir_if_needed(ARCHIVE_PATH+'Deltas/', 'Archive/Deltas') 328 | 329 | if ARCHIVE_ZIPS: 330 | create_dir_if_needed(ARCHIVE_PATH+'Zips/', 'Archive/Zips') 331 | 332 | 333 | 334 | 335 | ## appcast setup 336 | appcast = Appcast() 337 | 338 | appcast.title = APPCAST_TITLE 339 | appcast.app_name = APP_NAME 340 | appcast.appcast_url = APPCAST_URL 341 | appcast.appcast_description = APPCAST_DESCRIPTION 342 | if APPCAST_RELEASE_NOTES_FILE: 343 | appcast.release_notes_file = APPCAST_RELEASE_NOTES_FILE 344 | appcast.launguage = APPCAST_LANGUAGE 345 | appcast.latest_version_number = BUNDLE_VERSION 346 | appcast.short_version_string = CURRENT_VERSION 347 | appcast.latest_version_update_description = APPCAST_LATEST_VERSION_UPDATE_DESCRIPTION 348 | appcast.pub_date = APPCAST_PUBDATE 349 | zipped_app = create_zip(LATEST_APP, new_name=LATEST_APP_ARCHIVE) 350 | 351 | if USE_S3_FOR_DOWNLOADS: 352 | s3_file_url = s3upload(zipped_app) 353 | appcast.latest_version_url = format_url(url=s3_file_url, title=LATEST_APP_ARCHIVE+" S3") 354 | else: 355 | appcast.latest_version_url = format_url(url=APPCAST_LATEST_VERSION_URL, title=LATEST_APP_ARCHIVE) 356 | 357 | 358 | 359 | appcast.latest_version_size = os.path.getsize(zipped_app) 360 | appcast.latest_version_dsa_key = sign_update(zipped_app, private_key_path=PRIVATE_KEY_PATH) 361 | 362 | 363 | 364 | ## deltas 365 | for app in apps: 366 | if app.endswith('.app'): 367 | if not app == LATEST_APP_ARCHIVE: 368 | app_path = APP_ARCHIVE_PATH + app 369 | delta = Delta() 370 | delta_file_name, delta_file_path = create_delta(old_source=app_path, new_source=CURRENT_APP_PATH+LATEST_APP) 371 | if USE_S3_FOR_DOWNLOADS: 372 | delta.delta_url = format_url(url=s3upload(delta_file_path, directory="deltas/"), title=delta_file_name) 373 | else: 374 | delta.delta_url = format_url(url=(APPCAST_DELTA_URL + delta_file_name), title=delta_file_name) 375 | delta.delta_to_version = BUNDLE_VERSION 376 | delta.delta_from_version = get_bundle_version(app_path) 377 | delta.short_version_string = CURRENT_VERSION 378 | delta.delta_size = os.path.getsize(delta_file_path) 379 | delta.delta_dsa_key = sign_update(delta_file_path, private_key_path=PRIVATE_KEY_PATH) 380 | appcast.append_delta(delta) 381 | 382 | 383 | ## write out the appcast 384 | appcast_xml = appcast.render() 385 | with open(APPCAST_FILE, 'w') as f: 386 | f.write(appcast_xml) 387 | log("create {}".format(APPCAST_FILE_NAME)) 388 | 389 | 390 | ################ 391 | ## Publishing ## 392 | ################ 393 | 394 | if PUBLISH: 395 | appcast_publish_path = PUBLISH_ROOT_PATH + PUBLISH_APPCAST_DIR 396 | downloads_publish_path = PUBLISH_ROOT_PATH + PUBLISH_DOWNLOADS_DIR 397 | deltas_publish_path = PUBLISH_ROOT_PATH + PUBLISH_DELTAS_DIR 398 | 399 | ## create directories if needed 400 | create_dir_if_needed(appcast_publish_path, 'Appcast Publish') 401 | create_dir_if_needed(downloads_publish_path, 'Downloads Publish') 402 | create_dir_if_needed(deltas_publish_path, 'Deltas Publish') 403 | 404 | appcast_publish_file = appcast_publish_path + APPCAST_FILE_NAME 405 | copy(APPCAST_FILE, appcast_publish_file) 406 | log("publish {}".format(APPCAST_FILE_NAME)) 407 | 408 | copy_files(origin=DELTAS_PATH, destination=deltas_publish_path, extension=".delta") 409 | copy_files(origin=ZIPS_PATH, destination=downloads_publish_path, extension=".zip") 410 | 411 | 412 | ############### 413 | ## Archiving ## 414 | ############### 415 | 416 | ## always archive the latest app unless it's already there 417 | 418 | if OVERWRITE_APP_ARCHIVES: 419 | if os.path.isdir(APP_ARCHIVE_PATH+LATEST_APP_ARCHIVE): 420 | rmtree(APP_ARCHIVE_PATH+LATEST_APP_ARCHIVE) 421 | 422 | if not os.path.isdir(APP_ARCHIVE_PATH+LATEST_APP_ARCHIVE): 423 | copytree(CURRENT_APP_PATH+LATEST_APP, APP_ARCHIVE_PATH+LATEST_APP_ARCHIVE) 424 | log("archive {}".format(LATEST_APP_ARCHIVE)) 425 | else: 426 | log("{} already archived - skipping".format(LATEST_APP_ARCHIVE)) 427 | 428 | 429 | if ARCHIVE_APPCASTS: 430 | archive_file(APPCAST_FILE, 'Appcasts/') 431 | 432 | ## archive Deltas 433 | if ARCHIVE_DELTAS: 434 | date = time.strftime("%m%d%Y") 435 | delta_directory = DELTAS_PATH 436 | if delta_directory.endswith('/'): 437 | delta_directory = delta_directory[:-1] 438 | new_directory = "{}/Deltas_{}".format(ARCHIVE_PATH+'Deltas/', date) 439 | i = 0 440 | while os.path.exists("{}_{}".format(new_directory, str(i))): 441 | i+=1 442 | copytree(DELTAS_PATH,"{}_{}".format(new_directory, str(i))) 443 | log("archive deltas") 444 | 445 | print "sparkle builder finished" 446 | print "update app url to point to: " + appcast.latest_version_url 447 | --------------------------------------------------------------------------------