586eb018578e68a2aa5b59b2347c0ca14a3db992
[debian/amanda] / config / automake / installperms.am
1 # vim:ft=automake
2 #
3 # Adjust post-install permissions settings.  This rule works off two
4 # specially-formatted variables, INSTALLPERMS_exec and INSTALLPERMS_data. 
5 # Each is a whitespace-separated list of commands, all of which are either
6 # a variable assignment or a filename.  Three variables are available:
7 #
8 #  - dest= sets the destination directory to e.g., $(sbindir)
9 #  - chown= controls changes in ownership; value is first argument to chown
10 #  - chmod= controls changes in permissions; value is first argument to chmod
11 #
12 # As a special case, chown=amanda is taken as equivalent to 
13 # chown=$(BINARY_OWNER):$(SETUID_GROUP), which may otherwise have problems with
14 # whitespace in the user/group names.
15
16 # when a filename is seen, the currently active variables are applied.
17 #
18 # Note that scripts are data, not executables!
19 #
20 # EXAMPLE
21 #
22 # sbin_PROGRAMS = foo bar bing
23 # libexec_PROGRAMS = pro gram
24 # sbin_SCRIPTS = sk ript
25 # INSTALLPERMS_exec = \
26 #       dest=$(sbindir) chown=amanda chmod= \
27 #               foo bar \
28 #       chmod=07450 \
29 #               bing
30 #       dest=$(libexecdir) chmod= \
31 #               $(libexec_PROGRAMS)
32 # INSTALLPERMS_data = \
33 #       dest=$(sbindir) chown=amanda chmod= \
34 #               $(sbin_SCRIPTS)
35 #
36 # This whole operation is not required when making builds for packaging,
37 # and can be disabled with --disable-installperms, via the WANT_INSTALLPERMS
38 # AM_CONDITIONAL.  When disabled, the file 'installperms.sh' in the top-level
39 # build directory is populated with a format suitable for shell interpretation,
40 # with lines like this:
41 #   installperm "amanda:disk" "04750" "/usr/local/sbin/bing"
42 # the arguments being, respectively, owner:group, mode, and filename.  There will
43 # be exactly one line for each file which has specific permissions.  The intention
44 # is that this file be used by packaging scripts to set correct permissions at install
45 # time.  Note that files which have no special permissions requirements do not appear 
46 # in this file at all, due to limitations of Automake.
47
48 # sed expression to strip leading directories from a filename; this converts e.g.,
49 # src/foo/bar.so to bar.so.
50 strip_leading_dirs=s|^.*/||
51
52 # define a snippet of the scripts below to either perform a chown/chmod operation,
53 # or record that operation in the logfile.  On entry to the snippet, $$dest is the
54 # destination directory, $$cmd is the srcdir-relative pathname of the target file,
55 # $$chown is the ownership, and $$chmod is the permission pattern.
56 if WANT_INSTALLPERMS
57 do_file=pa="$(DESTDIR)$$dest"/`echo "$$cmd"|sed '$(strip_leading_dirs)'|sed '$(transform)'`; \
58     if test -n "$$chown"; then \
59         echo chown "$$chown" "$$pa"; \
60         chown "$$chown" "$$pa" || exit 1; \
61     fi; \
62     if test -n "$$chmod"; then \
63         echo chmod "$$chmod" "$$pa"; \
64         chmod "$$chmod" "$$pa" || exit 1; \
65     fi 
66 else
67 installperms_sh="$(top_builddir)/installperms.sh"
68 do_file=pa="$$dest"/`echo "$$cmd"|sed '$(strip_leading_dirs)'|sed '$(transform)'`; \
69     echo "installperm \"$$chown\" \"$$chmod\" \"$$pa\"" >> "$(installperms_sh)"
70 DISTCLEANFILES += $(installperms_sh)
71 endif
72
73 installperms-exec:
74         @installperms="$(INSTALLPERMS_exec)"; \
75         test -n "$$installperms" && echo "Setting installation permissions on executables"; \
76         dest=; chown=; chmod=; \
77         for cmd in $$installperms; do \
78             case "$$cmd" in \
79                 chown=amanda) \
80                         echo "  ($$cmd)"; chown="$(BINARY_OWNER):$(SETUID_GROUP)";; \
81                 dest=*|chown=*|chmod=*) \
82                         echo "  ($$cmd)"; eval $$cmd;; \
83                 *) $(do_file) ;; \
84             esac; \
85         done
86
87 installperms-data:
88         @installperms="$(INSTALLPERMS_data)"; \
89         dest=; chown=; chmod=; \
90         for cmd in $$installperms; do \
91             case "$$cmd" in \
92                 chown=amanda) \
93                         echo "  ($$cmd)"; chown="$(BINARY_OWNER):$(SETUID_GROUP)";; \
94                 dest=*|chown=*|chmod=*) \
95                         echo "  ($$cmd)"; eval $$cmd;; \
96                 *)  $(do_file) ;; \
97             esac; \
98         done
99
100 install-exec-hook: installperms-exec
101 install-data-hook: installperms-data
102
103 # define a rule to initialize the installperms manifest file
104 if WANT_INSTALLPERMS
105 installperms-init:
106 else
107 installperms-init:
108         rm -f "$(installperms_sh)"
109 endif