summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-08-30 16:07:02 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-08-30 16:07:02 +0100
commit56048c5a7f47f915ed7506779fd8f75bb90bee78 (patch)
treee3ff3bad35d1337d18b500b4c1be025a4809c402 /bin
parenta797a8a9d11b0f0ca9bc738192475b06d5aacc9a (diff)
downloadgitano-56048c5a7f47f915ed7506779fd8f75bb90bee78.tar.gz
BUILD: More work towards an installer
Diffstat (limited to 'bin')
-rw-r--r--bin/.gitignore1
-rw-r--r--bin/gitano-auth.in2
-rw-r--r--bin/gitano-post-receive-hook.in2
-rw-r--r--bin/gitano-setup.in163
-rw-r--r--bin/gitano-update-hook.in2
-rw-r--r--bin/gitano-update-ssh.in2
6 files changed, 172 insertions, 0 deletions
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)