]> git.lizzy.rs Git - torbrowser-launcher.git/blobdiff - torbrowser-launcher
using subprocess.Popen instead of subprocess.check_output, to be compatible with...
[torbrowser-launcher.git] / torbrowser-launcher
index 32a05ed58fb83a7d6b26e300120dc9f2264a2f0f..a178be69e438c8be9c345643b38c1490084cabc0 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-import os, sys, subprocess, locale, urllib2, gobject
+import os, sys, subprocess, locale, urllib2, gobject, time
 
 import pygtk
 pygtk.require('2.0')
@@ -10,9 +10,9 @@ class TorBrowserLauncher:
   def __init__(self, current_tbb_version):
     # initialize the app
     self.current_tbb_version = current_tbb_version
-    self.discover_arch_lang();
-    self.build_paths();
-    self.mkdirs();
+    self.discover_arch_lang()
+    self.build_paths()
+    self.mkdirs()
 
     launch_gui = True
 
@@ -28,14 +28,14 @@ class TorBrowserLauncher:
           launch_gui = False
         elif installed_tbb_version < self.current_tbb_version:
           # there is a tbb upgrade available
-          self.set_gui('task', "Your Tor Browser Launcher is out of date. Click Start to download the latest version from https://www.torproject.org.", ['download_tarball', 'download_tarball_sig', 'verify', 'extract', 'run'])
+          self.set_gui('task', "Your Tor Browser is out of date. Click Start to download the latest version from https://www.torproject.org.", ['download_tarball', 'download_tarball_sig', 'verify', 'extract', 'run'])
         else:
           # for some reason the installed tbb is newer than the current version?
-          self.set_gui('error', "Something is wrong. The version of Tor Browser Bundle you have installed is newer than the current version?")
+          self.set_gui('error', "Something is wrong. The version of Tor Browser Bundle you have installed is newer than the current version?", [])
 
       else:
         # if tbb is installed but the version file doesn't exist, something is wrong
-        self.set_gui('error', "Something is wrong. You have the Tor Browser Bundle installed, but the version file is missing.")
+        self.set_gui('error', "Something is wrong. You have the Tor Browser Bundle installed, but the version file is missing.", [])
 
     # not installed
     else:
@@ -58,7 +58,7 @@ class TorBrowserLauncher:
   # discover the architecture and language
   def discover_arch_lang(self):
     # figure out the architecture
-    self.architecture = subprocess.check_output(['arch']).strip('\n')
+    self.architecture = subprocess.Popen(['arch'], stdout=subprocess.PIPE, stderr=None).stdout.read().strip('\n')
 
     # figure out the language
     available_languages = ['en-US', 'ar', 'de', 'es-ES', 'fa', 'fr', 'it', 'ko', 'nl', 'pl', 'pt-PT', 'ru', 'vi', 'zh-CN']
