From 67fb576fdc67a67b59b614b14d90b64263906707 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] Rename virt-p2v.ml -> virt-p2v, add update wrapper. --- MANIFEST | 3 +- Makefile | 14 +++++--- README.developers | 6 ++-- inittab | 4 +-- iso-attach | 6 ++-- livecd-post.sh.in | 27 +++++++++++---- virt-p2v.ml => virt-p2v | 90 +++++-------------------------------------------- virt-p2v-update-wrapper | 29 ++++++++++++++++ 8 files changed, 78 insertions(+), 101 deletions(-) rename virt-p2v.ml => virt-p2v (95%) create mode 100755 virt-p2v-update-wrapper diff --git a/MANIFEST b/MANIFEST index 27e3daf..8976fd6 100644 --- a/MANIFEST +++ b/MANIFEST @@ -10,4 +10,5 @@ Makefile MANIFEST README README.developers -virt-p2v.ml +virt-p2v +virt-p2v-update-wrapper diff --git a/Makefile b/Makefile index 5b69322..731783f 100644 --- a/Makefile +++ b/Makefile @@ -72,11 +72,15 @@ livecd.ks: livecd.ks.in livecd-post.sh Makefile -e 's|@TIMEZONE@|$(TIMEZONE)|g' \ < $< | cat - livecd-post.sh > $@ -livecd-post.sh: livecd-post.sh.in virt-p2v.ml inittab lvm.conf Makefile +livecd-post.sh: livecd-post.sh.in virt-p2v virt-p2v-update-wrapper iso-attach inittab lvm.conf Makefile rm -f $@ sed \ - -e '/@VIRT-P2V.ML@/ r virt-p2v.ml' \ - -e '/@VIRT-P2V.ML@/ d' \ + -e '/@VIRT-P2V@/ r virt-p2v' \ + -e '/@VIRT-P2V@/ d' \ + -e '/@VIRT-P2V-UPDATE-WRAPPER@/ r virt-p2v-update-wrapper' \ + -e '/@VIRT-P2V-UPDATE-WRAPPER@/ d' \ + -e '/@ISO-ATTACH@/ r iso-attach' \ + -e '/@ISO-ATTACH@/ d' \ -e '/@INITTAB@/ r inittab' \ -e '/@INITTAB@/ d' \ -e '/@LVM.CONF@/ r lvm.conf' \ @@ -104,7 +108,7 @@ boot: update: checkroot checkscript -./iso-attach delete $(ISO) - ./iso-attach add $(ISO) virt-p2v.ml + ./iso-attach add $(ISO) virt-p2v # Check that we are root. @@ -117,7 +121,7 @@ checkroot: # Check that the script compiles. checkscript: - ./virt-p2v.ml --test + ./virt-p2v --test # Clean. diff --git a/README.developers b/README.developers index b7082f3..f7b205e 100644 --- a/README.developers +++ b/README.developers @@ -28,10 +28,10 @@ p2v.init This is installed on the live CD as /etc/init.d/p2v, and it causes the live CD to boot into the P2V configuration tool (see next). -virt-p2v.ml +virt-p2v - This is the virt-p2v.ml P2V configuration tool itself. It is - installed on the live CD as /usr/bin/virt-p2v.ml and runs after the + This is the virt-p2v P2V configuration tool itself. It is + installed on the live CD as /usr/bin/virt-p2v and runs after the live CD has booted. All the P2V stuff happens from this script. It uses the 'dialog' program to ask questions. diff --git a/inittab b/inittab index 0b2f417..335b6a7 100644 --- a/inittab +++ b/inittab @@ -25,8 +25,8 @@ pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down" # If power was restored before the shutdown kicked in, cancel it. pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled" -# Run virt-p2v.ml on tty1 -1:3:once:/usr/bin/virt-p2v.ml --update tty1 +# Run virt-p2v on tty1 +1:3:once:/usr/bin/virt-p2v-update-wrapper /usr/bin/virt-p2v tty1 # Run gettys but not on tty1 which is where virt-p2v runs. 2:2345:respawn:/sbin/mingetty tty2 diff --git a/iso-attach b/iso-attach index 107b63e..a6aad26 100755 --- a/iso-attach +++ b/iso-attach @@ -1,6 +1,6 @@ #!/usr/bin/ocamlrun /usr/bin/ocaml (* -*- tuareg -*- *) -(* iso-attach attaches an updated 'virt-p2v.ml' file to the end of +(* iso-attach attaches an updated 'virt-p2v' file to the end of * an ISO image. This is just for quick developer builds because it * takes ages to rebuild a full ISO. * @@ -113,7 +113,7 @@ SYNOPSIS DESCRIPTION -iso-attach attaches an updated 'virt-p2v.ml' file to the end of +iso-attach attaches an updated 'virt-p2v' file to the end of an ISO image. This is just for quick developer builds because it takes ages to rebuild a full ISO. @@ -245,3 +245,5 @@ and do_get isoname output = close fd let () = main () + +(* This file must end with a newline. *) diff --git a/livecd-post.sh.in b/livecd-post.sh.in index f85dbd0..3112682 100644 --- a/livecd-post.sh.in +++ b/livecd-post.sh.in @@ -19,17 +19,30 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# $Id$ # This is the virt-p2v script. - -cat > /usr/bin/virt-p2v.ml << '__EOF1234__' -@VIRT-P2V.ML@ +cat > /usr/bin/virt-p2v << '__EOF1234__' +@VIRT-P2V@ __EOF1234__ -chmod 0755 /usr/bin/virt-p2v.ml -/sbin/restorecon /usr/bin/virt-p2v.ml +chmod 0755 /usr/bin/virt-p2v +/sbin/restorecon /usr/bin/virt-p2v + +# iso-attach program. +cat > /usr/bin/iso-attach << '__EOF2134__' +@ISO-ATTACH@ +__EOF2134__ + +chmod 0755 /usr/bin/iso-attach +/sbin/restorecon /usr/bin/iso-attach + +# Update wrapper - checks the CD-ROM for any attached file. +cat > /usr/bin/virt-p2v-update-wrapper << '__EOF1243__' +@VIRT-P2V-UPDATE-WRAPPER@ +__EOF1243__ + +chmod 0755 /usr/bin/virt-p2v-update-wrapper +/sbin/restorecon /usr/bin/virt-p2v-update-wrapper # Install custom inittab. cat > /etc/inittab << '__EOF4123__' diff --git a/virt-p2v.ml b/virt-p2v similarity index 95% rename from virt-p2v.ml rename to virt-p2v index 8e3dd53..edf637e 100755 --- a/virt-p2v.ml +++ b/virt-p2v @@ -1,5 +1,6 @@ #!/usr/bin/ocamlrun /usr/bin/ocaml -(* virt-p2v.ml is a script which performs a physical to +(* -*- tuareg -*- *) +(* virt-p2v is a script which performs a physical to * virtual conversion of local disks. * * Copyright (C) 2007-2008 Red Hat Inc. @@ -590,7 +591,7 @@ let rec main ttyname = dup2 fd stdin; dup2 fd stdout; close fd); - printf "virt-p2v.ml starting up ...\n%!"; + printf "virt-p2v starting up ...\n%!"; (* Disable screen blanking on tty. *) sh "setterm -blank 0"; @@ -600,7 +601,7 @@ let rec main ttyname = fail_dialog "You should only run this script from the live CD or a USB key."; - printf "virt-p2v.ml detecting hard drives (this may take some time) ...\n%!"; + printf "virt-p2v detecting hard drives (this may take some time) ...\n%!"; (* Search for all non-removable block devices. Do this early and bail * if we can't find anything. This is a list of strings, like "hda". @@ -795,7 +796,7 @@ let rec main ttyname = ) all_partitions in - printf "virt-p2v.ml finished detecting hard drives\n%!"; + printf "virt-p2v finished detecting hard drives\n%!"; (* Dialogs. *) let ask_greeting state = @@ -1477,7 +1478,7 @@ MAC address: %s" exit 0 let usage () = - eprintf "usage: virt-p2v [ttyname]\n%!"; + eprintf "usage: virt-p2v [--test] [ttyname]\n%!"; exit 2 (* Make sure that exceptions from 'main' get printed out on stdout @@ -1488,88 +1489,15 @@ let handle_exn f arg = try f arg with exn -> print_endline (Printexc.to_string exn); raise exn -(* If the ISO image has an attachment then it could be a new version - * of virt-p2v.ml (this script). Get the attachment and run it - * instead. Useful mainly for testing, in conjunction with the - * 'make update' target in the virt-p2v Makefile. - *) -let magic = "ISOATTACHMENT002" -let magiclen = String.length magic (* = 16 bytes *) -let trailerlen = magiclen + 8 + 8 (* magic + file start + true size *) - -let int64_of_string str = - let i = ref 0L in - let add offs shift = - i := - Int64.logor - (Int64.shift_left (Int64.of_int (Char.code str.[offs])) shift) !i - in - add 0 56; add 1 48; add 2 40; add 3 32; - add 4 24; add 5 16; add 6 8; add 7 0; - !i - -let update ttyname = - let cdrom = "/dev/cdrom" in - let output = "/tmp/virt-p2v.ml" in - - try - let fd = openfile cdrom [O_RDONLY] 0 in - ignore (LargeFile.lseek fd (Int64.of_int ~-trailerlen) SEEK_END); - let buf = String.create magiclen in - if read fd buf 0 magiclen <> magiclen || buf <> magic then ( - close fd; - raise Exit - ); - - (* Read the size. *) - let buf = String.create 8 in - if read fd buf 0 8 <> 8 then - failwith "cannot read attachment offset"; - let offset = int64_of_string buf in - let buf = String.create 8 in - if read fd buf 0 8 <> 8 then - failwith "cannot read attachment size"; - let size = Int64.to_int (int64_of_string buf) in - - (* Seek to beginning of the attachment. *) - ignore (LargeFile.lseek fd offset SEEK_SET); - - (* Copy out the attachment. *) - let fd2 = openfile output [O_WRONLY; O_CREAT; O_TRUNC] 0o755 in - let bufsize = 4 * 1024 in - let buffer = String.create bufsize in - let rec copy remaining = - if remaining > 0 then ( - let n = min remaining bufsize in - let n = read fd buffer 0 n in - if n = 0 then failwith "corrupted or partial attachment"; - ignore (write fd2 buffer 0 n); - copy (remaining - n) - ) - in - copy size; - close fd2; - - close fd; - - (* Run updated virt-p2v script. *) - execv output [| output; ttyname |] - with - Unix_error _ | Exit -> - (* Some error, or no attachment, so keep running this script. *) - handle_exn main (Some ttyname) - (* Test harness for the Makefile. The Makefile invokes this script as - * 'virt-p2v.ml --test' just to check it compiles. When it is running + * 'virt-p2v --test' just to check it compiles. When it is running * from the actual live CD, there is a single parameter which is the - * tty name (so usually 'virt-p2v.ml tty1'). + * tty name (so usually 'virt-p2v tty1'). *) let () = match Array.to_list Sys.argv with - | [ _; "--test" ] -> () (* Makefile test - do nothing. *) - | [ _; "--update"; ttyname ] -> (* Test for update and run. *) - update ttyname | [ _; ("--help"|"-help"|"-?"|"-h") ] -> usage (); + | [ _; "--test" ] -> () (* Makefile test - do nothing. *) | [ _; ttyname ] -> (* Run main with ttyname. *) handle_exn main (Some ttyname) | [ _ ] -> (* Interactive - no ttyname. *) diff --git a/virt-p2v-update-wrapper b/virt-p2v-update-wrapper new file mode 100755 index 0000000..6490527 --- /dev/null +++ b/virt-p2v-update-wrapper @@ -0,0 +1,29 @@ +#!/bin/sh - +# +# This is a wrapper which checks for an attachment on the ISO image / +# CDROM device. If found then it uses it to replace files within the +# filesystem. Mainly used for quick development builds where it is +# simpler to replace files rather than rebuilding the whole ISO. +# +# Copyright (C) 2008 Red Hat Inc. +# Written by Richard W.M. Jones +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +if /usr/bin/iso-attach has /dev/cdrom; then + iso-attach get /dev/cdrom /usr/bin/virt-p2v +fi + +exec "$@" -- 1.8.3.1