Kill shell script wrappers

nixos has trouble with the shell script wrappers - readlink isn't
available by default!

But, there's a better approach: just get rid of them and use symlinks
instead, and have main() check what we're supposed to be.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2023-09-22 14:06:55 -04:00
parent f76c449ec0
commit 731926b5e5
6 changed files with 26 additions and 23 deletions

View File

@ -1,6 +1,7 @@
PREFIX?=/usr/local
PKG_CONFIG?=pkg-config
INSTALL=install
LN=ln
ifeq ("$(origin V)", "command line")
BUILD_VERBOSE = $(V)
@ -152,15 +153,15 @@ install: INITRAMFS_HOOK=$(INITRAMFS_DIR)/hooks/bcachefs
install: INITRAMFS_SCRIPT=$(INITRAMFS_DIR)/scripts/local-premount/bcachefs
install: bcachefs
$(INSTALL) -m0755 -D bcachefs -t $(DESTDIR)$(ROOT_SBINDIR)
$(INSTALL) -m0755 fsck.bcachefs $(DESTDIR)$(ROOT_SBINDIR)
$(INSTALL) -m0755 mkfs.bcachefs $(DESTDIR)$(ROOT_SBINDIR)
$(INSTALL) -m0755 mount.bcachefs $(DESTDIR)$(ROOT_SBINDIR)
$(INSTALL) -m0755 fsck.bcachefs $(DESTDIR)$(ROOT_SBINDIR)/fsck.fuse.bcachefs
$(INSTALL) -m0755 mkfs.bcachefs $(DESTDIR)$(ROOT_SBINDIR)/mkfs.fuse.bcachefs
$(INSTALL) -m0755 mount.fuse.bcachefs $(DESTDIR)$(ROOT_SBINDIR)
$(INSTALL) -m0644 -D bcachefs.8 -t $(DESTDIR)$(PREFIX)/share/man/man8/
$(INSTALL) -m0755 -D initramfs/script $(DESTDIR)$(INITRAMFS_SCRIPT)
$(INSTALL) -m0755 -D initramfs/hook $(DESTDIR)$(INITRAMFS_HOOK)
$(LN) -sr $(DESTDIR)$(ROOT_SBINDIR)/bcachefs $(DESTDIR)$(ROOT_SBINDIR)/mkfs.bcachefs
$(LN) -sr $(DESTDIR)$(ROOT_SBINDIR)/bcachefs $(DESTDIR)$(ROOT_SBINDIR)/fsck.bcachefs
$(LN) -sr $(DESTDIR)$(ROOT_SBINDIR)/bcachefs $(DESTDIR)$(ROOT_SBINDIR)/mount.bcachefs
$(LN) -sr $(DESTDIR)$(ROOT_SBINDIR)/bcachefs $(DESTDIR)$(ROOT_SBINDIR)/mkfs.fuse.bcachefs
$(LN) -sr $(DESTDIR)$(ROOT_SBINDIR)/bcachefs $(DESTDIR)$(ROOT_SBINDIR)/fsck.fuse.bcachefs
$(LN) -sr $(DESTDIR)$(ROOT_SBINDIR)/bcachefs $(DESTDIR)$(ROOT_SBINDIR)/mount.fuse.bcachefs
sed -i '/^# Note: make install replaces/,$$d' $(DESTDIR)$(INITRAMFS_HOOK)
echo "copy_exec $(ROOT_SBINDIR)/bcachefs /sbin/bcachefs" >> $(DESTDIR)$(INITRAMFS_HOOK)

View File

@ -188,6 +188,24 @@ int main(int argc, char *argv[])
full_cmd = argv[0];
/* Are we being called via a symlink? */
if (strstr(full_cmd, "mkfs"))
return cmd_format(argc, argv);
if (strstr(full_cmd, "fsck"))
return cmd_fsck(argc, argv);
#ifdef BCACHEFS_FUSE
if (strstr(full_cmd, "mount.fuse"))
return cmd_fusemount(argc, argv);
#endif
#ifndef BCACHEFS_NO_RUST
if (strstr(full_cmd, "mount"))
return cmd_mount(argc, argv);
#endif
setvbuf(stdout, NULL, _IOLBF, 0);
char *cmd = pop_cmd(&argc, argv);
@ -253,9 +271,8 @@ int main(int argc, char *argv[])
if (!strcmp(cmd, "setattr"))
return cmd_setattr(argc, argv);
#ifndef BCACHEFS_NO_RUST
if (!strcmp(cmd, "mount")) {
if (!strcmp(cmd, "mount"))
return cmd_mount(argc, argv);
}
#endif
#ifdef BCACHEFS_FUSE

View File

@ -1,4 +0,0 @@
#!/bin/sh
SDIR="$(readlink -f "$0")"
exec "${SDIR%/*}/bcachefs" fsck "$@"

View File

@ -1,4 +0,0 @@
#!/bin/sh
SDIR="$(readlink -f "$0")"
exec "${SDIR%/*}/bcachefs" format "$@"

View File

@ -1,4 +0,0 @@
#!/bin/sh
SDIR="$(readlink -f "$0")"
exec "${SDIR%/*}/bcachefs" mount "$@"

View File

@ -1,3 +0,0 @@
#!/bin/sh
exec bcachefs fusemount "$@"