chiark / gitweb /
fixes
[inn-innduct.git] / support / fixscript.in
1 #! @_PATH_SH@
2
3 ##  $Id: fixscript.in 2805 1999-11-27 07:23:49Z rra $
4 ##
5 ##  Fix interpretor paths and INN variable load paths.
6 ##
7 ##  Scripts shipped with INN always have the invocation path for the
8 ##  interpretor on the first line and the command to load INN variable
9 ##  settings into the script on the second line.  For example, for a Bourne
10 ##  shell script:
11 ##
12 ##      #!/bin/sh
13 ##      . /var/news/lib/innshellvars
14 ##
15 ##  This script takes as input such a script and outputs the same script
16 ##  with the first two lines replaced to have the correct path to the
17 ##  interpretor and to the INN variable library, as determined by configure.
18 ##
19 ##  If the script is invoked with the -i flag, only fix the interpretor
20 ##  path and don't modify the second line of the file to include the
21 ##  appropriate innshellvars.
22
23 SED='@_PATH_SED@'
24
25 PERLPATH='@_PATH_PERL@'
26 SHPATH='@_PATH_SH@'
27 LIBDIR='@LIBDIR@'
28
29 options=true
30 addlib=true
31 while $options ; do
32     case X"$1" in
33     X-i) addlib=false  ;;
34     *)   options=false ;;
35     esac
36     $options && shift
37 done
38
39 input="$1"
40 if [ -z "$input" ] ; then
41     echo "No input file specified" >&2
42     exit 1
43 fi
44
45 output="$2"
46 if [ -z "$output" ] ; then
47     output=`echo "$input" | sed 's/\.in$//'`
48 fi
49 if [ x"$input" = x"$output" ] ; then
50     echo "No output file specified and input file doesn't end in .in" >&2
51     exit 1
52 fi
53
54 interpretor=`head -1 "$input"`
55 case "$interpretor" in
56 */sh|*SH*)
57     path="$SHPATH"
58     lib=". $LIBDIR/innshellvars"
59     ;;
60 */perl*|*PERL*)
61     path=`echo "$interpretor" | sed 's%^#! *[^ ][^ ]*%'"$PERLPATH%"`
62     lib="require '$LIBDIR/innshellvars.pl';"
63     ;;
64 *)
65     echo "Unknown interpretor $interpretor" >&2
66     exit 1
67     ;;
68 esac
69
70 echo "#! $path"          >  "$output"
71 if $addlib ; then
72     echo "$lib"          >> "$output"
73     "$SED" 1,2d "$input" >> "$output"
74 else
75     "$SED" 1d "$input"   >> "$output"
76 fi
77 chmod 755 "$output"