Commit Graph

155 Commits

Author SHA1 Message Date
Pino Toscano
6e198634ac firstboot: make SysV symlinks as relative on Debian
Turn the rc.d symlinks for the guestfs-firstboot service as relative,
instead of absolute paths: the result is the same (the service works the
same), and this way is more coherent with symlinks created by
update-rc.d.
2016-08-04 13:53:31 +02:00
Pino Toscano
d394e01c2b firstboot: rename systemd and sysvinit
Currently we install a systemd service named firstboot.service and a
SysV service named virt-sysprep-firstboot.  On systems where systemd is
the init system and runs with the SysV compatibility, the different
names make systemd handle them as different services, and thus trying to
run the firstboot script runner twice.

Rename both the systemd service and the SysV one to guestfs-firstboot:
the new name is less generic, and allows the systemd service to be
shadowed by the SysV service (and thus running just once).

Also cleanup the old services: the old SysV service can be removed
directly, since its former name had "virt-sysprep" in it, and so there
could not be much room for confusion and conflict.  Regarding the old
systemd service: to avoid leaving it behind, a simple cleanup strategy
is in place, checking the content of the old firstboot.service to really
ensure we are removing one of our versions of this file.
2016-08-04 13:44:03 +02:00
Pino Toscano
bb842b415e customize: use --noconfirm when installing Arch Linux packages
Otherwise the installation will fail right away, since pacman by default
asks for confirmation of the operation.
2016-07-21 13:53:27 +02:00
Pino Toscano
a5176e6014 customize: password: use SHA-512 on Void Linux and Arch Linux
They are rolling distributions, so we can assume they have a glibc
version greater than 2.7 (cca Oct 2007).
2016-07-21 13:53:27 +02:00
Richard W.M. Jones
fb1e9267fe mllib, customize: Don't add -g option to ocamlmklib command line.
ocamlmklib -g does not work in OCaml 4.01.0.  It does work (and is
desirable) in OCaml 4.02.2.  However since we would like to support
back to OCaml 3.11, we cannot use it.
2016-07-20 12:24:10 +01:00
Richard W.M. Jones
8d518c37cd customize: Fix the test.
In libguestfs 1.33.43 we managed to release a completely
non-functional virt-customize binary (it ran without error but did
nothing at all, whatever command line arguments you gave it).

Improve the test so this cannot happen again.
2016-07-19 19:01:54 +01:00
Richard W.M. Jones
08e27451a6 tests: Add script to check documented tool options match actual options.
podcheck.pl is run as part of the tests to perform various checks on
the documentation and the tool.

Currently we check only that the documented options matches the
options that the tool implements and vice versa.  This commit would
also allow us (in future) to check --help, --long-options,
--short-options, --version output.

This commit includes scripts to run the tests and various fixes to the
manual pages to ensure that the tests pass.
2016-07-19 13:06:14 +01:00
Richard W.M. Jones
ba2cf9a2eb mllib: Use L"..." and S '...' for long and short options.
There is also an M"..." variant which acts the same way as
L but handles the annoying virt-v2v two letter options.
2016-07-18 17:01:22 +01:00
Richard W.M. Jones
c2fda2c1f2 build: Factor out definition of BEST and OCAMLLINKFLAGS.
No change, just refactoring.
2016-07-18 14:11:22 +01:00
Richard W.M. Jones
2c6bfccb06 build: Fix dependencies on mllib and customize.
Binaries should be rebuilt if mllib.cma/mllib.cmxa or
customize.cma/customize.cmxa change.

Fixes commit 1e2877c6f4.
2016-07-18 14:10:28 +01:00
Richard W.M. Jones
fde0b73597 customize: Build virt-customize properly.
Fixes commit 6a0fe553b9.
2016-07-18 13:54:23 +01:00
Richard W.M. Jones
6a0fe553b9 customize: Build a customize.cma/customize.cmxa library.
Instead of linking with individual objects, which is very tedious,
build a proper library and link virt-builder, virt-customize and
virt-sysprep to it.

This makes the binaries a tiny bit smaller because .cmxa/.a files
allow unused code to be removed by the linker, whereas explicitly
linking .cmx/.o files does not.
2016-07-14 15:40:42 +01:00
Richard W.M. Jones
1e2877c6f4 mllib: Build a mllib.cma/mllib.cmxa library.
Instead of linking with individual objects, which is very tedious,
build a proper library and link the other tools with it.

