2 * Copyright (C) 2009-2010 Red Hat Inc.
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.
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.
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
19 (* ArchLinux support. *)
24 open Febootstrap_package_handlers
25 open Febootstrap_utils
26 open Febootstrap_cmdline
28 (* Create a temporary directory for use by all the functions in this file. *)
29 let tmpdir = tmpdir ()
31 let pacman_detect () =
32 file_exists "/etc/arch-release" &&
35 let pacman_resolve_dependencies_and_download names =
37 sprintf "pactree -u %s | sort -u"
38 (String.concat " " (List.map Filename.quote names)) in
39 let pkgs = run_command_get_lines cmd in
41 (* Exclude packages matching [--exclude] regexps on the command line. *)
45 not (List.exists (fun re -> Str.string_match re name 0) excludes)
48 (* Download the packages. I could use wget `pacman -Sp`, but this
49 * narrows the pacman -Sy window
52 sprintf "cd %s && mkdir -p var/lib/pacman && fakeroot pacman -Syw --noconfirm --cachedir=$(pwd) --root=$(pwd) %s"
53 (Filename.quote tmpdir)
54 (String.concat " " (List.map Filename.quote pkgs)) in
57 (* Find out what pacman downloaded. *)
58 (*let files = Sys.readdir tmpdir in
62 (* Look for 'pkg*.pkg.tar.xz' in the list of files. *)
66 for i = 0 to Array.length files - 1 do
67 if string_prefix pre files.(i) then (
73 eprintf "febootstrap: pacman: error: no file was downloaded corresponding to package %s\n" pkg;
79 List.sort compare pkgs
81 let pacman_list_files pkg =
82 debug "unpacking %s ..." pkg;
84 (* We actually need to extract the file in order to get the
85 * information about modes etc.
87 let pkgdir = tmpdir // pkg ^ ".d" in
90 sprintf "tar -xf %s-* -C %s"
91 (tmpdir // pkg ) pkgdir in
94 let cmd = sprintf "cd %s && find ." pkgdir in
95 let lines = run_command_get_lines cmd in
97 let files = List.map (
99 assert (path.[0] = '.');
102 if path = "." then "/"
103 else String.sub path 1 (String.length path - 1) in
105 (* Find out what it is and get the canonical filename. *)
106 let statbuf = lstat (pkgdir // path) in
107 let is_dir = statbuf.st_kind = S_DIR in
109 (* No per-file metadata like in RPM, but we can synthesize it
112 let config = statbuf.st_kind = S_REG && string_prefix path "/etc/" in
114 let mode = statbuf.st_perm in
116 (path, { ft_dir = is_dir; ft_config = config; ft_mode = mode;
122 (* Easy because we already unpacked the archive above. *)
123 let pacman_get_file_from_package pkg file =
124 tmpdir // pkg ^ ".d" // file
128 ph_detect = pacman_detect;
129 ph_resolve_dependencies_and_download =
130 pacman_resolve_dependencies_and_download;
131 ph_list_files = pacman_list_files;
132 ph_get_file_from_package = pacman_get_file_from_package;
134 register_package_handler "pacman" ph