aboutsummaryrefslogtreecommitdiff
path: root/ops/cynerd_account
blob: 941ff6671520a24f5d781bbcddc8edc6b5cb3258 (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
55
56
57
58
59
60
61
62
63
64
65
# vim:ft=sh:noexpandtab
# My personal account

# Configuration options:
#   CYNERD_ACCOUNT_GROUPS - Additional groups to default cynerd,wheel
#   CYNERD_ACCOUNT_SSH_KEY - ssh public key to be added as authorized_keys
#   CYNERD_ACCOUNT_CONFIGS - myconfigs branch (currently accepting only server)

. tools/grusr
. tools/package
. tools/git

CYNERD_ACCOUNT_ARGS=""
CYNERD_ACCOUNT_MYCNF_GIT=""

cynerd_account_check() {
	package_check zsh || CYNERD_ACCOUNT_NEED="zsh"
	user_check $CYNERD_ACCOUNT_ARGS || CYNERD_ACCOUNT_NEED="$CYNERD_ACCOUNT_NEED user"
	# TODO check that we have correct ssh key
	package_check rsync || CYNERD_ACCOUNT_NEED="$CYNERD_ACCOUNT_NEED rsync"
	git_check $CYNERD_ACCOUNT_MYCNF_GIT || CYNERD_ACCOUNT_NEED="$CYNERD_ACCOUNT_NEED myconfigs"
	if [ -n "$CYNERD_ACCOUNT_NEED" ]; then
		echo_info "Cynerd account requires update of these components: $CYNERD_ACCOUNT_NEED"
		return 1
	fi
}

cynerd_account_prepare() {
	for N in $CYNERD_ACCOUNT_NEED; do
		case "$N" in
			zsh|rsync)
				package_prepare "$N" || return 1
				;;
			user)
				user_prepare $CYNERD_ACCOUNT_ARGS || return 1
				;;
			myconfigs)
				git_prepare $CYNERD_ACCOUNT_MYCNF_GIT || return 1
				;;
		esac
	done
}

cynerd_account_apply() {
	for N in $CYNERD_ACCOUNT_NEED; do
		case "$N" in
			zsh|rsync)
				package_apply "$N" || return 1
				;;
			user)
				user_apply $CYNERD_ACCOUNT_ARGS || return 1
				;;
			myconfigs)
				git_apply $CYNERD_ACCOUNT_MYCNF_GIT || return 1
				;;
		esac
	done
}

cynerd_account_clean() {
	local FAIL=0
	package_clean zsh rsync || FAIL=1
	git_clean $CYNERD_ACCOUNT_MYCNF_GIT || FAIL=1
	return $FAIL
}