blob: 74eda61abaded5ee323d529a30d6c9f024db2bf1 (
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
52
53
54
|
#!/usr/bin/env bash
playbook_add() {
notice "$BASHTARD_PLAYBOOK" "Installing packages"
pkg install git
notice "$BASHTARD_PLAYBOOK" "Creating user 'git'"
useradd \
--home-dir "$(config "git.repodir")" \
--create-home \
--shell "$(config "fs.bindir")/git-shell" \
"$(config "git.user")"
playbook_sync
}
playbook_sync() {
notice "$BASHTARD_PLAYBOOK" "Setting up authorized_keys"
mkdir -pv -- "$(config "git.repodir")/.ssh"
cat "$BASHTARD_ETCDIR/playbooks.d/$BASHTARD_PLAYBOOK/share/pubkeys.d/"* > "$(config "git.repodir")/.ssh/authorized_keys"
chown -Rv "$(config "git.user"):$(config "git.user")" "$(config "git.repodir")/.ssh"
chmod -v 700 "$(config "git.repodir")/.ssh"
chmod -v 644 "$(config "git.repodir")/.ssh/authorized_keys"
notice "$BASHTARD_PLAYBOOK" "Configure git"
file_template "gitconfig" \
> "$(config "git.repodir")/.gitconfig"
notice "$BASHTARD_PLAYBOOK" "Ensuring all desired repositories exist"
while read -r repo
do
local name="$(config "git.repos.$repo.name" "$repo")"
local path="$(config "git.repodir")/$(config "git.repos.$repo.path" "$name").git"
info "$BASHTARD_PLAYBOOK" "Ensuring $name exists ($repo)"
if [[ ! -d "$path" ]]
then
notice "$BASHTARD_PLAYBOOK" "Creating bare repository at $path"
sudo -u git mkdir -pv -- "$path"
sudo -u git git -C "$path" --bare init
fi
printf "$(config "git.repos.$repo.description" "Nondescript")\n" > "$path/description"
done < <(config_subkeys "git.repos")
}
playbook_del() {
notice "$BASHTARD_PLAYBOOK" "Cleaning up repodir"
rm -frv --one-file-system -- "$(config "git.repodir")"
userdel "$(config "git.user")"
}
|