Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 504954 - app-misc/pax-utils: port lddtree.sh to POSIX shell
Summary: app-misc/pax-utils: port lddtree.sh to POSIX shell
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Hardened (show other bugs)
Hardware: All Linux
: Normal enhancement (vote)
Assignee: SpanKY
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-18 13:04 UTC by Natanael Copa
Modified: 2014-03-20 08:27 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
lddtree-sh.patch (lddtree-sh.patch,5.45 KB, patch)
2014-03-18 13:04 UTC, Natanael Copa
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Natanael Copa 2014-03-18 13:04:52 UTC
Created attachment 372928 [details, diff]
lddtree-sh.patch

Attatched is a patch that makes lddtree.sh to work with busybox shell instead of /bin/bash.

I think it is fairly close to work with any POSIX shell.
Comment 1 Rick Farina (Zero_Chaos) gentoo-dev 2014-03-18 13:08:15 UTC
why is this needed?
Comment 2 Natanael Copa 2014-03-18 13:13:59 UTC
(In reply to Rick Farina (Zero_Chaos) from comment #1)
> why is this needed?

It is needed for distros that don't want pull in /bin/bash to be able to use lddtree.

Alpine Linux is planning to use it for generating initramfs images but does not have (and want to avoid) /bin/bash installed by default.

Please point me to the pax-utils' upstream if this is not it.

Thanks!
Comment 3 Anthony Basile gentoo-dev 2014-03-18 14:31:15 UTC
(In reply to Natanael Copa from comment #2)
> (In reply to Rick Farina (Zero_Chaos) from comment #1)
> > why is this needed?
> 
> It is needed for distros that don't want pull in /bin/bash to be able to use
> lddtree.
> 
> Alpine Linux is planning to use it for generating initramfs images but does
> not have (and want to avoid) /bin/bash installed by default.
> 
> Please point me to the pax-utils' upstream if this is not it.
> 
> Thanks!

Upstream is vapier@gentoo.org.  But I'm confused here.  pax-utils hasn't shipped with lddtree.sh in ages.  It currently ships with lddtree written in python.
Comment 4 Martin Väth 2014-03-18 14:58:50 UTC
(In reply to Anthony Basile from comment #3)
> pax-utils hasn't shipped with lddtree.sh in ages.
> It currently ships with lddtree written in python.

pax-utils supports USE=python. I guess both versions are shipped and the Makefile decides according to the setting of USE_PYTHON which version to install.
Comment 5 Anthony Basile gentoo-dev 2014-03-18 15:07:19 UTC
(In reply to Martin Väth from comment #4)
> (In reply to Anthony Basile from comment #3)
> > pax-utils hasn't shipped with lddtree.sh in ages.
> > It currently ships with lddtree written in python.
> 
> pax-utils supports USE=python. I guess both versions are shipped and the
> Makefile decides according to the setting of USE_PYTHON which version to
> install.

Ah yes, I see that now.
Comment 6 SpanKY gentoo-dev 2014-03-19 02:08:30 UTC
yes, i don't see much value in lddtree.sh anymore.  the python version is the future (it does a lot more useful stuff, and is way faster).

unfortunately, this change is not entirely correct.  the point of using arrays is so that files get properly quoted.  by converting to strings, you lose that.

in fact, the stated use case (generating standalone images) is exactly what the python lddtree is designed to handle.  if you're writing your own tooling on top of lddtree.sh, then honestly, you're doing it wrong for no good reason and you're wasting your time.

$ lddtree --copy-to-tree /tmp/initramfs --bin /bin /bin/sh /bin/ls
$ tree /tmp/initramfs/
/tmp/initramfs/
|-- bin
|   |-- ls
|   `-- sh
`-- lib64
    |-- ld-linux-x86-64.so.2
    |-- libacl.so.1
    |-- libattr.so.1
    |-- libcap.so.2
    `-- libc.so.6

see the announcement on gentoo-dev@ a while ago on the topic.
Comment 7 Natanael Copa 2014-03-19 07:13:28 UTC
(In reply to SpanKY from comment #6)
> yes, i don't see much value in lddtree.sh anymore.  the python version is
> the future (it does a lot more useful stuff, and is way faster).
> 
> unfortunately, this change is not entirely correct.  the point of using
> arrays is so that files get properly quoted.  by converting to strings, you
> lose that.
> 
> in fact, the stated use case (generating standalone images) is exactly what
> the python lddtree is designed to handle.  if you're writing your own
> tooling on top of lddtree.sh, then honestly, you're doing it wrong for no
> good reason and you're wasting your time.
> 
> $ lddtree --copy-to-tree /tmp/initramfs --bin /bin /bin/sh /bin/ls
> $ tree /tmp/initramfs/
> /tmp/initramfs/
> |-- bin
> |   |-- ls
> |   `-- sh
> `-- lib64
>     |-- ld-linux-x86-64.so.2
>     |-- libacl.so.1
>     |-- libattr.so.1
>     |-- libcap.so.2
>     `-- libc.so.6
> 
> see the announcement on gentoo-dev@ a while ago on the topic.

thats exactly the thing i need, except that the tool need to be *way* smaller and cannot depend on python.
Comment 8 SpanKY gentoo-dev 2014-03-20 06:16:13 UTC
(In reply to Natanael Copa from comment #7)

a stripped down python install can be easily under ~20MB, but i'm guessing that's too big and you don't want to try to strip it down further.

i'm not wasting any more real time on extending the functionality of lddtree.sh.  it makes no sense to write it twice.  the python version is way faster and more maintainable (to understand, update, fix, extend, etc...), and can be imported into other python projects (which i do).  a C version doesn't make sense as it has really none of those features.  the shell version sticks around since it's already been written and provides some useful minimal functionality.

i didn't pick python because i'm super in love with the language.  if that were the case, i wouldn't be maintaining portage-utils & pax-utils (which are pure C).  i picked python because it makes hell of a lot of sense and my experience with the languages shows that it's a clear winner.

maybe you can find a python compiler that'll produce a standalone binary.
Comment 9 Natanael Copa 2014-03-20 08:27:21 UTC
(In reply to SpanKY from comment #8)
> (In reply to Natanael Copa from comment #7)
> 
> a stripped down python install can be easily under ~20MB, but i'm guessing
> that's too big and you don't want to try to strip it down further.

Correct. It can be done in 80k (shell + scanelf) which is approx 0.4% the 20MB python thingy. I know most ppl don't care about that. A few does.

> i'm not wasting any more real time on extending the functionality of
> lddtree.sh.  it makes no sense to write it twice.  the python version is way
> faster and more maintainable (to understand, update, fix, extend, etc...),
> and can be imported into other python projects (which i do).  a C version
> doesn't make sense as it has really none of those features.  the shell
> version sticks around since it's already been written and provides some
> useful minimal functionality.

I'm glad you kept it. The minimal functionality does the job for me (with a few modifications). I created this bug after asking in #gentoo-hardened if there was any interest in porting it to posix shell (or actually busybox ash).
 
> i didn't pick python because i'm super in love with the language.  if that
> were the case, i wouldn't be maintaining portage-utils & pax-utils (which
> are pure C).  i picked python because it makes hell of a lot of sense and my
> experience with the languages shows that it's a clear winner.

It makes sense yes. specially in gentoo context because you will hardly find any gentoo install without python.

I also looked at implementing it in C too, so I have no problem understand why you didn't.

Lua would be small enough for me though... yeah no worries, I understand why you picked python.

> maybe you can find a python compiler that'll produce a standalone binary.

Or I can fork it.
https://github.com/ncopa/lddtree

(the space in filename/path problem should be fixed too now)

Thanks!