mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
customize: Use Common_utils.error function instead of failwith.
This is just code refactoring.
This commit is contained in:
@@ -198,20 +198,20 @@ exec >>%s 2>&1
|
||||
| `FirstbootCommand cmd ->
|
||||
incr i;
|
||||
msg (f_"Installing firstboot command: [%d] %s") !i cmd;
|
||||
Firstboot.add_firstboot_script g root !i cmd
|
||||
Firstboot.add_firstboot_script ~prog g root !i cmd
|
||||
|
||||
| `FirstbootPackages pkgs ->
|
||||
incr i;
|
||||
msg (f_"Installing firstboot packages: [%d] %s") !i
|
||||
(String.concat " " pkgs);
|
||||
let cmd = guest_install_command pkgs in
|
||||
Firstboot.add_firstboot_script g root !i cmd
|
||||
Firstboot.add_firstboot_script ~prog g root !i cmd
|
||||
|
||||
| `FirstbootScript script ->
|
||||
incr i;
|
||||
msg (f_"Installing firstboot script: [%d] %s") !i script;
|
||||
let cmd = read_whole_file script in
|
||||
Firstboot.add_firstboot_script g root !i cmd
|
||||
Firstboot.add_firstboot_script ~prog g root !i cmd
|
||||
|
||||
| `Hostname hostname ->
|
||||
msg (f_"Setting the hostname: %s") hostname;
|
||||
|
||||
@@ -78,10 +78,7 @@ StandardError=inherit
|
||||
WantedBy=default.target
|
||||
" firstboot_dir
|
||||
|
||||
let failed fs =
|
||||
ksprintf (fun msg -> failwith (s_"firstboot: failed: " ^ msg)) fs
|
||||
|
||||
let rec install_service (g : Guestfs.guestfs) distro =
|
||||
let rec install_service ~prog (g : Guestfs.guestfs) distro =
|
||||
g#mkdir_p firstboot_dir;
|
||||
g#mkdir_p (sprintf "%s/scripts" firstboot_dir);
|
||||
g#write (sprintf "%s/firstboot.sh" firstboot_dir) firstboot_sh;
|
||||
@@ -97,7 +94,7 @@ let rec install_service (g : Guestfs.guestfs) distro =
|
||||
if g#is_dir "/etc/systemd/system" then
|
||||
install_systemd_service g;
|
||||
if g#is_dir "/etc/rc.d" || g#is_dir "/etc/init.d" then
|
||||
install_sysvinit_service g distro
|
||||
install_sysvinit_service ~prog g distro
|
||||
|
||||
(* Install the systemd firstboot service, if not installed already. *)
|
||||
and install_systemd_service g =
|
||||
@@ -106,7 +103,7 @@ and install_systemd_service g =
|
||||
g#ln_sf (sprintf "%s/firstboot.service" firstboot_dir)
|
||||
"/etc/systemd/system/default.target.wants"
|
||||
|
||||
and install_sysvinit_service g = function
|
||||
and install_sysvinit_service ~prog g = function
|
||||
| "fedora"|"rhel"|"centos"|"scientificlinux"|"redhat-based" ->
|
||||
install_sysvinit_redhat g
|
||||
| "opensuse"|"sles"|"suse-based" ->
|
||||
@@ -114,7 +111,7 @@ and install_sysvinit_service g = function
|
||||
| "debian"|"ubuntu" ->
|
||||
install_sysvinit_debian g
|
||||
| distro ->
|
||||
failed "guest type %s is not supported" distro
|
||||
error ~prog (f_"guest type %s is not supported") distro
|
||||
|
||||
and install_sysvinit_redhat g =
|
||||
g#mkdir_p "/etc/rc.d/rc2.d";
|
||||
@@ -155,12 +152,12 @@ and install_sysvinit_debian g =
|
||||
g#ln_sf "/etc/init.d/virt-sysprep-firstboot"
|
||||
"/etc/rc5.d/S99virt-sysprep-firstboot"
|
||||
|
||||
let add_firstboot_script (g : Guestfs.guestfs) root i content =
|
||||
let add_firstboot_script ~prog (g : Guestfs.guestfs) root i content =
|
||||
let typ = g#inspect_get_type root in
|
||||
let distro = g#inspect_get_distro root in
|
||||
match typ, distro with
|
||||
| "linux", _ ->
|
||||
install_service g distro;
|
||||
install_service ~prog g distro;
|
||||
let t = Int64.of_float (Unix.time ()) in
|
||||
let r = string_random8 () in
|
||||
let filename = sprintf "%s/scripts/%04d-%Ld-%s" firstboot_dir i t r in
|
||||
@@ -168,4 +165,4 @@ let add_firstboot_script (g : Guestfs.guestfs) root i content =
|
||||
g#chmod 0o755 filename
|
||||
|
||||
| _ ->
|
||||
failed "guest type %s/%s is not supported" typ distro
|
||||
error ~prog (f_"guest type %s/%s is not supported") typ distro
|
||||
|
||||
@@ -16,12 +16,13 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*)
|
||||
|
||||
val add_firstboot_script : Guestfs.guestfs -> string -> int -> string -> unit
|
||||
(** [add_firstboot_script g root idx content] adds a firstboot
|
||||
val add_firstboot_script : prog:string -> Guestfs.guestfs -> string -> int -> string -> unit
|
||||
(** [add_firstboot_script ~prog g root idx content] adds a firstboot
|
||||
script called [shortname] containing [content].
|
||||
|
||||
NB. [content] is the contents of the script, {b not} a filename.
|
||||
|
||||
The scripts run in index ([idx]) order.
|
||||
|
||||
You should make sure the filesystem is relabelled after calling this. *)
|
||||
For Linux guests using SELinux you should make sure the
|
||||
filesystem is relabelled after calling this. *)
|
||||
|
||||
Reference in New Issue
Block a user