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|listall [--utc]"
63 echo " listcounters|resetcounters [name]"
64 echo " leases [<poolname> [<address>]]"
65 echo " rereadsecrets|rereadgroups"
66 echo " rereadcacerts|rereadaacerts|rereadocspcerts"
67 echo " rereadacerts|rereadcrls|rereadall"
68 echo " purgeocsp|purgecrls|purgecerts|purgeike"
76 echo "Some of these functions have their own manual pages, e.g. ipsec_scepclient(8)."
91 copyright|--copyright)
93 # and fall through, invoking "ipsec _copyright"
99 echo "Usage: $IPSEC_SCRIPT down <connection name>"
103 if [ -e $IPSEC_CHARON_PID ]
105 $IPSEC_STROKE down "$1"
114 echo "Usage: $IPSEC_SCRIPT down-srcip <start> [<end>]"
118 if [ -e $IPSEC_CHARON_PID ]
120 $IPSEC_STROKE down-srcip $*
125 listcards|rereadgroups)
128 if [ -e $IPSEC_CHARON_PID ]
139 if [ -e $IPSEC_CHARON_PID ]
142 0) $IPSEC_STROKE "$op" ;;
143 1) $IPSEC_STROKE "$op" "$1" ;;
144 *) $IPSEC_STROKE "$op" "$1" "$2" ;;
150 listalgs|listpubkeys|listplugins|\
151 listcerts|listcacerts|listaacerts|\
152 listacerts|listgroups|listocspcerts|\
153 listcainfos|listcrls|listocsp|listall|\
154 rereadsecrets|rereadcacerts|rereadaacerts|\
155 rereadacerts|rereadocspcerts|rereadcrls|\
156 rereadall|purgeocsp|listcounters|resetcounters)
160 if [ -e $IPSEC_CHARON_PID ]
162 $IPSEC_STROKE "$op" "$@"
167 purgeike|purgecrls|purgecerts)
169 if [ -e $IPSEC_CHARON_PID ]
178 if [ -e $IPSEC_STARTER_PID ]
180 echo "Reloading strongSwan IPsec configuration..." >&2
181 kill -USR1 `cat $IPSEC_STARTER_PID` 2>/dev/null && rc=0
183 echo "Reloading strongSwan IPsec failed: starter is not running" >&2
188 $IPSEC_SBINDIR/$IPSEC_SCRIPT stop
191 exec $IPSEC_SBINDIR/$IPSEC_SCRIPT start "$@"
199 echo "Usage: $IPSEC_SCRIPT $op <connection name>"
202 if [ -e $IPSEC_CHARON_PID ]
204 $IPSEC_STROKE "$op" "$1"
211 if [ -e $IPSEC_CHARON_PID ]
213 $IPSEC_STROKE rereadsecrets
220 if [ -d /var/lock/subsys ]; then
221 touch /var/lock/subsys/ipsec
223 exec $IPSEC_STARTER "$@"
227 # Return value is slightly different for the status command:
228 # 0 - service up and running
229 # 1 - service dead, but /var/run/ pid file exists
230 # 2 - service dead, but /var/lock/ lock file exists
231 # 3 - service not running (unused)
232 # 4 - service status unknown :-(
233 # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
237 if [ -e $IPSEC_CHARON_PID ]
242 if [ -e $IPSEC_CHARON_PID ]
244 $IPSEC_STROKE "$op" "$1"
247 if [ -e $IPSEC_STARTER_PID ]
249 kill -0 `cat $IPSEC_STARTER_PID` 2>/dev/null
255 # stopping a not-running service is considered as success
256 if [ -e $IPSEC_STARTER_PID ]
258 echo "Stopping strongSwan IPsec..." >&2
259 spid=`cat $IPSEC_STARTER_PID`
262 kill $spid 2>/dev/null
264 while [ $loop -gt 0 ] ; do
265 kill -0 $spid 2>/dev/null || break
271 kill -KILL $spid 2>/dev/null
272 rm -f $IPSEC_STARTER_PID
276 echo "Stopping strongSwan IPsec failed: starter is not running" >&2
278 if [ -d /var/lock/subsys ]; then
279 rm -f /var/lock/subsys/ipsec
287 echo "Usage: $IPSEC_SCRIPT up <connection name>"
291 if [ -e $IPSEC_CHARON_PID ]
293 $IPSEC_STROKE up "$1"
299 if [ -e $IPSEC_STARTER_PID ]
301 echo "Updating strongSwan IPsec configuration..." >&2
302 kill -HUP `cat $IPSEC_STARTER_PID`
305 echo "Updating strongSwan IPsec failed: starter is not running" >&2
310 printf "$OS_NAME $IPSEC_NAME $IPSEC_VERSION\n"
311 printf "$IPSEC_DISTRO\n"
312 printf "See '$IPSEC_SCRIPT --copyright' for copyright information.\n"
316 echo "$0: unknown option \`$1' (perhaps command name was omitted?)" >&2
324 path="$IPSEC_DIR/$cmd"
328 path="$IPSEC_DIR/$cmd"
331 echo "$0: unknown IPsec command \`$cmd' (\`$IPSEC_SCRIPT --help' for list)" >&2