aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Lutomirski <luto@amacapital.net>2014-09-07 15:05:18 -0700
committerAndy Lutomirski <luto@amacapital.net>2014-09-09 15:54:42 -0700
commit7a7166871e06d6ca229395b65717e55dcae13671 (patch)
treef9118efb433b5d5db8b99f3cd778353c3fc70a58
parent26d3b29bf713e12753e3181c51b0374c8e0b42ad (diff)
downloadvirtme-7a7166871e06d6ca229395b65717e55dcae13671.tar.gz
Move guest tools into virtme/guest and hopefully fix installation
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
-rwxr-xr-xsetup.py9
-rwxr-xr-xvirtme-run9
-rw-r--r--virtme/commands/run.py36
-rwxr-xr-xvirtme/guest/virtme-init (renamed from guest-tools/virtme-init)0
-rwxr-xr-xvirtme/guest/virtme-loadmods (renamed from guest-tools/virtme-loadmods)0
-rwxr-xr-xvirtme/guest/virtme-udhcpc-script (renamed from guest-tools/virtme-udhcpc-script)0
-rw-r--r--virtme/guest_tools.py75
7 files changed, 101 insertions, 28 deletions
diff --git a/setup.py b/setup.py
index a4c2d77..a4e9a9f 100755
--- a/setup.py
+++ b/setup.py
@@ -19,12 +19,19 @@ setup(
url='https://git.kernel.org/cgit/utils/kernel/virtme/virtme.git',
license=open('./LICENSE').read(),
long_description=open('./README.md').read(),
- packages=['virtme'],
+ packages=['virtme', 'virtme.commands'],
install_requires=[],
entry_points = {
'console_scripts': [
'virtme-run = virtme.commands.run:main',
]
},
+ data_files = [
+ ('share/virtme-guest-0',
+ ['virtme/guest/virtme-init',
+ 'virtme/guest/virtme-udhcpc-script',
+ 'virtme/guest/virtme-loadmods',
+ ]),
+ ],
classifiers=['Environment :: Console']
)
diff --git a/virtme-run b/virtme-run
index 1af3c71..f9457db 100755
--- a/virtme-run
+++ b/virtme-run
@@ -6,9 +6,8 @@
# as a file called LICENSE with SHA-256 hash:
# 8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643
-import os
-from virtme.commands import run
-
-mypath = os.path.dirname(os.path.realpath(os.path.abspath(__file__)))
+# This file is not installed; it's just use to run virtme from inside
+# a source distribution.
-exit(run.main(mypath=mypath))
+from virtme.commands import run
+exit(run.main())
diff --git a/virtme/commands/run.py b/virtme/commands/run.py
index ea21e2c..44880ed 100644
--- a/virtme/commands/run.py
+++ b/virtme/commands/run.py
@@ -18,6 +18,7 @@ from .. import modfinder
from .. import mkinitramfs
from .. import qemu_helpers
from .. import architectures
+from .. import guest_tools
uname = os.uname()
@@ -135,7 +136,7 @@ def quote_karg(arg):
else:
return arg
-def main(mypath = None):
+def main():
args = _ARGPARSER.parse_args()
qemu = qemu_helpers.Qemu(args.arch)
@@ -159,30 +160,21 @@ def main(mypath = None):
# Set up virtfs
export_virtfs(qemu, arch, qemuargs, args.root, '/dev/root')
- def root_has_dir(path):
- # Don't use os.path.join: we want to treat absolute paths
- # as relative.
- return os.path.isdir(args.root + '/' + path)
-
- if root_has_dir('/usr/local/share/virtme-guest-0'):
- virtme_init = '/usr/local/share/virtme-guest-0/virtme-init'
- elif root_has_dir('/usr/share/virtme-guest-0'):
- virtme_init = '/usr/share/virtme-guest-0/virtme-init'
- elif (mypath is not None and
- os.path.isdir(os.path.join(mypath, 'guest-tools'))):
- if args.root == '/':
- virtme_init = os.path.join(mypath, 'guest-tools/virtme-init')
- else:
- virtme_init = '/run/virtme/guesttools/virtme-init'
- export_virtfs(qemu, arch, qemuargs,
- os.path.join(mypath, 'guest-tools'),
- 'virtme.guesttools')
- need_initramfs = True
- else:
+ guest_tools_in_guest, guest_tools_path = \
+ guest_tools.find_best_guest_tools(args.root)
+ if guest_tools_path is None:
raise ValueError("couldn't find usable virtme guest tools")
+ if guest_tools_in_guest:
+ virtme_init = os.path.join(guest_tools_path, 'virtme-init')
+ else:
+ virtme_init = '/run/virtme/guesttools/virtme-init'
+ export_virtfs(qemu, arch, qemuargs, guest_tools_path,
+ 'virtme.guesttools')
+ need_initramfs = True
+
# TODO: This has escaping issues for now
- kernelargs.append('init=%s' % virtme_init)
+ kernelargs.append('init=%s' % os.path.join('/', virtme_init))
# Map modules
if moddir is not None:
diff --git a/guest-tools/virtme-init b/virtme/guest/virtme-init
index 2d97010..2d97010 100755
--- a/guest-tools/virtme-init
+++ b/virtme/guest/virtme-init
diff --git a/guest-tools/virtme-loadmods b/virtme/guest/virtme-loadmods
index 2c16db2..2c16db2 100755
--- a/guest-tools/virtme-loadmods
+++ b/virtme/guest/virtme-loadmods
diff --git a/guest-tools/virtme-udhcpc-script b/virtme/guest/virtme-udhcpc-script
index 6d76e98..6d76e98 100755
--- a/guest-tools/virtme-udhcpc-script
+++ b/virtme/guest/virtme-udhcpc-script
diff --git a/virtme/guest_tools.py b/virtme/guest_tools.py
new file mode 100644
index 0000000..c6d4819
--- /dev/null
+++ b/virtme/guest_tools.py
@@ -0,0 +1,75 @@
+#!/usr/bin/python3
+# -*- mode: python -*-
+# resources.py: Find virtme's resources
+# Copyright © 2014 Andy Lutomirski
+# Licensed under the GPLv2, which is available in the virtme distribution
+# as a file called LICENSE with SHA-256 hash:
+# 8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643
+
+"""Helpers to find virtme's guest tools."""
+
+import os
+import pkg_resources
+
+def find_dist_guest_tools():
+ """Return the path of the guest tools installed with the running virtme.
+
+ This is much more complicated than it deserves to be.
+ """
+
+ # First try: look for an ordinary resource. This will succeed when
+ # running from the source tree, but it is unlikely to succeed
+ # if we're running out of any sort of installation.
+ if pkg_resources.resource_isdir(__name__, 'guest'):
+ return pkg_resources.resource_filename(__name__, 'guest')
+
+ # Second try: look for a distribution resource.
+ provider = pkg_resources.get_provider(__name__)
+ if provider.egg_info is not None:
+ dist = pkg_resources.Distribution.from_filename(provider.egg_root)
+ req = dist.as_requirement()
+ if pkg_resources.resource_isdir(req, 'share/virtme-guest-0'):
+ return pkg_resources.resource_filename(req, 'share/virtme-guest-0')
+
+ # No luck. This is somewhat surprising.
+ return None
+
+def find_installed_guest_tools(root):
+ def has_dir(path):
+ # Don't use os.path.join: we want to treat absolute paths
+ # as relative.
+ return os.path.isdir(root + '/' + path)
+
+ if has_dir('usr/local/share/virtme-guest-0'):
+ return '/usr/local/share/virtme-guest-0'
+ elif has_dir('usr/share/virtme-guest-0'):
+ return 'usr/share/virtme-guest-0'
+ else:
+ return None
+
+def find_best_guest_tools(root):
+ """Returns the path to the best choice of guest tools.
+
+ This returns a tuple (in_guest, relative_path). If in_guest is true,
+ then relative_path is guaranteed to be relative.
+ """
+
+ # Always prefer the installed guest tools. This way blocking access
+ # to /home is more likely to work.
+ path = find_installed_guest_tools(root)
+ if path is not None:
+ return (True, path)
+
+ # Now try the host's copy. This is here to keep root != '/' as consistent
+ # as possible
+ if root != '/':
+ path = find_installed_guest_tools('/')
+ if path is not None:
+ return (False, path)
+
+ # Now try the dist copy.
+ path = find_dist_guest_tools()
+ if path is not None:
+ return (root == '/', os.path.relpath(path, '/'))
+
+ return (None, None)