~alpine/aports

2

[alpine-aports] [PATCH 1/3] main/debootstrap: cleanup by providing custom makedev script

Details
Message ID
<1439923587-3822-1-git-send-email-soeren+git@soeren-tempel.net>
Sender timestamp
1439923585
DKIM signature
missing
Download raw message
Patch: +39 -28
Instead of replicating the Makefile devices.tar.gz rule in the package()
APKBUILD function.
---
 main/debootstrap/APKBUILD   | 48 +++++++++++++++++++--------------------------
 main/debootstrap/makedev.sh | 19 ++++++++++++++++++
 2 files changed, 39 insertions(+), 28 deletions(-)
 create mode 100755 main/debootstrap/makedev.sh

diff --git a/main/debootstrap/APKBUILD b/main/debootstrap/APKBUILD
index 247da7d..787d95b 100644
--- a/main/debootstrap/APKBUILD
+++ b/main/debootstrap/APKBUILD
@@ -1,3 +1,4 @@
# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=debootstrap
pkgver=1.0.72
@@ -7,46 +8,37 @@ url="http://packages.qa.debian.org/d/debootstrap.html"
arch="all"
license="GPL2"
depends="dpkg tar"
makedepends=""
install=""
subpackages=""
source="http://ftp.de.debian.org/debian/pool/main/d/debootstrap/debootstrap_$pkgver.tar.gz
	pkgdetails.c"
	pkgdetails.c
	makedev.sh"

_builddir="$srcdir"/debootstrap-$pkgver
build() {
	cd "$_builddir"
	${CC:-gcc} $CFLAGS $LDFLAGS -o pkgdetails \
	chmod +x "$srcdir/makedev.sh"
	${CC:-gcc} $CFLAGS $LDFLAGS -o "$_builddir"/pkgdetails \
		"$srcdir"/pkgdetails.c || return 1
}

package() {
	cd "$_builddir"
	# create devices.tar.gz
	rm -rf dev
	mkdir -p dev
	chown 0:0 dev
	chmod 755 dev
	( cd dev
		ln -s /proc/self/fd fd
		ln -s fd/0 stdin
		ln -s fd/1 stdout
		ln -s fd/2 stderr
		mknod full c 1 7
		mknod null c 1 3
		mknod ptmx c 5 2
		mkdir pts shm
		mknod random c 1 8
		mknod tty c 5 0
		mknod urandom c 1 9
		mknod zero c 1 5
	)
	tar -czf devices.tar.gz dev
	rm -rf dev
	make DESTDIR="$pkgdir" install || return

	# This can only be done in a fakeroot
	make MAKEDEV="$srcdir/makedev.sh" \
		devices.tar.gz || return 1

	make DESTDIR="$pkgdir" install || return 1
	install -Dm755 pkgdetails "$pkgdir"/usr/lib/debootstrap/pkgdetails
}

md5sums="0cacf6e3bd8b566e921d2a326d6fd2bd  debootstrap_1.0.72.tar.gz
66b6fb6d862ba4886701c9b056088479  pkgdetails.c"
66b6fb6d862ba4886701c9b056088479  pkgdetails.c
ef5038e52173de7a18c37a0925ccf383  makedev.sh"
sha256sums="90f4cf1390326f020b9192b6a45ba1d323fffab9c22c6f62451780e6f5482f8d  debootstrap_1.0.72.tar.gz
1cf1644e8400693fd41d378f972c15fa7b32f3282117ea967c995705256a84d6  pkgdetails.c"
1cf1644e8400693fd41d378f972c15fa7b32f3282117ea967c995705256a84d6  pkgdetails.c
3f26318b59c7697205285d04eb68a4c65905faedd7bbcb4e53e803f9ea8e5c97  makedev.sh"
sha512sums="b8f186b13f66789e96f775337d06821cfb464e35dd661a2bff1420bfb1254cf85ce9eb46be1a27dad7a462628e441cbfcdfffaf12ee5a394d15c248882295848  debootstrap_1.0.72.tar.gz
432313c8aef4974f21cb81b48d9f1c319692325f24a456e460e6f92c6a15ade7f29dfee4bf2ab3664c90b09d1f16e46cb8dd898ebd317f2547e63a64a773d971  pkgdetails.c"
432313c8aef4974f21cb81b48d9f1c319692325f24a456e460e6f92c6a15ade7f29dfee4bf2ab3664c90b09d1f16e46cb8dd898ebd317f2547e63a64a773d971  pkgdetails.c
71f1dfe7d785cf5f4b2db7e4de01b5e542b33a1a49194a53665d4d68b5de47fc3c5b37ad2d1a7c37fb14d10c6758fa2fb043bd68a6fbb8b9dba90fb071a9db9c  makedev.sh"
diff --git a/main/debootstrap/makedev.sh b/main/debootstrap/makedev.sh
new file mode 100755
index 0000000..bee4ff8
--- /dev/null
+++ b/main/debootstrap/makedev.sh
@@ -0,0 +1,19 @@
#!/bin/sh
# Use this instead of packaging makedev.

