[Pkg-ocaml-maint-commits] [SCM] oasis2debian project branch, master, updated. bc9e1c496c65a65508359c9fe211ec8b27eb7b03

Sylvain Le Gall gildor at debian.org
Tue Mar 12 00:42:47 UTC 2013


The following commit has been merged in the master branch:
commit bc9e1c496c65a65508359c9fe211ec8b27eb7b03
Author: Sylvain Le Gall <gildor at debian.org>
Date:   Tue Mar 12 00:42:39 2013 +0000

    Allow to edit .postinst/.postrm: add user, chown/chmod files.

diff --git a/_tags b/_tags
index 5deb5f4..560c39b 100644
--- a/_tags
+++ b/_tags
@@ -65,3 +65,5 @@
 "src/Copyright.ml": syntax_camlp4o
 "src/Rules.ml": syntax_camlp4o
 "src/DhFiles.ml": syntax_camlp4o
+"src/Group.ml": syntax_camlp4o
+"src/DpkgStatOverride.ml": syntax_camlp4o
diff --git a/src/ActInit.ml b/src/ActInit.ml
index 1154ebd..e2976ec 100644
--- a/src/ActInit.ml
+++ b/src/ActInit.ml
@@ -30,16 +30,22 @@ open Common
 let itp =
   Conf.create
     ~cli:"--itp"
-    "Bug number of the ITP for the package"
+    "int Bug number of the ITP for the package."
     Conf.ShortInput
 
 let bts_query =
   Conf.create_full 
     ~cli:"--bts-query"
     bool_of_string
-    "Query the BTS for ITP (true/false)"
+    "bool Query the BTS for ITP (true/false)."
     (Conf.Value true)
 
+let distribution =
+  Conf.create
+    ~cli:"--distribution"
+    "str Distribution for the package."
+    Conf.ShortInput
+
 let dh_compat = "7"
 
 let run ~ctxt args = 
@@ -78,21 +84,30 @@ let run ~ctxt args =
 
     if debian_not_exist "changelog" then
       begin
-        let itp = 
-          Conf.get ~ctxt itp 
-        in
         let opts =
           ""
         in
+        let opts = 
+          if Conf.is_set itp then
+            opts^" --closes "^(Conf.get ~ctxt itp)
+          else
+            opts^" 'Initial release.'"
+        in
         let opts =
           if Conf.get ~ctxt bts_query then
             opts
           else
             opts^" --no-query"
         in
+        let opts =
+          if Conf.is_set distribution then
+            opts^" --distribution "^(Conf.get ~ctxt distribution)
+          else 
+            opts
+        in
           assert_command ~ctxt  
             (interpolate 
-               "dch --create --package $t.deb_name --newversion $pkg_version-1 --closes $itp $opts")
+               "dch --create --package $t.deb_name --newversion $pkg_version-1 $opts")
       end
   in
 
@@ -100,7 +115,10 @@ let run ~ctxt args =
     Control.create t;
     Copyright.create ~ctxt t;
     Rules.create t;
-    DhFiles.create ~ctxt t
+    DhFiles.create ~ctxt t;
+    Group.create ~ctxt t;
+    DpkgStatOverride.create ~ctxt t;
+    DhDirs.create ~ctxt t;
   in 
 
     ()
diff --git a/src/Common.ml b/src/Common.ml
index e0ca6c2..6b62d80 100644
--- a/src/Common.ml
+++ b/src/Common.ml
@@ -73,22 +73,28 @@ let debian_fn =
 let debian_not_exist fn =
   not (test Exists (debian_fn fn))
 
+(** Execute [f] on a file inside debian/, in append mode. *)
+let debian_with_append_fn fn f =
+  let real_fn = 
+    debian_fn fn 
+  in
+  let () = 
+    mkdir ~parent:true (FilePath.dirname real_fn)
+  in
+  let chn = 
+    open_out_gen 
+      [Open_wronly; Open_append; Open_creat; Open_text]
+      0o666
+      real_fn
+  in
+    f chn;
+    close_out chn
+
 (** Only execute [f] if the file doesn't exist 
   *)
 let debian_with_fn fn f = 
   if debian_not_exist fn then
-    begin
-      let real_fn = 
-        debian_fn fn
-      in
-      let () = 
-        mkdir ~parent:true (FilePath.dirname real_fn)
-      in
-      let chn = open_out real_fn
-      in
-        f chn;
-        close_out chn
-    end
+    debian_with_append_fn fn f
 
 (** Run a command and file if exit code is non-zero
   *)
