2 # prefix command to run stuff from our programs directory
3 # Copyright (C) 1998-2002 Henry Spencer.
4 # Copyright (C) 2006 Andreas Steffen
5 # Copyright (C) 2006 Martin Willi
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; either version 2 of the License, or (at your
10 # option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 # define a minimum PATH environment in case it is not set
20 PATH="/sbin:/bin:/usr/sbin:/usr/bin:@IPSEC_SBINDIR@"
23 # name and version of the ipsec implementation
24 IPSEC_NAME="@IPSEC_NAME@"
25 IPSEC_VERSION="U@IPSEC_VERSION@/K`uname -r`"
27 # where the private directory and the config files are
28 IPSEC_DIR="@IPSEC_DIR@"
29 IPSEC_SBINDIR="@IPSEC_SBINDIR@"
30 IPSEC_CONFDIR="@IPSEC_CONFDIR@"
31 IPSEC_PIDDIR="@IPSEC_PIDDIR@"
33 IPSEC_STARTER_PID="${IPSEC_PIDDIR}/starter.pid"
34 IPSEC_PLUTO_PID="${IPSEC_PIDDIR}/pluto.pid"
35 IPSEC_CHARON_PID="${IPSEC_PIDDIR}/charon.pid"
37 IPSEC_WHACK="${IPSEC_DIR}/whack"
38 IPSEC_STROKE="${IPSEC_DIR}/stroke"
39 IPSEC_STARTER="${IPSEC_DIR}/starter"
41 export IPSEC_DIR IPSEC_SBINDIR IPSEC_CONFDIR IPSEC_PIDDIR IPSEC_VERSION IPSEC_NAME IPSEC_STARTER_PID IPSEC_PLUTO_PID IPSEC_CHARON_PID
43 IPSEC_DISTRO="Institute for Internet Technologies and Applications\nUniversity of Applied Sciences Rapperswil, Switzerland"
47 echo "Usage: ipsec command argument ..."
48 echo "Use --help for list of commands, or see ipsec(8) manual page"
49 echo "or the $IPSEC_NAME documentation for names of the common ones."
50 echo "Most have their own manual pages, e.g. ipsec_auto(8)."
51 echo "See <http://www.strongswan.org> for more general info."
55 echo "Usage: ipsec command argument ..."
56 echo "where command is one of:"
57 echo " start|restart arguments..."
58 echo " update|reload|stop"
59 echo " up|down|route|unroute <connectionname>"
60 echo " status|statusall [<connectionname>]"
62 echo " listalgs|listpubkeys|listcerts [--utc]"
63 echo " listcacerts|listaacerts|listocspcerts [--utc]"
64 echo " listacerts|listgroups|listcainfos [--utc]"
65 echo " listcrls|listocsp|listcards|listall [--utc]"
66 echo " rereadsecrets|rereadgroups"
67 echo " rereadcacerts|rereadaacerts|rereadocspcerts"
68 echo " rereadacerts|rereadcrls|rereadall"
70 echo " scencrypt|scdecrypt <value> [--inbase <base>] [--outbase <base>] [--keyid <id>]"
80 echo "Some of these functions have their own manual pages, e.g. ipsec_scepclient(8)."
95 copyright|--copyright)
97 # and fall through, invoking "ipsec _copyright"
103 echo "Usage: ipsec down <connection name>"
107 if [ -e $IPSEC_PLUTO_PID ]
109 $IPSEC_WHACK --name "$1" --terminate
112 if [ -e $IPSEC_CHARON_PID ]
114 $IPSEC_STROKE down "$1"
119 listalgs|listpubkeys|\listcards|\rereadgroups)
122 if [ -e $IPSEC_PLUTO_PID ]
124 $IPSEC_WHACK "$@" "--$op"
127 if [ -e $IPSEC_CHARON_PID ]
135 listcerts|listcacerts|listaacerts|\
136 listacerts|listgroups|listocspcerts|\
137 listcainfos|listcrls|listocsp|listall|\
138 rereadsecrets|rereadcacerts|rereadaacerts|\
139 rereadacerts|rereadocspcerts|rereadcrls|\
144 if [ -e $IPSEC_PLUTO_PID ]
146 $IPSEC_WHACK "$@" "--$op"
149 if [ -e $IPSEC_CHARON_PID ]
151 $IPSEC_STROKE "$op" "$@"
158 if [ -e $IPSEC_PLUTO_PID ]
160 $IPSEC_WHACK --listen
168 if [ -e $IPSEC_STARTER_PID ]
170 echo "Reloading strongSwan IPsec configuration..." >&2
171 kill -s USR1 `cat $IPSEC_STARTER_PID` 2>/dev/null && rc=0
173 echo "Reloading strongSwan IPsec failed: starter is not running" >&2
178 $IPSEC_SBINDIR/ipsec stop
181 exec $IPSEC_SBINDIR/ipsec start "$@"
189 echo "Usage: ipsec $op <connection name>"
192 if [ -e $IPSEC_PLUTO_PID ]
194 $IPSEC_WHACK --name "$1" "--$op"
197 if [ -e $IPSEC_CHARON_PID ]
199 $IPSEC_STROKE "$op" "$1"
207 if [ -e $IPSEC_PLUTO_PID ]
209 $IPSEC_WHACK "--$op" "$@"
217 if [ -e $IPSEC_PLUTO_PID ]
219 $IPSEC_WHACK --rereadsecrets
222 if [ -e $IPSEC_CHARON_PID ]
224 $IPSEC_STROKE rereadsecrets
231 exec $IPSEC_STARTER "$@"
235 # Return value is slightly different for the status command:
236 # 0 - service up and running
237 # 1 - service dead, but /var/run/ pid file exists
238 # 2 - service dead, but /var/lock/ lock file exists
239 # 3 - service not running (unused)
240 # 4 - service status unknown :-(
241 # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
245 if [ -e $IPSEC_PLUTO_PID ]
249 if [ -e $IPSEC_CHARON_PID ]
254 if [ -e $IPSEC_PLUTO_PID ]
256 $IPSEC_WHACK --name "$1" "--$op"
258 if [ -e $IPSEC_CHARON_PID ]
260 $IPSEC_STROKE "$op" "$1"
263 if [ -e $IPSEC_STARTER_PID ]
265 kill -0 `cat $IPSEC_STARTER_PID` 2>/dev/null
271 # stopping a not-running service is considered as success
272 if [ -e $IPSEC_STARTER_PID ]
274 echo "Stopping strongSwan IPsec..." >&2
275 spid=`cat $IPSEC_STARTER_PID`
278 kill $spid 2>/dev/null
280 while [ $loop -gt 0 ] ; do
281 kill -s 0 $spid 2>/dev/null || break
287 kill -s KILL $spid 2>/dev/null
288 rm -f $IPSEC_STARTER_PID
292 echo "Stopping strongSwan IPsec failed: starter is not running" >&2
300 echo "Usage: ipsec up <connection name>"
304 if [ -e $IPSEC_PLUTO_PID ]
306 $IPSEC_WHACK --name "$1" --initiate
309 if [ -e $IPSEC_CHARON_PID ]
311 $IPSEC_STROKE up "$1"
317 if [ -e $IPSEC_STARTER_PID ]
319 echo "Updating strongSwan IPsec configuration..." >&2
320 kill -s HUP `cat $IPSEC_STARTER_PID`
323 echo "Updating strongSwan IPsec failed: starter is not running" >&2
328 echo "Linux $IPSEC_NAME $IPSEC_VERSION"
329 echo -e $IPSEC_DISTRO
330 echo "See \`ipsec --copyright' for copyright information."
334 echo "$0: unknown option \`$1' (perhaps command name was omitted?)" >&2
342 path="$IPSEC_DIR/$cmd"
346 path="$IPSEC_DIR/$cmd"
349 echo "$0: unknown IPsec command \`$cmd' (\`ipsec --help' for list)" >&2