From 51198e1ca2146da5083f470945d4b0215624ded9 Mon Sep 17 00:00:00 2001 From: DTB Date: Tue, 12 Sep 2023 21:57:25 -0400 Subject: [PATCH] pschdir(1) --- Makefile | 20 ++++++++++++++++++++ pschdir/Makefile | 2 ++ pschdir/pschdir.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 pschdir/Makefile create mode 100644 pschdir/pschdir.c diff --git a/Makefile b/Makefile index d2dfc03..7d192f3 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,10 @@ dist/grammy.tmp/weather.com.png: dist/grammy.tmp dist/ifpublic: cp ifpublic/ifpublic dist/ +dist/pschdir: + $(MAKE) -C pschdir + cp pschdir/pschdir dist/pschdir + dist/spacer.bin: # creates an 8GB empty file # that way when the alarm bells go off you can delete it to save a @@ -97,6 +101,14 @@ $(PREFIX)/bin/bspwm: git clone https://github.com/baskerville/bspwm.git $(PREFIX)/src/bspwm $(MAKE) -C $(PREFIX)/src/bspwm install +# Installs the Python script without documentation because I'm lazy and don't +# wanna run the upstream Makefile and then deal with filtering out the Python +# stuff (which is specific to 3.6 which is a little outdated). +# depends on apk:git apk:python +$(PREFIX)/bin/git-filter-repo: + git clone https://github.com/newren/git-filter-repo.git $(PREFIX)/src/git-filter-repo + $(INSTALL) -Dm0755 $(PREFIX)/src/git-filter-repo/git-filter-repo $(PREFIX)/bin/git-filter-repo + # nmap 7.80 is the last Free nmap release # depends on apk:linux-headers # had to # ln -s /bin/gmake /usr/local/bin/make @@ -134,6 +146,14 @@ $(PREFIX)/bin/scrot: sh -c 'cd $(PREFIX)/src/scrot && ./autogen.sh && ./configure MAKE=$(MAKE) PREFIX=$(PREFIX)' $(MAKE) -C $(PREFIX)/src/scrot install +# depends on +# apk:sudo +$(PREFIX)/src/wiringpi: + git clone https://github.com/WiringPi/WiringPi.git $(PREFIX)/src/wiringpi + git -C $(PREFIX)/src/wiringpi checkout final_official_2.50 + sed -i .tmp -e /^sudo/d $(PREFIX)/src/wiringpi/build + sh -c 'cd $(PREFIX)/src/wiringpi; sudo=sudo ./build' + $(PREFIX)/bin/xdo: git clone https://github.com/baskerville/xdo.git $(PREFIX)/src/xdo $(MAKE) -C $(PREFIX)/src/xdo install diff --git a/pschdir/Makefile b/pschdir/Makefile new file mode 100644 index 0000000..97ed279 --- /dev/null +++ b/pschdir/Makefile @@ -0,0 +1,2 @@ +pschdir: pschdir.c + $(CC) $(CFLAGS) -o pschdir pschdir.c diff --git a/pschdir/pschdir.c b/pschdir/pschdir.c new file mode 100644 index 0000000..8f5f196 --- /dev/null +++ b/pschdir/pschdir.c @@ -0,0 +1,41 @@ +#include /* EACCESS, ELOOP, ENAMETOOLONG, ENOENT, ENOTDIR, errno */ +#include /* fprintf(3) */ +#include /* stderr */ +#include /* EX_OSERR, EX_NOPERM, EX_NOINPUT, EX_UNAVAILABLE, + * EX_USAGE */ +#include /* chdir(2) */ + +static char *program_name = "pschdir"; + +int main(int argc, char *argv[]){ + + if(argc < 3){ + fprintf(stderr, + "Usage: %s [directory] [command (argument...)]\n", + argv[0] == NULL ? program_name : argv[0]); + return EX_USAGE; + } + + if(chdir(argv[1]) != 0){ + fprintf(stderr, "%s: %s: ", argv[0], argv[1]); + switch(errno){ + case EACCES: + fprintf(stderr, "Access to directory denied.\n"); + return EX_NOPERM; + case ELOOP: + fprintf(stderr, "Symbolic link loop.\n"); + return EX_UNAVAILABLE; + case ENAMETOOLONG: + fprintf(stderr, "Name too long.\n"); + return EX_OSERR; + case ENOENT: + fprintf(stderr, "Not found.\n"); + return EX_NOINPUT; + case ENOTDIR: + fprintf(stderr, "Not a directory.\n"); + return EX_NOINPUT; + } + } + + execvp(argv[2], argv + 2); +}