summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2014-05-16 22:32:58 +0200
committerPhilipp Gesang <phg42.2a@gmail.com>2014-05-16 22:32:58 +0200
commite0531b22b9adc94cd9ce8f1200dd9f47d37e1ee2 (patch)
tree6a62ef7833636cbbd656b01738606076aca4a599
parent2ca9786014c5d1dacfd8a6dd6e754ce7a118c1c7 (diff)
downloadcontext-mirror-bot-e0531b22b9adc94cd9ce8f1200dd9f47d37e1ee2.tar.gz
install Context license in repo
-rw-r--r--context_mirror_bot.ml43
1 files changed, 41 insertions, 2 deletions
diff --git a/context_mirror_bot.ml b/context_mirror_bot.ml
index 529e05a..fd71688 100644
--- a/context_mirror_bot.ml
+++ b/context_mirror_bot.ml
@@ -56,9 +56,10 @@ type timestamp_status = Changed of float | Unchanged
type status = Good | Bad of errmsg
and errmsg = string
-(*type environment_status = New | Last of Unix.tm | Fail*)
exception Bad_env of string
+exception Prepare_failed of string
+
let bootstrap_repo = "git://repo.or.cz/context.git" (* Marius’s mirror *)
let garden_repo = "http://git.contextgarden.net/context/context.git" (* official, but broken *)
let mirror_repo = "git@bitbucket.org:phg/context-mirror.git" (* our mirror *)
@@ -79,6 +80,11 @@ let git_config_file = Filename.concat git_dir "config"
let ssh_wrapper = Filename.concat repo_root "git-ssh-wrapper.sh"
let ssh_id = "context_mirror_bot_id_rsa"
let ssh_id_dst = (Filename.concat repo_root ssh_id)
+let static_files = [
+ ("context-license.txt", "COPYING")
+ (*("context-readme.txt", "README")*)
+]
+
let gitconfig = Printf.sprintf "\
[core]
@@ -286,6 +292,7 @@ end = struct
exception Git_checkout_failed of string
exception Git_branch_failed of string
exception Git_commit_failed of string
+ exception Import_files_failed
exception Copy_ssh_key_failed
let write_config () =
@@ -306,6 +313,20 @@ end = struct
let install_files () = write_config (); install_ssh_wrapper ()
+ let import_static_files () =
+ let rec aux = function
+ | [] -> true
+ | (src, dst) :: tl ->
+ begin
+ let fullsrc = Filename.concat repo_root src in
+ let fulldst = Filename.concat repo_dir dst in
+ match list_of_pipe (Printf.sprintf "cp -f %s %s" fullsrc fulldst) with
+ | None -> false
+ | Some _ -> aux tl
+ end
+ in
+ aux static_files
+
let init () =
msg ("Initializing new repository with state from " ^ bootstrap_repo);
match exec_commands [
@@ -386,6 +407,7 @@ end = struct
| Some _ -> ()
| None -> raise (Git_branch_failed branch)
end;
+ if import_static_files () = false then raise Import_files_failed;
match list_of_pipe (Printf.sprintf "git commit --message=\"%s\"" (format_time ts)) with
| Some _ -> gc (); Imported branch
| None -> raise (Git_commit_failed branch)
@@ -430,9 +452,25 @@ let ensure_dst_repo d =
`Exists
end
+let copy_static_files () =
+ List.iter
+ (fun (src, _) ->
+ let dst = Filename.concat repo_root src in
+ if file_exists dst then
+ msg ~lev:1 (Printf.sprintf "File %s exists at %s, skipping." src dst)
+ else
+ begin
+ msg ~lev:1 (Printf.sprintf "Install %s exists to %s" src dst);
+ match list_of_pipe (Printf.sprintf "cp -f %s %s" src dst) with
+ | None -> raise (Prepare_failed (Printf.sprintf "Error preparing file %s." src))
+ | Some _ -> ()
+ end)
+ static_files
+
let prepare_dst () =
try
ensure_dir repo_dir;
+ copy_static_files ();
ensure_dst_repo repo_dir
with
| _ -> `Fail
@@ -568,7 +606,7 @@ and job_kind = Status (* output status of local repo *)
| Nil (* no-op *)
let usage = Printf.sprintf "Usage:
- %s [ -check | -status | -update ]
+ %s [ --check | --status | --update ]
" Sys.argv.(0)
let parse_argv () =
@@ -634,6 +672,7 @@ let run_check () =
let run_prepare () =
ensure_dir repo_dir;
+ copy_static_files ();
match ensure_dst_repo repo_dir with
| `New -> msg (Printf.sprintf "Created new local repository at %s." repo_dir)
| `Exists -> msg (Printf.sprintf