1cdf0e10cSrcweir: # -*- perl -*-
2cdf0e10cSrcweireval 'exec perl -wS $0 ${1+"$@"}'
3cdf0e10cSrcweir    if 0;
4*bb113e63SAndrew Rist# *************************************************************
5*bb113e63SAndrew Rist#
6*bb113e63SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
7*bb113e63SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
8*bb113e63SAndrew Rist#  distributed with this work for additional information
9*bb113e63SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
10*bb113e63SAndrew Rist#  to you under the Apache License, Version 2.0 (the
11*bb113e63SAndrew Rist#  "License"); you may not use this file except in compliance
12*bb113e63SAndrew Rist#  with the License.  You may obtain a copy of the License at
13*bb113e63SAndrew Rist#
14*bb113e63SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
15*bb113e63SAndrew Rist#
16*bb113e63SAndrew Rist#  Unless required by applicable law or agreed to in writing,
17*bb113e63SAndrew Rist#  software distributed under the License is distributed on an
18*bb113e63SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19*bb113e63SAndrew Rist#  KIND, either express or implied.  See the License for the
20*bb113e63SAndrew Rist#  specific language governing permissions and limitations
21*bb113e63SAndrew Rist#  under the License.
22*bb113e63SAndrew Rist#
23*bb113e63SAndrew Rist# *************************************************************
24cdf0e10cSrcweir# create setup self extracting script
25cdf0e10cSrcweir
26cdf0e10cSrcweirif( $#ARGV < 2 )
27cdf0e10cSrcweir  {
28cdf0e10cSrcweir    print <<ENDHELP;
29cdf0e10cSrcweirUSAGE: $0 <inputshellscript> <libraryfile> <outputshellscript>
30cdf0e10cSrcweir    <inputshellscript>: the start shell script, located next to this perl script
31cdf0e10cSrcweir    <libraryfile>: the library file, that is included into the shell script
32cdf0e10cSrcweir    <outfile>: the target shellscript
33cdf0e10cSrcweir
34cdf0e10cSrcweirENDHELP
35cdf0e10cSrcweir  exit;
36cdf0e10cSrcweir  }
37cdf0e10cSrcweir
38cdf0e10cSrcweir$infile		= $ARGV[0];
39cdf0e10cSrcweir$library	= $ARGV[1];
40cdf0e10cSrcweir$outfile	= $ARGV[2];
41cdf0e10cSrcweir$infile     =~ tr/[A-Z]/[a-z]/;
42cdf0e10cSrcweir
43cdf0e10cSrcweir# read script header
44cdf0e10cSrcweiropen( SCRIPT, "<$infile" ) || die "cannot open $infile";
45cdf0e10cSrcweiropen( OUTFILE, ">$outfile$$.tmp" ) || die "cannot open $outfile";
46cdf0e10cSrcweir@scriptlines = <SCRIPT>;
47cdf0e10cSrcweir$linenum = $#scriptlines+2;
48cdf0e10cSrcweirforeach (@scriptlines)
49cdf0e10cSrcweir{
50cdf0e10cSrcweir  # lineend conversion (be on the safe side)
51cdf0e10cSrcweir  chomp;
52cdf0e10cSrcweir  $_ =~ tr/\r//;
53cdf0e10cSrcweir  s/^\s*linenum=.*$/linenum=$linenum/;
54cdf0e10cSrcweir  print OUTFILE "$_\n";
55cdf0e10cSrcweir}
56cdf0e10cSrcweirclose( SCRIPT );
57cdf0e10cSrcweirclose( OUTFILE );
58cdf0e10cSrcweir
59cdf0e10cSrcweirsystem( "cat $library >>$outfile$$.tmp" );
60cdf0e10cSrcweirrename "$outfile$$.tmp", "$outfile";
61cdf0e10cSrcweir
62cdf0e10cSrcweirchmod 0775, $outfile;
63cdf0e10cSrcweir
64cdf0e10cSrcweirexit;
65