aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--host/CMakeLists.txt1
-rw-r--r--host/utils/CMakeLists.txt8
-rw-r--r--host/utils/uhd_images_downloader.py.in69
3 files changed, 55 insertions, 23 deletions
diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt
index 8bc761c42..fc8c0a240 100644
--- a/host/CMakeLists.txt
+++ b/host/CMakeLists.txt
@@ -198,6 +198,7 @@ INSTALL(FILES
# Images download directory for utils/uhd_images_downloader.py
########################################################################
+SET(UHD_IMAGES_MD5SUM "776eae14a5cc570dcf8692b847783515")
SET(UHD_IMAGES_DOWNLOAD_SRC "http://files.ettus.com/binaries/maint_images/archive/uhd-images_003.005.002-release.zip")
########################################################################
diff --git a/host/utils/CMakeLists.txt b/host/utils/CMakeLists.txt
index 9e997071e..6fc11d747 100644
--- a/host/utils/CMakeLists.txt
+++ b/host/utils/CMakeLists.txt
@@ -76,6 +76,14 @@ INSTALL(PROGRAMS
DESTINATION ${PKG_LIB_DIR}/utils
COMPONENT utilities
)
+IF(LINUX)
+ INSTALL(PROGRAMS
+ ${CMAKE_CURRENT_BINARY_DIR}/uhd_images_downloader.py
+ RENAME uhd_images_downloader
+ DESTINATION ${RUNTIME_DIR}
+ COMPONENT utilities
+ )
+ENDIF(LINUX)
IF(ENABLE_USRP2)
IF(WIN32 AND UHD_RELEASE_MODE) #include dd.exe
diff --git a/host/utils/uhd_images_downloader.py.in b/host/utils/uhd_images_downloader.py.in
index 8c8d2df81..e7fc9e8a5 100644
--- a/host/utils/uhd_images_downloader.py.in
+++ b/host/utils/uhd_images_downloader.py.in
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2012 Ettus Research LLC
+# Copyright 2012-2013 Ettus Research LLC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -17,15 +17,27 @@
#
import atexit
+import hashlib
from optparse import OptionParser
import os
import os.path
import shutil
+import string
import sys
import tempfile
import urllib2
import zipfile
+def md5Checksum(filePath):
+ with open(filePath, 'rb') as fh:
+ m = hashlib.md5()
+ while True:
+ data = fh.read(8192)
+ if not data:
+ break
+ m.update(data)
+ return m.hexdigest()
+
class temp_dir():
def __enter__(self):
@@ -44,6 +56,7 @@ if __name__ == "__main__":
#Configuring image download info
images_src = "@UHD_IMAGES_DOWNLOAD_SRC@"
+ images_zip_md5sum = "@UHD_IMAGES_MD5SUM@"
filename = images_src.split("/")[-1]
with temp_dir() as dirname:
@@ -57,7 +70,9 @@ if __name__ == "__main__":
else:
images_dir = "@CMAKE_INSTALL_PREFIX@/share/uhd/images"
- u = urllib2.urlopen(images_src)
+ opener = urllib2.build_opener()
+ opener.add_headers = [('User-Agent', 'UHD Images Downloader')]
+ u = opener.open(images_src)
f = open(filename, "wb")
meta = u.info()
filesize = float(meta.getheaders("Content-Length")[0])
@@ -81,29 +96,37 @@ if __name__ == "__main__":
f.close()
- #Extracting contents of zip file
- if os.path.exists("tempdir"):
- shutil.rmtree("tempdir")
- os.mkdir("tempdir")
+ #Checking md5sum of zip file
+ downloaded_zip_md5sum = md5Checksum(filename)
+ if images_zip_md5sum != downloaded_zip_md5sum:
+ print "\nMD5 checksum does not match!"
+ print "Expected %s, got %s" % (images_zip_md5sum, downloaded_zip_md5sum)
+ os.remove(filename)
+ os.chdir("/".join(images_dir.split("/")[:-1]))
+ else:
+ #Extracting contents of zip file
+ if os.path.exists("tempdir"):
+ shutil.rmtree("tempdir")
+ os.mkdir("tempdir")
- images_zip = zipfile.ZipFile(filename)
- images_zip.extractall("tempdir")
+ images_zip = zipfile.ZipFile(filename)
+ images_zip.extractall("tempdir")
- #Removing images currently in images_dir
- if os.path.exists(images_dir):
- try:
- shutil.rmtree(images_dir)
- except:
- sys.stderr.write("\nMake sure you have write permissions in the images directory.\n")
- sys.exit(0)
+ #Removing images currently in images_dir
+ if os.path.exists(images_dir):
+ try:
+ shutil.rmtree(images_dir)
+ except:
+ sys.stderr.write("\nMake sure you have write permissions in the images directory.\n")
+ sys.exit(0)
- #Copying downloaded images into images_dir
- shutil.copytree("tempdir/%s/share/uhd/images" % filename[:-4],images_dir)
+ #Copying downloaded images into images_dir
+ shutil.copytree("tempdir/%s/share/uhd/images" % filename[:-4],images_dir)
- #Removing tempdir and zip file
- shutil.rmtree("tempdir")
- images_zip.close()
- os.remove(filename)
+ #Removing tempdir and zip file
+ shutil.rmtree("tempdir")
+ images_zip.close()
+ os.remove(filename)
- os.chdir(images_dir)
- print "\nImages successfully installed to: %s" % images_dir
+ os.chdir(images_dir)
+ print "\nImages successfully installed to: %s" % images_dir