# Exit on failure.
set -e

# Create devices in $PWD.
ln -s /proc/self/fd fd
ln -s fd/0 stdin
ln -s fd/1 stdout
ln -s fd/2 stderr
mknod full c 1 7
mknod null c 1 3
mknod ptmx c 5 2
mkdir pts shm
mknod random c 1 8
mknod tty c 5 0
mknod urandom c 1 9
mknod zero c 1 5
-- 
2.5.0



---
Unsubscribe:  alpine-aports+unsubscribe@lists.alpinelinux.org
Help:         alpine-aports+help@lists.alpinelinux.org
---

[alpine-aports] [PATCH 2/3] main/debootstrap: add doc subpackage

Details
Message ID
<1439923587-3822-2-git-send-email-soeren+git@soeren-tempel.net>
In-Reply-To
<1439923587-3822-1-git-send-email-soeren+git@soeren-tempel.net> (view parent)
Sender timestamp
1439923586
DKIM signature
missing
Download raw message
Patch: +6 -3
---
 main/debootstrap/APKBUILD | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/main/debootstrap/APKBUILD b/main/debootstrap/APKBUILD
index 787d95b..d8d2137 100644
--- a/main/debootstrap/APKBUILD
+++ b/main/debootstrap/APKBUILD
@@ -2,7 +2,7 @@
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=debootstrap
pkgver=1.0.72
pkgrel=0
pkgrel=1
pkgdesc="Debian/Ubuntu bootstrap scripts"
url="http://packages.qa.debian.org/d/debootstrap.html"
arch="all"
@@ -10,7 +10,7 @@ license="GPL2"
depends="dpkg tar"
makedepends=""
install=""
subpackages=""
subpackages="$pkgname-doc"
source="http://ftp.de.debian.org/debian/pool/main/d/debootstrap/debootstrap_$pkgver.tar.gz
	pkgdetails.c
	makedev.sh"
@@ -30,7 +30,10 @@ package() {
		devices.tar.gz || return 1

	make DESTDIR="$pkgdir" install || return 1
	install -Dm755 pkgdetails "$pkgdir"/usr/lib/debootstrap/pkgdetails
	install -Dm755 pkgdetails \
		"$pkgdir"/usr/lib/debootstrap/pkgdetails || return 1
	install -Dm644 $pkgname.8 \
		"$pkgdir"/usr/share/man/man8/$pkgname.8 || return 1
}

md5sums="0cacf6e3bd8b566e921d2a326d6fd2bd  debootstrap_1.0.72.tar.gz
-- 
2.5.0



---
Unsubscribe:  alpine-aports+unsubscribe@lists.alpinelinux.org
Help:         alpine-aports+help@lists.alpinelinux.org
---

[alpine-aports] [PATCH 3/3] main/debootstrap: remove pkgdetails.c

