summaryrefslogtreecommitdiff
path: root/bins/trove-early-setup
blob: 82aec11cbff294c3f0052eb4897f94a1471c63d4 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/make -f
# -*- Make -*-

all: substitutions-done gitano-configured lorry-configured cache-configured mason-configured nfs-configured

USERS := git lorry cache mason

.PHONY: substitutions-done
substitutions-done: /etc/trove-setup.sed hostname-not-baserock
	sed -f /etc/trove-setup.sed -i \
               /usr/share/gitano/skel/gitano-admin/*/*.lace \
               /usr/share/gitano/skel/gitano-admin/*/*.lua \
               /usr/share/gitano/skel/gitano-admin/users/*/user.conf \
	       /etc/cgitrc /etc/gitano-setup.clod /etc/lorry.conf

/etc/trove-setup.sed:
	@echo "You need to create $@ to continue."
	@echo "There is $@.example which you can work from."
	@echo "re-run trove-early-setup once you're done with this."
	@exit 1

.PHONY: hostname-not-baserock
hostname-not-baserock:
	test "x$$(hostname)" != "baserock"

# $1 == username to make
define make_user_rules

/home/$1/.created:
	adduser -g "Trove $1 service" -s /bin/bash -D $1
	su -c 'mkdir .ssh; chmod 750 .ssh' - $1
	su -c 'ssh-keygen -t rsa -N "" -q -f .ssh/id_rsa' - $1
	(cat /etc/ssh/ssh_host_*_key.pub | cut -d\  -f1,2 | \
	 sed -e's/^/'$(shell hostname)',localhost /' > \
	 /home/$1/.ssh/known_hosts)
	chown $1:$1 /home/$1/.ssh/known_hosts
	chmod 600 /home/$1/.ssh/known_hosts
	touch $$@

ALL_USER_TARGETS := $$(ALL_USER_TARGETS) /home/$1/.created

endef

$(eval $(foreach USER,$(USERS),$(call make_user_rules,$(USER))))

/home/git/.git-setup: $(ALL_USER_TARGETS)
	su -c 'git config --global user.name "Trove Git Controller"' - git
	su -c 'git config --global user.email "git@trove"' - git
	touch $@

/home/git/.gitano-setup: /home/git/.git-setup
	su -c 'gitano-setup /etc/gitano-setup.clod' - git
	passwd -u git
	touch $@

/home/git/.gitano-lorry-setup: /home/git/.gitano-setup
	cp /home/lorry/.ssh/id_rsa.pub /tmp/lorry.pub
	su -c 'ssh git@localhost as lorry sshkey add trove < /tmp/lorry.pub' - git
	rm /tmp/lorry.pub
	touch $@

.PHONY: gitano-configured
gitano-configured: /home/git/.gitano-setup

/home/lorry/.lorry-setup: $(ALL_USER_TARGETS)
	su -c 'mkdir /home/lorry/bundles /home/lorry/tarballs' - lorry
	touch $@

/home/lorry/.lorry-controller-setup: /home/lorry/.lorry-setup /home/git/.gitano-lorry-setup
	PREFIX=$$(echo "##PREFIX##" | sed -f /etc/trove-setup.sed); \
	su -c "ssh localhost create $${PREFIX}/local-config/lorries" - git; \
	su -c "git clone ssh://localhost/$${PREFIX}/local-config/lorries.git /tmp/lorries" - git; \
	su -c "mkdir /home/lorry/lorry-controller-area" - lorry; \
	su -c "git clone ssh://git@localhost/$${PREFIX}/local-config/lorries.git /home/lorry/lorry-controller-area/git" - lorry
	su -c "sed -f /etc/trove-setup.sed < /usr/share/trove-setup/lorry-controller.conf > /tmp/lorries/lorry-controller.conf" - git
	su -c "sed -f /etc/trove-setup.sed < /usr/share/trove-setup/README.lorry-controller > /tmp/lorries/README" - git
	su -c "cd /tmp/lorries; git add README lorry-controller.conf; git commit -m 'Initial configuration'; git push origin master" - git
	su -c "rm -rf /tmp/lorries" - git
	su -c "cd /home/lorry/lorry-controller-area/git; git remote update; git checkout master" - lorry
	su -c "echo '*/1 * * * * flock -x -n /home/lorry/lorry-controller-area/lockfile -c lorry-controller --work-area=/home/lorry/lorry-controller-area --log=syslog --log-level=info --html-file=/home/lorry/lc-status.html' | crontab -" - lorry
	touch $@

.PHONY: lorry-configured
lorry-configured: /home/lorry/.lorry-setup /home/lorry/.lorry-controller-setup

/home/cache/.cache-setup: $(ALL_USER_TARGETS)
	su -c 'mkdir /home/cache/artifacts' - cache
	su -c 'mkdir /home/cache/ccache' - cache
	echo '/home/cache/ccache *(rw,all_squash,no_subtree_check,anonuid=1002,anongid=1002)' > /etc/exports.cache
	touch $@

.PHONY: cache-configured
cache-configured: /home/cache/.cache-setup

/home/git/.mason-setup: /home/git/.gitano-setup $(ALL_USER_TARGETS)
	PREFIX=$$(echo "##PREFIX##" | sed -f /etc/trove-setup.sed); \
	su -c "ssh localhost create $${PREFIX}/local-config/mason" - git; \
	su -c "git clone ssh://localhost/$${PREFIX}/local-config/mason.git /tmp/mason-config" - git
	su -c "cd /tmp/mason-config; mkdir ci1; (echo '[';echo ']') > ci1/systems.json.txt" - git
	su -c "cd /tmp/mason-config; (echo '['; echo ']') > ci1/hosts.json.txt" - git
	su -c "cd /tmp/mason-config; git add ci1; git commit -m 'Set initial Mason config'; git push origin master" - git
	su -c "rm -fr /tmp/mason-config" - git
	su -c 'mkdir /home/mason/jobs' - mason
	echo '/home/mason/jobs *(rw,all_squash,no_subtree_check,anonuid=1003,anongid=1003)' > /etc/exports.mason
	touch $@

.PHONY: mason-configured
mason-configured: /home/git/.mason-setup

/etc/exports: /home/cache/.cache-setup /home/git/.mason-setup
	cat /etc/exports.cache /etc/exports.mason >/etc/exports

.PHONY: nfs-configured
nfs-configured: /etc/exports