summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2019-01-19 13:43:09 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2019-01-19 13:43:09 +0000
commit5d01ab0e5948d8726d99bd58ec786f61d62702ea (patch)
treeed815b1fe5a8ca8bba56dd04bc3663c24e6b9610
parentaab70777f26e52216f64024612baaed58b394653 (diff)
downloadgitano-5d01ab0e5948d8726d99bd58ec786f61d62702ea.tar.gz
Preserve ssh authorized_keys suffix/prefix
-rw-r--r--lib/gitano/config.lua33
1 files changed, 31 insertions, 2 deletions
diff --git a/lib/gitano/config.lua b/lib/gitano/config.lua
index ebf9181..ea54425 100644
--- a/lib/gitano/config.lua
+++ b/lib/gitano/config.lua
@@ -353,8 +353,11 @@ local function get_default_hook_content(conf, filename)
]], conf.commit.sha .. "::[[" .. filename .. "]]"
end
+local SSH_KEYS_MARKER_START = "### Gitano Keys ###"
+local SSH_KEYS_MARKER_END = "### End Gitano Keys ###"
+
local function generate_ssh_config(conf)
- local ret = {"","### Gitano Keys ###"}
+ local ret = {SSH_KEYS_MARKER_START}
for u, t in pairs(conf.users) do
for ktag, keytab in pairs(t.keys) do
log.debug(i18n.expand("DEBUG_ADDING_SSH_KEY", {user=u, key=ktag}))
@@ -363,7 +366,7 @@ local function generate_ssh_config(conf)
format(lib_bin_path, repo_path, u, ktag, keytab.data))
end
end
- ret[#ret+1] = "### End Gitano Keys ###"
+ ret[#ret+1] = SSH_KEYS_MARKER_END
ret[#ret+1] = ""
return tconcat(ret, "\n")
end
@@ -381,6 +384,30 @@ local function update_ssh_keys(conf, ssh_path)
ssh_path = home .. "/.ssh/authorized_keys"
end
+ local prefix, suffix = "", ""
+ local rfh, err = sio.open(ssh_path, "r")
+ if rfh then
+ local accum = {}
+ local l = rfh:read("*l")
+ while l ~= nil do
+ if l == SSH_KEYS_MARKER_START then
+ accum[#accum+1] = ""
+ prefix = tconcat(accum, "\n")
+ accum = {}
+ elseif l == SSH_KEYS_MARKER_END then
+ accum = {}
+ else
+ accum[#accum+1] = l
+ end
+ l = rfh:read("*l")
+ end
+ if prefix ~= "" then
+ accum[#accum+1] = ""
+ suffix = tconcat(accum, "\n")
+ end
+ rfh:close()
+ end
+
local create_path = ssh_path .. ".new"
local cfh, err = sio.open(create_path, "cew")
@@ -389,7 +416,9 @@ local function update_ssh_keys(conf, ssh_path)
log.fatal(i18n.expand("ERROR_UNABLE_TO_CREATE", {path=create_path}))
end
+ cfh:write(prefix)
cfh:write(ssh_config)
+ cfh:write(suffix)
cfh:close()
local ret, errno = luxio.rename(create_path, ssh_path)