[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r18400 - gnunet-update/gnunet_update
From: |
gnunet |
Subject: |
[GNUnet-SVN] r18400 - gnunet-update/gnunet_update |
Date: |
Wed, 30 Nov 2011 10:01:23 +0100 |
Author: harsha
Date: 2011-11-30 10:01:23 +0100 (Wed, 30 Nov 2011)
New Revision: 18400
Modified:
gnunet-update/gnunet_update/dependency.py
gnunet-update/gnunet_update/install.py
gnunet-update/gnunet_update/update.py
gnunet-update/gnunet_update/util.py
Log:
added update module
Modified: gnunet-update/gnunet_update/dependency.py
===================================================================
--- gnunet-update/gnunet_update/dependency.py 2011-11-30 08:46:58 UTC (rev
18399)
+++ gnunet-update/gnunet_update/dependency.py 2011-11-30 09:01:23 UTC (rev
18400)
@@ -69,7 +69,7 @@
return (self.name == other.name)
def __hash__(self):
- """Calculates the hashes of dependency name."""
+ """Calculates the hash of dependency name."""
return hash(self.name)
Modified: gnunet-update/gnunet_update/install.py
===================================================================
--- gnunet-update/gnunet_update/install.py 2011-11-30 08:46:58 UTC (rev
18399)
+++ gnunet-update/gnunet_update/install.py 2011-11-30 09:01:23 UTC (rev
18400)
@@ -46,21 +46,21 @@
-h, --help : prints this message
"""
-def shared_library_setup(install_path):
- print ("Shared libraries have been installed into the following path:\n"
- + install_path)
+def shared_library_setup(shared_library_paths):
+ print ("Shared libraries have been installed into the following path(s):")
+ for path in shared_library_paths: print path
print (
"""To continue runtime usage of these libraries or for any of the installed
programs to work you must either do one of the following:
- * Add the above directory to /etc/ld.so.conf and run `ldconfig' as root so
that the
+ * Add the above path(s) to /etc/ld.so.conf and run `ldconfig' as root so that
the
libraries are stored in the dynamic linker's cache
- * Add the above directory to LD_LIBRARY_PATH environmental variable.
Optionally you
+ * Add the above path(s) to LD_LIBRARY_PATH environmental variable. Optionally
you
can save this setting into your ~/.profile file
If you are buildling other software and would like to use the installed
libraries, you may have to either:
- * Add the above directory to /etc/ld.so.conf and run `ldconfig' as root
- * Add the above directory to LD_RUN_PATH environmental variable. Optionally
you can
+ * Add the above path(s) to /etc/ld.so.conf and run `ldconfig' as root
+ * Add the above path(s) to LD_RUN_PATH environmental variable. Optionally you
can
save this setting into your ~/.profile file
* Include the above directory in the linker flags so that the linker can
search for it while linking
@@ -106,25 +106,15 @@
to_be_installed_deps = util.filter_needed_deps(needed_deps,
available_libs)
- #FIXME: Security warning! Perhaps we should examin the contents of tarfile
- #before extracting
- for member in package_tarfile.getmembers():
- if ("metadata.dat" == member.name or
- "metadata.dat.asc" == member.name or
- "install-prefix" == member.name or
- member.name.startswith("dependencies/")):
- continue
- elif member.name.startswith("install-prefix"):
- # Remove the `install-prefix' directory
- member.name = member.name.replace("install-prefix/","",1)
- package_tarfile.extract(member, install_dir)
- installed_files.append(member.name)
+ # Extract the package's main software contents
+ util.extract_install_prefix(package_tarfile, install_dir, installed_files)
# Install the needed dependencies from tarfile
dep_dir = os.path.join(install_dir, "lib/gnunet-deps")
if not os.path.exists(dep_dir):
os.makedirs(dep_dir)
- installed_files.append(dep_dir)
+ # Add the gnunet dependency dir to the install manifest
+ installed_files.append("lib/gnunet-deps")
orig_working_dir = os.getcwd()
# Change to dep install dir
os.chdir(dep_dir)
@@ -134,7 +124,7 @@
# Remove the `dependencies/' in member.name
dep_tarinfo.name = dep_tarinfo.name.replace("dependencies/","",1)
package_tarfile.extract(dep_tarinfo, "./")
- installed_files.append(os.path.join(dep_dir, dep_tarinfo.name))
+ installed_files.append(os.path.join("lib/gnunet-deps/",
dep_tarinfo.name))
# Check the hash of the extracted file
if util.sha512_hexdigest(dep_tarinfo.name) != dep.hash:
print (dep_tarinfo.name +
@@ -169,7 +159,8 @@
install_manifest_fd.close()
print "Installation Successful!"
print "GNUNET has been installed at: " + install_dir
- shared_library_setup(dep_dir)
+ shared_library_setup([os.path.join(install_dir, "lib"),
+ dep_dir])
if "__main__" == __name__:
main()
Modified: gnunet-update/gnunet_update/update.py
===================================================================
--- gnunet-update/gnunet_update/update.py 2011-11-30 08:46:58 UTC (rev
18399)
+++ gnunet-update/gnunet_update/update.py 2011-11-30 09:01:23 UTC (rev
18400)
@@ -25,7 +25,13 @@
import gpgme
import getopt
import sys
+import re
+import shutil
+import subprocess
+import util
+import metadata
+
def usage():
"""Print helpful usage information."""
print """
@@ -65,6 +71,126 @@
package_tarfile = tarfile.open(args[0], 'r')
install_dir = args[1]
+ # We have to read the install manifest to know the currently installed
+ # files. install_dir must point to an already installed location, if not
+ # we'll fail
+ install_manifest = open(os.path.join(install_dir,
+
"share/gnunet-update/install-manifest"),
+ "rb");
+ install_manifest_files = install_manifest.readlines()
+ install_manifest.close()
+
+ previously_installed_depfiles = [ file for file in install_manifest_files
+ if file.startswith("lib/gnunet-deps") ]
+
+ # We delete all the files except the installed dependencies
+ delete_list = [file for file in install_manifest_files
+ if not in (previosly_installed_depfiles + ["lib"])]
+
+ # First delete the files
+ for file in delete_list:
+ if os.path.isdir(file):
+ continue # We skip deleting directories
+ os.remove(file)
+ delete_list.remove(file)
+ # Now delete directories
+ for dir in delete_list:
+ os.rmdir(dir)
+
+ # find the dependencies installed in the dep dir
+ regex = re.compile("(.+\.so\.\d+).*")
+ previously_installed_deps = list()
+ for dep_file in previously_installed_depfiles:
+ match = regex.match(os.path.basename(dep_file))
+ if match:
+ name = match.group(1)
+ dep = Dependency(name)
+ dep.set_path(dep_file)
+ previously_installed_deps.append(dep)
+ else:
+ raise Exception("Unable to determine the name of installed
dependency")
+
+ available_libs = util.get_available_libs() # already available
dependencies
+ needed_deps = metadata.dependencies.keys() # Required dependencies
+ satisfying_deps = list() # satisfying dependencies
+ to_be_installed_deps = util.filter_needed_deps(needed_deps,
+ available_libs)
+ to_be_installed_deps = util.filter_needed_deps(to_be_installed_deps,
+ previously_installed_deps,
+ trace=satisfying_deps)
+ # No longer needed - to be deleted deps
+ old_notuseful_deps = [dep for dep in previously_installed_deps
+ if dep not in satisfying_deps]
+ # Delete the dependencies which are no longer needed
+ for dep in old_notuseful_deps:
+ os.remove(dep.path)
+
+ # Remove the symbolic links in the dep dir
+ for root, dirs, files in os.walk(os.path.join(install_dir,
+ "lib/gnunet-deps")):
+ for file in files:
+ file_path = os.path.join(root, file)
+ if os.path.islink(file_path):
+ os.remove(file_path)
+
+ installed_files = list() # List of files that are installed from package
+ # Extract the package's main software contents
+ util.extract_install_prefix(package_tarfile, install_dir, installed_files)
+
+ ######## DUPLICATED FROM INSTALL ########
+
+ # Install the needed dependencies from tarfile
+ dep_dir = os.path.join(install_dir, "lib/gnunet-deps")
+ if not os.path.exists(dep_dir):
+ os.makedirs(dep_dir)
+
+ # Add the gnunet dependency dir to the install manifest
+ installed_files.append("lib/gnunet-deps")
+ orig_working_dir = os.getcwd()
+ # Change to dep install dir
+ os.chdir(dep_dir)
+
+ for dep in to_be_installed_deps:
+ dep_tarinfo = package_tarfile.getmember("dependencies/" + dep.realname)
+ # Remove the `dependencies/' in member.name
+ dep_tarinfo.name = dep_tarinfo.name.replace("dependencies/","",1)
+ package_tarfile.extract(dep_tarinfo, "./")
+ installed_files.append(os.path.join("lib/gnunet-deps/",
dep_tarinfo.name))
+ # Check the hash of the extracted file
+ if util.sha512_hexdigest(dep_tarinfo.name) != dep.hash:
+ print (dep_tarinfo.name +
+ " not matched with the expected hash " + dep.hash)
+ print "Given package contains code not signed by trusted packager"
+ print "Installation failed due to security reasons."
+ package_tarfile.close()
+ os.chdir(orig_working_dir)
+ shutil.rmtree(install_dir)
+ sys.exit(0)
+
+ # Generate symbolic link from dep.name to dep.realname
+ # NOTE: Available only on Unix type systems!
+ if os.path.exists(dep.name):
+ os.remove(dep.name)
+ os.symlink(dep.realname, dep.name)
+ installed_files.append(os.path.join("lib/gnunet-deps", dep.name))
+ package_tarfile.close()
+
+ # run ldconfig -n in the dep_dir
+ proc = subprocess.Popen(["ldconfig", "-n"])
+ proc.wait()
+ os.chdir(orig_working_dir)
+
+ # Write install manifest file
+ if not os.path.exists(os.path.join(install_dir, "share/gnunet-update/")):
+ os.makedirs(os.path.join(install_dir, "share/gnunet-update/"))
+ install_manifest_fd = open(os.path.join(install_dir,
+
"share/gnunet-update/install-manifest"),
+ "wb")
+ map((lambda name: install_manifest_fd.write(name + '\n')), installed_files)
+ install_manifest_fd.close()
+ ######## DUPLICATED FROM INSTALL ########
+ # FIXME: Add shared library installation message
+
if "__main__" == __name__:
main()
Modified: gnunet-update/gnunet_update/util.py
===================================================================
--- gnunet-update/gnunet_update/util.py 2011-11-30 08:46:58 UTC (rev 18399)
+++ gnunet-update/gnunet_update/util.py 2011-11-30 09:01:23 UTC (rev 18400)
@@ -210,7 +210,7 @@
return dep
return map(create_dependency, parsed_dep_list)
-def filter_needed_deps(needed_deps, available_deps):
+def filter_needed_deps(needed_deps, available_deps, trace=None):
"""
Returns the list of needed_deps which are not satisfied by the available
libraries
@@ -218,12 +218,15 @@
needed_deps: The list of dependencies that are needed by the binary objects
available_deps: The list of dependencies that are already
available/installed in the system
+ trace: This should be a list. When not None it will be used to store the
+ available deps that have satisfied needed deps
"""
# FIXME: Add filtering in config
dep_filter = ["/lib/ld-linux.so.2"]
adep_cnt = 0 # Counter for accessing available deps
ndep_cnt = 0 # Counter for accessing needed deps
to_be_installed_deps = list() # Must be installed dependencies
+ # Sort it to get O(nlogn) else O(n^2) :x
available_deps.sort(key=(lambda dep: dep.name))
needed_deps.sort(key=(lambda dep: dep.name))
while True:
@@ -241,7 +244,9 @@
# FIXME: Add configurable option through which user can override
# this beharivour. Also add whether new libraries with greater
# revision numbers are to be preferred
- ndep_cnt += 1; continue
+ ndep_cnt += 1;
+ if trace is not None: trace.append(available_deps[adep_cnt])
+ continue
elif needed_deps[ndep_cnt].name < available_deps[adep_cnt].name:
# There is no installed dep matching this dep hence we have to
# install it
@@ -249,4 +254,26 @@
ndep_cnt += 1; continue
elif needed_deps[ndep_cnt].name > available_deps[adep_cnt].name:
adep_cnt += 1; continue
+ # We did not find any matching dependencies, hence we install
+ to_be_installed_deps.append(needed_deps[ndep_cnt])
+ ndep_cnt += 1;
return to_be_installed_deps;
+
+def extract_install_prefix(package_tarfile, install_dir, installed_files=None):
+ """
+ Extracts the tarfile objects contents into install_dir
+
+ package_tarfile: the tarfile object on which extraction is done
+ install_dir: the directory where the extracted objects are to be placed
+ installed_files: If not None, it should be a list object. It can be used to
+ have a list of files extracted into the install_dir
+ """
+
+ #FIXME: Security warning! Perhaps we should examin the contents of tarfile
+ #before extracting
+ for member in package_tarfile.getmembers():
+ if member.name.startswith("install-prefix/"):
+ # Remove the `install-prefix' directory
+ member.name = member.name.replace("install-prefix/","",1)
+ package_tarfile.extract(member, install_dir)
+ if installed_files is not None: installed_files.append(member.name)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r18400 - gnunet-update/gnunet_update,
gnunet <=