GNUmakefile.in 4.36 KB
Newer Older
Timothy Stack's avatar
   
Timothy Stack committed
1
2
#
# EMULAB-COPYRIGHT
3
# Copyright (c) 2005, 2006 University of Utah and the Flux Group.
Timothy Stack's avatar
   
Timothy Stack committed
4
5
6
7
8
9
10
11
12
13
# All rights reserved.
#
# This is the Emulab specific makefile.
#

SRCDIR          = @srcdir@
TESTBED_SRCDIR  = @top_srcdir@
OBJDIR          = ../..
SUBDIR          = sensors/nfstrace

Timothy Stack's avatar
   
Timothy Stack committed
14
15
NFSTRACESUPPORT = @NFSTRACESUPPORT@

Timothy Stack's avatar
   
Timothy Stack committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
include $(OBJDIR)/Makeconf

all: nfstrace.proxy nfsdump2db nfsdump nfstrace.init

include $(TESTBED_SRCDIR)/GNUmakerules

#
# Install to the ops directory.
#
PREFIX=$(INSTALL_DIR)/opsdir
INSTALL_ETC=$(PREFIX)/etc
INSTALL_INITD=$(PREFIX)/etc/rc.d
INSTALL_SBIN=$(PREFIX)/sbin
INSTALL_MAN=$(PREFIX)/man

PW=/usr/sbin/pw
Timothy Stack's avatar
   
Timothy Stack committed
32
33
NFSTRACE_HOME=/var/nfstrace
NFSTRACE_DBDIR=/var/db/nfstrace
Timothy Stack's avatar
   
Timothy Stack committed
34
35
36
37

$(SRCDIR)/nfsdump2/config.status:
	cd $(SRCDIR)/nfsdump2 && ./configure

38
39
make.nfsdump:
	cd $(SRCDIR)/nfsdump2/ && ./config.status
Timothy Stack's avatar
   
Timothy Stack committed
40
41
	cd $(SRCDIR)/nfsdump2 && $(MAKE)

42
clean.nfsdump: $(SRCDIR)/nfsdump2/config.status
43
44
45
	cd $(SRCDIR)/nfsdump2/ && ./config.status
	cd $(SRCDIR)/nfsdump2 && $(MAKE) clean

Timothy Stack's avatar
   
Timothy Stack committed
46
47
48
49
50
$(SRCDIR)/nfsdump2/nfsdump: $(SRCDIR)/nfsdump2/config.status make.nfsdump

nfsdump: $(SRCDIR)/nfsdump2/nfsdump
	cp $(SRCDIR)/nfsdump2/nfsdump .

Timothy Stack's avatar
   
Timothy Stack committed
51
client client-install control-install:
Timothy Stack's avatar
   
Timothy Stack committed
52

Timothy Stack's avatar
   
Timothy Stack committed
53
54
55
56
$(NFSTRACE_HOME):
	sudo mkdir -m 0750 $(NFSTRACE_HOME)

add-nfstrace-user: $(NFSTRACE_HOME)
Timothy Stack's avatar
   
Timothy Stack committed
57
	@if ! id nfstrace > /dev/null 2>&1; then \
Timothy Stack's avatar
   
Timothy Stack committed
58
		sudo $(PW) useradd nfstrace -d $(NFSTRACE_HOME) \
Timothy Stack's avatar
   
Timothy Stack committed
59
60
61
			-s /sbin/nologin -u 50,200 \
			-c "NFS Tracing Daemon"; \
	fi
Timothy Stack's avatar
   
Timothy Stack committed
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
	@if ! id -Gn mysql | grep nfstrace > /dev/null 2>&1; then \
		sudo $(PW) usermod -n mysql -G "`id -Gn mysql` nfstrace"; \
	fi
	sudo chown nfstrace $(NFSTRACE_HOME)
	sudo chgrp wheel $(NFSTRACE_HOME)
	sudo chgrp nfstrace /dev/bpf0
	sudo chmod g+r /dev/bpf0

$(NFSTRACE_DBDIR):
	sudo mkdir -m 0750 -p $@
	sudo chown nfstrace $@
	sudo chgrp nfstrace $@

$(NFSTRACE_HOME)/dbpass:
	head -c 32 /dev/urandom | md5 -q | head -c 8 > $@
	sudo chown nfstrace $@
	sudo chgrp wheel $@
	sudo chmod o-r $@
	@if test ! -s $@; then \
		echo "error: generated empty password..."; \
		rm $@; \
		exit 1; \
Timothy Stack's avatar
   
Timothy Stack committed
84
	fi
Timothy Stack's avatar
   
Timothy Stack committed
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

