diff options
author | Timo Teräs <timo.teras@iki.fi> | 2017-01-10 14:16:16 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2017-01-10 14:16:16 +0200 |
commit | 6926e206a82f7cebd5827d3493e988b1d95046db (patch) | |
tree | 25354d16ca63c3f4460e16cfd2cc277056081ec9 | |
parent | 8bddd02b10cd581f0f0966375a93180b0cb2bb33 (diff) | |
download | abuild-6926e206a82f7cebd5827d3493e988b1d95046db.tar.gz abuild-6926e206a82f7cebd5827d3493e988b1d95046db.tar.bz2 abuild-6926e206a82f7cebd5827d3493e988b1d95046db.tar.xz abuild-6926e206a82f7cebd5827d3493e988b1d95046db.zip |
abuild-gzsplit: new tool to split .apk to it's base components
required tool for re-signing packages
-rw-r--r-- | Makefile | 10 | ||||
-rw-r--r-- | abuild-gzsplit.c | 75 |
2 files changed, 83 insertions, 2 deletions
@@ -10,7 +10,7 @@ datadir ?= $(prefix)/share/$(PACKAGE) SCRIPTS := abuild abuild-keygen abuild-sign newapkbuild \ abump apkgrel buildlab apkbuild-cpan checkapk \ apkbuild-gem-resolver -USR_BIN_FILES := $(SCRIPTS) abuild-tar abuild-sudo abuild-fetch +USR_BIN_FILES := $(SCRIPTS) abuild-tar abuild-gzsplit abuild-sudo abuild-fetch SAMPLES := sample.APKBUILD sample.initd sample.confd \ sample.pre-install sample.post-install AUTOTOOLS_TOOLCHAIN_FILES := config.sub config.guess @@ -38,13 +38,16 @@ SED_REPLACE := -e 's:@VERSION@:$(FULL_VERSION):g' \ SSL_CFLAGS ?= $(shell pkg-config --cflags openssl) SSL_LDFLAGS ?= $(shell pkg-config --cflags openssl) SSL_LIBS ?= $(shell pkg-config --libs openssl) - +ZLIB_LIBS ?= $(shell pkg-config --libs zlib) OBJS-abuild-tar = abuild-tar.o CFLAGS-abuild-tar.o = $(SSL_CFLAGS) LDFLAGS-abuild-tar = $(SSL_LDFLAGS) LIBS-abuild-tar = $(SSL_LIBS) +OBJS-abuild-gzsplit = abuild-gzsplit.o +LDFLAGS-abuild-gzsplit = $(ZLIB_LIBS) + OBJS-abuild-sudo = abuild-sudo.o OBJS-abuild-fetch = abuild-fetch.o @@ -76,6 +79,9 @@ abuild-tar: abuild-tar.o abuild-fetch: abuild-fetch.o $(LINK) +abuild-gzsplit: abuild-gzsplit.o + $(LINK) + abuild-tar.static: abuild-tar.o $(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS-$@) -o $@ -static $(LIBS-$@) $^ diff --git a/abuild-gzsplit.c b/abuild-gzsplit.c new file mode 100644 index 0000000..5e7a698 --- /dev/null +++ b/abuild-gzsplit.c @@ -0,0 +1,75 @@ +#include <stdio.h> +#include <fcntl.h> +#include <string.h> +#include <unistd.h> + +#include <zlib.h> + +int main(void) +{ + char obuf[8*1024], ibuf[8*1024]; + z_stream zs; + int r = Z_OK, rc = 1, fd = -1; + size_t len; + + if (inflateInit2(&zs, 15+32) != Z_OK) + goto err; + + zs.avail_out = sizeof obuf; + zs.next_out = obuf; + + while (1) { + if (zs.avail_in == 0) { + zs.avail_in = read(STDIN_FILENO, ibuf, sizeof ibuf); + zs.next_in = ibuf; + if (zs.avail_in < 0) goto err; + if (zs.avail_in == 0 && r == Z_STREAM_END) goto ok; + } + + r = inflate(&zs, Z_NO_FLUSH); + if (r != Z_OK && r != Z_STREAM_END) goto err; + + len = sizeof obuf - zs.avail_out; + if (len) { + if (fd < 0) { + const char *fn; + if (strncmp(obuf, ".SIGN.", 6) == 0) + fn = "signatures.tar.gz"; + else if (strncmp(obuf, ".PKGINFO", 8) == 0) + fn = "control.tar.gz"; + else if (rc == 1) + fn = "data.tar.gz", rc = 2; + else + goto err; + fd = open(fn, O_CREAT|O_TRUNC|O_WRONLY, 0777); + if (fd < 0) goto err; + } + zs.next_out = obuf; + zs.avail_out = sizeof obuf; + } + + if (zs.avail_in == 0 || r == Z_STREAM_END) { + len = (void *)zs.next_in - (void *)ibuf; + if (write(fd, ibuf, len) != len) goto err; + memmove(ibuf, zs.next_in, zs.avail_in); + zs.next_in = ibuf; + } + + if (r == Z_STREAM_END) { + if (fd >= 0) { + close(fd); + fd = -1; + } + inflateEnd(&zs); + if (inflateInit2(&zs, 15+32) != Z_OK) goto err; + } + } +ok: + rc = 0; +err: + if (fd >= 0) close(fd); + inflateEnd(&zs); + if (rc) fprintf(stderr, "failed\n"); + return rc; +} + |