[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r18225 - in gnunet-update: doc gnunet_update test
From: |
gnunet |
Subject: |
[GNUnet-SVN] r18225 - in gnunet-update: doc gnunet_update test |
Date: |
Sun, 20 Nov 2011 23:48:41 +0100 |
Author: harsha
Date: 2011-11-20 23:48:41 +0100 (Sun, 20 Nov 2011)
New Revision: 18225
Added:
gnunet-update/doc/manifest.txt
gnunet-update/gnunet_update/update.py
Modified:
gnunet-update/gnunet_update/__main__.py
gnunet-update/gnunet_update/install.py
gnunet-update/gnunet_update/util.py
gnunet-update/test/package.sh
Log:
moved redundant code to util, started update module
Added: gnunet-update/doc/manifest.txt
===================================================================
--- gnunet-update/doc/manifest.txt (rev 0)
+++ gnunet-update/doc/manifest.txt 2011-11-20 22:48:41 UTC (rev 18225)
@@ -0,0 +1,19 @@
+Install Manifest
+
+This is a file to track the files installed through gnunet-update
+
+* Rationale
+ During update from older revision to newer revision often not all files may
+ need to be updated. This behaviour often helps us to keep updates small in
+ size. The update happens by replacing files which need to be updated by their
+ newer versions. These newly updated files may no longer depend on files which
+ the older files need. To keep the installation root clean we need those files
+ to be deleted. It is in such situations, being aware of what files were
+ installed is helpful and the install manifest file is used to address this
+ issue.
+
+* Format
+ This file is simply a listing of all the file paths of installed files with
+ the file path being relative to the installation base directory.
+
+ The location of this file is in share/gnunet-update/install-manifest
Modified: gnunet-update/gnunet_update/__main__.py
===================================================================
--- gnunet-update/gnunet_update/__main__.py 2011-11-20 21:26:35 UTC (rev
18224)
+++ gnunet-update/gnunet_update/__main__.py 2011-11-20 22:48:41 UTC (rev
18225)
@@ -34,6 +34,7 @@
Valid actions are:
package
install
+ update
To know more about each action and what it does type:
gnunet-update action --help
@@ -52,7 +53,10 @@
elif "install" == function:
import install
install.main()
+elif "update" == function:
+ import update
+ update.main()
else:
#Print usage information
usage()
- sys.exit(1)
\ No newline at end of file
+ sys.exit(1)
Modified: gnunet-update/gnunet_update/install.py
===================================================================
--- gnunet-update/gnunet_update/install.py 2011-11-20 21:26:35 UTC (rev
18224)
+++ gnunet-update/gnunet_update/install.py 2011-11-20 22:48:41 UTC (rev
18225)
@@ -26,10 +26,8 @@
import sys
import os
import getopt
-import platform
import subprocess
import tempfile
-import shutil
import util
from metadata import Metadata
@@ -68,17 +66,6 @@
search for it while linking
""")
-def get_available_libs():
- """Finds from `ldconfig -v' the installed deps."""
- global available_libs
- proc = subprocess.Popen(["ldconfig", "-p"], stdout=subprocess.PIPE)
- (ldconfig_output, ldconfig_err) = proc.communicate()
- proc.stdout.close()
- parsed_dep_list = util.parse_ldconfig_output(ldconfig_output)
- def create_dependency(parsed_dep_line):
- return Dependency(parsed_dep_line[0])
- return map(create_dependency, parsed_dep_list)
-
def main():
"""Execution start point."""
try:
@@ -100,67 +87,24 @@
sys.exit(1)
config = GnunetUpdateConfig() # Configuration
- package_tarfile = tarfile.open(args[0],'r')
- install_dir = args[1]
- # Check for the metadata file and its signature in the given tarfile
- try:
- metadata_tarinfo = package_tarfile.getmember("metadata.dat")
- metadata_sig_tarinfo = package_tarfile.getmember("metadata.dat.asc")
- except KeyError as no_file:
- print no_file + " not found in the given tarfile. Quitting"
- package_tarfile.close()
+ metadata = util.verify_metadata(args[0],
+ config.get('SECURITY', 'PGP_SIGN_KEY'))
+ if metadata is None:
sys.exit(2)
- # Temporary directory for package extraction
- temp_dir = tempfile.mkdtemp()
- package_tarfile.extract(metadata_tarinfo, temp_dir)
- package_tarfile.extract(metadata_sig_tarinfo, temp_dir)
-
-
- # Verify metadata signature
- metadata_fd = open(os.path.join(temp_dir, metadata_tarinfo.name), "rb")
- metadata_sig_fd = open(os.path.join(temp_dir, metadata_sig_tarinfo.name),
"rb")
-
- sig = util.gpg_verify_sign(metadata_fd,
- metadata_sig_fd,
- config.get('SECURITY', 'PGP_SIGN_KEY'),
- detached=True)
- metadata_sig_fd.close()
- metadata_fd.close()
-
- if sig[0].status is not None:
- print "Error verifying the signature of metadata: " + sig[0].status[2]
- shutil.rmtree(temp_dir)
- package_tarfile.close()
- sys.exit(2)
-
- metadata = Metadata()
- metadata.read_from_file(os.path.join(temp_dir, metadata_tarinfo.name))
- shutil.rmtree(temp_dir)
-
- #check whether the system and machine architecture match
- host_system = platform.system()
- host_machine = platform.machine()
-
- if metadata.system != host_system or metadata.machine != host_machine:
- print "The given package is not suited for this platform."
- package_tarfile.close()
- sys.exit(1)
-
#Platform check is done; now unpack the tarfile into destination directory
+ package_tarfile = tarfile.open(args[0],'r')
+ install_dir = args[1]
try:
os.stat(install_dir)
except OSError: # Given directory not present
os.mkdir(install_dir, 0755)
available_libs = get_available_libs() # already available dependencies
- new_binary_objects = metadata.binary_objects # To be installed objects
available_libs.sort(key=(lambda dep: dep.name))
-
installed_files = list() # List of files that are installed from package
+ needed_deps = metadata.dependencies # Required dependencies
- needed_deps = metadata.dependencies
-
# FIXME: Add filtering in config
dep_filter = ["/lib/ld-linux.so.2"]
to_be_installed_deps = [(dep) for dep in needed_deps
@@ -182,10 +126,9 @@
installed_files.append(member.name)
# Install the needed dependencies from tarfile
- dep_dir = install_dir + "/lib/gnunet-deps"
+ dep_dir = os.path.join(install_dir, "lib/gnunet-deps")
if not os.path.exists(dep_dir):
os.makedirs(dep_dir)
-
orig_working_dir = os.getcwd()
# Change to dep install dir
os.chdir(dep_dir)
@@ -212,24 +155,16 @@
if os.path.exists(dep.name):
os.remove(dep.name)
os.symlink(dep.realname, dep.name)
- installed_files.append(os.path.join(dep_dir, 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()
+ # Write install manifest file
+ util.write_install_manifest(install_dir, installed_files)
os.chdir(orig_working_dir)
- 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()
-
print "Installation Successful!"
print "GNUNET has been installed at: " + install_dir
shared_library_setup(dep_dir)
Added: gnunet-update/gnunet_update/update.py
===================================================================
--- gnunet-update/gnunet_update/update.py (rev 0)
+++ gnunet-update/gnunet_update/update.py 2011-11-20 22:48:41 UTC (rev
18225)
@@ -0,0 +1,70 @@
+# This file is part of GNUnet.
+# (C) 2001--2011 Christian Grothoff (and other contributing authors)
+#
+# GNUnet is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published
+# by the Free Software Foundation; either version 2, or (at your
+# option) any later version.
+#
+# GNUnet is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNUnet; see the file COPYING. If not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+# File: gnunet_update/update.py
+# Author: Sree Harsha Totakura
+#
+# Updates an existing installation of gnunet to a new release
+
+import os
+import gpgme
+import getopt
+import sys
+
+def usage():
+ """Print helpful usage information."""
+ print """
+Usage arguments: [options] <package_file> </install/location>
+This script tries to update an existing installation at /install/location to
+the new version contained in the package_file
+
+Options:
+ -h, --help : prints this message
+"""
+
+def main():
+ """Execution start point."""
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
+ except getopt.GetoptError, err:
+ print err
+ print "Execption occured"
+ usage()
+ sys.exit(1)
+
+ for option, value in opts:
+ if option in ("-h", "--help"):
+ usage()
+ sys.exit(2)
+
+ if len(args) != 2:
+ print "Incorrect number of arguments"
+ usage()
+ sys.exit(1)
+
+ config = GnunetUpdateConfig() # Configuration
+ metadata = util.verify_metadata(args[0],
+ config.get('SECURITY', 'PGP_SIGN_KEY'))
+ if metadata is None:
+ sys.exit(2)
+ package_tarfile = tarfile.open(args[0], 'r')
+ install_dir = args[1]
+
+if "__main__" == __name__:
+ main()
+
Modified: gnunet-update/gnunet_update/util.py
===================================================================
--- gnunet-update/gnunet_update/util.py 2011-11-20 21:26:35 UTC (rev 18224)
+++ gnunet-update/gnunet_update/util.py 2011-11-20 22:48:41 UTC (rev 18225)
@@ -24,7 +24,14 @@
from hashlib import sha512
import gpgme
import os
+import tempfile
+import tarfile
+import shutil
+import platform
+from metadata import Metadata
+from dependency import Dependency
+
def parse_ldd_output(ldd_output, splitted_input=False):
"""Parses ldd output.
@@ -126,7 +133,83 @@
new_sigs = ctx.verify(sign_fd, None, plain_fd)
else:
new_sigs = ctx.verify(sign_fd, plain_fd, None)
+ return new_sigs
+def verify_metadata(package_tarfile_path, key_fpr):
+ """Verifys whether metadata of the package is valid and authentic
+ package_tarfile_path: The path of the package file. This tarfile will be
+ examined for metadata and its signature
+ key_fpr: The key to validate the metadata signature
- return new_sigs
+ return: If metadata of the package is valid and authentic, the metadata is
+ read into a Metadata object which is returned. If it is found to be not
+ valid or authentic then None is returned.
+ """
+ package_tarfile = tarfile.open(package_tarfile_path, 'r')
+ # Check for the metadata file and its signature in the given tarfile
+ try:
+ metadata_tarinfo = package_tarfile.getmember("metadata.dat")
+ metadata_sig_tarinfo = package_tarfile.getmember("metadata.dat.asc")
+ except KeyError as no_file:
+ print no_file + " not found in the given tarfile. Quitting"
+ package_tarfile.close()
+ return None
+
+ # Temporary directory for package extraction
+ temp_dir = tempfile.mkdtemp()
+ package_tarfile.extract(metadata_tarinfo, temp_dir)
+ package_tarfile.extract(metadata_sig_tarinfo, temp_dir)
+ package_tarfile.close()
+
+ # Verify metadata signature
+ metadata_fd = open(os.path.join(temp_dir, metadata_tarinfo.name), "rb")
+ metadata_sig_fd = open(os.path.join(temp_dir, metadata_sig_tarinfo.name),
"rb")
+
+ sig = gpg_verify_sign(metadata_fd,
+ metadata_sig_fd,
+ key_fpr,
+ detached=True)
+ metadata_sig_fd.close()
+ metadata_fd.close()
+ if sig[0].status is not None:
+ print "Error verifying the signature of metadata: " + sig[0].status[2]
+ shutil.rmtree(temp_dir)
+ return None
+
+ #check whether the system and machine architecture match
+ metadata = Metadata()
+ metadata.read_from_file(os.path.join(temp_dir, metadata_tarinfo.name))
+ shutil.rmtree(temp_dir)
+ host_system = platform.system()
+ host_machine = platform.machine()
+ if metadata.system != host_system or metadata.machine != host_machine:
+ print "The given package is not suited for this platform."
+ return None
+
+ return metadata
+
+def write_install_manifest(install_dir, filenames):
+ """Writes install manifest data into the given directory.
+
+ install_dir: The directory where the manifest file is created
+ filenames: Filenames that are to be included in the 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')), filenames)
+ install_manifest_fd.close()
+
+def get_available_libs():
+ """Finds from `ldconfig -v' the installed libraries."""
+ proc = subprocess.Popen(["ldconfig", "-p"], stdout=subprocess.PIPE)
+ (ldconfig_output, ldconfig_err) = proc.communicate()
+ proc.stdout.close()
+ parsed_dep_list = parse_ldconfig_output(ldconfig_output)
+ def create_dependency(parsed_dep_line):
+ return Dependency(parsed_dep_line[0])
+ return map(create_dependency, parsed_dep_list)
+
Modified: gnunet-update/test/package.sh
===================================================================
--- gnunet-update/test/package.sh 2011-11-20 21:26:35 UTC (rev 18224)
+++ gnunet-update/test/package.sh 2011-11-20 22:48:41 UTC (rev 18225)
@@ -43,4 +43,4 @@
fi
cd $GNUNET_UPDATE_HOME; bin/gnunet-update package test/old/test-package
/tmp/test-pack && \
- bin/gnunet-update install /tmp/test-pack.meta /tmp/test-pack.tgz
/tmp/test-install
+ bin/gnunet-update install /tmp/test-pack.tgz /tmp/test-install
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r18225 - in gnunet-update: doc gnunet_update test,
gnunet <=