summaryrefslogtreecommitdiff
path: root/bin/gitano-setup.in
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-08-30 18:37:59 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-08-30 18:37:59 +0100
commitd2732c73915f3bec423dc89d3b3d185b6b7917e3 (patch)
tree7c70dae1c4f0df070e36ebc3f4be98da201bd798 /bin/gitano-setup.in
parent56048c5a7f47f915ed7506779fd8f75bb90bee78 (diff)
downloadgitano-d2732c73915f3bec423dc89d3b3d185b6b7917e3.tar.gz
INSTALLER: make install and gitano-setup should work (mostly)
Diffstat (limited to 'bin/gitano-setup.in')
-rw-r--r--bin/gitano-setup.in155
1 files changed, 143 insertions, 12 deletions
diff --git a/bin/gitano-setup.in b/bin/gitano-setup.in
index 8edaf60..211f669 100644
--- a/bin/gitano-setup.in
+++ b/bin/gitano-setup.in
@@ -16,6 +16,7 @@ local sio = require "luxio.simple"
local clod = require "clod"
-- @@GITANO_BIN_PATH
+-- @@GITANO_SHARE_PATH
local possible_answers = {...}
@@ -85,7 +86,7 @@ function look_for_path(path)
if ret ~= 0 then
return false, path .. ": " .. luxio.strerror(stat)
end
- if not luxio.S_ISDIR(stat.mode) then
+ if luxio.S_ISDIR(stat.mode) == 0 then
return false, path .. ": not a directory"
end
return true
@@ -107,9 +108,9 @@ function file_exists(path)
return true
end
-function validate_username(n)
+function validate_name(n)
if not n:match("^[a-z_][a-z0-9_%-]*$") then
- error("Invalid username: " .. n, 2)
+ error("Invalid name: " .. n, 2)
end
end
@@ -119,16 +120,19 @@ else
gitano.log.info("Interactive mode engaged")
end
-gitano.log.info("Step 1: Determine everything")
+gitano.log.chat("Step 1: Determine everything")
validate_path(ask_for("paths.home", "Home directory for new Gitano user",
os.getenv "HOME"))
+ask_for("paths.ssh", "SSH directory for new Gitano user",
+ get("paths.home") .. "/.ssh")
+
local pubkey_path
-if look_for_path(get("paths.home") .. "/.ssh") then
+if look_for_path(get("paths.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"
+ local pk = get("paths.ssh") .. "/id_" .. ktype .. ".pub"
if file_exists(pk) then
pubkey_path = pk
break
@@ -136,7 +140,7 @@ if look_for_path(get("paths.home") .. "/.ssh") then
end
end
-assert(file_exists(ask_for("paths.pubkey", "Public key for admin user",
+assert(file_exists(ask_for("paths.pubkey", "Public key file for admin user",
pubkey_path)),
"Cannot find public key")
@@ -145,19 +149,146 @@ ask_for("paths.repos", "Repository path for new Gitano instance",
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"))
+validate_name(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")
+validate_name(ask_for("admin.keyname", "Key name for administrator",
+ "default"))
+
+ask_for("site.name", "Site name", "a random Gitano instance")
+ask_for("log.prefix", "Site log prefix", "gitano")
+gitano.log.chat("Step 2: Gather required content")
+
+gitano.log.info("=> Prepare site config")
local completely_flat = {}
local site_conf = clod.parse("")
---site_conf.settings[
+site_conf.settings["site_name"] = get "site.name"
+site_conf.settings["repository_root"] = get "paths.repos"
+site_conf.settings["graveyard_root"] = get "paths.graveyard"
+site_conf.settings["log.prefix"] = get "log.prefix"
+completely_flat["site.conf"] = site_conf:serialise()
+
+-- Acquire the contents of the skeleton gitano-admin repository
+gitano.log.info("=> Acquire skeleton gitano-admin")
+local skel_path = gitano.config.share_path() .. "/skel/gitano-admin"
+local skel = assert(sio.opendir(skel_path))
+local function acquire(dir, base, path)
+ gitano.log.ddebug("Acquire skeleton in:", path)
+ for ent in dir:iterate() do
+ if not (ent == "." or ent == "..") then
+ local entpath = path .. "/" .. ent
+ local treeent = base .. ent
+ if look_for_path(entpath) then
+ local subdir = assert(sio.opendir(entpath))
+ acquire(subdir, treeent .. "/", entpath)
+ subdir:close()
+ else
+ local fh = io.open(entpath, "r")
+ completely_flat[treeent] = fh:read "*a"
+ fh:close()
+ end
+ end
+ end
+end
+acquire(skel, "", skel_path)
+skel:close()
+
+-- Now build the user files
+gitano.log.info("=> Preparing administration user (" .. get("admin.username") .. ")")
+local userpath = "users/" .. get("admin.username") .. "/user.conf"
+local keypath = "users/" .. get("admin.username") .. "/" .. get("admin.keyname") .. ".key"
+local userconf = clod.parse("")
+userconf.settings.real_name = get("admin.realname")
+userconf.settings.email_address = get("admin.email")
+completely_flat[userpath] = userconf:serialise()
+completely_flat[keypath] = assert(sio.open(get("paths.pubkey"), "r")):read "*a"
+
+-- And now the gitano-admin group
+gitano.log.info("=> Preparing gitano-admin group")
+local groupconf = clod.parse("")
+groupconf.settings.description = "Gitano Instance Administrators"
+groupconf.settings["members.*"] = get("admin.username")
+completely_flat["groups/gitano-admin.conf"] = groupconf:serialise()
+
+gitano.log.chat("Step 3: Write out paths and gitano-admin.git")
+
+function mkdir_p(path)
+ if look_for_path(path) then
+ return
+ end
+ local parent = path:match("^(.+)/.*")
+ if not look_for_path(parent) then
+ mkdir_p(parent)
+ end
+ assert(sio.mkdir(path))
+end
+
+gitano.log.info("=> Make paths")
+mkdir_p(get "paths.repos")
+mkdir_p(get "paths.graveyard")
+mkdir_p(get "paths.ssh")
+assert(sio.chmod(get "paths.ssh", "0700"))
+
+gitano.log.info("=> Prepare repository")
+
+local raw_repo = assert(gitano.git.repository.create(get("paths.repos") ..
+ "/gitano-admin.git"))
+
+gitano.log.info("=> Create a flattened tree")
+for k, v in pairs(completely_flat) do
+ gitano.log.debug(" => Make object", k)
+ completely_flat[k] = gitano.git.object.create(raw_repo, "blob", v)
+end
+
+gitano.log.info("=> Commit that tree")
+local real_tree = assert(gitano.git.tree.create(raw_repo, completely_flat))
+
+local person = {
+ realname = get "admin.realname",
+ email = get "admin.email",
+}
+local commit_data = {
+ author = person,
+ committer = person,
+ tree = real_tree,
+ message = "Initial setup",
+}
+
+local commit_obj = assert(gitano.git.commit.create(raw_repo, commit_data))
+
+gitano.log.info("=> Attach that commit to master")
+
+assert(raw_repo:update_ref("refs/heads/master", commit_obj.sha,
+ "Create initial master ref"))
+
+gitano.log.info("=> Ensure we can parse our resultant admin repository")
+
+local admin_head = raw_repo:get(raw_repo.HEAD)
+
+if not admin_head then
+ gitano.log.fatal("Unable to find the HEAD of the administration repository. Cannot continue");
+end
+
+local config = assert(gitano.config.parse(admin_head))
+-- Restore the prefix for our logging
+gitano.log.set_prefix("gitano-setup")
+-- Verify that our user exists
+
+assert(config.users[get "admin.username"], "Could not find user")
+assert(config.groups["gitano-admin"].filtered_members[get "admin.username"],
+ "User was not a gitano-admin")
+
+gitano.log.info("=> Change the admin ref for gitano-admin.git")
+config.repo:set_description("Instance administration repository")
+config.repo:set_owner(get "admin.username")
-gitano.log.info("Step 3: Hook into SSH")
+gitano.log.info("=> Write the SSH authorized_keys file out")
+gitano.config.writessh(config, get("paths.ssh") .. "/authorized_keys")
+assert(sio.chmod(get("paths.ssh") .. "/authorized_keys", "0600"))