Skip to content

Commit

Permalink
posix (#6)
Browse files Browse the repository at this point in the history
Merge pull request 'sysusers: get rid of an unneccesary id line' (#5) from Dudemanguy/opensysusers:posix into posix

sysusers: get rid of an unneccesary id line

This line is actually bad and will cause the creation of some users to
fail. The reason is simply because id -g arg can't take an argument of a
group that does not have a user. So it will fail here for many conf
files. This line doesn't really appear to have any particular purpose
either since add_user will check if ${id} is equal to "-" and handle
that logic for us. Just get rid of it altogether.

Merge pull request 'sysusers: process final line if it fails on read' (#4) from Dudemanguy/opensysusers:posix into posix

sysusers: process final line if it fails on read

If the last line lacks an EOL/newline, read will return false thus
exiting the loop. However, the line will be a non-zero string. So just
add an extra check for this case and parse the string.

Merge pull request 'remove separate {,open}sysusers command and common.sh' (#2) from Dudemanguy/opensysusers:posix into posix

remove separate {,open}sysusers command and common.sh

remove all arguments if command is invoked as opensysusers to force
the simple non-systemd-sysusers implementation codepath
reorganize to deduplicate lots of code
replace the one remaining use of get_conf_files and get_conf_paths with
a much shorter inlined equivalent, remove those functions

make POSIX sh compatible
    remove array usage
    remove local builtin usage
    remove herestring usage
    remove string indexing usage

use shellcheck directive to specify source file locations

use manual shell option processing instead of getopt

use : to delimit file names in list instead of space like PATH

check command results directly instead of checking $?

make sed usage POSIX compatible and more concise

use case to check variables against multiple strings instead of a series
of ifs

replace incorrect usages of continue with return where appropriate

remove unused library functions

replace getent usage with more portable methods of checking for
groups/users

Signed-off-by: Ethan Sommer <e5ten.arch at gmail.com>
Signed-off-by: artoo <artoo@artixlinux.org>

Co-authored-by: Dudemanguy <dudemanguy@artixlinux.org>
Co-authored-by: Ethan Sommer <e5ten@artixlinux.org>
  • Loading branch information
3 people committed Jul 17, 2020
1 parent 6de96f4 commit a59433f
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 373 deletions.
60 changes: 21 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
VERSION = 0.5
SYSCONFDIR = /etc
PREFIX ?= /usr/local
BINDIR = $(PREFIX)/bin
Expand All @@ -15,22 +14,19 @@ HAVESYSTEMD = yes
HAVEOPENRC = no
HAVEMAN = yes

LIBS = lib/common.sh
INITD = openrc/opensysusers.initd
INITD = opensysusers.initd

BASIC = sysusers.d/basic.conf
BASIC = basic.conf

ifeq ($(HAVESYSTEMD),yes)
BINPROGS = bin/sysusers
BINNAME = sysusers
else
BINPROGS = bin/opensysusers
BINNAME = opensysusers
endif

TESTFILES = $(wildcard test/*.conf)

all: $(BINPROGS)
all: sysusers
ifeq ($(HAVEOPENRC),yes)
all: $(INITD)
endif
Expand All @@ -39,25 +35,19 @@ all:
+$(MAKE) INSTALL=$(INSTALL) DOCMODE=$(MODE) MANDIR=$(MANDIR) DOCDIR=$(DOCDIR) DESTDIR=$(DESTDIR) -C man
endif


EDIT = sed -e "s|@LIBDIR[@]|$(LIBDIR)|" \
-e "s|@BINNAME[@]|$(BINNAME)|g" \
-e "s|@VERSION[@]|$(VERSION)|"
EDIT = sed "s|@BINNAME[@]|$(BINNAME)|"

RM = rm -f
M4 = m4 -P
CHMODAW = chmod a-w
CHMODX = chmod +x
CHMOD = chmod $(BINMODE)

opensysusers: sysusers
$(INSTALL) $< $@

%: %.in Makefile
$(INITD): $(INITD).in
@echo "GEN $@"
@$(RM) "$@"
@$(M4) $@.in | $(EDIT) >$@
@$(CHMODAW) "$@"
@$(CHMODX) "$@"

clean-bin:
$(RM) $(BINPROGS)
@$(EDIT) $< >"$@"
@$(CHMOD) "$@"

clean-openrc:
$(RM) $(INITD)
Expand All @@ -74,36 +64,28 @@ clean: clean-man
endif

install-shared:
$(INSTALL) -d $(DESTDIR)$(LIBDIR)/opensysusers
$(INSTALL) -m $(BINMODE) $(LIBS) $(DESTDIR)$(LIBDIR)/opensysusers
$(INSTALL) -d $(DESTDIR)$(LIBDIR)/sysusers.d
$(INSTALL) -m $(BINMODE) $(BASIC) $(DESTDIR)$(LIBDIR)/sysusers.d
$(INSTALL) -Dm $(MODE) $(BASIC) $(DESTDIR)$(LIBDIR)/sysusers.d/$(BASIC)

install-default-bin:
$(INSTALL) -d $(DESTDIR)$(BINDIR)
$(INSTALL) -m $(BINMODE) $(BINPROGS) $(DESTDIR)$(BINDIR)
install-default-bin: sysusers
$(INSTALL) -Dm $(BINMODE) sysusers $(DESTDIR)$(BINDIR)/$(BINNAME)

install-custom-bin:
$(INSTALL) -m $(BINMODE) $(BINPROGS) $(DESTDIR)$(BINDIR)/$(BINNAME)
install-custom-bin: sysusers
$(INSTALL) -Dm $(BINMODE) sysusers $(DESTDIR)$(BINDIR)/$(BINNAME)

install-openrc:
$(INSTALL) -d $(DESTDIR)$(SYSCONFDIR)/init.d
$(INSTALL) -m $(BINMODE) $(INITD) $(DESTDIR)$(SYSCONFDIR)/init.d/opensysusers
install-openrc: $(INITD)
$(INSTALL) -Dm $(BINMODE) $(INITD) $(DESTDIR)$(SYSCONFDIR)/init.d/opensysusers

install-man:
+$(MAKE) INSTALL=$(INSTALL) DOCMODE=$(MODE) MANDIR=$(MANDIR) DOCDIR=$(DOCDIR) DESTDIR=$(DESTDIR) -C man install

install-tests:
$(INSTALL) -d $(DESTDIR)$(TESTDIR)
$(INSTALL) -m $(MODE) $(TESTFILES) $(DESTDIR)$(TESTDIR)
$(INSTALL) -Dm $(MODE) $(TESTFILES) $(DESTDIR)$(TESTDIR)/

uninstall-shared:
for lib in $(notdir ${LIBS}); do $(RM) $(DESTDIR)$(LIBDIR)/opensysusers/$$lib; done
$(RM)r --one-file-system $(DESTDIR)$(LIBDIR)/opensysusers
for f in $(notdir ${LIBS}); do $(RM) $(DESTDIR)$(LIBDIR)/sysusers.d/$$f; done
$(RM) $(DESTDIR)$(LIBDIR)/sysusers.d/$(BASIC)

uninstall-default-bin:
$(RM) $(DESTDIR)$(BINDIR)/$(notdir $(BINPROGS))
$(RM) $(DESTDIR)$(BINDIR)/$(BINNAME)

uninstall-custom-bin:
$(RM) $(DESTDIR)$(BINDIR)/$(BINNAME)
Expand Down
File renamed without changes.
18 changes: 0 additions & 18 deletions bin/opensysusers.in

This file was deleted.

124 changes: 0 additions & 124 deletions bin/sysusers.in

This file was deleted.

Loading

0 comments on commit a59433f

Please sign in to comment.