diff --git a/centos-requirements.txt b/centos-requirements.txt index eef8ada9..ad292633 100644 --- a/centos-requirements.txt +++ b/centos-requirements.txt @@ -1,3 +1,4 @@ python34 python34-devel - +python34-pip +rsync diff --git a/python-requirements.txt b/python-requirements.txt index 5664f42c..4df50017 100644 --- a/python-requirements.txt +++ b/python-requirements.txt @@ -1,2 +1,2 @@ psutil - +doit diff --git a/wlutil/fedora/overlay/.gitignore b/wlutil/fedora/overlay/.gitignore index 31fcb34b..8c93fc7a 100644 --- a/wlutil/fedora/overlay/.gitignore +++ b/wlutil/fedora/overlay/.gitignore @@ -1,2 +1 @@ -# This file is autogenerated by the scripts -firesim.sh +etc/systemd/system/firesim.service diff --git a/wlutil/fedora/overlay/etc/firesim/.gitignore b/wlutil/fedora/overlay/etc/firesim/.gitignore new file mode 100644 index 00000000..fd1ff69a --- /dev/null +++ b/wlutil/fedora/overlay/etc/firesim/.gitignore @@ -0,0 +1,2 @@ +# This file is auto-generated by the build system +firesim.sh diff --git a/wlutil/fedora/overlay/etc/systemd/system/firesim.service b/wlutil/fedora/overlay/etc/systemd/system/firesim.service deleted file mode 100644 index 9d2b786d..00000000 --- a/wlutil/fedora/overlay/etc/systemd/system/firesim.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Requires=multi-user.target -After=multi-user.target -Before=firesim.target -Wants=firesim.target - -[Service] -ExecStart=/etc/firesim/firesim.sh runArg -StandardOutput=journal+console \ No newline at end of file diff --git a/wlutil/wlutil.py b/wlutil/wlutil.py index 5a66acd7..ff07caae 100644 --- a/wlutil/wlutil.py +++ b/wlutil/wlutil.py @@ -7,6 +7,7 @@ import sys import collections import shutil +from contextlib import contextmanager wlutil_dir = os.path.normpath(os.path.dirname(__file__)) root_dir = os.getcwd() @@ -106,15 +107,59 @@ def genRunScript(command): return commandScript +# XXX This isn't working with the initramfs option. Go back to requiring sudo +# for now, I'll revisit later. + +# Frustratingly, the same commands don't work/exist on various platforms so we +# need to figure out what mounting options are available to us: +# if shutil.which('guestmount') is not None: +# # This is the preferred method because it doesn't require sudo +# @contextmanager +# def mountImg(imgPath, mntPath): +# run(['guestmount', '-a', imgPath, '-m', '/dev/sda', mntPath]) +# try: +# yield mntPath +# finally: +# run(['guestunmount', mntPath]) +# +# elif shutil.whcih('fuse-ext2') is not None: +# # Roughly the same as guestmount +# @contextmanager +# def mountImg(imgPath, mntPath): +# run(['fuse-ext2', '-o', 'rw+', imgPath, mntPath]) +# try: +# yield mntPath +# finally: +# run(['fusermount', '-u', mntPath]) +# +# elif shutil.which('mount') is not None: +# # if True: +# # Should be available everywhere, requires sudo +# @contextmanager +# def mountImg(imgPath, mntPath): +# run(['sudo', 'mount', '-o', 'loop', imgPath, mntPath]) +# try: +# yield mntPath +# finally: +# run(['sudo', 'umount', mntPath]) +# +# else: +# raise ImportError("No compatible 'mount' command found") + +@contextmanager +def mountImg(imgPath, mntPath): + run(['sudo', 'mount', '-o', 'loop', imgPath, mntPath]) + try: + yield mntPath + finally: + run(['sudo', 'umount', mntPath]) + def toCpio(config, src, dst): log = logging.getLogger() - run(['sudo', 'mount', '-o', 'loop', src, mnt]) - try: + with mountImg(src, mnt): # Fedora needs a special init in order to boot from initramfs run("sudo find -print0 | sudo cpio --owner root:root --null -ov --format=newc > " + dst, shell=True, cwd=mnt) - finally: - run(['sudo', 'umount', mnt]) # fedora needs a special init to work if config['distro'] == 'fedora': @@ -136,19 +181,12 @@ def copyImgFiles(img, files, direction): if not os.path.exists(mnt): run(['mkdir', mnt]) - # The guestmount options (and rsync without chown) are to avoid dependence - # on sudo, but they require libguestfs-tools to be installed. There are - # other sudo dependencies in fedora.py though. - # run(['guestmount', '-a', img, '-m', '/dev/sda', mnt]) - # run(['fuse-ext2', '-o', 'rw+', img, mnt]) - run(['sudo', 'mount', '-o', 'loop', img, mnt]) - try: + with mountImg(img, mnt): for f in files: # Overlays may not be owned by root, but the filesystem must be. # Rsync lets us chown while copying. # Note: shell=True because f.src is allowed to contain globs # Note: os.path.join can't handle overlay-style concats (e.g. join('foo/bar', '/baz') == '/baz') - # run('cp -a ' + f.src + " " + os.path.normpath(mnt + f.dst), shell=True) if direction == 'in': run('sudo rsync -a --chown=root:root ' + f.src + " " + os.path.normpath(mnt + f.dst), shell=True) elif direction == 'out': @@ -156,7 +194,3 @@ def copyImgFiles(img, files, direction): run('sudo rsync -a --chown=' + str(uid) + ':' + str(uid) + ' ' + os.path.normpath(mnt + f.src) + " " + f.dst, shell=True) else: raise ValueError("direction option must be either 'in' or 'out'") - finally: - # run(['guestunmount', mnt]) - # run(['fusermount', '-u', mnt]) - run(['sudo', 'umount', mnt])