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
17 # define a minimum PATH environment in case it is not set
18 PATH="/sbin:/bin:/usr/sbin:/usr/bin:@IPSEC_SBINDIR@"
21 # name and version of the ipsec implementation
23 IPSEC_NAME="@IPSEC_NAME@"
24 IPSEC_VERSION="U@IPSEC_VERSION@/K`uname -r`"
26 # where the private directory and the config files are
27 IPSEC_DIR="@IPSEC_DIR@"
28 IPSEC_SBINDIR="@IPSEC_SBINDIR@"
29 IPSEC_CONFDIR="@IPSEC_CONFDIR@"
30 IPSEC_PIDDIR="@IPSEC_PIDDIR@"
31 IPSEC_SCRIPT="@IPSEC_SCRIPT@"
33 IPSEC_STARTER_PID="${IPSEC_PIDDIR}/starter.pid"
34 IPSEC_CHARON_PID="${IPSEC_PIDDIR}/charon.pid"
36 IPSEC_STROKE="${IPSEC_DIR}/stroke"
37 IPSEC_STARTER="${IPSEC_DIR}/starter"
39 export IPSEC_DIR IPSEC_SBINDIR IPSEC_CONFDIR IPSEC_PIDDIR IPSEC_SCRIPT IPSEC_VERSION IPSEC_NAME IPSEC_STARTER_PID IPSEC_CHARON_PID
41 IPSEC_DISTRO="Institute for Internet Technologies and Applications\nUniversity of Applied Sciences Rapperswil, Switzerland"
45 echo "Usage: $IPSEC_SCRIPT command argument ..."
46 echo "Use --help for list of commands, or see $IPSEC_SCRIPT(8) manual "
47 echo "page or the $IPSEC_NAME documentation for names of the common "
49 echo "See <http://www.strongswan.org> for more general info."
53 echo "Usage: $IPSEC_SCRIPT command argument ..."
54 echo "where command is one of:"
55 echo " start|restart arguments..."
56 echo " update|reload|stop"
57 echo " up|down|route|unroute <connectionname>"
58 echo " status|statusall [<connectionname>]"
59 echo " listalgs|listpubkeys|listcerts [--utc]"
60 echo " listcacerts|listaacerts|listocspcerts [--utc]"
61 echo " listacerts|listgroups|listcainfos [--utc]"
62 echo " listcrls|listocsp|listcards|listplugins|listcounters|listall [--utc]"
63 echo " leases [<poolname> [<address>]]"
64 echo " rereadsecrets|rereadgroups"
65 echo " rereadcacerts|rereadaacerts|rereadocspcerts"
66 echo " rereadacerts|rereadcrls|rereadall"
67 echo " purgeocsp|purgecrls|purgecerts|purgeike"
75 echo "Some of these functions have their own manual pages, e.g. ipsec_scepclient(8)."
90 copyright|--copyright)
92 # and fall through, invoking "ipsec _copyright"
98 echo "Usage: $IPSEC_SCRIPT down <connection name>"
102 if [ -e $IPSEC_CHARON_PID ]
104 $IPSEC_STROKE down "$1"
113 echo "Usage: $IPSEC_SCRIPT down-srcip <start> [<end>]"
117 if [ -e $IPSEC_CHARON_PID ]
119 $IPSEC_STROKE down-srcip $*
124 listcards|rereadgroups)
127 if [ -e $IPSEC_CHARON_PID ]
138 if [ -e $IPSEC_CHARON_PID ]
141 0) $IPSEC_STROKE "$op" ;;
142 1) $IPSEC_STROKE "$op" "$1" ;;
143 *) $IPSEC_STROKE "$op" "$1" "$2" ;;
149 listalgs|listpubkeys|listplugins|\
150 listcerts|listcacerts|listaacerts|\
151 listacerts|listgroups|listocspcerts|\
152 listcainfos|listcrls|listocsp|listcounters|listall|\
153 rereadsecrets|rereadcacerts|rereadaacerts|\
154 rereadacerts|rereadocspcerts|rereadcrls|\
159 if [ -e $IPSEC_CHARON_PID ]
161 $IPSEC_STROKE "$op" "$@"
166 purgeike|purgecrls|purgecerts)
168 if [ -e $IPSEC_CHARON_PID ]
177 if [ -e $IPSEC_STARTER_PID ]
179 echo "Reloading strongSwan IPsec configuration..." >&2
180 kill -USR1 `cat $IPSEC_STARTER_PID` 2>/dev/null && rc=0
182 echo "Reloading strongSwan IPsec failed: starter is not running" >&2
187 $IPSEC_SBINDIR/$IPSEC_SCRIPT stop
190 exec $IPSEC_SBINDIR/$IPSEC_SCRIPT start "$@"
198 echo "Usage: $IPSEC_SCRIPT $op <connection name>"
201 if [ -e $IPSEC_CHARON_PID ]
203 $IPSEC_STROKE "$op" "$1"
210 if [ -e $IPSEC_CHARON_PID ]
212 $IPSEC_STROKE rereadsecrets
219 if [ -d /var/lock/subsys ]; then
220 touch /var/lock/subsys/ipsec
222 exec $IPSEC_STARTER "$@"
226 # Return value is slightly different for the status command:
227 # 0 - service up and running
228 # 1 - service dead, but /var/run/ pid file exists
229 # 2 - service dead, but /var/lock/ lock file exists
230 # 3 - service not running (unused)
231 # 4 - service status unknown :-(
232 # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
236 if [ -e $IPSEC_CHARON_PID ]
241 if [ -e $IPSEC_CHARON_PID ]
243 $IPSEC_STROKE "$op" "$1"
246 if [ -e $IPSEC_STARTER_PID ]
248 kill -0 `cat $IPSEC_STARTER_PID` 2>/dev/null
254 # stopping a not-running service is considered as success
255 if [ -e $IPSEC_STARTER_PID ]
257 echo "Stopping strongSwan IPsec..." >&2
258 spid=`cat $IPSEC_STARTER_PID`
261 kill $spid 2>/dev/null
263 while [ $loop -gt 0 ] ; do
264 kill -0 $spid 2>/dev/null || break
270 kill -KILL $spid 2>/dev/null
271 rm -f $IPSEC_STARTER_PID
275 echo "Stopping strongSwan IPsec failed: starter is not running" >&2
277 if [ -d /var/lock/subsys ]; then
278 rm -f /var/lock/subsys/ipsec
286 echo "Usage: $IPSEC_SCRIPT up <connection name>"
290 if [ -e $IPSEC_CHARON_PID ]
292 $IPSEC_STROKE up "$1"
298 if [ -e $IPSEC_STARTER_PID ]
300 echo "Updating strongSwan IPsec configuration..." >&2
301 kill -HUP `cat $IPSEC_STARTER_PID`
304 echo "Updating strongSwan IPsec failed: starter is not running" >&2
309 printf "$OS_NAME $IPSEC_NAME $IPSEC_VERSION\n"
310 printf "$IPSEC_DISTRO\n"
311 printf "See '$IPSEC_SCRIPT --copyright' for copyright information.\n"
315 echo "$0: unknown option \`$1' (perhaps command name was omitted?)" >&2
323 path="$IPSEC_DIR/$cmd"
327 path="$IPSEC_DIR/$cmd"
330 echo "$0: unknown IPsec command \`$cmd' (\`$IPSEC_SCRIPT --help' for list)" >&2