sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

commit 986bbb9253526d29e056ca57ce1ed87fbf65f920
parent 58ec1f628525b538cf52bf8f1bda1068dd0929f2
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 26 Sep 2023 20:27:08 +0200

sbase-box: Add -i flag

Diffstat:
MMakefile | 9+++------
Mscripts/mkbox | 36++++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile @@ -237,14 +237,11 @@ sbase-box: $(BIN) sbase-box-install: sbase-box mkdir -p $(DESTDIR)$(PREFIX)/bin + mkdir -p $(DESTDIR)$(MANPREFIX)/man1 cp -f sbase-box $(DESTDIR)$(PREFIX)/bin chmod 755 $(DESTDIR)$(PREFIX)/bin/sbase-box - for f in $(BIN); do ln -sf sbase-box $(DESTDIR)$(PREFIX)/bin/"$$f"; done - ln -sf sbase-box $(DESTDIR)$(PREFIX)/bin/[ - mv -f $(DESTDIR)$(PREFIX)/bin/xinstall $(DESTDIR)$(PREFIX)/bin/install - mkdir -p $(DESTDIR)$(MANPREFIX)/man1 - for m in $(MAN); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done - cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN) + $(DESTDIR)$(PREFIX)/bin/sbase-box -i $(DESTDIR)$(PREFIX)/bin/ + cp -f $(MAN) $(DESTDIR)$(MANPREFIX)/man1/ mv -f $(DESTDIR)$(MANPREFIX)/man1/xinstall.1 $(DESTDIR)$(MANPREFIX)/man1/install.1 sbase-box-uninstall: uninstall diff --git a/scripts/mkbox b/scripts/mkbox @@ -8,7 +8,10 @@ mkdir -p build cp *.h build cat > build/sbase-box.c <<EOF +#include <unistd.h> + #include <libgen.h> +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -38,6 +41,35 @@ done) {NULL}, }; +static void +install(char *path) +{ + int r; + struct cmd *bp; + char fname[FILENAME_MAX]; + + if (path == NULL) { + fputs("sbase-box [-i path] [command]\n", stderr); + exit(1); + } + + for (bp = cmds; bp->name; ++bp) { + r = snprintf(fname, sizeof(fname), "%s/%s", path, bp->name); + if (r < 0 || r >= sizeof(fname)) { + fprintf(stderr, + "sbase-box: destination path truncated for '%s'\n", + bp->name); + exit(1); + } + if (symlink("sbase-box", fname) < 0) { + fprintf(stderr, + "sbase-box: %s: %s\n", + bp->name, strerror(errno)); + exit(1); + } + } +} + int main(int argc, char *argv[]) { @@ -46,6 +78,10 @@ main(int argc, char *argv[]) if(!strcmp(s,"sbase-box")) { argc--; argv++; + if (strcmp(argv[0], "-i") == 0) { + install(argv[1]); + exit(0); + } s = basename(argv[0]); }