diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-08-30 16:07:02 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-08-30 16:07:02 +0100 |
commit | 56048c5a7f47f915ed7506779fd8f75bb90bee78 (patch) | |
tree | e3ff3bad35d1337d18b500b4c1be025a4809c402 | |
parent | a797a8a9d11b0f0ca9bc738192475b06d5aacc9a (diff) | |
download | gitano-56048c5a7f47f915ed7506779fd8f75bb90bee78.tar.gz |
BUILD: More work towards an installer
-rw-r--r-- | Makefile | 24 | ||||
-rw-r--r-- | bin/.gitignore | 1 | ||||
-rw-r--r-- | bin/gitano-auth.in | 2 | ||||
-rw-r--r-- | bin/gitano-post-receive-hook.in | 2 | ||||
-rw-r--r-- | bin/gitano-setup.in | 163 | ||||
-rw-r--r-- | bin/gitano-update-hook.in | 2 | ||||
-rw-r--r-- | bin/gitano-update-ssh.in | 2 | ||||
-rw-r--r-- | lib/gitano/config.lua | 10 | ||||
-rw-r--r-- | utils/install-lua-bin | 6 |
9 files changed, 202 insertions, 10 deletions
@@ -11,9 +11,15 @@ LUA_MOD_PATH := $(INST_ROOT)/share/lua/$(LUA_VER) LUA_MOD_INST_PATH := $(DESTDIR)$(LUA_MOD_PATH) BIN_PATH := $(INST_ROOT)/bin BIN_INST_PATH := $(DESTDIR)$(BIN_PATH) +LIB_BIN_PATH := $(INST_ROOT)/lib/gitano/bin +LIB_BIN_INST_PATH := $(DESTDIR)$(LIB_BIN_PATH) +SHARE_PATH := $(INST_ROOT)/share/gitano +SHARE_INST_PATH := $(DESTDIR)$(SHARE_PATH) -BINS := gitano-auth gitano-post-receive-hook gitano-update-hook \ - gitano-update-ssh +LIB_BINS := gitano-auth gitano-post-receive-hook gitano-update-hook \ + gitano-update-ssh + +BINS := gitano-setup MODS := gitano \ \ @@ -29,21 +35,21 @@ MOD_DIRS := gitano gitano/git MOD_FILES := $(patsubst %,%.lua,$(subst .,/,$(MODS))) SRC_MOD_FILES := $(patsubst %,lib/%,$(MOD_FILES)) -LOCAL_BINS := $(patsubst %,bin/%,$(BINS)) -BIN_SRCS := $(patsubst %,bin/%.in,$(BINS)) +LOCAL_BINS := $(patsubst %,bin/%,$(BINS) $(LIB_BINS)) +LIB_BIN_SRCS := $(patsubst %,bin/%.in,$(LIB_BINS)) GEN_BIN := utils/install-lua-bin RUN_GEN_BIN := $(LUA) $(GEN_BIN) $(LUA) define GEN_LOCAL_BIN -$(RUN_GEN_BIN) $(shell pwd)/lib $1 $2 +$(RUN_GEN_BIN) $(shell pwd) $(shell pwd)/bin $(shell pwd)/lib $1 $2 chmod 755 $2 endef define GEN_INSTALL_BIN -$(RUN_GEN_BIN) $(LUA_MOD_PATH) $1 $2 +$(RUN_GEN_BIN) $(SHARE_PATH) $(LIB_BIN_PATH) $(LUA_MOD_PATH) $1 $2 chmod 755 $2 endef @@ -63,12 +69,16 @@ clean: bin/%: bin/%.in $(GEN_BIN) $(call GEN_LOCAL_BIN,$<,$@) -install: install-bins install-mods +install: install-bins install-lib-bins install-mods install-bins: $(BIN_SRCS) $(GEN_BIN) mkdir -p $(BIN_INST_PATH) $(foreach BIN,$(BINS),$(call GEN_INSTALL_BIN,bin/$(BIN).in,$(BIN_INST_PATH)/$(BIN))) +install-lib-bins: $(LIB_BIN_SRCS) $(GEN_BIN) + mkdir -p $(LIB_BIN_INST_PATH) + $(foreach BIN,$(LIB_BINS),$(call GEN_INSTALL_BIN,bin/$(BIN).in,$(LIB_BIN_INST_PATH)/$(BIN))) + install-mods: $(SRC_MOD_FILES) mkdir -p $(patsubst %,$(LUA_MOD_INST_PATH)/%,$(MOD_DIRS)) $(foreach MOD,$(MOD_FILES),$(call GEN_INSTALL_MOD,lib/$(MOD),$(LUA_MOD_INST_PATH)/$(MOD))) diff --git a/bin/.gitignore b/bin/.gitignore index 344c403..fc66b5f 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -2,3 +2,4 @@ gitano-auth gitano-post-receive-hook gitano-update-hook gitano-update-ssh +gitano-setup diff --git a/bin/gitano-auth.in b/bin/gitano-auth.in index a16c4df..4679732 100644 --- a/bin/gitano-auth.in +++ b/bin/gitano-auth.in @@ -15,6 +15,8 @@ local luxio = require "luxio" local sio = require "luxio.simple" local sp = require "luxio.subprocess" +-- @@GITANO_BIN_PATH + local repo_root, username, keytag = ... local cmdline = luxio.getenv "SSH_ORIGINAL_COMMAND" or "" diff --git a/bin/gitano-post-receive-hook.in b/bin/gitano-post-receive-hook.in index 9b5ae37..6354592 100644 --- a/bin/gitano-post-receive-hook.in +++ b/bin/gitano-post-receive-hook.in @@ -15,6 +15,8 @@ local luxio = require "luxio" local sio = require "luxio.simple" local sp = require "luxio.subprocess" +-- @@GITANO_BIN_PATH + local start_log_level = gitano.log.get_level() -- Clamp level at info until we have checked if the caller -- is an admin or not diff --git a/bin/gitano-setup.in b/bin/gitano-setup.in new file mode 100644 index 0000000..8edaf60 --- /dev/null +++ b/bin/gitano-setup.in @@ -0,0 +1,163 @@ +-- @@SHEBANG +-- -*- Lua -*- +-- gitano-setup +-- +-- Git (with) Augmented network operations -- Instance setup tool +-- +-- Copyright 2012 Daniel Silverstone <dsilvers@digital-scurf.org> +-- +-- + +-- @@GITANO_LUA_PATH + +local gitano = require "gitano" +local luxio = require "luxio" +local sio = require "luxio.simple" +local clod = require "clod" + +-- @@GITANO_BIN_PATH + +local possible_answers = {...} + +if possible_answers[1] == "--help" or + possible_answers[1] == "-h" or + possible_answers[1] == "--usage" then + sio.stderr:write([[ +usage: gitano-setup [<answers-file>...] + +This tool creates the basic repository setup for a Gitano instance. + +This is an interactive tool where if it has any questions for you, it will +visit each answers file in turn until it finds the answer. This means +that for automation purposes you can specify multiple answers files with +the earlier ones overriding the later ones. + +In summary, the behaviour is as follows: + +The repository root is created if it does not exist, and a gitano-admin.git +repository is created within it. Said repository is populated with the +example administration repository rules and an admin user and group. +]]) + return 1 +end + +local conf = clod.parse("") + +gitano.log.set_prefix("gitano-setup") +gitano.log.bump_level(gitano.log.level.CHAT) + +for i = #possible_answers, 1, -1 do + gitano.log.debug("Parsing answers file:", possible_answers[1]) + local one_conf = assert(clod.parse(assert(io.open(possible_answers[1], "r")):read "*a", + "@" .. possible_answers[1])) + gitano.log.debug("Combining answers into conf...") + for k,v in one_conf:each() do + gitano.log.ddebug(tostring(k) .. " = " .. tostring(v)) + conf.settings[k] = v + end +end + +gitano.log.chat("Welcome to the Gitano setup process") + +function get(key) + return conf.settings[key] +end + +function ask_for(key, prompt, default) + local cur_value = conf.settings[key] or default + gitano.log.ddebug("ask_for(", tostring(key), ", ", tostring(prompt), ", ", + tostring(default), ") [", tostring(cur_value), " ]") + if not conf.settings["setup.batch"] then + local default_str = (cur_value == nil) and "" or " [" .. tostring(cur_value) .. "]" + sio.stdout:write((prompt or key) .. default_str .. ": ") + local new_value = sio.stdin:read("*l") + if new_value ~= "" then + cur_value = new_value + end + end + gitano.log.info("Setting:", key, "is", tostring(cur_value)) + conf.settings[key] = cur_value + return cur_value +end + +function look_for_path(path) + local ret, stat = luxio.stat(path) + if ret ~= 0 then + return false, path .. ": " .. luxio.strerror(stat) + end + if not luxio.S_ISDIR(stat.mode) then + return false, path .. ": not a directory" + end + return true +end + +function validate_path(path) + local ok, msg = look_for_path(path) + if not ok then + error(msg, 2) + end +end + +function file_exists(path) + local fh = io.open(tostring(path), "r") + if not fh then + return false + end + fh:close() + return true +end + +function validate_username(n) + if not n:match("^[a-z_][a-z0-9_%-]*$") then + error("Invalid username: " .. n, 2) + end +end + +if conf.settings["setup.batch"] then + gitano.log.info("Batch mode engaged") +else + gitano.log.info("Interactive mode engaged") +end + +gitano.log.info("Step 1: Determine everything") + +validate_path(ask_for("paths.home", "Home directory for new Gitano user", + os.getenv "HOME")) + +local pubkey_path +if look_for_path(get("paths.home") .. "/.ssh") then + -- Try and find a pubkey to use + for _, ktype in ipairs { "rsa", "ecdsa" } do + local pk = get("paths.home") .. "/.ssh/id_" .. ktype .. ".pub" + if file_exists(pk) then + pubkey_path = pk + break + end + end +end + +assert(file_exists(ask_for("paths.pubkey", "Public key for admin user", + pubkey_path)), + "Cannot find public key") + +ask_for("paths.repos", "Repository path for new Gitano instance", + get("paths.home") .. "/repos") +ask_for("paths.graveyard", "Graveyard path for new Gitano instance", + get("paths.home") .. "/graveyard") + +validate_username(ask_for("admin.username", "User name for admin user", + os.getenv "USER" or "admin")) +ask_for("admin.realname", "Real name for admin user", + "Administrator") + +ask_for("admin.email", "Email address for admin user", + "admin@administrator.local") + +gitano.log.info("Step 2: Set up the respositories") + +local completely_flat = {} +local site_conf = clod.parse("") +--site_conf.settings[ + +gitano.log.info("Step 3: Hook into SSH") + diff --git a/bin/gitano-update-hook.in b/bin/gitano-update-hook.in index 51283b7..806a35b 100644 --- a/bin/gitano-update-hook.in +++ b/bin/gitano-update-hook.in @@ -15,6 +15,8 @@ local luxio = require "luxio" local sio = require "luxio.simple" local sp = require "luxio.subprocess" +-- @@GITANO_BIN_PATH + local refname, oldsha, newsha = ... local start_log_level = gitano.log.get_level() diff --git a/bin/gitano-update-ssh.in b/bin/gitano-update-ssh.in index aa3f957..d4bf54d 100644 --- a/bin/gitano-update-ssh.in +++ b/bin/gitano-update-ssh.in @@ -15,6 +15,8 @@ local luxio = require "luxio" local sio = require "luxio.simple" local sp = require "luxio.subprocess" +-- @@GITANO_BIN_PATH + local repo_root = ... gitano.log.bump_level(gitano.log.level.CHAT) diff --git a/lib/gitano/config.lua b/lib/gitano/config.lua index ddc4130..5eac287 100644 --- a/lib/gitano/config.lua +++ b/lib/gitano/config.lua @@ -18,6 +18,8 @@ local pcall = pcall local pairs = pairs local tconcat = table.concat +local lib_bin_path = "/tmp/DOES_NOT_EXIST" + local admin_name = { realname = "Gitano", email = "gitano@gitano-admin.git" @@ -26,7 +28,6 @@ local admin_name = { local required_confs = { site_name = "string", repository_root = "string", - bin_path = "string", graveyard_root = "string", } @@ -292,7 +293,7 @@ local function generate_ssh_config(conf) log.debug("Adding <" .. u .. "> <" .. ktag .. ">") ret[#ret+1] = (('command="%s/gitano-auth \\"%s\\" \\"%s\\" \\"%s\\"",no-agent-forwarding,no-port-forwarding,no-pty,no-user-rc,no-X11-forwarding %s'): - format(conf.global.bin_path, conf.global.repository_root, u, ktag, keytab.data)) + format(lib_bin_path, conf.global.repository_root, u, ktag, keytab.data)) end end ret[#ret+1] = "### End Gitano Keys ###" @@ -438,6 +439,10 @@ local function commit_config_changes(conf, desc, username) return true, commit end +local function set_lib_bin_path(p) + lib_bin_path = p +end + return { genssh = generate_ssh_config, writessh = update_ssh_keys, @@ -447,4 +452,5 @@ return { load_file_content = load_file_content, get_default_hook_content = get_default_hook_content, has_global_hook = has_global_hook, + lib_bin_path = set_lib_bin_path, } diff --git a/utils/install-lua-bin b/utils/install-lua-bin index 1e5b105..71d4a14 100644 --- a/utils/install-lua-bin +++ b/utils/install-lua-bin @@ -1,6 +1,6 @@ -- Run this explicitly through -*- Lua -*- -local lua_bin, inst_mod_path, input_name, output_name = ... +local lua_bin, inst_share_path, inst_bin_path, inst_mod_path, input_name, output_name = ... local input_fh = assert(io.open(input_name, "r")) local output_fh = assert(io.open(output_name, "w")) @@ -34,6 +34,10 @@ while line do output_fh:write("-- Gitano modules installed into " .. inst_mod_path .. "\n") end + elseif token == "GITANO_BIN_PATH" then + output_fh:write(("gitano.config.lib_bin_path(%q)\n"):format(inst_bin_path)) + elseif token == "GITANO_SHARE_PATH" then + output_fh:write(("gitano.config.share_path = %q\n"):format(inst_share_path)) else output_fh:write("-- Unknown token: " .. token .. "\n") end |