On 12 Feb 2004, at 4:33 PM, Daniel Macks wrote:

On Thu, Feb 12, 2004 at 12:53:09AM +1100, Rohan Lloyd wrote:

In writing the InstallScript for a new package I wanted to be able to fold long lines, to make it more readable. ie. have:

 /usr/bin/install -m 755 common/fink/emacsen-install \
                         %i/lib/emacsen-common/packages/install/%n

Instead of:

/usr/bin/install -m 755 common/fink/emacsen-install %i/lib/emacsen-common/packages/install/%n

Not a bad idea.

Thanks. 8v)

I discovered that fink did not like this. If I add a "#!/bin/sh" to the
first line, it saves the script to a file, and then runs it through
/bin/sh which works, but I don't get to see the individual commands as
they are run.

Try '#!/bin/sh -x' instead.

That's not quite as friendly, as it prints out the command after all the shell globbing etc. For example, you get:

/bin/rm -rf /sw/src/root-cedet-common-1.0beta1c-1
/bin/mkdir -p /sw/src/root-cedet-common-1.0beta1c-1/sw
/bin/mkdir -p /sw/src/root-cedet-common-1.0beta1c-1/DEBIAN
/var/tmp/tmp.1.yygucg
+ /usr/bin/install -m 755 -d /sw/src/root-cedet-common-1.0beta1c-1/sw/share/cedet-common/icons
+ /usr/bin/install -m 644 common/icons/Makefile common/icons/Project.ede common/icons/bits.xpm common/icons/bitsbang.xpm common/icons/box-minus.xpm common/icons/box-plus.xpm common/icons/box.xpm common/icons/checkmark.xpm common/icons/dir-minus.xpm common/icons/dir-plus.xpm common/icons/dir.xpm common/icons/doc-minus.xpm common/icons/doc-plus.xpm common/icons/doc.xpm common/icons/info.xpm common/icons/key.xpm common/icons/label.xpm common/icons/lock.xpm common/icons/mail.xpm common/icons/page-minus.xpm common/icons/page-plus.xpm common/icons/page.xpm common/icons/tag-gt.xpm common/icons/tag-minus.xpm common/icons/tag-plus.xpm common/icons/tag-type.xpm common/icons/tag-v.xpm common/icons/tag.xpm common/icons/unlock.xpm /sw/src/root-cedet-common-1.0beta1c-1/sw/share/cedet-common/icons
+ /usr/bin/install -m 755 -d /sw/src/root-cedet-common-1.0beta1c-1/sw/share/emacs/site-lisp/cedet- common
+ /usr/bin/install -m 644 common/cedet-autogen.el common/cedet-compat.el common/cedet-load.el common/cedet-loaddefs.el common/cedet.el common/ezimage.el common/inversion.el common/pprint.el common/sformat.el common/working.el /sw/src/root-cedet-common-1.0beta1c-1/sw/share/emacs/site-lisp/cedet- common
+ /usr/bin/install -m 755 -d /sw/src/root-cedet-common-1.0beta1c-1/sw/lib/emacsen-common/packages/ install
+ /usr/bin/install -m 755 common/fink/emacsen-install /sw/src/root-cedet-common-1.0beta1c-1/sw/lib/emacsen-common/packages/ install/cedet-common
install: common/fink/emacsen-install: No such file or directory

Instead of:

/bin/rm -rf /sw/src/root-cedet-common-1.0beta1c-1
/bin/mkdir -p /sw/src/root-cedet-common-1.0beta1c-1/sw
/bin/mkdir -p /sw/src/root-cedet-common-1.0beta1c-1/DEBIAN
/usr/bin/install -m 755 -d /sw/src/root-cedet-common-1.0beta1c-1/sw/share/cedet-common/icons
/usr/bin/install -m 644 common/icons/* /sw/src/root-cedet-common-1.0beta1c-1/sw/share/cedet-common/icons
/usr/bin/install -m 755 -d /sw/src/root-cedet-common-1.0beta1c-1/sw/share/emacs/site-lisp/cedet- common
/usr/bin/install -m 644 common/*.el /sw/src/root-cedet-common-1.0beta1c-1/sw/share/emacs/site-lisp/cedet- common
/usr/bin/install -m 755 -d /sw/src/root-cedet-common-1.0beta1c-1/sw/lib/emacsen-common/packages/ install
/usr/bin/install -m 755 common/fink/emacsen-install /sw/src/root-cedet-common-1.0beta1c-1/sw/lib/emacsen-common/packages/ install/cedet-common
install: common/fink/emacsen-install: No such file or directory

While I was there, I found the following 2 lines at the top of
execute_script:

$script =~ s/[\r\n]+$//s; # Remove empty lines
$script =~ s/^\s*//; # Remove white spaces from the
start of each line

Neither of these lines works. The first one only deletes blank lines at
the end of the script, while the second only removes white space from
the first line.

So, I just deleted them. Blank lines, and leading white space are
correctly handled anyway.

Luckily, Mac BSD seems to ignore the leading space in the first line
of a script (i.e., " #!/bin/sh"). It's not really correct to write
that, however; 'file' will report the script as only "ASCII text". We
should probably remove the whitespace in that line when dumping to the
tempfile. Also, what about if a *Script has blank lines at the beginning?
InstallScript: <<


#!/bin/bash -ex ... <<

The existing leading-whitespace regex, though mis-commented, has the
effect of removing these.

Actually by the time the script gets here, all leading blank lines have been stripped (apart from a leading '\n' character). The second regex deletes this '\n' and any whitespace before the "#!". The first regex only deletes trailing blank lines.

I find the incorrectly commented, and redundant regexes very confusing, and would prefer to remove them. I'd also like to get my one line change that allows folding of lines in.

So I've come up with the following:

• Remove these regexes
• When checking for "#!" allow leading whitespace
  - If "#!" strip leading whitespace on first line only
  - Otherwise, unfold lines and strip leading whitespace on all lines.

This should work for all existing "#!" scripts, allows folding of lines, and cleans up the output. (It used to indent all lines of a script other than the first.)

Here's a new patch:


Attachment: Services.pm.patch
Description: Binary data



--
Rohan Lloyd

Reply via email to