sbase-box: Add -i flag

This commit is contained in:
Roberto E. Vargas Caballero 2023-09-26 20:27:08 +02:00
parent 58ec1f6285
commit 986bbb9253
2 changed files with 39 additions and 6 deletions

View File

@ -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

View File

@ -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]);
}