diff --git a/.reuse/dep5 b/.reuse/dep5 index bd9eed6..0a36a50 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -9,6 +9,6 @@ Source: https://github.com/fosslinux/live-bootstrap # Copyright: $YEAR $NAME <$CONTACT> # License: ... -Files: sys*/SHA256SUMS.sources sysa/pre-sha.sha256sums sysa/*/*.checksums sysa/SHA256SUMS.pkgs sysc/musl-1.2.3/ld-musl-i386.path +Files: sys*/SHA256SUMS.sources sysa/checksum-transcriber.SHA256SUM sysa/pre-sha.sha256sums sysa/*/*.checksums sysa/SHA256SUMS.pkgs sysc/musl-1.2.3/ld-musl-i386.path Copyright: none License: MIT diff --git a/sysa/after.kaem b/sysa/after.kaem index 3bfdd8f..fd72235 100755 --- a/sysa/after.kaem +++ b/sysa/after.kaem @@ -32,6 +32,7 @@ cp /${ARCH_DIR}/bin/hex2 ${bindir}/hex2 cp /${ARCH_DIR}/bin/kaem ${bindir}/kaem cp /${ARCH_DIR}/bin/match ${bindir}/match cp /${ARCH_DIR}/bin/M1 ${bindir}/M1 +cp /${ARCH_DIR}/bin/M2-Mesoplanet ${bindir}/M2-Mesoplanet cp /${ARCH_DIR}/bin/M2-Planet ${bindir}/M2-Planet cp /${ARCH_DIR}/bin/mkdir ${bindir}/mkdir cp /${ARCH_DIR}/bin/sha256sum ${bindir}/sha256sum @@ -50,6 +51,7 @@ chmod 755 ${bindir}/hex2 chmod 755 ${bindir}/kaem chmod 755 ${bindir}/match chmod 755 ${bindir}/M1 +chmod 755 ${bindir}/M2-Mesoplanet chmod 755 ${bindir}/M2-Planet chmod 755 ${bindir}/mkdir chmod 755 ${bindir}/sha256sum diff --git a/sysa/checksum-transcriber.SHA256SUM b/sysa/checksum-transcriber.SHA256SUM new file mode 100644 index 0000000..3737ed5 --- /dev/null +++ b/sysa/checksum-transcriber.SHA256SUM @@ -0,0 +1 @@ +48831089e26bee3c6ab7f0db048ded98dfbd7d78a75fefb9e0918a346dff10c0 /usr/bin/checksum-transcriber diff --git a/sysa/checksum-transcriber.c b/sysa/checksum-transcriber.c new file mode 100644 index 0000000..bbb3179 --- /dev/null +++ b/sysa/checksum-transcriber.c @@ -0,0 +1,84 @@ +#include +#include +#include +#include +#include + +#define MAX_STRING 4096 +#define MAX_TOKENS 3 + +char *get_distfiles(char **envp) { + char *envvar = "distfiles="; + int i = 0; + while (envp[i] != NULL && strncmp(envp[i], envvar, strlen(envvar)) != 0) i += 1; + // Now we have distfiles= - get just the part we want. + require(envp[i] != NULL, "Unable to find distfiles environment variable"); + return envp[i] + strlen(envvar); +} + +int main(int argc, char **argv, char **envp) { + // Random file things + require(argc == 2, "Usage: checksum-transcriber FILENAME"); + char *input = argv[1]; + FILE *in = fopen(input, "r"); + require(in != NULL, "File does not exist"); + char *output = calloc(MAX_STRING, sizeof(char)); + require(strcpy(output, input) != NULL, "Failed copying string"); + require(strcat(output, ".SHA256SUM") != NULL, "Failed concating string"); + FILE *out = fopen(output, "w+"); + require(out != NULL, "Failed opening output file"); + + char *orig_line; + char *line = calloc(MAX_STRING, sizeof(char)); + require(line != NULL, "Failed allocating string"); + char **tokens; + char *new_line; + char *checksum; + char *filename; + int i; + fgets(line, MAX_STRING, in); + while (strlen(line) != 0) { + // Split each line into tokens + orig_line = line; + tokens = calloc(MAX_TOKENS, sizeof(char*)); + i = 0; + while (i < MAX_TOKENS) { + tokens[i] = line; + new_line = strchr(line, ' '); + // Occurs when there are only two tokens + if (new_line == NULL) break; + line = new_line; + line[0] = '\0'; + line += 1; + i += 1; + } + line = strchr(line, '\n'); + line[0] = '\0'; + // Get checksum and filename + checksum = tokens[1]; + if (tokens[2] != NULL) { + filename = tokens[2]; + } else { + filename = strrchr(tokens[0], '/'); + filename += 1; + } + // Put it all together + fputs(checksum, out); + fputs(" ", out); + fputs(get_distfiles(envp), out); + fputc('/', out); + fputs(filename, out); + fputc('\n', out); + // Cleanup + i = 0; + free(orig_line); + free(tokens); + line = calloc(MAX_STRING, sizeof(char)); + require(line != NULL, "Failed allocating string"); + fgets(line, MAX_STRING, in); + } + + // Clean up + fclose(in); + fclose(out); +} diff --git a/sysa/run.kaem b/sysa/run.kaem index e4ba312..80e2951 100755 --- a/sysa/run.kaem +++ b/sysa/run.kaem @@ -9,6 +9,11 @@ set -ex +# checksum-transcriber utility +M2LIBC_PATH=/M2libc +M2-Mesoplanet --architecture ${ARCH} -f checksum-transcriber.c -o ${bindir}/checksum-transcriber +sha256sum -c checksum-transcriber.SHA256SUM + # Environmental variables needed for mes NYACC_PKG=nyacc-1.00.2 MES_VERSION=0.24