add mini programs (do not push to galaxy branch!)
This commit is contained in:
parent
e09790470e
commit
96dcbab49c
101
cosmo-mini/Dockerfile
Normal file
101
cosmo-mini/Dockerfile
Normal file
|
@ -0,0 +1,101 @@
|
|||
ARG CC=cosmocc CFLAGS="-fdiagnostics-color=always -Os -g -Wall -Wextra -Wwrite-strings -Wno-unused"
|
||||
FROM localhost/notwa-util AS downloader
|
||||
|
||||
# MAIN: https://nullprogram.com/blog/2019/03/22/
|
||||
# REPO: https://github.com/skeeto/endlessh
|
||||
ARG ENDLESSH_COMMIT=dfe44eb2c5b6fc3c48a39ed826fe0e4459cdf6ef
|
||||
ARG ENDLESSH_SHA256=c8989988af0a8c848d1a4979962f008c504a12ed6fe6a12e032c37feaa0ae5f8
|
||||
|
||||
# MAIN: n/a
|
||||
# REPO: https://github.com/leahneukirchen/lr
|
||||
ARG LR_COMMIT=5af9b79e4ecd07a600ded1a801023536cde97f95
|
||||
ARG LR_SHA256=3901287cdcf09d0d8f77f8aaa19ca24e9a873d904e201ab8e7bf102426607dcc
|
||||
|
||||
# MAIN: n/a
|
||||
# REPO: https://github.com/leahneukirchen/xe
|
||||
ARG XE_COMMIT=8a2a4899769335bc14c62aef12cdf26f2f487f2a
|
||||
ARG XE_SHA256=f1ac997912c9be92a74a67a766dde74d1f9b6b20e48d7c7e71598ad4b787b37d
|
||||
|
||||
# MAIN: http://selfie.cs.uni-salzburg.at/
|
||||
# REPO: https://github.com/cksystemsteaching/selfie
|
||||
ARG SELFIE_COMMIT=25ccf7313f8e28a1ed5cd0a8737c246e0f79539b
|
||||
ARG SELFIE_SHA256=58d2eead6cf7916d9024cb0499659fd012f88a54b36d4254f5d530f8bd0d07ba
|
||||
|
||||
# MAIN: n/a
|
||||
# REPO: https://github.com/atomicobject/heatshrink
|
||||
ARG HEATSHRINK_COMMIT=7d419e1fa4830d0b919b9b6a91fe2fb786cf3280
|
||||
ARG HEATSHRINK_SHA256=b18a1b7ad6f51eac7ac1a81ca072703bd21d6d8727c05cd505843643705af65d
|
||||
|
||||
RUN --mount=type=cache,id=common,target=/media/common,sharing=locked \
|
||||
--mount=type=tmpfs,target=/tmp : \
|
||||
&& acquire from=github repo=skeeto/endlessh dest=/endlessh env=ENDLESSH \
|
||||
&& acquire from=github repo=leahneukirchen/lr dest=/lr env=LR \
|
||||
&& acquire from=github repo=leahneukirchen/xe dest=/xe env=XE \
|
||||
&& acquire from=github repo=cksystemsteaching/selfie dest=/selfie env=SELFIE \
|
||||
&& acquire from=github repo=atomicobject/heatshrink dest=/heatshrink env=HEATSHRINK \
|
||||
;
|
||||
|
||||
FROM localhost/cosmo-base AS mini
|
||||
RUN tar zxf /cosmopolitan/dist/headers.tar.gz -C /cosmopolitan
|
||||
COPY --chmod=0755 --from=localhost/notwa-util /nu/ /usr/bin/
|
||||
WORKDIR /o
|
||||
|
||||
FROM mini AS mini_endlessh
|
||||
COPY --from=downloader /endlessh /o
|
||||
ARG CC CFLAGS
|
||||
RUN : \
|
||||
&& shed endlessh.c \
|
||||
's/\bINET6_ADDRSTRLEN\b/65/g' \
|
||||
'/\bswitch (errno) {/,/default:/s/\bcase \([A-Z]\+\):/} else if (errno == \1) {/g' \
|
||||
'/\bswitch (errno) {/,/default:/s/default\:/} else {/' \
|
||||
's/\bswitch (errno) {/if (0) {/' \
|
||||
'/ENDLESSH_VERSION/i\static const struct in6_addr in6addr_any = {0};' \
|
||||
's/int fd = accept(server, 0, 0);/struct sockaddr_in dummy1; unsigned int dummy2 = sizeof(dummy1); int fd = accept(server, (struct sockaddr *)\&dummy1, \&dummy2);/' \
|
||||
&& ofc endlessh.c \
|
||||
;
|
||||
|
||||
FROM mini AS mini_lr
|
||||
COPY --from=downloader /lr /o
|
||||
COPY lr.patch /o/
|
||||
ARG CC CFLAGS
|
||||
RUN : \
|
||||
&& /usr/bin/busybox patch -p1 -i lr.patch \
|
||||
&& shed lr.c \
|
||||
'/_GNU_SOURCE/a\\#include "libc/dce.h"' \
|
||||
's/\bnlink_t\b/uint32_t/g' \
|
||||
's/\bdefined(__/&sometimes_/g' \
|
||||
's/\b__linux__\b/__sometimes_linux__/g' \
|
||||
'/#warning fstype/d' \
|
||||
&& ofc lr.c \
|
||||
;
|
||||
|
||||
FROM mini AS mini_xe
|
||||
COPY --from=downloader /xe /o
|
||||
ARG CC CFLAGS
|
||||
RUN ofc xe.c
|
||||
|
||||
FROM mini AS mini_selfie
|
||||
COPY --from=downloader /selfie /o
|
||||
ARG CC CFLAGS
|
||||
RUN shed selfie.c '/\bPAGESIZE\b/i\\#undef PAGESIZE' && ofc selfie.c
|
||||
|
||||
FROM mini AS mini_heatshrink
|
||||
COPY --from=downloader /heatshrink /o
|
||||
ARG CC CFLAGS
|
||||
RUN : \
|
||||
&& shed heatshrink.c '/encoder\.h/a\\#include "heatshrink_encoder.c"' \
|
||||
&& shed heatshrink.c '/decoder\.h/a\\#include "heatshrink_decoder.c"' \
|
||||
&& shed heatshrink_encoder.c 's/\b\(output_info\|st_yield_literal\)\b/&_e/g' \
|
||||
&& shed heatshrink_decoder.c 's/\b\(output_info\|st_yield_literal\)\b/&_d/g' \
|
||||
&& CFLAGS="$CFLAGS -Wno-implicit-fallthrough" ofc heatshrink.c \
|
||||
;
|
||||
|
||||
FROM scratch AS runner
|
||||
COPY --chmod=0755 --from=localhost/cosmo /cosmopolitan/bin/ape /bin/ape
|
||||
COPY --chmod=0755 --from=localhost/notwa-util /nu/busybox /bin/
|
||||
COPY --chmod=0755 --from=mini_endlessh /o/*.com /o/*.com.dbg /bin/
|
||||
COPY --chmod=0755 --from=mini_heatshrink /o/*.com /o/*.com.dbg /bin/
|
||||
COPY --chmod=0755 --from=mini_lr /o/*.com /o/*.com.dbg /bin/
|
||||
COPY --chmod=0755 --from=mini_selfie /o/*.com /o/*.com.dbg /bin/
|
||||
COPY --chmod=0755 --from=mini_xe /o/*.com /o/*.com.dbg /bin/
|
||||
ENTRYPOINT ["/bin/busybox", "sh"]
|
64
cosmo-mini/lr.patch
Normal file
64
cosmo-mini/lr.patch
Normal file
|
@ -0,0 +1,64 @@
|
|||
--- lr/lr.c.old
|
||||
+++ lr/lr.c
|
||||
@@ -934,6 +910,25 @@
|
||||
}
|
||||
|
||||
static const char *
|
||||
+xextnam(const char *s)
|
||||
+{
|
||||
+ /* does not treat extensionless dotfiles as file extensions */
|
||||
+ char *r = strrchr(s, '/');
|
||||
+ char *e = strrchr(s, '.');
|
||||
+ if (!r || r + 1 < e)
|
||||
+ return e && e != s ? e + 1 : "";
|
||||
+ return "";
|
||||
+}
|
||||
+
|
||||
+static char
|
||||
+dotted(const char *s)
|
||||
+{
|
||||
+ char *r = strrchr(s, '/');
|
||||
+ char *e = strchr(r ? r : s, '.');
|
||||
+ return (r && r + 1 == e || s == e) ? '.' : '\0';
|
||||
+}
|
||||
+
|
||||
+static const char *
|
||||
readlin(const char *p, const char *alt)
|
||||
{
|
||||
static char b[PATH_MAX];
|
||||
@@ -1453,6 +1447,8 @@
|
||||
case 'I': CMP(fb->sb.st_ino, fa->sb.st_ino);
|
||||
case 'd': CMP(fa->depth, fb->depth);
|
||||
case 'D': CMP(fb->depth, fa->depth);
|
||||
+ case 'u': CMP(!dotted(fa->fpath), !dotted(fb->fpath));
|
||||
+ case 'U': CMP(!dotted(fb->fpath), !dotted(fa->fpath));
|
||||
case 't': CMP("ZZZZAZZZZZZZZZZZ"[(fa->sb.st_mode >> 12) & 0x0f],
|
||||
"ZZZZAZZZZZZZZZZZ"[(fb->sb.st_mode >> 12) & 0x0f]);
|
||||
case 'T': CMP("ZZZZAZZZZZZZZZZZ"[(fb->sb.st_mode >> 12) & 0x0f],
|
||||
@@ -1461,8 +1457,8 @@
|
||||
case 'N': STRCMP(fb->fpath, fa->fpath);
|
||||
case 'f': STRCMP(basenam(fa->fpath), basenam(fb->fpath));
|
||||
case 'F': STRCMP(basenam(fb->fpath), basenam(fa->fpath));
|
||||
- case 'e': STRCMP(extnam(fa->fpath), extnam(fb->fpath));
|
||||
- case 'E': STRCMP(extnam(fb->fpath), extnam(fa->fpath));
|
||||
+ case 'e': STRCMP(xextnam(fa->fpath), xextnam(fb->fpath));
|
||||
+ case 'E': STRCMP(xextnam(fb->fpath), xextnam(fa->fpath));
|
||||
case 'p': DIRCMP(fa->fpath, fb->fpath);
|
||||
case 'P': DIRCMP(fb->fpath, fa->fpath);
|
||||
case 'v': VERCMP(fa->fpath, fb->fpath);
|
||||
@@ -2156,6 +2152,15 @@
|
||||
fi->color = current_color;
|
||||
memcpy((char *)&fi->sb, (char *)sb, sizeof (struct stat));
|
||||
|
||||
+ if (IsWindows() && !S_ISDIR(fi->sb.st_mode)) {
|
||||
+ /* pretend that only .exe and .com files are executable */
|
||||
+ char *ext = extnam(fi->fpath);
|
||||
+ if (strcasecmp(ext, "exe") && strcasecmp(ext, "com"))
|
||||
+ fi->sb.st_mode &= ~0111;
|
||||
+ /* MSYS also reads the first two bytes of the file and compares
|
||||
+ * them to "MZ" and "#!", but let's avoid doing that for now. */
|
||||
+ }
|
||||
+
|
||||
prune = 0;
|
||||
if (expr && !eval(expr, fi)) {
|
||||
if (Bflag && S_ISDIR(fi->sb.st_mode) && !prune) {
|
Loading…
Reference in New Issue
Block a user