1: # -*- perl -*-
2eval 'exec perl -wS $0 ${1+"$@"}'
3    if 0;
4# create setup self extracting script
5
6if( $#ARGV < 2 )
7  {
8    print <<ENDHELP;
9USAGE: $0 <inputshellscript> <libraryfile> <outputshellscript>
10    <inputshellscript>: the start shell script, located next to this perl script
11    <libraryfile>: the library file, that is included into the shell script
12    <outfile>: the target shellscript
13
14ENDHELP
15  exit;
16  }
17
18$infile		= $ARGV[0];
19$library	= $ARGV[1];
20$outfile	= $ARGV[2];
21$infile     =~ tr/[A-Z]/[a-z]/;
22
23# read script header
24open( SCRIPT, "<$infile" ) || die "cannot open $infile";
25open( OUTFILE, ">$outfile$$.tmp" ) || die "cannot open $outfile";
26@scriptlines = <SCRIPT>;
27$linenum = $#scriptlines+2;
28foreach (@scriptlines)
29{
30  # lineend conversion (be on the safe side)
31  chomp;
32  $_ =~ tr/\r//;
33  s/^\s*linenum=.*$/linenum=$linenum/;
34  print OUTFILE "$_\n";
35}
36close( SCRIPT );
37close( OUTFILE );
38
39system( "cat $library >>$outfile$$.tmp" );
40rename "$outfile$$.tmp", "$outfile";
41
42chmod 0775, $outfile;
43
44exit;
45