debian, pacman: incorrect detection of config files.
[febootstrap.git] / 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_resolve_dependencies_and_download : string list -> string list;
28   ph_list_files : string -> (string * file_type) list;
29   ph_get_file_from_package : string -> string -> string
30 }
31 and file_type = {
32   ft_dir : bool;
33   ft_config : bool;
34   ft_ghost : bool;
35   ft_mode : int;
36 }
37
38 let tmpdir = tmpdir ()
39
40 let handlers = ref []
41
42 let register_package_handler name ph =
43   debug "registering package handler: %s" name;
44   handlers := (name, ph) :: !handlers
45
46 let handler = ref None
47
48 let check_system () =
49   try
50     handler := Some (
51       List.find (
52         fun (_, ph) ->
53           ph.ph_detect ()
54       ) !handlers
55     )
56   with Not_found ->
57     eprintf "\
58 febootstrap: could not detect package manager used by this system or distro.
59
60 If this is a new Linux distro, or not Linux, or a Linux distro that uses
61 an unusual packaging format then you may need to port febootstrap.  If
62 you are expecting that febootstrap should work on this system or distro
63 then it may be that the package detection code is not working.
64 ";
65     exit 1
66
67 let rec get_package_handler () =
68   match !handler with
69   | Some (_, ph) -> ph
70   | None ->
71       check_system ();
72       get_package_handler ()
73
74 let rec get_package_handler_name () =
75   match !handler with
76   | Some (name, _) -> name
77   | None ->
78       check_system ();
79       get_package_handler_name ()