[Pkg-libvirt-commits] [libguestfs] 40/78: customize: add the chmod command
Hilko Bengen
bengen at moszumanska.debian.org
Fri May 9 12:55:52 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to branch experimental
in repository libguestfs.
commit f63d82781924b2e399a97f0024c7816bd3cd61e9
Author: Pino Toscano <ptoscano at redhat.com>
Date: Fri Apr 4 16:09:51 2014 +0200
customize: add the chmod command
Add the chmod customize command to change the permissions of files.
---
builder/cmdline.ml | 2 +-
customize/customize_run.ml | 8 ++++++++
customize/test-virt-customize.sh | 1 +
generator/customize.ml | 10 ++++++++++
4 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/builder/cmdline.ml b/builder/cmdline.ml
index 3a620fe..45c87fc 100644
--- a/builder/cmdline.ml
+++ b/builder/cmdline.ml
@@ -315,7 +315,7 @@ read the man page virt-builder(1).
| `Delete _ | `Edit _ | `FirstbootCommand _ | `FirstbootPackages _
| `FirstbootScript _ | `Hostname _ | `Link _ | `Mkdir _
| `Password _ | `RootPassword _ | `Scrub _ | `Timezone _ | `Upload _
- | `Write _ -> false
+ | `Write _ | `Chmod _ -> false
) ops.ops in
if requires_execute_on_guest then (
eprintf (f_"%s: sorry, cannot run commands on a guest with a different architecture\n")
diff --git a/customize/customize_run.ml b/customize/customize_run.ml
index 8a1df32..4d83e90 100644
--- a/customize/customize_run.ml
+++ b/customize/customize_run.ml
@@ -168,6 +168,14 @@ exec >>%s 2>&1
(* Perform the remaining customizations in command-line order. *)
List.iter (
function
+ | `Chmod (mode, path) ->
+ msg (f_"Changing permissions of %s to %s") path mode;
+ (* If the mode string is octal, add the OCaml prefix for octal values
+ * so it is properly converted as octal integer.
+ *)
+ let mode = if string_prefix mode "0" then "0o" ^ mode else mode in
+ g#chmod (int_of_string mode) path
+
| `Command cmd ->
msg (f_"Running: %s") cmd;
do_run ~display:cmd cmd
diff --git a/customize/test-virt-customize.sh b/customize/test-virt-customize.sh
index be61796..623e6a2 100755
--- a/customize/test-virt-customize.sh
+++ b/customize/test-virt-customize.sh
@@ -29,6 +29,7 @@ for f in ../tests/guests/{debian,fedora,ubuntu}.img; do
$VG ./virt-customize -n -a $f \
--no-network \
--write /etc/motd:HELLO \
+ --chmod 0600:/etc/motd \
--delete /etc/motd
fi
done
diff --git a/generator/customize.ml b/generator/customize.ml
index 0b0580a..275b087 100644
--- a/generator/customize.ml
+++ b/generator/customize.ml
@@ -44,6 +44,16 @@ and op_type =
| UserPasswordSelector of string (* user:selector *)
let ops = [
+ { op_name = "chmod";
+ op_type = StringPair "PERMISSIONS:FILE";
+ op_discrim = "`Chmod";
+ op_shortdesc = "Change the permissions of a file";
+ op_pod_longdesc = "\
+Change the permissions of C<FILE> to C<PERMISSIONS>.
+
+I<Note>: C<PERMISSIONS> by default would be decimal, unless you prefix
+it with C<0> to get octal, ie. use C<0700> not C<700>.";
+ };
{ op_name = "delete";
op_type = String "PATH";
op_discrim = "`Delete";
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git
More information about the Pkg-libvirt-commits
mailing list