Details
Message ID
<1439923587-3822-3-git-send-email-soeren+git@soeren-tempel.net>
In-Reply-To
<1439923587-3822-1-git-send-email-soeren+git@soeren-tempel.net> (view parent)
Sender timestamp
1439923587
DKIM signature
missing
Download raw message
Patch: +5 -362
In my opinion it doesn't belong in this package, it could be shipped by
a separate package but I don't think that it is that useful.
---
 main/debootstrap/APKBUILD     |  20 +--
 main/debootstrap/pkgdetails.c | 347 ------------------------------------------
 2 files changed, 5 insertions(+), 362 deletions(-)
 delete mode 100644 main/debootstrap/pkgdetails.c

diff --git a/main/debootstrap/APKBUILD b/main/debootstrap/APKBUILD
index d8d2137..c83dca4 100644
--- a/main/debootstrap/APKBUILD
+++ b/main/debootstrap/APKBUILD
@@ -2,46 +2,36 @@
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=debootstrap
pkgver=1.0.72
pkgrel=1
pkgrel=2
pkgdesc="Debian/Ubuntu bootstrap scripts"
url="http://packages.qa.debian.org/d/debootstrap.html"
arch="all"
arch="noarch"
license="GPL2"
depends="dpkg tar"
makedepends=""
install=""
subpackages="$pkgname-doc"
source="http://ftp.de.debian.org/debian/pool/main/d/debootstrap/debootstrap_$pkgver.tar.gz
	pkgdetails.c
source="http://ftp.de.debian.org/debian/pool/main/d/$pkgname/${pkgname}_${pkgver}.tar.gz
	makedev.sh"

