Wrapper script

2007-04-24 Thread Manuel Prinz
Hi everyone,

I ITP a package that provides a single binary that expects its input
file named in a special way, and writes two files with fixed names. One
of those is only temporary and not really usefull, so one usually
deletes it. I thought of writing a wrapper script, so the user can give
the input and output filename, the renaming would be done by the script,
as well as taking care of not overriding files if they already exist.

Are there any guideline how this is done? I've seen packages using
foo.bin for the original binary and foo for the wrapper script, or
some using a different location such as /usr/lib/foo/bin for the binary.
Or should one leave the binary as foo to provide the know behavior and
use foo-wrapper for the script?

I'd also be glad if you could point me out to some good source of how to
use /tmp in a secure way in scripts; I'd like to run the binary there
because I'm not a fan of joking around in the filesystem. (IIRC, tools
like pdfjam do so as well.)

Any advise would be very welcome!

Best regards,
Manuel



signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil


Re: Wrapper script

2007-04-24 Thread Justin Pryzby
On Tue, Apr 24, 2007 at 11:33:15AM +0200, Manuel Prinz wrote:
 Hi everyone,
 
 I ITP a package that provides a single binary that expects its input
 file named in a special way, and writes two files with fixed names. One
 of those is only temporary and not really usefull, so one usually
 deletes it. I thought of writing a wrapper script, so the user can give
 the input and output filename, the renaming would be done by the script,
 as well as taking care of not overriding files if they already exist.
Okay, it would be good to provide an option to inhibit deletion of the
file, and it would be good if the renames would be guaranteed to be on
the same filesystem and thus atomic.

Also be sure to use exec if this is a shells script, so you don't
have a needless bash process which is hanging around just going to do
wait(); exit();

 Are there any guideline how this is done? I've seen packages using
 foo.bin for the original binary and foo for the wrapper script, or
 some using a different location such as /usr/lib/foo/bin for the binary.
 Or should one leave the binary as foo to provide the know behavior and
 use foo-wrapper for the script?
These are all possibilities from which to choose depending on your
goals.  Another possibility is to make source changes to support
--input, --output, --[no-]remove.

 I'd also be glad if you could point me out to some good source of how to
 use /tmp in a secure way in scripts;
The important thing is that (at a low level) you open files with
O_CREAT|O_EXCL.  If you do this, it is safe: you won't clobber any
existing file.  If you don't, it is unsafe.  See also this manpages
bug:

  http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=368501

 I'd like to run the binary there
 because I'm not a fan of joking around in the filesystem.
Check if TMPDIR is set, and use it instead.

 Any advise would be very welcome!
The Debian tools to create tempfiles are tmpfile and mktemp.  These
will use /tmp by default, and handle TMPDIR.  Or, if you put the
tempfiles in the same dir as the final pathnames, then you can do mv
and it will be atomic.  Or, you can use mkdtemp -d to make a directory
directly below the final pathname (also guaranteed to be on the same
FS).  Since it's a new dir, you can assume it's empty.  If ther user
modifies things in it you can assume they know what they're doing.

Justin


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Wrapper script

2007-04-24 Thread Manuel Prinz
Am Dienstag, den 24.04.2007, 08:29 -0400 schrieb Justin Pryzby:
 On Tue, Apr 24, 2007 at 11:33:15AM +0200, Manuel Prinz wrote:
 [...]
  Are there any guideline how this is done? I've seen packages using
  foo.bin for the original binary and foo for the wrapper script, or
  some using a different location such as /usr/lib/foo/bin for the binary.
  Or should one leave the binary as foo to provide the know behavior and
  use foo-wrapper for the script?
 These are all possibilities from which to choose depending on your
 goals.  Another possibility is to make source changes to support
 --input, --output, --[no-]remove.

Unfortunately, this is not easily possible due to limitations in
Fortran. This would require a recent Fortran compiler that supports
Fortran2003, which is AFAIK not standard. (I can just say from my own
experience.) We have those in Debian, but I'm not sure about other
distributions. The program as is compiles fine with F77 compilers, so I
thought it may be easier to enhance functionality by a shell script, as
suggested by upstream.

 [...]
 The Debian tools to create tempfiles are tmpfile and mktemp.  These
 will use /tmp by default, and handle TMPDIR.  Or, if you put the
 tempfiles in the same dir as the final pathnames, then you can do mv
 and it will be atomic.  Or, you can use mkdtemp -d to make a directory
 directly below the final pathname (also guaranteed to be on the same
 FS).  Since it's a new dir, you can assume it's empty.  If ther user
 modifies things in it you can assume they know what they're doing.

Thanks for the pointers, that was what I'm looking for!

Best regards,
Manuel



signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil