Skip to content
Browse files

[scripts] add a small script to initialize rsync and server repositories

  • Loading branch information...
1 parent 7e5fe8a commit 9fd1a527ae3e5a5d3362180f6f0fc71ff5f38c5a @samoht samoht committed
View
2 Makefile
@@ -6,7 +6,7 @@ TARGETS = opam opam-server \
opam-rsync-init opam-rsync-update opam-rsync-download opam-rsync-upload \
opam-git-init opam-git-update opam-git-download opam-git-upload \
opam-server-init opam-server-update opam-server-download opam-server-upload \
- opam-mk-config opam-mk-install
+ opam-mk-config opam-mk-install opam-mk-repo
.PHONY: all
View
9 opam.ocp
@@ -141,11 +141,16 @@ end
(* Helpers *)
begin program "opam-mk-config"
- files = [ "src/opam_mk_config.ml" ]
+ files = [ "src/scripts/opam_mk_config.ml" ]
requires = [ "opam-lib" ]
end
begin program "opam-mk-install"
- files = [ "src/opam_mk_install.ml" ]
+ files = [ "src/scripts/opam_mk_install.ml" ]
+ requires = [ "opam-lib" ]
+end
+
+begin program "opam-mk-repo"
+ files = [ "src/scripts/opam_mk_repo.ml" ]
requires = [ "opam-lib" ]
end
View
4 src/client.ml
@@ -176,7 +176,7 @@ let init repo =
let config_f = Path.G.config root in
if Filename.exists config_f then
Globals.error_and_exit "%s already exist" (Filename.to_string config_f)
- else
+ else try
let opam_version = OPAM_V.of_string Globals.opam_version in
let ocaml_version = OCaml_V.of_string Sys.ocaml_version in
let config = File.Config.create opam_version [repo] ocaml_version in
@@ -195,6 +195,8 @@ let init repo =
update ();
(* Install the initial package *)
install_initial_package ()
+ with _ ->
+ Dirname.rmdir (Path.G.root root)
let indent_left s nb =
let nb = nb - String.length s in
View
0 src/opam_mk_config.ml → src/scripts/opam_mk_config.ml
File renamed without changes.
View
0 src/opam_mk_install.ml → src/scripts/opam_mk_install.ml
File renamed without changes.
View
83 src/scripts/opam_mk_repo.ml
@@ -0,0 +1,83 @@
+(***********************************************************************)
+(* *)
+(* Copyright 2012 OCamlPro *)
+(* Copyright 2012 INRIA *)
+(* *)
+(* All rights reserved. This file is distributed under the terms of *)
+(* the GNU Public License version 3.0. *)
+(* *)
+(* TypeRex is distributed in the hope that it will be useful, *)
+(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)
+(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)
+(* GNU General Public License for more details. *)
+(* *)
+(***********************************************************************)
+
+(* A script helper to initialize an OPAM repo.
+ It takes as input a directory where:
+ * opam/ contains some OPAM files
+ * descr/ contains some description files
+ * archives/ might contain some archive
+ * url/$name.$version contains archive address
+ * files/$name.$version contains some files to include in
+ the archives (typically .config.in
+ and .install)
+
+ After the script is run, archives/ contains all the package archives
+ for the available descr and OPAM files *)
+
+module F = Filename
+
+let tmp_dir = F.concat F.temp_dir_name "opam-mk-repo"
+
+open Types
+
+let root = Path.R.of_path (Dirname.cwd ())
+
+let opams = Path.R.available root
+
+let archives =
+ NV.Set.filter (fun nv ->
+ not (Filename.exists (Path.R.archive root nv))
+ ) opams
+
+let url nv =
+ Raw.to_string (Filename.read (Path.R.root root / "url" // NV.to_string nv))
+
+let files nv =
+ Path.R.root root / "files" / NV.to_string nv
+
+let tmp nv =
+ Path.R.root root / "tmp" / NV.to_string nv
+
+let tmp_dir nv =
+ Dirname.of_string tmp_dir / NV.to_string nv
+
+let wget src =
+ match Globals.os with
+ | Globals.Darwin -> Printf.sprintf "ftp %s" src
+ | _ -> Printf.sprintf "wget %s" src
+
+let () =
+ Dirname.mkdir (Path.R.archive_dir root);
+ NV.Set.iter (fun nv ->
+ let url = url nv in
+ let tmp_dir = tmp_dir nv in
+ let err = Dirname.exec (tmp nv) [ wget url ] in
+ if err = 0 then (
+ Dirname.rmdir tmp_dir;
+ Filename.extract (tmp nv // F.basename url) tmp_dir;
+ List.iter (fun f ->
+ Filename.copy_in f tmp_dir
+ ) (Filename.list (files nv));
+ let err = Dirname.exec (Path.R.archive_dir root)
+ [ Printf.sprintf
+ "tar cz %s > %s.tar.gz"
+ (Dirname.to_string tmp_dir)
+ (NV.to_string nv)
+ ] in
+ if err <> 0 then
+ Globals.error_and_exit "Cannot compress %s" (Dirname.to_string tmp_dir)
+ ) else
+ Globals.error_and_exit "Cannot get %s" url;
+ ) opams
View
4 src/types.ml
@@ -42,6 +42,7 @@ end
(* Absolute directory names *)
module Dirname: sig
include Abstract
+ val cwd: unit -> t
val rmdir: t -> unit
val mkdir: t -> unit
val exec: t -> string list -> int
@@ -57,6 +58,9 @@ end = struct
let rmdir dirname =
Run.remove (to_string dirname)
+ let cwd () =
+ of_string (Run.cwd ())
+
let mkdir dirname =
Run.mkdir (to_string dirname)
View
3 src/types.mli
@@ -43,6 +43,9 @@ module Dirname: sig
include Abstract
+ (** Return the current working directory *)
+ val cwd: unit -> t
+
(** Remove a directory *)
val rmdir: t -> unit

0 comments on commit 9fd1a52

Please sign in to comment.
Something went wrong with that request. Please try again.