2 # Pluto database-loading script
3 # Copyright (C) 1998, 1999, 2001 Henry Spencer.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2 of the License, or (at your
8 # option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # RCSID $Id: _plutoload,v 1.2 2001/10/31 01:39:03 henry Exp $
17 # exit status is 13 for protocol violation, that of Pluto otherwise
19 me='ipsec _plutoload' # for messages
24 --load) plutoload="$2" ; shift ;;
25 --start) plutostart="$2" ; shift ;;
26 --wait) plutowait="$2" ; shift ;;
27 --post) postpluto="$2" ; shift ;;
29 -*) echo "$me: unknown option \`$1'" >&2 ; exit 2 ;;
36 if test " $plutoload" = " %search"
38 eval `ipsec _confread --varprefix PLUTO --search auto add route start`
39 if test " $PLUTO_confreadstatus" != " "
41 echo "auto=add/route/start search: $PLUTO_confreadstatus"
42 echo "unable to determine what conns to add -- adding none"
45 plutoload="$PLUTO_confreadnames"
48 if test " $plutostart" = " %search"
50 eval `ipsec _confread --varprefix PLUTO --search auto route start`
51 if test " $PLUTO_confreadstatus" != " "
53 echo "auto=route/start search: $PLUTO_confreadstatus"
54 echo "unable to determine what conns to route -- routing none"
57 plutoroute="$PLUTO_confreadnames"
59 eval `ipsec _confread --varprefix PLUTO --search auto start`
60 if test " $PLUTO_confreadstatus" != " "
62 echo "auto=start search: $PLUTO_confreadstatus"
63 echo "unable to determine what conns to start -- starting none"
66 plutostart="$PLUTO_confreadnames"
70 # the way the searches were done ensures plutoload >= plutoroute >= plutostart
72 # await Pluto's readiness (not likely to be an issue, but...)
77 'Pluto initialized') eofed= ; break ;; # NOTE BREAK OUT
78 *) echo "pluto unexpectedly said \`$saying'" ;;
83 echo "pluto died unexpectedly!?!"
90 ipsec auto --add $tu ||
91 echo "...could not add conn \"$tu\""
97 # execute any post-startup cleanup
98 if test " $postpluto" != " "
104 echo "...postpluto command exited with status $st"
108 # quickly establish routing
109 for tu in $plutoroute
111 ipsec auto --route $tu ||
112 echo "...could not route conn \"$tu\""
115 # tunnel initiation, which may take a while
117 if test " $plutowait" = " no"
119 async="--asynchronous"
121 for tu in $plutostart
123 ipsec auto --up $async $tu ||
124 echo "...could not start conn \"$tu\""
127 # report any further utterances, and watch for exit status
132 exit) eofed= ; break ;; # NOTE BREAK OUT
133 *) echo "pluto unexpectedly says \`$saying'" ;;
138 echo "pluto died without exit status!?!"
145 echo "pluto yielded no exit status!?!"