$(NFSTRACE_HOME)/.my.cnf: $(NFSTRACE_HOME)/dbpass
	echo "[client]" > $@
	echo "user=nfstrace" >> $@
	echo "password=`cat $(NFSTRACE_HOME)/dbpass`" >> $@
	echo "[mysqldump]" >> $@
	echo "user=nfstrace" >> $@
	echo "password=`cat $(NFSTRACE_HOME)/dbpass`" >> $@
	sudo chown nfstrace $@
	sudo chgrp wheel $@
	sudo chmod o-r $@

# XXX Needs to be updated to properly create the DB and user.
create-db: $(NFSTRACE_HOME)/.my.cnf $(NFSTRACE_DBDIR)
	@if ! id mysql > /dev/null 2>&1; then \
		:; \
	elif sudo -u nfstrace -H mysqldump -d nfsdb > nfsdb-dump.sql; then \
		perl $(TESTBED_SRCDIR)/utils/schemadiff nfsdb-dump.sql \
			$(SRCDIR)/nfsdb-create.sql > nfsdb.diff; \
		if test -s nfsdb.diff; then \
			echo "error: nfsdb is out of sync"; \
			cat nfsdb.diff; \
			exit 1; \
		fi \
	else \
		echo "create database nfsdb" | sudo -u root mysql; \
		sudo -u nfstrace -H mysql nfsdb < $(SRCDIR)/nfsdb-create.sql; \
Timothy Stack's avatar
   
Timothy Stack committed
112
	fi
Timothy Stack's avatar
   
Timothy Stack committed
113
114
115
116
117
118

ifeq ($(NFSTRACESUPPORT),1)
fs-install: all add-nfstrace-user create-db
	-mkdir -p $(INSTALL_DIR)/sbin
	-mkdir -p $(INSTALL_DIR)/etc
	-mkdir -p $(INSTALL_DIR)/etc/rc.d
Timothy Stack's avatar
   
Timothy Stack committed
119
120
121
122
	$(INSTALL) -m 0755 nfsdump $(DESTDIR)$(INSTALL_SBINDIR)
	$(INSTALL) -m 0755 $(SRCDIR)/nfsdump2db $(DESTDIR)$(INSTALL_SBINDIR)
	$(INSTALL) -m 0755 $(SRCDIR)/nfstrace.proxy $(DESTDIR)$(INSTALL_SBINDIR)
	$(INSTALL) -m 0755 nfstrace.init $(INSTALL_DIR)/etc/rc.d/nfstrace
Timothy Stack's avatar
   
Timothy Stack committed
123
124
125
126
127
128
129
130
	-mkdir -p $(INSTALL_DIR)/man/man8
	$(INSTALL) -m 0644 $(SRCDIR)/nfstrace.proxy.8 \
		$(INSTALL_DIR)/man/man8/nfstrace.proxy.8
	$(INSTALL) -m 0644 $(SRCDIR)/nfsdump2db.8 \
		$(INSTALL_DIR)/man/man8/nfsdump2db.8
	-mkdir -p $(INSTALL_DIR)/man/man7
	$(INSTALL) -m 0644 $(SRCDIR)/nfstrace.7 \
		$(INSTALL_DIR)/man/man7/nfstrace.7
Timothy Stack's avatar
   
Timothy Stack committed
131
132
133
134
135

install: all
	$(INSTALL) -m 0755 nfsdump $(DESTDIR)$(INSTALL_SBIN)
	$(INSTALL) -m 0755 $(SRCDIR)/nfsdump2db $(DESTDIR)$(INSTALL_SBIN)
	$(INSTALL) -m 0755 $(SRCDIR)/nfstrace.proxy $(DESTDIR)$(INSTALL_SBIN)
136
	-mkdir -p $(DESTDIR)$(INSTALL_ETC)/rc.d
Timothy Stack's avatar
   
Timothy Stack committed
137
	$(INSTALL) -m 0755 nfstrace.init $(DESTDIR)$(INSTALL_ETC)/rc.d/nfstrace
Timothy Stack's avatar
   
Timothy Stack committed
138
139
140
141
142
143
144
145
146
147
148
	-mkdir -p $(INSTALL_DIR)/opsdir/man/man8
	$(INSTALL) -m 0644 $(SRCDIR)/nfstrace.proxy.8 \
		$(INSTALL_DIR)/opsdir/man/man8/nfstrace.proxy.8
	$(INSTALL) -m 0644 $(SRCDIR)/nfsdump2db.8 \
		$(INSTALL_DIR)/opsdir/man/man8/nfsdump2db.8
	-mkdir -p $(INSTALL_DIR)/opsdir/man/man7
	$(INSTALL) -m 0644 $(SRCDIR)/nfstrace.7 \
		$(INSTALL_DIR)/opsdir/man/man7/nfstrace.7
else
fs-install install:
endif
Leigh B. Stoller's avatar
Leigh B. Stoller committed
149

150
clean:	clean.nfsdump
151
	rm -f *.o core nfsdump nfstrace.init