Commit ce9361c5 authored by Michael Pöhn's avatar Michael Pöhn

pythonic check for required binaries, updated readme

parent d24454a8
# makebuildserver\_basebox.py
This script bootstraps vagrant boxes for F-Droid buildserver. It supports libvirt and vitualbox.
This script bootstraps vagrant boxes for F-Droid buildserver. It supports
'libvirt' (qemu/kvm) and 'vitualbox'.
## useage example
# bootstrap virtualbox image
sudo makebuildserver_basebox.py
vagrant box add fdroid-jessie64.box jessie64
### bootstrap a libvirt box
#### Fetch this script via git:
git clone https://gitlab.com/fdroid/basebox
cd basebox
#### Bootstrap and add box:
sudo ./makebuildserver_basebox.py --provider libvirt
vagrant box add jessie64 fdroid-jessie64.box
That's it, _makebuildserver.py_ should be able to find the basebox now.
#### (optional) cleanup:
rm fdroid-jessie64.box
## FAQ
### Why does this script need root?
Because it's using `vmdebootstrap` for building the box. Typically
_debootstrap_ is only available for super users, because it's
bootstrapping an entirely new Debian system inside a change-root.
So root privileges are needed for assigning file-access permissions.
_vmdebootstrap_ additionally needs to mount a loop-back device for
dumping the change-root as a raw disk image.
......@@ -21,6 +21,7 @@ import os
import json
import math
import stat
import shutil
import logging
import tarfile
import tempfile
......@@ -121,7 +122,7 @@ def exec_vmdebootstrap(params, provider, verbose=False, dry_run=False):
write_bootstrap_script(params['boostrapscript'],
params['username'])
cmd = ['/usr/sbin/vmdebootstrap',
cmd = [shutil.which('vmdebootstrap'),
'--verbose' if verbose else None,
'--grub',
'--image={}'.format(params['img_path_raw']),
......@@ -149,7 +150,7 @@ def exec_vmdebootstrap(params, provider, verbose=False, dry_run=False):
def libvirt_convert_raw_to_qcow2(params, verbose=False, dry_run=False):
cmd = ('/usr/bin/qemu-img',
cmd = (shutil.which('qemu-img'),
'convert',
'-f', 'raw',
'-O', 'qcow2',
......@@ -215,7 +216,7 @@ def get_resource_as_string(resource_name):
def vbox_convert_raw_to_vmdk(params, dry_run=False):
cmd = ('/usr/bin/VBoxManage',
cmd = (shutil.which('VBoxManage'),
'convertfromraw',
params['img_path_raw'],
params['img_path_vmdk'],
......@@ -270,7 +271,7 @@ def vbox_package_box(params, dry_run=False):
logging.info('(dry run) Skip packaging box file.')
def main(provider='libvirt', verbose=False, dry_run=False):
def main(provider='virtualbox', verbose=False, dry_run=False):
if not os.geteuid() == 0:
raise BaseboxException('This script requires super user privileges. '
......@@ -284,10 +285,17 @@ def main(provider='libvirt', verbose=False, dry_run=False):
supported=providers))
logging.info("selected provider: '{}'".format(provider))
if not os.path.exists('/usr/sbin/vmdebootstrap'):
raise BaseboxException("Can not find or access "
"'/usr/sbin/vmdebootstrap'. "
"(Is vmdebootstrap installed?)")
if not shutil.which('vmdebootstrap'):
raise BaseboxException("Can not find 'vmdebootstrap' executable. "
"(Please install vmdebootstrap.)")
if provider == 'virtualbox':
if not shutil.which('VBoxManage'):
raise BaseboxException("Can not find 'VBoxManage' executable. "
"(Please install virtualbox.)")
elif provider == 'libvirt':
if not shutil.which('qemu-img'):
raise BaseboxException("Can not fine 'qemu-img' executable. "
"(Please install qemu-utils.)")
with tempfile.TemporaryDirectory() as tmpdir:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment