commit 4a007ee83d32d91a69a7705b2afe3c2914e4faa0 parent 2a955252e3104b568306d72b7f0b957df1c02106 Author: Jacob R. Edwards <jacobouno@protonmail.com> Date: Tue, 31 Aug 2021 19:26:46 -0700 Add installation program I think if I'm using an uncommon program in the Makefile it should be included along with it. The module program is similar to cast except it doesn't support path substitution. As such some module's immidiate sub-directories were renamed to be placed into XDG directories (some of which were changed) with the exception of bin, which is placed in the home directory. Diffstat:
59 files changed, 241 insertions(+), 20 deletions(-)
diff --git a/global/Makefile b/global/Makefile @@ -1,4 +1,6 @@ -CFLAGS = +LIB = ../lib +ACTION = force copy +TARGET = / MODULES =\ doas\ rc\ @@ -6,10 +8,4 @@ MODULES =\ wsconsctl\ xenodm\ -all: install - -install: - chown root:wheel `cast ${CFLAGS} -cf ${MODULES} /` - -uninstall: - rm -v `cast ${CFLAGS} -v ${MODULES} /` +.include "../lib/module.make" diff --git a/global/xenodm/etc/X11/xenodm/Xsession b/global/xenodm/etc/X11/xenodm/Xsession diff --git a/lib/Makefile b/lib/Makefile @@ -0,0 +1,22 @@ +cc = cc +cflags = -Wall -Wno-write-strings +ldflags = -static +src = module.c +name = module + +all: ${name} + +.c.o: + ${cc} ${cflags} -c -o $@ $< + +${obj}: mkfile ${hdr} + +${name}: ${name}.c + ${cc} ${cflags} -o ${name} ${name}.c ${ldflags} + + +clean: + rm -f ${name} ${obj} + +.SUFFIXES: .c .o +.PHONY: clean install uninstall diff --git a/lib/module.c b/lib/module.c @@ -0,0 +1,194 @@ +#include <sys/stat.h> + +#define SHIFT(N) { argc -= N; argv += N; } + +#ifdef PROGCOPY +#include <sys/wait.h> +#else +#include <fcntl.h> +#endif + +#include <errno.h> +#include <fts.h> +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +static int argtoo; /* Install given directories too, not just their contents. */ +static int force; /* Install even if the target exists. */ +static int (*action)(char *, char *); /* Install function (link, copy, or none). */ + +void +die(char *s) +{ + perror(s); + exit(1); +} + +/* + * I'm on the debating as to which one to use, keeping both for now. + */ +#ifdef PROGCOPY +int +copy(char *a, char *b) +{ + int status; + pid_t pid; + + pid = fork(); + if (pid == 0) { + execv("/bin/cp", (char *[]){ "cp", "-p", a, b, NULL }); + perror("/bin/cp"); + _exit(1); + } + + if (pid < 0 || waitpid(pid, &status, 0) < 0) + return 1; + return WEXITSTATUS(status); +} +#else +int +copy(char *a, char *b) +{ + char buf[4096]; + int af, bf; + int len; + struct stat as; + + af = open(a, O_RDONLY); + if (af < 0) + return 1; + + if (fstat(af, &as)) { + close(af); + return 1; + } + + bf = open(b, O_WRONLY | O_CREAT | O_EXCL, as.st_mode); + if (bf < 0) { + close(af); + return 1; + } + + /* Leave owner and group untouched for global module. */ + if (fchflags(bf, as.st_flags)) { + close(af); + close(bf); + return 1; + } + + while ((len = read(af, buf, sizeof(buf))) > 0 && write(bf, buf, len) == len) + ; + if (close(af) + close(bf) || len != 0) { + unlink(b); + return 1; + } + return 0; +} +#endif + +int +none(char *a, char *b) +{ + return 0; +} + +int +main(int argc, char *argv[]) +{ + FTS *fts; + FTSENT *ent; + char new[PATH_MAX]; + char prefix[PATH_MAX]; + int status; + size_t arglen; + struct stat st; + char *progname; + + progname = *argv; + if (argc < 4) { +usage: + fprintf(stderr, "usage: %s [force] action source ... target\n", progname); + return 1; + } + + SHIFT(1); + if (strcmp(*argv, "force") == 0) { + force = 1; + SHIFT(1); + } + + if (strcmp(argv[0], "copy") == 0) + action = copy; + else if (strcmp(argv[0], "link") == 0) + action = link; + else { + action = none; + if (strcmp(argv[0], "remove") == 0) + force = 1; + else if (strcmp(argv[0], "list") == 0) + force = 0; + else + goto usage; + } + SHIFT(1); + + if (realpath(argv[--argc], prefix) == NULL) + die(argv[argc]); + argv[argc] = NULL; + + fts = fts_open(argv, 0, NULL); + if (fts == NULL) + die("fts_open"); + + arglen = 0; + while ((ent = fts_read(fts))) { + if (!argtoo && ent->fts_level == 0 && ent->fts_info == FTS_D) + arglen = strlen(ent->fts_path); + if (snprintf(new, sizeof(new), "%s/%s", prefix, ent->fts_path + arglen) >= sizeof(new)) { + errno = ENAMETOOLONG; + die(ent->fts_path); + } + + if (stat(new, &st) < 0 && errno != ENOENT) + die(new); + + status = 0; + switch (ent->fts_info) { + case FTS_DNR: + case FTS_ERR: + case FTS_NS: + errno = ent->fts_errno; + die(ent->fts_path); + case FTS_DP: + break; + case FTS_D: + if (errno == ENOENT || !S_ISDIR(st.st_mode)) + status = mkdir(new, ent->fts_statp->st_mode); + break; + case FTS_F: + if (errno == ENOENT) { + status = action(ent->fts_accpath, new); + } else if (action == link && st.st_ino == ent->fts_statp->st_ino) { + ; + } else if (force) { + status = (unlink(new) || action(ent->fts_accpath, new)); + } else if (action != none) { + errno = EEXIST; + status = 1; + } + if (!status) + puts(new); + break; + default: + fprintf(stderr, "%s: Not a regular file.\n", ent->fts_path); + status = 1; + } + if (status) + die(new); + } + + return fts_close(fts) != 0; +} diff --git a/lib/module.make b/lib/module.make @@ -0,0 +1,13 @@ +all: install + +lib: + make -C ${LIB} + +install: lib + ${LIB}/module ${ACTION} ${MODULES} ${TARGET} + +uninstall: lib + ${LIB}/module remove ${MODULES} ${TARGET} + +.PHONY: all lib install uninstall + diff --git a/local/Makefile b/local/Makefile @@ -1,4 +1,6 @@ -CFLAGS = -s.config=local/config -s.local=local +LIB = ../lib +ACTION = link +TARGET = ${HOME} MODULES =\ bin\ git\ @@ -14,10 +16,4 @@ MODULES =\ xmodmap\ xresources\ -all: install - -install: - cast ${CFLAGS} -p ${MODULES} ${HOME} - -uninstall: - rm -v `cast ${CFLAGS} -v ${MODULES} ${HOME}` +.include "../lib/module.make" diff --git a/local/bin/.local/bin/9term b/local/bin/bin/9term diff --git a/local/bin/.local/bin/ac b/local/bin/bin/ac diff --git a/local/bin/.local/bin/acme b/local/bin/bin/acme diff --git a/local/bin/.local/bin/backup3 b/local/bin/bin/backup3 diff --git a/local/bin/.local/bin/bwrite b/local/bin/bin/bwrite diff --git a/local/bin/.local/bin/ccom b/local/bin/bin/ccom diff --git a/local/bin/.local/bin/cdec b/local/bin/bin/cdec diff --git a/local/bin/.local/bin/cdef b/local/bin/bin/cdef diff --git a/local/bin/.local/bin/clipswap b/local/bin/bin/clipswap diff --git a/local/bin/.local/bin/cnoname b/local/bin/bin/cnoname diff --git a/local/bin/.local/bin/dl b/local/bin/bin/dl diff --git a/local/bin/.local/bin/dp b/local/bin/bin/dp diff --git a/local/bin/.local/bin/fed b/local/bin/bin/fed diff --git a/local/bin/.local/bin/feed b/local/bin/bin/feed diff --git a/local/bin/.local/bin/fp b/local/bin/bin/fp diff --git a/local/bin/.local/bin/fsmenu b/local/bin/bin/fsmenu diff --git a/local/bin/.local/bin/gp b/local/bin/bin/gp diff --git a/local/bin/.local/bin/hd b/local/bin/bin/hd diff --git a/local/bin/.local/bin/human.awk b/local/bin/bin/human.awk diff --git a/local/bin/.local/bin/keysym b/local/bin/bin/keysym diff --git a/local/bin/.local/bin/mark b/local/bin/bin/mark diff --git a/local/bin/.local/bin/mem b/local/bin/bin/mem diff --git a/local/bin/.local/bin/now b/local/bin/bin/now diff --git a/local/bin/.local/bin/pkg_depend b/local/bin/bin/pkg_depend diff --git a/local/bin/.local/bin/pkg_list b/local/bin/bin/pkg_list diff --git a/local/bin/.local/bin/sargs b/local/bin/bin/sargs diff --git a/local/bin/.local/bin/setbg b/local/bin/bin/setbg diff --git a/local/bin/.local/bin/sfextract b/local/bin/bin/sfextract diff --git a/local/bin/.local/bin/sman b/local/bin/bin/sman diff --git a/local/bin/.local/bin/sman.sed b/local/bin/bin/sman.sed diff --git a/local/bin/.local/bin/src b/local/bin/bin/src diff --git a/local/bin/.local/bin/tat b/local/bin/bin/tat diff --git a/local/bin/.local/bin/tips b/local/bin/bin/tips diff --git a/local/bin/.local/bin/tspm b/local/bin/bin/tspm diff --git a/local/bin/.local/bin/upfeed b/local/bin/bin/upfeed diff --git a/local/bin/.local/bin/urls b/local/bin/bin/urls diff --git a/local/bin/.local/bin/wcp b/local/bin/bin/wcp diff --git a/local/bin/.local/bin/wid b/local/bin/bin/wid diff --git a/local/bin/.local/bin/wpaper b/local/bin/bin/wpaper diff --git a/local/bin/.local/bin/www b/local/bin/bin/www diff --git a/local/bin/.local/bin/xgrab b/local/bin/bin/xgrab diff --git a/local/bin/.local/bin/xurls b/local/bin/bin/xurls diff --git a/local/git/.config/git/config b/local/git/config/git/config diff --git a/local/git/.config/git/ignore b/local/git/config/git/ignore diff --git a/local/ksh/.profile b/local/ksh/.profile @@ -15,7 +15,7 @@ export VISUAL=$EDITOR # xdg export XDG_CACHE_HOME="$HOME/local/cache/" -export XDG_CONFIG_HOME="$HOME/local/config/" +export XDG_CONFIG_HOME="$HOME/config/" export XDG_DATA_HOME="$HOME/local/share/" # make(1) @@ -29,5 +29,5 @@ export LESS='-2MSWXiqrx~ -b80 -h15 -z23 -j5 -x8' export LESSHISTFILE=/dev/null export MANPATH=/usr/share/man:/usr/X11R6/man:/usr/local/man export PLAN9=/usr/local/plan9/ -export PATH="$HOME/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin:/usr/games:$PLAN9/bin:$PLAN9/bin/fs" +export PATH="$HOME/bin:$HOME/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin:/usr/games:$PLAN9/bin:$PLAN9/bin/fs" export font=$PLAN9/font/misc/unicode.6x13.font diff --git a/local/ksh/.config/kshrc b/local/ksh/config/kshrc diff --git a/local/rc/lib/profile b/local/rc/lib/profile @@ -5,7 +5,7 @@ PLAN9 = /usr/local/plan9/ font = $PLAN9/font/misc/unicode.6x13.font # rc -path = (. $home/local/bin /bin /sbin /usr/bin /usr/sbin /usr/local/bin\ +path = (. $home/bin $home/local/bin /bin /sbin /usr/bin /usr/sbin /usr/local/bin\ /usr/local/sbin /usr/X11R6/bin /usr/games $PLAN9/bin $PLAN9/bin/fs) prompt = ('; ' ' ') history = $home/lib/history-`{ date +%Y-%m } # Not in standard rc; costom patch. @@ -24,7 +24,7 @@ VISUAL = $EDITOR # XDG directories XDG_CACHE_HOME = $home/local/cache/ -XDG_CONFIG_HOME = $home/local/config/ +XDG_CONFIG_HOME = $home/config/ XDG_DATA_HOME = $home/local/share/ # make(1) diff --git a/local/sxiv/.config/sxiv/exec/key-handler b/local/sxiv/config/sxiv/exec/key-handler diff --git a/local/tmux/.config/tmux/tmux.conf b/local/tmux/config/tmux/tmux.conf diff --git a/local/urls/.config/urls b/local/urls/config/urls diff --git a/local/xenodm/.config/xsession b/local/xenodm/config/xsession diff --git a/local/xmodmap/.config/xmodmaprc b/local/xmodmap/config/xmodmaprc diff --git a/local/xresources/.config/Xresources b/local/xresources/config/Xresources