@@ -93,10 +93,8 @@ class TorBrowserLauncher:
         'verify': '/usr/share/torbrowser-launcher/verify.sh'
       },
       'url': {
-        #'tarball': 'https://www.torproject.org/dist/torbrowser/linux/'+tarball_filename,
-        #'tarball_sig': 'https://www.torproject.org/dist/torbrowser/linux/'+tarball_filename+'.asc'
-        'tarball': 'http://localhost/'+tarball_filename,
-        'tarball_sig': 'http://localhost/'+tarball_filename+'.asc'
+        'tarball': 'https://www.torproject.org/dist/torbrowser/linux/'+tarball_filename,
+        'tarball_sig': 'https://www.torproject.org/dist/torbrowser/linux/'+tarball_filename+'.asc'
       },
       'filename': {
         'tarball': tarball_filename,
@@ -121,10 +119,18 @@ class TorBrowserLauncher:
   def build_ui(self):
     self.timer = False
 
+    # allow buttons to have icons
+    try:
+      settings = gtk.settings_get_default()
+      settings.props.gtk_button_images = True
+    except:
+      pass
+
+    # set up the window
     self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
-    self.window.set_title("Tor Browser Launcher")
+    self.window.set_title("Tor Browser")
+    self.window.set_position(gtk.WIN_POS_CENTER)
     self.window.set_border_width(10)
-    
     self.window.connect("delete_event", self.delete_event)
     self.window.connect("destroy", self.destroy)
 
@@ -133,25 +139,28 @@ class TorBrowserLauncher:
 
     if self.gui == 'error':
       # labels
-      self.label1 = gtk.Label( self.gui_message ); 
+      self.label1 = gtk.Label( self.gui_message ) 
       self.label1.set_line_wrap(True)
       self.box.pack_start(self.label1, True, True, 0)
       self.label1.show()
 
-      self.label2 = gtk.Label("You can fix the problem by deleting:\n"+self.paths['dir']['data']+"\n\nHowever, you will lose all your bookmarks and other Tor Browser preferences."); 
+      self.label2 = gtk.Label("You can fix the problem by deleting:\n"+self.paths['dir']['data']+"\n\nHowever, you will lose all your bookmarks and other Tor Browser preferences.") 
       self.label2.set_line_wrap(True)
       self.box.pack_start(self.label2, True, True, 0)
       self.label2.show()
 
       # exit button
+      exit_image = gtk.Image()
+      exit_image.set_from_stock(gtk.STOCK_CANCEL, gtk.ICON_SIZE_BUTTON)
       self.exit_button = gtk.Button("Exit")
+      self.exit_button.set_image(exit_image)
       self.exit_button.connect("clicked", self.destroy, None)
       self.box.add(self.exit_button)
       self.exit_button.show()
 
     elif self.gui == 'task':
       # label
-      self.label = gtk.Label( self.gui_message ); 
+      self.label = gtk.Label( self.gui_message ) 
       self.label.set_line_wrap(True)
       self.box.pack_start(self.label, True, True, 0)
       self.label.show()
@@ -159,6 +168,7 @@ class TorBrowserLauncher:
       # progress bar
       self.progressbar = gtk.ProgressBar(adjustment=None)
       self.progressbar.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
+      self.progressbar.set_pulse_step(0.01)
       self.box.pack_start(self.progressbar, True, True, 0)
 
       # button box
@@ -168,19 +178,25 @@ class TorBrowserLauncher:
       self.button_box.show()
 
       # start button
+      start_image = gtk.Image()
+      start_image.set_from_stock(gtk.STOCK_APPLY, gtk.ICON_SIZE_BUTTON)
       self.start_button = gtk.Button("Start")
+      self.start_button.set_image(start_image)
       self.start_button.connect("clicked", self.start, None)
       self.button_box.add(self.start_button)
       self.start_button.show()
 
       # exit button
+      exit_image = gtk.Image()
+      exit_image.set_from_stock(gtk.STOCK_CANCEL, gtk.ICON_SIZE_BUTTON)
       self.exit_button = gtk.Button("Exit")
+      self.exit_button.set_image(exit_image)
       self.exit_button.connect("clicked", self.destroy, None)
       self.button_box.add(self.exit_button)
       self.exit_button.show()
 
     self.box.show()
-    self.window.show();
+    self.window.show()
 
   # start button clicked, begin tasks
   def start(self, widget, data=None):
@@ -221,6 +237,10 @@ class TorBrowserLauncher:
     elif task == 'run':
       print 'Running '+self.paths['file']['start']
       self.run()
+    
+    elif task == 'start_over':
+      print 'Starting download over again'
+      self.start_over()
 
 
   def download(self, name, url, path):
@@ -230,7 +250,7 @@ class TorBrowserLauncher:
     self.progressbar.show()
 
     # start the download
-    self.dl_response = urllib2.urlopen(url);
+    self.dl_response = urllib2.urlopen(url)
     self.dl_total_size = self.dl_response.info().getheader('Content-Length').strip()
     self.dl_total_size = int(self.dl_total_size)
     self.dl_bytes_so_far = 0
@@ -266,21 +286,56 @@ class TorBrowserLauncher:
     return True
 
   def verify(self):
-    verify_output = subprocess.check_output([self.paths['file']['verify']])
-    if 'Good signature' in verify_output:
-      self.run_task();
+    # initialize the progress bar
+    self.progressbar.set_fraction(0) 
+    self.progressbar.set_text('Verifying Signature')
+    self.progressbar.show()
 
+    p = subprocess.Popen([self.paths['file']['verify'], self.paths['dir']['gpg'], self.paths['file']['tarball_sig']], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+    self.pulse_until_process_exits(p)
+
+    output = p.stdout.read()
+    
+    if 'Good signature' in output:
+      self.run_task()
     else:
-      self.label = "Signature verification failed!"
+      self.progressbar.hide()
+      self.label.set_text("SIGNATURE VERIFICATION FAILED!\n\nYou might be under attack, or there might just be a networking problem. Click Start try the download again.")
+      self.gui_tasks = ['start_over']
+      self.gui_task_i = 0
+      self.start_button.set_sensitive(True)
 
   def extract(self):
-    subprocess.call(['tar', '-xf', self.paths['file']['tarball'], '-C', self.paths['dir']['tbb']])
-    self.run_task();
+    # initialize the progress bar
+    self.progressbar.set_fraction(0) 
+    self.progressbar.set_text('Installing')
+    self.progressbar.show()
+
+    p = subprocess.Popen(['tar', '-xf', self.paths['file']['tarball'], '-C', self.paths['dir']['tbb']], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+    self.pulse_until_process_exits(p)
+
+    self.run_task()
 
   def run(self, run_next_task = True):
     subprocess.Popen([self.paths['file']['start']])
     if run_next_task:
-      self.run_task();
+      self.run_task()
+
+  # make the progress bar pulse until process p (a Popen object) finishes
+  def pulse_until_process_exits(self, p):
+    while p.poll() == None:
+      time.sleep(0.01)
+      self.progressbar.pulse()
+      # redraw gtk
+      while gtk.events_pending():
+         gtk.main_iteration(False)
+
+  # start over and download TBB again
+  def start_over(self):
+    self.label.set_text("Downloading Tor Browser Bundle over again.")
+    self.gui_tasks = ['download_tarball', 'download_tarball_sig', 'verify', 'extract', 'run']
+    self.gui_task_i = 0
+    self.start(None)
   
   # exit
   def delete_event(self, widget, event, data=None):
@@ -293,9 +348,12 @@ class TorBrowserLauncher:
     gtk.main_quit()
 
 if __name__ == "__main__":
+  current_tbl_version = '0.1'
+  current_tbb_version = '2.3.25-2'
+
   print 'Tor Browser Launcher'
+  print 'version %s' % (current_tbl_version)
   print 'https://github.com/micahflee/torbrowser-launcher'
 
-  current_tbb_version = '2.3.25-2'
   app = TorBrowserLauncher(current_tbb_version)