_builddir="$srcdir"/debootstrap-$pkgver
build() {
_builddir="$srcdir"/$pkgname-$pkgver
prepare() {
	chmod +x "$srcdir/makedev.sh"
	${CC:-gcc} $CFLAGS $LDFLAGS -o "$_builddir"/pkgdetails \
		"$srcdir"/pkgdetails.c || return 1
}

package() {
	cd "$_builddir"

	# This can only be done in a fakeroot
	make MAKEDEV="$srcdir/makedev.sh" \
		devices.tar.gz || return 1

	make DESTDIR="$pkgdir" install || return 1
	install -Dm755 pkgdetails \
		"$pkgdir"/usr/lib/debootstrap/pkgdetails || return 1
	install -Dm644 $pkgname.8 \
		"$pkgdir"/usr/share/man/man8/$pkgname.8 || return 1
}

md5sums="0cacf6e3bd8b566e921d2a326d6fd2bd  debootstrap_1.0.72.tar.gz
66b6fb6d862ba4886701c9b056088479  pkgdetails.c
ef5038e52173de7a18c37a0925ccf383  makedev.sh"
sha256sums="90f4cf1390326f020b9192b6a45ba1d323fffab9c22c6f62451780e6f5482f8d  debootstrap_1.0.72.tar.gz
1cf1644e8400693fd41d378f972c15fa7b32f3282117ea967c995705256a84d6  pkgdetails.c
3f26318b59c7697205285d04eb68a4c65905faedd7bbcb4e53e803f9ea8e5c97  makedev.sh"
sha512sums="b8f186b13f66789e96f775337d06821cfb464e35dd661a2bff1420bfb1254cf85ce9eb46be1a27dad7a462628e441cbfcdfffaf12ee5a394d15c248882295848  debootstrap_1.0.72.tar.gz
432313c8aef4974f21cb81b48d9f1c319692325f24a456e460e6f92c6a15ade7f29dfee4bf2ab3664c90b09d1f16e46cb8dd898ebd317f2547e63a64a773d971  pkgdetails.c
71f1dfe7d785cf5f4b2db7e4de01b5e542b33a1a49194a53665d4d68b5de47fc3c5b37ad2d1a7c37fb14d10c6758fa2fb043bd68a6fbb8b9dba90fb071a9db9c  makedev.sh"
diff --git a/main/debootstrap/pkgdetails.c b/main/debootstrap/pkgdetails.c
deleted file mode 100644
index 99ee190..0000000
--- a/main/debootstrap/pkgdetails.c
@@ -1,347 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include <errno.h>

#define MAX_LINE 1000
#define MAX_PKGS 100

char *checksum_field=NULL;

static void oom_die(void)
{
    fputs("Out of memory!\n", stderr);
    exit(1);
}

static char *xvasprintf(const char *fmt, va_list ap) {
    char *ret;

    if (vasprintf (&ret, fmt, ap) < 0) {
        if (errno == ENOMEM)
            oom_die();
        return NULL;
    }
    return ret;
}

static char *xasprintf(const char *fmt, ...) {
    va_list ap;
    char *ret;

    va_start(ap, fmt);
    ret = xvasprintf(fmt, ap);
    va_end(ap);
    return ret;
}

static char *fieldcpy(char *dst, char *fld) {
    while (*fld && *fld != ':') 
        fld++;
    if (!*(fld++)) 
        return NULL;
    while (isspace(*fld)) fld++;
    return strcpy(dst, fld);
}

static void outputdeps(char *deps) {
    char *pch = deps;

    while (1) {
        while (isspace(*pch)) pch++;
        if (!*pch) break;

        while (*pch && *pch != '(' && *pch != '|' && *pch != ','
               && !isspace(*pch))
        {
            fputc(*pch++, stdout);
        }
        fputc('\n', stdout);
        while (*pch && *pch++ != ',') (void)NULL;
    }
}

static void dogetdeps(char *pkgsfile, char **in_pkgs, int pkgc) {
    char buf[MAX_LINE];
    char cur_pkg[MAX_LINE];
    char cur_deps[MAX_LINE];
    char cur_predeps[MAX_LINE];
    char prev_pkg[MAX_LINE];
    char *pkgs[MAX_PKGS];
    int i;
    int skip;
    FILE *f;
    int output_pkg = -1;

    cur_pkg[0] = cur_deps[0] = cur_predeps[0] = prev_pkg[0] = '\0';

    for (i = 0; i < pkgc; i++) pkgs[i] = in_pkgs[i];

    f = fopen(pkgsfile, "r");
    if (f == NULL) {
        perror(pkgsfile);
        exit(1);
    }

    skip = 1;
    while (fgets(buf, sizeof(buf), f)) {
        if (*buf && buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
        if (strncasecmp(buf, "Package:", 8) == 0) {
            int any = 0;
            skip = 1;
            fieldcpy(cur_pkg, buf);
            if (strcmp(cur_pkg, prev_pkg) != 0) {
                if (output_pkg != -1)
                    pkgs[output_pkg] = NULL;
                if (cur_deps[0])
                    outputdeps(cur_deps);
                if (cur_predeps[0])
                    outputdeps(cur_predeps);
                strcpy(prev_pkg, cur_pkg);
            }
            cur_deps[0] = cur_predeps[0] = '\0';
            output_pkg = -1;
	    for (i = 0; i < pkgc; i++) {
		if (!pkgs[i]) continue;
		any = 1;
                if (strcmp(cur_pkg, pkgs[i]) == 0) {
                    skip = 0;
                    output_pkg = i;
                    break;
                }
            }
            if (!any) break;
        } else if (!skip && strncasecmp(buf, "Depends:", 8) == 0)
            fieldcpy(cur_deps, buf);
        else if (!skip && strncasecmp(buf, "Pre-Depends:", 12) == 0)
            fieldcpy(cur_predeps, buf);
    }
    if (cur_deps[0])
        outputdeps(cur_deps);
    if (cur_predeps[0])
        outputdeps(cur_predeps);
    fclose(f);
}

static void dopkgmirrorpkgs(int uniq, char *mirror, char *pkgsfile, 
        char *fieldname, char **in_pkgs, int pkgc) 
{
    char buf[MAX_LINE];
    char cur_field[MAX_LINE];
    char cur_pkg[MAX_LINE];
    char cur_ver[MAX_LINE];
    char cur_arch[MAX_LINE];
    char cur_size[MAX_LINE];
    char cur_checksum[MAX_LINE];
    char cur_filename[MAX_LINE];
    char prev_pkg[MAX_LINE];
    char *pkgs[MAX_PKGS];
    int i;
    FILE *f;
    char *output = NULL;
    int output_pkg = -1;

    cur_field[0] = cur_pkg[0] = cur_ver[0] = cur_arch[0] = cur_filename[0] = prev_pkg[0] = '\0';

    for (i = 0; i < pkgc; i++) pkgs[i] = in_pkgs[i];

    f = fopen(pkgsfile, "r");
    if (f == NULL) {
        perror(pkgsfile);
        exit(1);
    }
    while (fgets(buf, sizeof(buf), f)) {
        if (*buf && buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
        if (strncasecmp(buf, fieldname, strlen(fieldname)) == 0) {
            fieldcpy(cur_field, buf);
	}
        if (strncasecmp(buf, "Package:", 8) == 0) {
            fieldcpy(cur_pkg, buf);
            if (strcmp(cur_pkg, prev_pkg) != 0) {
                if (output)
                    fputs(output, stdout);
                if (uniq && output_pkg != -1)
                    pkgs[output_pkg] = NULL;
                strcpy(prev_pkg, cur_pkg);
            }
            free(output);
            output = NULL;
            output_pkg = -1;
        } else if (strncasecmp(buf, "Version:", 8) == 0) {
            fieldcpy(cur_ver, buf);
        } else if (strncasecmp(buf, "Architecture:", 13) == 0) {
            fieldcpy(cur_arch, buf);
        } else if (strncasecmp(buf, "Size:", 5) == 0) {
            fieldcpy(cur_size, buf);
        } else if (strncasecmp(buf, checksum_field, strlen(checksum_field)) == 0
	           && buf[strlen(checksum_field)] == ':') {
            fieldcpy(cur_checksum, buf);
        } else if (strncasecmp(buf, "Filename:", 9) == 0) {
            fieldcpy(cur_filename, buf);
        } else if (!*buf) {
	    int any = 0;
	    for (i = 0; i < pkgc; i++) {
		if (!pkgs[i]) continue;
		any = 1;
                if (strcmp(cur_field, pkgs[i]) == 0) {
                    free(output);
                    output = xasprintf("%s %s %s %s %s %s %s\n", cur_pkg, cur_ver, cur_arch, mirror, cur_filename, cur_checksum, cur_size);
                    output_pkg = i;
		    break;
		}
            }
	    if (!any) break;
            cur_field[0] = '\0';
        }
    }
    if (output)
        fputs(output, stdout);
    if (uniq && output_pkg != -1)
        pkgs[output_pkg] = NULL;
    fclose(f);

    /* any that weren't found are returned as "pkg -" */
    if (uniq) {
        for (i = 0; i < pkgc; i++) {
            if (pkgs[i]) {
                printf("%s -\n", pkgs[i]);
            }
        }
    }
}

static void dopkgstanzas(char *pkgsfile, char **pkgs, int pkgc)
{
    char buf[MAX_LINE];
    char *accum;
    size_t accum_size = 0, accum_alloc = MAX_LINE * 2;
    char cur_pkg[MAX_LINE];
    FILE *f;

    accum = malloc(accum_alloc);
    if (!accum)
        oom_die();

    f = fopen(pkgsfile, "r");
    if (f == NULL) {
        perror(pkgsfile);
        free(accum);
        exit(1);
    }
    while (fgets(buf, sizeof(buf), f)) {
        if (*buf) {
	    size_t len = strlen(buf);
            if (accum_size + len + 1 > accum_alloc) {
                accum_alloc = (accum_size + len + 1) * 2;
                accum = realloc(accum, accum_alloc);
                if (!accum)
                    oom_die();
            }
            strcpy(accum + accum_size, buf);
	    accum_size += len;
        }
        if (*buf && buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
        if (strncasecmp(buf, "Package:", 8) == 0) {
            fieldcpy(cur_pkg, buf);
        } else if (!*buf) {
            int i;
            for (i = 0; i < pkgc; i++) {
                if (!pkgs[i]) continue;
                if (strcmp(cur_pkg, pkgs[i]) == 0) {
                    fputs(accum, stdout);
		    if (accum[accum_size - 1] != '\n')
			fputs("\n\n", stdout);
		    else if (accum[accum_size - 2] != '\n')
			fputc('\n', stdout);
                    break;
                }
            }
            *accum = '\0';
            accum_size = 0;
        }
    }
    fclose(f);

    free(accum);
}

static int dotranslatewgetpercent(int low, int high, int end, char *str) {
    int ch;
    int val, lastval;

    /* print out anything that looks like a % on its own line, appropriately
     * scaled */

    lastval = val = 0;
    while ( (ch = getchar()) != EOF ) {
        if (isdigit(ch)) {
	    val *= 10; val += ch - '0';
	} else if (ch == '%') {
	    float f = (float) val / 100.0 * (high - low) + low;
	    if (str) {
	    	printf("P: %d %d %s\n", (int) f, end, str);
	    } else {
	    	printf("P: %d %d\n", (int) f, end);
	    }
	    lastval = val;
	} else {
	    val = 0;
	}
    }
    return lastval == 100;
}

int main(int argc, char *argv[]) {
    checksum_field=getenv("DEBOOTSTRAP_CHECKSUM_FIELD");
    if (checksum_field == NULL) {
        checksum_field="MD5sum";
    }

    if ((argc == 6 || argc == 5) && strcmp(argv[1], "WGET%") == 0) {
	if (dotranslatewgetpercent(atoi(argv[2]), atoi(argv[3]), 
	                           atoi(argv[4]), argc == 6 ? argv[5] : NULL))
	{
	    exit(0);
	} else {
	    exit(1);
	}
    } else if (argc >= 4 && strcmp(argv[1], "GETDEPS") == 0) {
        int i;
        for (i = 3; argc - i > MAX_PKGS; i += MAX_PKGS) {
	    dogetdeps(argv[2], argv+i, MAX_PKGS);
	}
	dogetdeps(argv[2], argv+i, argc-i);
	exit(0);
    } else if (argc >= 5 && strcmp(argv[1], "PKGS") == 0) {
        int i;
        for (i = 4; argc - i > MAX_PKGS; i += MAX_PKGS) {
	    dopkgmirrorpkgs(1, argv[2], argv[3], "Package:", argv+i, MAX_PKGS);
	}
	dopkgmirrorpkgs(1, argv[2], argv[3], "Package:", argv+i, argc-i);
	exit(0);
    } else if (argc >= 6 && strcmp(argv[1], "FIELD") == 0) {
        int i;
        for (i = 5; argc - i > MAX_PKGS; i += MAX_PKGS) {
	    dopkgmirrorpkgs(0, argv[3], argv[4], argv[2], argv+i, MAX_PKGS);
	}
	dopkgmirrorpkgs(0, argv[3], argv[4], argv[2], argv+i, argc-i);
	exit(0);
    } else if (argc >= 4 && strcmp(argv[1], "STANZAS") == 0) {
	int i;
	for (i = 3; argc - i > MAX_PKGS; i += MAX_PKGS) {
	    dopkgstanzas(argv[2], argv+i, MAX_PKGS);
	}
	dopkgstanzas(argv[2], argv+i, argc-i);
	exit(0);
    } else {
        fprintf(stderr, "usage: %s PKGS mirror packagesfile pkgs..\n", argv[0]);
        fprintf(stderr, "   or: %s FIELD field mirror packagesfile pkgs..\n", 
                argv[0]);
        fprintf(stderr, "   or: %s GETDEPS packagesfile pkgs..\n", argv[0]);
        fprintf(stderr, "   or: %s STANZAS packagesfile pkgs..\n", argv[0]);
	fprintf(stderr, "   or: %s WGET%% low high end reason\n", argv[0]);
        exit(1);
    }
}
-- 
2.5.0



---
Unsubscribe:  alpine-aports+unsubscribe@lists.alpinelinux.org
Help:         alpine-aports+help@lists.alpinelinux.org
---
Reply to thread Export thread (mbox)