helper: Print /modules when verbose >= 2
[febootstrap.git] / src / febootstrap_package_handlers.ml
1 (* febootstrap 3
2  * Copyright (C) 2009-2010 Red Hat Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  *)
18
19 open Unix
20 open Printf
21
22 open Febootstrap_utils
23 open Febootstrap_cmdline
24
25 type package_handler = {
26   ph_detect : unit -> bool;
27   ph_init : unit -> unit;
28   ph_resolve_dependencies_and_download : string list -> string list;
29   ph_list_files : string -> (string * file_type) list;
30   ph_get_file_from_package : string -> string -> string
31 }
32 and file_type = {
33   ft_dir : bool;
34   ft_config : bool;
35   ft_ghost : bool;
36   ft_mode : int;
37   ft_size : int;
38 }
39
40 let tmpdir = tmpdir ()
41
42 let handlers = ref []
43
44 let register_package_handler name ph =
45   debug "registering package handler: %s" name;
46   handlers := (name, ph) :: !handlers
47
48 let handler = ref None
49
50 let rec check_system () =
51   try
52     handler := Some (
53       List.find (
54         fun (_, ph) ->
55           ph.ph_detect ()
56       ) !handlers
57     );
58     (get_package_handler ()).ph_init ()
59   with Not_found ->
60     eprintf "\
61 febootstrap: could not detect package manager used by this system or distro.
62
63 If this is a new Linux distro, or not Linux, or a Linux distro that uses
64 an unusual packaging format then you may need to port febootstrap.  If
65 you are expecting that febootstrap should work on this system or distro
66 then it may be that the package detection code is not working.
67 ";
68     exit 1
69
70 and get_package_handler () =
71   match !handler with
72   | Some (_, ph) -> ph
73   | None ->
74       check_system ();
75       get_package_handler ()
76
77 and get_package_handler_name () =
78   match !handler with
79   | Some (name, _) -> name
80   | None ->
81       check_system ();
82       get_package_handler_name ()