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 -d %i/lib/emacsen-common/packages/install /usr/bin/install -m 755 common/fink/emacsen-install \ %i/lib/emacsen-common/packages/install/%n
Instead of:
/usr/bin/install -m 755 -d %i/lib/emacsen-common/packages/install
/usr/bin/install -m 755 common/fink/emacsen-install %i/lib/emacsen-common/packages/install/%n
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.
So I poked around in Services.pm and added code to Unfold multiline commands. It's a simple one line addition in execute_script
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.
I fixed these by changing them to:
$script =~ s/([\r\n])[\r\n]*/${1}/g; # Remove empty lines
$script =~ s/^\s*//mg; # Remove white spaces from the start of each line
But then after thinking about it, I'm not sure these should be done anyway.
These lines are executed before we have decided whether to execute line by line, or whether to save to a file and run through external command.
What if the script was a python script? By removing leading white space we would be changing the code, and break the script. So I decided to just remove them. However the I had to tweak the check for "#!" to allow white space before, in order to be backwards compatible.
So, I just deleted them. Blank lines, and leading white space are correctly handled anyway.
Attached is a patch that adds the line folding, and removes these broken lines.
So what do you think? Any problems with it? Can someone add it?
Thanks
Services.pm.patch
Description: Binary data
-- Rohan Lloyd