Skip to content
This repository was archived by the owner on Aug 13, 2022. It is now read-only.

Commit fd95fce

Browse files
udevedcromerc
authored andcommitted
M4 patch (#10)
* use m4 to sed make params * fix install and uninstall conditions * add ifneq BINNAME * remove single quotes fron BINNAME * fix BINNAME condition * rm destdir from libdir sed * sed version via makefile * Nakefile: fix uninstall * MAKEFILE: add HAVEMAN * rename systemd-sysusers -> sysusers * Makefile: fix BINNAME condition * Makefile: check if PREFIX is defined * lib: skip comment lines when parsing the conf file (#11) * lib: skip comment lines when parsing the conf file * fix missing phony targets change rc to openrc change defaults
1 parent c5011b0 commit fd95fce

6 files changed

Lines changed: 155 additions & 48 deletions

File tree

Makefile

Lines changed: 136 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,151 @@
1-
LIBS = common.sh
2-
CONFFILES = test/*
1+
VERSION = 0.4.6
2+
SYSCONFDIR = /etc
3+
ifdef PREFIX
34
PREFIX = /usr/local
4-
BINDIR = /bin
5-
LIBDIR = /lib
6-
MANDIR = /share/man
7-
DOCDIR = /share/doc/opensysusers
8-
CONFDIR = /run/sysusers.d
5+
endif
6+
BINDIR = $(PREFIX)/bin
7+
LIBDIR = $(PREFIX)/lib
8+
MANDIR = $(PREFIX)/share/man
9+
DOCDIR = $(PREFIX)/share/doc/opensysusers
10+
TESTDIR = /run/sysusers.d
911
BINMODE = 0755
10-
CONFMODE = 0644
11-
DOCMODE = 0644
12+
MODE = 0644
1213
INSTALL = install
1314
MAKE = make
14-
SYSTEMDCOMPAT = TRUE
15-
ifeq ($(SYSTEMDCOMPAT),TRUE)
16-
BINPROGS = systemd-sysusers
15+
16+
HAVESYSTEMD = yes
17+
HAVEOPENRC = no
18+
HAVEMAN = yes
19+
20+
LIBS = lib/common.sh
21+
INITD = openrc/opensysusers.initd
22+
23+
ifeq ($(HAVESYSTEMD),yes)
24+
BINPROGS = bin/sysusers
25+
BINNAME = sysusers
1726
else
18-
BINPROGS = opensysusers
27+
BINPROGS = bin/opensysusers
28+
BINNAME = opensysusers
1929
endif
2030
BINNAME = $(BINPROGS)
2131

32+
TESTFILES = $(wildcard test/*.conf)
33+
34+
all: $(BINPROGS)
35+
ifeq ($(HAVEOPENRC),yes)
36+
all: $(INITD)
37+
endif
38+
ifeq ($(HAVEMAN),yes)
2239
all:
23-
+$(MAKE) INSTALL=$(INSTALL) DOCMODE=$(DOCMODE) MANDIR=$(MANDIR) DOCDIR=$(DOCDIR) PREFIX=$(PREFIX) DESTDIR=$(DESTDIR) -C man
24-
sed -e "s|@BINFILE@|$(BINNAME)|" openrc/opensysusers.initd.in | tee openrc/opensysusers.initd 1> /dev/null
40+
+$(MAKE) INSTALL=$(INSTALL) DOCMODE=$(MODE) MANDIR=$(MANDIR) DOCDIR=$(DOCDIR) DESTDIR=$(DESTDIR) -C man
41+
endif
42+
43+
44+
EDIT = sed -e "s|@LIBDIR[@]|$(LIBDIR)|" \
45+
-e "s|@BINNAME[@]|$(BINNAME)|g" \
46+
-e "s|@VERSION[@]|$(VERSION)|"
47+
48+
RM = rm -f
49+
M4 = m4 -P
50+
CHMODAW = chmod a-w
51+
CHMODX = chmod +x
52+
53+
%: %.in Makefile
54+
@echo "GEN $@"
55+
@$(RM) "$@"
56+
@$(M4) $@.in | $(EDIT) >$@
57+
@$(CHMODAW) "$@"
58+
@$(CHMODX) "$@"
59+
60+
clean-bin:
61+
$(RM) $(BINPROGS)
62+
63+
clean-openrc:
64+
$(RM) $(INITD)
65+
66+
clean-man:
67+
+$(MAKE) INSTALL=$(INSTALL) DOCMODE=$(MODE) MANDIR=$(MANDIR) DOCDIR=$(DOCDIR) DESTDIR=$(DESTDIR) -C man clean
68+
69+
clean: clean-bin
70+
ifeq ($(HAVEOPENRC),yes)
71+
clean: clean-openrc
72+
endif
73+
ifeq ($(HAVEMAN),yes)
74+
clean: clean-man
75+
endif
76+
77+
install-shared:
78+
$(INSTALL) -d $(DESTDIR)$(BINDIR)
79+
$(INSTALL) -d $(DESTDIR)$(LIBDIR)/opensysusers
80+
$(INSTALL) -m $(BINMODE) $(LIBS) $(DESTDIR)$(LIBDIR)/opensysusers
2581

26-
clean:
27-
+$(MAKE) INSTALL=$(INSTALL) DOCMODE=$(DOCMODE) MANDIR=$(MANDIR) DOCDIR=$(DOCDIR) PREFIX=$(PREFIX) DESTDIR=$(DESTDIR) -C man clean
82+
install-default-bin:
83+
$(INSTALL) -m $(BINMODE) $(BINPROGS) $(DESTDIR)$(BINDIR)
2884

29-
install:
30-
$(INSTALL) -d $(DESTDIR)$(PREFIX)$(BINDIR)
31-
$(INSTALL) -m $(BINMODE) $(BINPROGS) $(DESTDIR)$(PREFIX)$(BINDIR)/$(BINNAME)
32-
$(INSTALL) -d $(DESTDIR)$(PREFIX)$(LIBDIR)/opensysusers
33-
$(INSTALL) -m $(BINMODE) $(LIBS) $(DESTDIR)$(PREFIX)$(LIBDIR)/opensysusers
34-
sed -e "s|@LIBDIR@|$(PREFIX)$(LIBDIR)|" -i $(DESTDIR)$(PREFIX)$(BINDIR)/$(BINNAME)
35-
+$(MAKE) INSTALL=$(INSTALL) DOCMODE=$(DOCMODE) MANDIR=$(MANDIR) DOCDIR=$(DOCDIR) PREFIX=$(PREFIX) DESTDIR=$(DESTDIR) -C man install
85+
install-custom-bin:
86+
$(INSTALL) -m $(BINMODE) $(BINPROGS) $(DESTDIR)$(BINDIR)/$(BINNAME)
87+
88+
install-openrc:
89+
$(INSTALL) -d $(DESTDIR)$(SYSCONFDIR)/{init.d,runlevels/boot}
90+
$(INSTALL) -m $(BINMODE) $(INITD) $(DESTDIR)$(SYSCONFDIR)/init.d/opensysusers
91+
ln -sf $(DESTDIR)$(SYSCONFDIR)/init.d/opensysusers $(DESTDIR)$(SYSCONFDIR)/runlevels/boot/
92+
93+
install-man:
94+
+$(MAKE) INSTALL=$(INSTALL) DOCMODE=$(MODE) MANDIR=$(MANDIR) DOCDIR=$(DOCDIR) DESTDIR=$(DESTDIR) -C man install
3695

3796
install-tests:
38-
$(INSTALL) -d $(DESTDIR)$(PREFIX)$(CONFDIR)
39-
$(INSTALL) -m $(CONFMODE) $(CONFFILES) $(DESTDIR)$(PREFIX)$(CONFDIR)
97+
$(INSTALL) -d $(DESTDIR)$(TESTDIR)
98+
$(INSTALL) -m $(MODE) $(TESTFILES) $(DESTDIR)$(TESTDIR)
99+
100+
uninstall-shared:
101+
for lib in $(notdir ${LIBS}); do $(RM) $(DESTDIR)$(LIBDIR)/opensysusers/$$lib; done
102+
$(RM)r --one-file-system $(DESTDIR)$(LIBDIR)/opensysusers
103+
104+
uninstall-default-bin:
105+
$(RM) $(DESTDIR)$(BINDIR)/$(notdir $(BINPROGS))
106+
107+
uninstall-custom-bin:
108+
$(RM) $(DESTDIR)$(BINDIR)/$(BINNAME)
109+
110+
uninstall-openrc:
111+
$(RM) $(DESTDIR)$(SYSCONFDIR)/init.d/opensysusers
112+
$(RM) $(DESTDIR)$(SYSCONFDIR)/runlevels/boot/opensysusers
113+
114+
uninstall-man:
115+
+$(MAKE) INSTALL=$(INSTALL) DOCMODE=$(MODE) MANDIR=$(MANDIR) DOCDIR=$(DOCDIR) DESTDIR=$(DESTDIR) -C man uninstall
116+
117+
ifeq ($(HAVESYSTEMD),yes)
118+
install: install-shared
119+
uninstall: uninstall-shared
120+
ifeq ($(HAVEMAN),yes)
121+
install: install-man
122+
uninstall: uninstall-man
123+
endif
124+
ifeq ($(BINNAME),sysusers)
125+
install: install-default-bin
126+
uninstall: uninstall-default-bin
127+
else
128+
install: install-custom-bin
129+
uninstall: uninstall-custom-bin
130+
endif
40131

41-
uninstall:
42-
for prog in ${BINPROGS}; do rm -f $(DESTDIR)$(PREFIX)$(BINDIR)/$$prog; done
43-
for lib in ${LIBS}; do rm -f $(DESTDIR)$(PREFIX)$(LIBDIR)/opensysusers/$$lib; done
44-
rm -rf --one-file-system $(DESTDIR)$(PREFIX)$(LIBDIR)/opensysusers
45-
+$(MAKE) INSTALL=$(INSTALL) DOCMODE=$(DOCMODE) MANDIR=$(MANDIR) DOCDIR=$(DOCDIR) PREFIX=$(PREFIX) DESTDIR=$(DESTDIR) -C man uninstall
46-
rm -f $(DESTDIR)$(PREFIX)$(BINDIR)/$(BINNAME)
132+
ifeq ($(HAVEOPENRC),yes)
133+
install: install-openrc
134+
uninstall: uninstall-openrc
135+
endif
136+
137+
else
138+
install: install-shared install-default-bin
139+
uninstall: uninstall-shared uninstall-default-bin
140+
ifeq ($(HAVEMAN),yes)
141+
install: install-man
142+
uninstall: uninstall-man
143+
endif
144+
ifeq ($(HAVEOPENRC),yes)
145+
install: install-openrc
146+
uninstall: uninstall-openrc
147+
endif
148+
149+
endif
47150

48-
.PHONY: all install install-tests uninstal
151+
.PHONY: all install install-custom-bin install-default-bin install-man install-openrc install-shared install-tests uninstall uninstall-custom-bin uninstall-default-bin uninstall-man uninstall-openrc uninstall-shared clean clean-bin clean-man clean-openrc

opensysusers renamed to bin/opensysusers.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#
55
# This is an implementation of sysusers.d spec without systemd command
66

7+
sysusersver=@VERSION@
8+
79
source @LIBDIR@/opensysusers/common.sh
810

911
get_conf_files

systemd-sysusers renamed to bin/sysusers.in

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
#
55
# This is an implementation of the systemd-sysusers command
66

7+
sysusersver=@VERSION@
8+
79
usage() {
8-
printf "systemd-sysusers\n\n"
10+
printf "@BINNAME@\n\n"
911

10-
printf "systemd-sysusers creates system users and groups, based on the file\n"
12+
printf "@BINNAME@ creates system users and groups, based on the file\n"
1113
printf "format and location specified in sysusers.d(5).\n\n"
1214

13-
printf "Usage: /usr/bin/systemd-sysusers [OPTIONS...] [CONFIGFILE...]\n\n"
15+
printf "Usage: /usr/bin/@BINNAME@ [OPTIONS...] [CONFIGFILE...]\n\n"
1416

1517
printf "Options:\n"
1618
printf " --root=root All paths will be prefixed with the\n"
@@ -24,7 +26,7 @@ usage() {
2426
printf " --version Print a short version string and exit.\n"
2527
}
2628

27-
TEMP=$(getopt -o "h" -l "root:,replace:,inline,help,version" -n "systemd-sysusers" -- "$@")
29+
TEMP=$(getopt -o "h" -l "root:,replace:,inline,help,version" -n "@BINNAME@" -- "$@")
2830
if [ $? -ne 0 ]; then
2931
usage
3032
exit 1;

common.sh renamed to lib/common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ parse_file() {
8888
local file="${1}"
8989
if [ -f ${file} ]; then
9090
while read cline; do
91+
[[ "${cline}" =~ ^#.*$ ]] && continue
9192
parse_string "${cline}"
9293
done < ${file}
9394
fi
@@ -188,4 +189,3 @@ sysusers_d=''
188189
replace=''
189190

190191
sysusers_dirs="${root}/usr/lib/sysusers.d ${root}/run/sysusers.d ${root}/etc/sysusers.d"
191-
sysusersver='0.4.5'

man/Makefile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ clean:
2323
rm $(docfiles)
2424

2525
install:
26-
$(INSTALL) -d $(DESTDIR)$(PREFIX)$(MANDIR)/man{5,8}
27-
$(INSTALL) -m $(DOCMODE) $(manfiles5) $(DESTDIR)$(PREFIX)$(MANDIR)/man5
28-
$(INSTALL) -m $(DOCMODE) $(manfiles8) $(DESTDIR)$(PREFIX)$(MANDIR)/man8
29-
$(INSTALL) -d $(DESTDIR)$(PREFIX)$(DOCDIR)
30-
$(INSTALL) -m $(DOCMODE) $(docfiles) $(DESTDIR)$(PREFIX)$(DOCDIR)
26+
$(INSTALL) -d $(DESTDIR)$(MANDIR)/man{5,8}
27+
$(INSTALL) -m $(DOCMODE) $(manfiles5) $(DESTDIR)$(MANDIR)/man5
28+
$(INSTALL) -m $(DOCMODE) $(manfiles8) $(DESTDIR)$(MANDIR)/man8
29+
$(INSTALL) -d $(DESTDIR)$(DOCDIR)
30+
$(INSTALL) -m $(DOCMODE) $(docfiles) $(DESTDIR)$(DOCDIR)
3131

3232
uninstall:
33-
for man in ${manfiles5}; do rm -f $(DESTDIR)$(PREFIX)$(MANDIR)/man5/$$man; done
34-
for man in ${manfiles8}; do rm -f $(DESTDIR)$(PREFIX)$(MANDIR)/man8/$$man; done
35-
for doc in ${docfiles}; do rm -f $(DESTDIR)$(PREFIX)$(DOCDIR)/$$doc; done
36-
rm -rf --one-file-system $(DESTDIR)$(PREFIX)$(DOCDIR)
33+
for man in ${manfiles5}; do rm -f $(DESTDIR)$(MANDIR)/man5/$$man; done
34+
for man in ${manfiles8}; do rm -f $(DESTDIR)$(MANDIR)/man8/$$man; done
35+
for doc in ${docfiles}; do rm -f $(DESTDIR)$(DOCDIR)/$$doc; done
36+
rm -rf --one-file-system $(DESTDIR)$(DOCDIR)
3737

3838
.PHONY: all install clean

openrc/opensysusers.initd.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ depend()
1212
start()
1313
{
1414
ebegin "Setting up sysusers.d entries"
15-
@BINFILE@
15+
@BINNAME@
1616
eend $?
1717
}

0 commit comments

Comments
 (0)