diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2009-06-24 09:59:39 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2009-06-24 09:59:39 +0100 |
commit | 46551d9c51193a4bca2e1b249b8c5f111e1dc7b5 (patch) | |
tree | 2beb1f4b3bc56eb54e377bcfccde6898c94e212c /fish | |
parent | 94a49c8207277ec4017a0fb9a3cd8f1e61a518f6 (diff) | |
download | libguestfs-46551d9c51193a4bca2e1b249b8c5f111e1dc7b5.tar.gz libguestfs-46551d9c51193a4bca2e1b249b8c5f111e1dc7b5.tar.xz libguestfs-46551d9c51193a4bca2e1b249b8c5f111e1dc7b5.zip |
Implement guestfish -f option to allow guestfish scripts.
New '-f' option allows scripts to be written using:
#!/usr/bin/guestfish -f
Diffstat (limited to 'fish')
-rw-r--r-- | fish/fish.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/fish/fish.c b/fish/fish.c index bf82b8af..cba0343b 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -102,6 +102,7 @@ usage (void) " -h|--cmd-help cmd Display detailed help on 'cmd'\n" " -a|--add image Add image\n" " -D|--no-dest-paths Don't tab-complete paths from guest fs\n" + " -f|--file file Read commands from file\n" " -m|--mount dev[:mnt] Mount dev on mnt (if omitted, /)\n" " -n|--no-sync Don't autosync\n" " -r|--ro Mount read-only\n" @@ -113,10 +114,11 @@ usage (void) int main (int argc, char *argv[]) { - static const char *options = "a:h::m:nrv?V"; + static const char *options = "a:f:h::m:nrv?V"; static struct option long_options[] = { { "add", 1, 0, 'a' }, { "cmd-help", 2, 0, 'h' }, + { "file", 1, 0, 'f' }, { "help", 0, 0, '?' }, { "mount", 1, 0, 'm' }, { "no-dest-paths", 0, 0, 'D' }, @@ -130,7 +132,7 @@ main (int argc, char *argv[]) struct drv *drv; struct mp *mps = NULL; struct mp *mp; - char *p; + char *p, *file = NULL; int c; initialize_readline (); @@ -183,6 +185,14 @@ main (int argc, char *argv[]) complete_dest_paths = 0; break; + case 'f': + if (file) { + fprintf (stderr, _("guestfish: only one -f parameter can be given\n")); + exit (1); + } + file = optarg; + break; + case 'h': if (optarg) display_command (optarg); @@ -246,6 +256,15 @@ main (int argc, char *argv[]) mount_mps (mps); } + /* -f (file) parameter? */ + if (file) { + close (0); + if (open (file, O_RDONLY) == -1) { + perror (file); + exit (1); + } + } + /* Interactive, shell script, or command(s) on the command line? */ if (optind >= argc) { if (isatty (0)) |