[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Random string generation during *-install
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.
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.
>> 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
Main Index |
Thread Index |