@@ -130,6 +136,24 @@ let assert_command_output ~ctxt cmd =
 let output_content str chn = 
   output_string chn (str^"\n")
 
+let lines_of_file fn =
+  let chn = open_in fn in
+  let lst = ref [] in
+  let () =
+    try 
+      while true do
+        lst := (input_line chn) :: !lst
+      done;
+    with End_of_file ->
+      close_in chn
+  in
+    List.rev !lst
+
+let file_of_lines fn lst =
+  let chn = open_out fn in
+    output_string chn (String.concat "\n" lst);
+    output_string chn "\n";
+    close_out chn
 
 module MapString = Map.Make(String)
 
diff --git a/src/Copyright.ml b/src/Copyright.ml
index 2744dfb..b22aa05 100644
--- a/src/Copyright.ml
+++ b/src/Copyright.ml
@@ -238,6 +238,6 @@ License: $license
 Files: debian/*
 Copyright: (C) ${year,%d} $t.uploader
 License: GPL-3+
-                
+
  See '/usr/share/common-licenses/GPL-3' for full text.
 "))
diff --git a/src/DhDirs.ml b/src/DhDirs.ml
new file mode 100644
index 0000000..6c1f292
--- /dev/null
+++ b/src/DhDirs.ml
@@ -0,0 +1,32 @@
+
+open Common
+
+let dirs = 
+  let lst = ref [] in
+    Conf.create_full
+      ~cli:"--dh-dirs"
+      (fun s ->
+         Scanf.sscanf 
+           s "%s@,%s"
+           (fun pkg fn ->
+              let lst' = 
+                (pkg, fn) :: !lst
+              in
+                lst := lst';
+                lst'))
+      "pkg,fn Add an entry in pkg.dirs."
+      (Conf.Value !lst)
+
+let create ~ctxt t =
+  let pkg_check pkg =
+    (* TODO *)
+    ()
+  in
+    List.iter
+      (fun (pkg, fn) ->
+         pkg_check pkg;
+         debian_with_append_fn
+           (pkg^".dirs")
+           (fun chn ->
+              output_string chn (fn^"\n")))
+      (Conf.get ~ctxt dirs)
diff --git a/src/DhFiles.ml b/src/DhFiles.ml
index 183c96f..7bcb256 100644
--- a/src/DhFiles.ml
+++ b/src/DhFiles.ml
@@ -265,10 +265,16 @@ Section: Programming/OCaml");
                           chn;
 
                         if e.has_native then
-                          output_content
-                            (interpolate
-                               "OPT: @OCamlStdlibDir@/$e.findlib_name/*.cmx*")
-                            chn;
+                          begin
+                            output_content
+                              (interpolate
+                                 "OPT: @OCamlStdlibDir@/$e.findlib_name/*.cmx")
+                              chn;
+                            output_content
+                              (interpolate
+                                  "OPT: @OCamlStdlibDir@/$e.findlib_name/*.cmxa")
+                              chn
+                          end;
 
                         if e.has_dll then
                           output_content
@@ -319,6 +325,11 @@ Section: Programming/OCaml");
                           output_content 
                             (interpolate
                                "@OCamlStdlibDir@/$e.findlib_name/*.cm[ao]")
+                            chn;
+                        if e.has_native then
+                          output_content
+                            (interpolate 
+                               "@OCamlStdlibDir@/$e.findlib_name/*.cmxs")
                             chn)
                      roots)
             end
@@ -357,3 +368,80 @@ Section: Programming/OCaml");
                     ()
             end
     end
+
+let insertion_point =
+  "# Insertion point for oasis2debian, do not remove."
+
+let snippet_start snippet_name = 
+  Printf.sprintf "# oasis2debian snippet '%s' start." snippet_name
+
+let snippet_end snippet_name =
+  Printf.sprintf "# oasis2debian snippet '%s' end." snippet_name
+
+
+(** Split a script file around its insertion point.
+  *)
+let dh_script_split fn =
+  let rec split = 
+    function
+      | hd :: tl ->
+          if hd = insertion_point then
+            [], hd, tl
+          else
+            let before, cur, after = 
+              split tl
+            in
+              hd :: before, cur, after
+      | [] ->
+          failwith 
+            (Printf.sprintf
+               "'%s' not found in file '%s'"
+               insertion_point fn)
+  in
+    if debian_not_exist fn then
+      debian_with_fn
+        fn
+        (output_content
+           (interpolate "\
+#!/bin/sh
+
+set -e
+
+$insertion_point"));
+    split (lines_of_file (debian_fn fn))
+
+
+(** Append data to debian/pkg.postinst.
+  *)
+let dh_postinst pkg snippet_name content = 
+  let basename = pkg^".postinst" in
+  let before, cur, after =
+    dh_script_split basename
+  in
+    file_of_lines
+      (debian_fn basename)
+      (before @ 
+       [snippet_start snippet_name;
+        content;
+        snippet_end snippet_name;
+        ""; cur] @ after)
+
+(** Prepend data to debian/pkg.prerm.
+  *)
+let dh_prerm pkg snippet_name content = 
+  let basename = pkg^".prerm" in
+  let before, cur, after =
+    dh_script_split basename
+  in
+    file_of_lines
+      (debian_fn basename)
+      (before @
+       [cur; ""; snippet_start snippet_name;
+        content;
+        snippet_end snippet_name] @ after)
+
+
+let dh_dirs pkg dir =
+  debian_with_append_fn
+    (pkg^".dirs")
+    (output_content dir)
diff --git a/src/DpkgStatOverride.ml b/src/DpkgStatOverride.ml
new file mode 100644
index 0000000..5ffd62b
--- /dev/null
+++ b/src/DpkgStatOverride.ml
@@ -0,0 +1,57 @@
+
+open Common
+
+type t =
+    {
+      fn: string;
+      owner: string;
+      group: string;
+      acl: string;
+    }
+
+let dpkg_statoverride = 
+  let lst = ref [] in
+    Conf.create_full
+      ~cli:"--dpkg-statoverride"
+      (fun s ->
+         Scanf.sscanf 
+           s "%s@,%s@,%s@,%s"
+           (fun fn owner group acl ->
+              let lst' = 
+                {fn = fn; owner = owner; group = group; acl = acl}
+                :: !lst
+              in
+                lst := lst';
+                lst'))
+      "fn,owner,group,acl Create a dpkg-statoverride entry (postinst/postrm)."
+      (Conf.Value !lst)
+
+let create ~ctxt t =
+  match Conf.get ~ctxt dpkg_statoverride, t.deb_exec with 
+    | _ :: _, None ->
+        failwith "--dpkg-statoverride called without an executable package."
+    | [], None ->
+        ()
+    | lst, Some {name = exec_name} ->
+        List.iter
+          (fun t ->
+             let snippet_name = Printf.sprintf "dpkg-statoverride(%s)" t.fn in
+               DhFiles.dh_postinst
+                 exec_name
+                 snippet_name
+                 (interpolate "\
+if [ \"\$1\" = configure ]; then
+  if ! dpkg-statoverride --list '$t.fn' >/dev/null 2>&1; then
+    chown '$t.owner:$t.group' '$t.fn'
+    chmod $t.acl '$t.fn'
+  fi
+fi");
+               DhFiles.dh_prerm
+                 exec_name
+                 snippet_name
+                 (interpolate "\
+if [ \"\$1\" = remove ]; then
+  rm -rf '$t.fn' || true
+fi"))
+          (List.rev lst)
+
diff --git a/src/Group.ml b/src/Group.ml
new file mode 100644
index 0000000..9e6a869
--- /dev/null
+++ b/src/Group.ml
@@ -0,0 +1,44 @@
+
+open Common
+
+let group = 
+  Conf.create_full
+    ~cli:"--group"
+    (fun s ->
+       Scanf.sscanf
+         s "%s@,%s"
+         (fun group homedir ->
+            Some (group, homedir)))
+    "group,homedir Create a group for the executable package (postinst/prerm)."
+    (Conf.Value None)
+
+let create ~ctxt t = 
+  match Conf.get ~ctxt group, t.deb_exec with 
+    | Some (group, homedir), Some {name = exec_name} ->
+        let snippet_name = Printf.sprintf "group(%s)" group in
+          DhFiles.dh_dirs
+            exec_name
+            homedir;
+          DhFiles.dh_postinst
+            exec_name
+            snippet_name
+            (interpolate "\
+if [ \"\$1\" = configure ]; then
+  if ! getent group '$group' > /dev/null; then
+    adduser --system --quiet --home '$homedir' --no-create-home \\
+      --disabled-password --group '$group'
+  fi
+fi");
+          DhFiles.dh_prerm
+            exec_name
+            snippet_name
+            (interpolate "\
+if [ \"\$1\" = remove ]; then
+  delgroup '$group' > /dev/null 2>&1 || true
+fi")
+
+    | Some _, None ->
+        failwith "--group without an executable package."
+
+    | None, _ ->
+        ()

-- 
oasis2debian project



More information about the Pkg-ocaml-maint-commits mailing list