Skip to content
Snippets Groups Projects
Forked from alpine / aports
198964 commits behind the upstream repository.
aaudit-repo-create 1.23 KiB
#!/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)