aboutsummaryrefslogtreecommitdiffstats
path: root/testing/aaudit/aaudit-repo-create
blob: 7b3ce912208315c94358b966e5b67c06d1c4a945 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/lua5.2

local posix = require 'posix'
local aaudit = require 'aaudit'

local function usage()
	print("usage: aaudit-repo-create [-a ADDRESS] -d DESCRIPTION [-i COMMIT_IDENTITY] [-m COMMIT_MESSAGE] [-g GROUPS]")
	os.exit(1)
end

local C = { initial=true }
local groups = {}
local address, description

for ret, optval in posix.getopt(arg, 'a:d:g:i:m:') do
	if ret == 'a' then
		address = optval
	elseif ret == 'd' then
		description = optval
	elseif ret == 'g' then
		groups['"'..optval..'"'] = true
	elseif ret == 'i' then
		C.identity = optval
	elseif ret == 'm' then
		C.message = optval
	else
		usage()
	end
end

if not address or not description then usage() end

-- For now default to use address as the repository name
local repo, repohome = address, aaudit.repohome(address)

-- Create repository + write config
os.execute(([[
mkdir -p %s; cd %s
git init --quiet --bare
]]):format(repohome, repohome))

aaudit.write_file(("%s/aaudit.conf"):format(repohome), ([[
address = "%s";
description = "%s";
groups = { %s };
]]):format(address, description, table.concat(groups, ', ')))

aaudit.write_file(("%s/description"):format(repohome), ("%s (%s)"):format(description, address))

-- Initial import of configuration
aaudit.import_commit(repohome, C)