Commit 6ade9c4e authored by ilv's avatar ilv
Browse files

Added preliminary script to upload Tor Browser to github

parent 5b827352
name = GitHub
fingerprint = 8738 A680 B84B 3031 A630 F2DB 416F 0610 63FE E659
en = Package (32-bit):
ASC signature (32-bit):
Package SHA256 checksum (32-bit): 7df98c47a629c78f648537b975c827ac83181ed1f82ac03759e8e3337aae00f3,
Package (64-bit):
ASC signature (64-bit):
Package SHA256 checksum (64-bit): 7df98c47a629c78f648537b975c827ac83181ed1f82ac03759e8e3337aae00f3
ar = Package (32/64-bit):
ASC signature (32/64-bit):
Package SHA256 checksum (32/64-bit): f4be40da212f5d0dc53dbcc254ec44a0a3a91c521c7df211b8d6d936ebdf42a6
en = Package (32-bit):
ASC signature (32-bit):
Package SHA256 checksum (32-bit): 55f5e4102c240d74e2dd2a48c55660426f17a226053aaaff172aaa13b7ae2b1d
# -*- coding: utf-8 -*-
# This file is part of GetTor, a Tor Browser distribution system.
# :authors: Israel Leiva <>
# see also AUTHORS file
# :copyright: (c) 2015, The Tor Project, Inc.
# (c) 2015, Israel Leiva
# :license: This is Free Software. See LICENSE for license information.
import os
import sys
import re
import hashlib
from import github
import gnupg
import gettor.core
def get_file_sha256(file):
"""Get the sha256 of a file.
:param: file (string) the path of the file.
:return: (string) the sha256 hash.
# as seen on the internetz
hasher = hashlib.sha256()
with open(file, 'rb') as afile:
buf =
while len(buf) > 0:
buf =
return hasher.hexdigest()
def get_bundle_info(file, osys):
"""Get the os, arch and lc from a bundle string.
:param: file (string) the name of the file.
:param: osys (string) the OS.
:raise: ValueError if the bundle doesn't have a valid bundle format.
:return: (list) the os, arch and lc.
if(osys == 'windows'):
m =
if m:
lc =
return 'windows', '32/64', lc
elif(osys == 'linux'):
m =
if m:
arch =
lc =
return 'linux', arch, lc
elif(osys == 'osx'):
m =
if m:
os = 'osx'
arch =
lc =
return 'osx', arch, lc
if __name__ == '__main__':
# this script should be called after fetching the latest Tor Browser,
# and specifying the latest version
version = sys.argv[1]
# the token allow us to run this script without GitHub user/pass
gh_token = 'secret-token'
# path to the fingerprint that signed the packages
tb_key = 'upload/torbrowser-key.asc'
# import key fingerprint
gpg = gnupg.GPG()
key_data = open(tb_key).read()
import_result = gpg.import_keys(key_data)
fp = import_result.results[0]['fingerprint']
# make groups of four characters to make fingerprint more readable
# e.g. 123A 456B 789C 012D 345E 678F 901G 234H 567I 890J
readable_fp = ' '.join(fp[i:i+4] for i in xrange(0, len(fp), 4))
# we should have previously created a repository on GitHub where we
# want to push the files using a SSH key (to avoid using user/pass)
remote = 'origin'
branch = 'master'
user = 'ilv'
repo = 'gettor'
path = 'upload'
raw_content = '' %\
(user, repo, branch, path)
# steps: 1) create dir for the new version, copy the latest Tor Browser
# files there, add the files via git, make a commit for the new version
# and push the changes (easier with system calls)
# os.system('mkdir %s' % version)
# os.system('cp latest/* %s' % version)
# os.system('git add %s;git commit -m "%s"' % (version, version))
# os.system('cd %s;git push %s %s' % (version, remote, branch))
gh = github.GitHub(gh_token, None)
repocontent = gh.repo(
).contents().get('%s/%s' % (path, version))
core = gettor.core.Core(
# erase old links, if any
core.create_links_file('GitHub', readable_fp)
for file in repocontent:
# e.g.
m ='%s.*\/(.*)' % raw_content, file[u'download_url'])
if m:
filename =
# get bundle info according to its OS
if re.match('.*\.exe$', filename):
osys, arch, lc = get_bundle_info(filename, 'windows')
filename_asc = filename.replace('exe', 'exe.asc')
elif re.match('.*\.dmg$', filename):
osys, arch, lc = get_bundle_info(filename, 'osx')
filename_asc = filename.replace('dmg', 'dmg.asc')
elif re.match('.*\.tar.xz$', filename):
osys, arch, lc = get_bundle_info(filename, 'linux')
filename_asc = filename.replace('tar.xz', 'tar.xz.asc')
# don't care about other files (asc or txt)
sha256 = get_file_sha256('%s/%s/%s' % (path, version, filename))
# since the url is easy to construct and it doesn't involve any
# kind of unique hash or identifier, we get the link for the
# asc signature just by adding '.asc'
link_asc = file[u'download_url'].replace(filename, filename_asc)
link = "Package (%s-bit): %s\nASC signature (%s-bit): %s\n"\
"Package SHA256 checksum (%s-bit): %s\n" %\
(arch, file[u'download_url'], arch, link_asc,
arch, sha256)
print "Adding %s" % file[u'download_url']
core.add_link('GitHub', osys, lc, link)
print "Github links updated!"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment