tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Random string generation during *-install



Le 25/05/2015 13:15, Taylor R Campbell a écrit :
    Date: Mon, 25 May 2015 01:31:01 +0200
    From: Jean-Yves Migeon <jeanyves.migeon%free.fr@localhost>

    Le 24/05/2015 20:47, Kamil Rytarowski a écrit :
    > Once I had to do something similar in a shell script and replace bash(1)
    > $RANDOM with a portable alternative.
    >
    > I went for awk(1), initial ideas are at http://awk.info/?tip/random

Beware that most programming languages' built-in random number
generators are lousy, and totally unfit for applications requiring
unpredictability.  E.g., if your application is a network daemon
requiring an unpredictable secret random seed, you cannot use awk's
rand safely to generate it.

Yep, those examples are downright dangerous if you need crypto quality randomness. However I do think they are ok to generate distinct identifiers upon building of my ill-conceived app.

    Thanks. I ended up using urandom and tr(1) and delete any non printable
    char, not quite perfect but does an ok job.

That's what I would recommend.

(tr -cd '[:graph:]' | head -c 20) < /dev/urandom

There's a slim chance that on some exotic Unixoid platform pkgsrc
supports, you can't assume there will be a /dev/urandom.  But I
wouldn't worry about it until someone actually trips over it.

That's almost what I did, the only difference being that I "LC_ALL=C" right before calling tr. On some platform it tries to parse /dev/urandom bytes as UTF-8 encoded strings (as per locale) and tr(1) chokes when encoding is invalid.

    >> What is the correct way of generating a fixed random string on
    >> pre-install or do-install stage?
    [...]
    BTW is there a way to add arbitrary commands to a pkginstall's INSTALL
    script? Just wondering whether binary packages would add even more
    restrictions to the environment (not needed in my present scenario, but
    alas, sooner or later...)

Don't use pre-install and do-install for this -- use the INSTALL
script alongside the Makefile.  The pre-install and do-install make
targets are always (unless you explicitly set USE_DESTDIR=no, which is
ill-advised) run at build-time when installing into a destdir before
creating a package, not at install-time when you actually install the
package.

This is what the pkgsrc's guide says, but alas it does not say what I am supposed to do to patch in some code in INSTALL. So what would be the recommended way to alter a pkginstall INSTALL script when generated by the templates? Does that mean someone(tm) has to "manually" patch WRKSRC/.pkginstall/INSTALL?

Cheers,

--
Jean-Yves Migeon


Home | Main Index | Thread Index | Old Index