summaryrefslogtreecommitdiff
path: root/playbook.bash
blob: 69c0ef0ba4ad528b44510996eed4869a0c56c95f (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
#!/usr/bin/env bash

BASHTARD_PLAYBOOK_VARS[$BASHTARD_PLAYBOOK.branch]=""
BASHTARD_PLAYBOOK_VARS[$BASHTARD_PLAYBOOK.generator]="required"
BASHTARD_PLAYBOOK_VARS[$BASHTARD_PLAYBOOK.path]=""
BASHTARD_PLAYBOOK_VARS[$BASHTARD_PLAYBOOK.remote]=""
BASHTARD_PLAYBOOK_VARS[$BASHTARD_PLAYBOOK.repository]="required"

playbook_add() {
	local path
	local remote
	local repo

	path="$(config "$BASHTARD_PLAYBOOK.path" "/var/www/$BASHTARD_PLAYBOOK")"
	remote="$(config "$BASHTARD_PLAYBOOK.remote" "origin")"
	repo="$(config "$BASHTARD_PLAYBOOK.repository")"

	mkdir -p -- "$path"
	git -C "$path" init
	git -C "$path" remote add "$remote" "$repo"

	playbook_sync
}

playbook_sync() {
	local branch
	local generator
	local path
	local remote

	branch="$(config "$BASHTARD_PLAYBOOK.branch" "master")"
	generator="$(config "$BASHTARD_PLAYBOOK.generator")"
	path="$(config "$BASHTARD_PLAYBOOK.path" "/var/www/$BASHTARD_PLAYBOOK")"
	remote="$(config "$BASHTARD_PLAYBOOK.remote" "origin")"

	git -C "$path" fetch "$remote" "$branch"
	git -C "$path" reset --hard "$remote/$branch"

	chgdir "$path"

	case "$generator" in
		hugo)
			hugo -D # This will generate all the draft content
			hugo    # And this will generate the actual live blog, but won't remove the draft content
			;;
		*)
			crit "$BASHTARD_PLAYBOOK/sync" "Unsupported generator '$generator'"
	esac
}

playbook_del() {
	rm -fr -- "$(config "$BASHTARD_PLAYBOOK.path" "/var/www/$BASHTARD_PLAYBOOK")"
}