This doesn't make the resulting binaries any larger.
2016-07-14 15:28:10 +01:00
Richard W.M. Jones
35bac3a650 lib: Deprecate old SELinux APIs, rewrite SELinux documentation (RHBZ#1152825).
Also turns the --selinux option of guestfish, guestmount and
virt-rescue into a no-op -- it didn't work before so this is
effectively no change.
2016-07-14 15:28:10 +01:00
Richard W.M. Jones
f3c69fe60b customize: Add module for doing SELinux relabel of filesystem (RHBZ#554829, RHBZ#983969, RHBZ#1089100).
This implements the --selinux-relabel option for virt-customize,
virt-builder and virt-sysprep.  There is no need to autorelabel
functionality now.

Thanks: Stephen Smalley
2016-07-14 15:28:10 +01:00
Richard W.M. Jones
eb22e2d36e v2v: Move augeas_debug_errors (renamed debug_augeas_errors) to common code.
Since the function uses the StringMap module, I also had to
move this to mllib.

The function is renamed and the 'if verbose ()' part is moved into the
function, but apart from that, it's all just code motion.
2016-07-14 11:40:22 +01:00
Pino Toscano
0f7bf8f714 OCaml tools: add and use a Getopt module
Add a new Getopt module to mllib, to parse command line arguments with
handlers close to the ones used with Arg, but using getopt(3) (actually
getopt_long_only) to do the real parsing.  This allow us to provide
options for OCaml tools with a syntax similar to the C tools, and use
the additional features getopt offers and Arg does not.
Getopt now handles every part of the command line handling, including
the output of short & long options.

Do a single-step conversion of Common_utils and all the OCaml tools to
the syntax of Getopt.

Move a couple of utility functions from Common_utils to Getopt, since
they fit better there (and Common_utils cannot be used in Getopt, as
the former already uses the latter).

As side-change due to the conversion, extra arguments for sysprep
operation can have more keys for the same argument.
2016-07-13 18:43:32 +02:00
Richard W.M. Jones
123dc018b8 mllib: Rename unshift -> push_front, push -> push_back etc.
The C++ function names are more regular.

Updates commit 1c57c71d46.
2016-07-08 09:56:47 +01:00
Richard W.M. Jones
442092a305 Replace 'xs := x :: !xs' with 'unshift x xs'.
In one case, I used prepend instead.
2016-07-07 18:13:07 +01:00
Richard W.M. Jones
7c52d86de9 virt tools: Use Sys.file_exists instead of clumsy open_in/close_in hack.
No functional change.

Fixes commit c466d4cb92.
2016-06-23 14:51:48 +01:00
Richard W.M. Jones
b000d6bc68 virt tools: Add common --colours option.
This option (alternately spelled: --color, --colour, --colors, or
--colours) enables ANSI colour sequences output even if that would be
disabled becaues the output is not a TTY.
2016-06-18 21:15:59 +01:00
Richard W.M. Jones
6e79a3c84d Convert source so it can be compiled with OCaml '-safe-string' option.
OCaml 4.02 introduced the 'bytes' type, a mutable string intended to
replace the existing 'string' type for those cases where the byte
array can be mutated.  In future the 'string' type will become
immutable.  This is not the default now, but it can be forced using
the '-safe-string' compile option.

This commit changes the code so that it could be compiled using
'-safe-string' (but does not actually make that change).

If we detect OCaml < 4.02, we create a dummy 'Bytes' compatibility
module ((nearly) an alias for the 'String' module).  The only
significant difference from upstream OCaml is that you must write the
'bytes' type as 'Bytes.t' in interfaces, apart from that everything
else should work.
2016-06-16 15:22:04 +01:00
Richard W.M. Jones
669e25049e sysprep: Add --network to enable the network (RHBZ#1345813).
In commit ae6f726ecc we started to use
the virt-customize code to replace various virt-sysprep operations.
This had the effect of adding many more possible operations to
virt-sysprep, but some of them (specifically --install) did not work
unless the appliance network is enabled.  It was not enabled in
virt-sysprep, so these operations never worked.

This change does NOT enable the network by default.  However it adds a
--network flag which may be used in conjunction with --install etc to
make those commands work.

In addition we now emit a warning for certain customize operations if
they fail and if the network is not enabled.  It will print:

  [   4.5] Installing packages: tcpdump
  Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again
  Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os&infra=stock error was

  virt-sysprep: warning: the command may have failed because the network is
  disabled.  Try either removing '--no-network' or adding '--network' on the
  command line.

  virt-sysprep: error: yum -y install 'tcpdump': command exited with an error

(If the network is already enabled, or if the command is successful,
then the warning is not printed.)

Thanks: Xianghua Chen
2016-06-13 15:39:34 +01:00
Richard W.M. Jones
a3cb12ab2c ocaml: Move identical rules for building OCaml objects to common file. 2016-06-13 08:51:46 +01:00
Richard W.M. Jones
6425a8824b customize: Add --uninstall operation (RHBZ#1343375). 2016-06-07 12:19:24 +01:00
Richard W.M. Jones
df7a33768e mllib: Add Common_utils.is_partition function.
Returns true if the device is a host partition.

The only tedious bit of this patch is that now Common_utils depends on
Dev_t so we have to add extra objects every time something links with
Common_utils.
2016-06-03 13:05:07 +01:00
Pino Toscano
ea41945e88 customize: random_seed: avoid one file checking for existing files
When the random-seed file is found, then avoid checking its existance
again.
2016-05-26 15:15:40 +02:00
Pino Toscano
77ad2e1f18 customize: add support for the xbps package manager 2016-05-24 18:14:38 +02:00
Cédric Bosdonnat
07f7bfa608 customize: fix windows firstboot script
Sync the windows firstboot script with its linux brother. Also change
the main redirection to append to the log rather than overwriting it.
With this change, the firstboot script will resist reboots in the
executed scripts.
2016-05-24 09:19:48 +01:00
Richard W.M. Jones
063af7f987 ocaml tools: Use a common debug function.
Add a common debug function for printing debugging messages.  It only
emits the debug message when the verbose (-v) flag is used on the
command line.

It sends the output to stderr, which is flushed immediately after the
message is printed (to help with debugging unexpected crashes).  There
are good arguments for sending the debug to either stdout or stderr,
and almost all existing debug messages replaced by this change went to
stdout.  However using stderr is consistent with libguestfs's own
debug messages which also go to stderr.

I only made simple changes to code of the form 'if verbose () then
printf ...'.  There are more places which could be changed in future.
In a few places I removed gettext calls since we probably should not
translate debug messages.
2016-05-23 10:30:56 +01:00
Richard W.M. Jones
87c18474b5 customize: Turn print into warning.
It is still only emitted if we are debugging in order not to cause
unnecessary alarm.  Note this code needs a better long term fix, this
is still a hack.
2016-05-23 10:30:56 +01:00
Pino Toscano
ff0a622a6f tests: fix --format in virt-customize
Only in very recent OCaml versions (or in Fedora) the Arg module
supports the --foo=bar syntax for options with arguments.  Do not
require it yet.

Fixes commit 64bb9edd52.
2016-05-20 13:21:15 +02:00
Cédric Bosdonnat
536ef6f34a customize: change windows firstboot path
Rename the C:\Program Files\Red Hat\Firstboot folder into the more vendor
independent C:\Program Files\Guestfs\Firstboot.
2016-05-20 10:48:50 +01:00
Cédric Bosdonnat
ee78c06b7f customize: add support for pvvxsvc
SUSE VMDP comes with a replacement for rhsrvany.exe named pvvxsvc.exe.
Check for either one of them instead of only rhsrvany.
2016-05-20 10:39:58 +01:00
Pino Toscano
64bb9edd52 tests: specify the image format when possible
When possible, make the disk image format explicit when invoking tools
or using add-drive. This avoids warnings from qemu about the unspecified
format for the image, and also makes qemu slightly faster (skipping the
disk image probing).
Tests checking the image probing are not touched.

This changes also:
- old-style invocations of tools (`$tool $filename`) into new style
  (`$tool -a $filename`)
- add-drive-ro/add-drive-with-if guestfish commands into add/add-drive
  with explicit readonly/iface arguments

There should be no change in the tests results.
2016-05-19 19:06:00 +02:00
Pino Toscano
b5c81b3e12 customize: fix ownership when creating ~/.ssh/authorized_keys (RHBZ#1337561)
When creating ~/.ssh and ~/.ssh/authorized_keys (in case they are
missing), change their ownership to the target user.  If not, they are
owned by root.
2016-05-19 19:06:00 +02:00
Pino Toscano
59690dfc04 customize: minor function factoring in ssh_key
Turn the snippet reading user information from /etc/passwd in a slightly
more generic function, so there is no need to copy&paste for other
details.

Mostly code motion.
2016-05-19 19:06:00 +02:00
Richard W.M. Jones
547662d9f6 customize: Improve the error messages when package manager is unknown or unsupported.
For Windows, we now print:

$ virt-customize -a ./test-data/phony-guests/windows.img --install MSSQL
[   0.0] Examining the guest ...
[  14.2] Setting a random seed
virt-customize: warning: random seed could not be set for this type of
guest
[  14.2] Installing packages: MSSQL
virt-customize: error: cannot use '--install' because no package manager
has been detected for this guest OS.

If this guest OS is a common one with ordinary package management then this
may have been caused by a failure of libguestfs inspection.

For OSes such as Windows that lack package management, this is not
possible.  Try using one of the '--firstboot*' flags instead (described in
the manual).
2016-05-04 17:48:25 +01:00
Pino Toscano
ae3224cf8a customize: remove "core" from description of --update
--update invokes a distribution update, updating all the installed
packages and not just some "core" ones.
2016-05-03 14:25:46 +02:00
Richard W.M. Jones
a1e47c4b47 tools: Reduce use of _ (wildcard) in match statements.
No functional change, just various improvements to the safety of match
statements.
2016-04-21 12:50:58 +01:00
Richard W.M. Jones
dec30914e8 mllib: Rename uRI -> URI.
There is no difference in the OCaml module name, which remains 'URI'.
2016-04-20 22:48:37 +01:00
Pino Toscano
f5821fe6b7 customize: cast value to intptr_t for pointer usage
Cast a Int64 OCaml value to intptr_t before casting it to a pointer, so
this avoids warnings about casting an int to pointer.

Fixes commit 80a13b7216.
2016-04-14 15:25:52 +02:00
Richard W.M. Jones
80a13b7216 customize/perl_edit-c.c: Don't use internal APIs.
We can now use the Guestfs.c_pointer method to access the underlying
guestfs_h *.  So no need to use internal APIs for this.
2016-04-12 10:37:12 +01:00
Pino Toscano
82b0d25bb2 mllib: factor out mounting of guest root
Introduce and use a new inspect_mount_root function to mount all the
mountpoints of a root in the guest, replacing the same code doing that
in different tools.

inspect_mount_root_ro is inspect_mount_root with readonly mount option.
2016-03-03 14:52:39 +01:00
Pino Toscano
13c3698358 customize: add globbing for --delete
Support globbing in paths passed to --delete, telling glob to not
return directories with leading slash.

This re-adds back globbing for --delete in virt-sysprep, which was
available before the integration with common code from virt-customize.
2016-02-04 11:26:20 +01:00
Richard W.M. Jones
53403fbdef ocaml, virt tools: More consistent naming for C functions.
For functions linked to virt tools, make sure the name of the function
actually matches the virt tool.  Because of the history of moving
functions across tools, some names no longer matched.

For mllib, use `guestfs_int_mllib_' prefix.

For OCaml bindings, use `guestfs_int_ocaml_' prefix.

This commit is by no means complete.  There are many other C functions
in other language bindings which could do with being more consistently
named.

There is no functional change, this is just refactoring.
2016-01-28 21:30:20 +00:00
Richard W.M. Jones
1b3d3a3589 customize: Remove "useless" sprintf.
Actually the OCaml compiler rewrites all printf functions at compile
time to a series of primitive string operations, so the use of sprintf
here doesn't really matter.  Still, it's a bit tidier not to use
sprintf where it's not needed.

Also this commit contains some code reformatting.

This is just refactoring.
2016-01-26 21:26:23 +00:00
Richard W.M. Jones
4470f0483b customize: Add support for the APK (Alpine Linux) package manager. 2016-01-26 17:54:20 +00:00
Richard W.M. Jones
446f7794e0 podwrapper: Add --warning flag for manual pages of CLI tools (RHBZ#1293527).
This doesn't add --warning flags to the translated pages,
which is a bug to be fixed at some point.
2016-01-11 13:42:49 +00:00
Richard W.M. Jones
3b8322e18c customize: Document missing command line parameters in the synopsis.
I noticed that the --attach option was not covered in the synopsis.
This commit documents all of the missing command line parameters in
the synopsis.
2016-01-11 13:42:49 +00:00