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@"
22 [ -z "$DAEMON_NAME" ] && DAEMON_NAME="charon"
24 # name and version of the ipsec implementation
26 IPSEC_NAME="@IPSEC_NAME@"
27 IPSEC_VERSION="U@IPSEC_VERSION@/K`uname -r`"
29 # where the private directory and the config files are
30 IPSEC_DIR="@IPSEC_DIR@"
31 IPSEC_SBINDIR="@IPSEC_SBINDIR@"
32 IPSEC_CONFDIR="@IPSEC_CONFDIR@"
33 IPSEC_PIDDIR="@IPSEC_PIDDIR@"
34 IPSEC_SCRIPT="@IPSEC_SCRIPT@"
36 IPSEC_STARTER_PID="${IPSEC_PIDDIR}/starter.${DAEMON_NAME}.pid"
37 IPSEC_CHARON_PID="${IPSEC_PIDDIR}/${DAEMON_NAME}.pid"
39 IPSEC_STROKE="${IPSEC_DIR}/stroke"
40 IPSEC_STARTER="${IPSEC_DIR}/starter"
42 export IPSEC_DIR IPSEC_SBINDIR IPSEC_CONFDIR IPSEC_PIDDIR IPSEC_SCRIPT IPSEC_VERSION IPSEC_NAME IPSEC_STARTER_PID IPSEC_CHARON_PID
44 IPSEC_DISTRO="Institute for Internet Technologies and Applications\nUniversity of Applied Sciences Rapperswil, Switzerland"
48 echo "Usage: $IPSEC_SCRIPT command argument ..."
49 echo "Use --help for list of commands, or see $IPSEC_SCRIPT(8) manual "
50 echo "page or the $IPSEC_NAME documentation for names of the common "
52 echo "See <http://www.strongswan.org> for more general info."
56 echo "Usage: $IPSEC_SCRIPT command argument ..."
57 echo "where command is one of:"
58 echo " start|restart arguments..."
59 echo " update|reload|stop"
60 echo " up|down|route|unroute <connectionname>"
61 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|listplugins|listall [--utc]"
66 echo " listcounters|resetcounters [name]"
67 echo " leases [<poolname> [<address>]]"
68 echo " rereadsecrets|rereadgroups"
69 echo " rereadcacerts|rereadaacerts|rereadocspcerts"
70 echo " rereadacerts|rereadcrls|rereadall"
71 echo " purgeocsp|purgecrls|purgecerts|purgeike"
79 echo "Some of these functions have their own manual pages, e.g. ipsec_scepclient(8)."
94 copyright|--copyright)
96 # and fall through, invoking "ipsec _copyright"
102 echo "Usage: $IPSEC_SCRIPT down <connection name>"
106 if [ -e $IPSEC_CHARON_PID ]
108 $IPSEC_STROKE down "$1"
117 echo "Usage: $IPSEC_SCRIPT down-srcip <start> [<end>]"
121 if [ -e $IPSEC_CHARON_PID ]
123 $IPSEC_STROKE down-srcip $*
128 listcards|rereadgroups)
131 if [ -e $IPSEC_CHARON_PID ]
142 if [ -e $IPSEC_CHARON_PID ]
145 0) $IPSEC_STROKE "$op" ;;
146 1) $IPSEC_STROKE "$op" "$1" ;;
147 *) $IPSEC_STROKE "$op" "$1" "$2" ;;
153 listalgs|listpubkeys|listplugins|\
154 listcerts|listcacerts|listaacerts|\
155 listacerts|listgroups|listocspcerts|\
156 listcainfos|listcrls|listocsp|listall|\
157 rereadsecrets|rereadcacerts|rereadaacerts|\
158 rereadacerts|rereadocspcerts|rereadcrls|\
159 rereadall|purgeocsp|listcounters|resetcounters)
163 if [ -e $IPSEC_CHARON_PID ]
165 $IPSEC_STROKE "$op" "$@"
170 purgeike|purgecrls|purgecerts)
172 if [ -e $IPSEC_CHARON_PID ]
181 if [ -e $IPSEC_STARTER_PID ]
183 echo "Reloading strongSwan IPsec configuration..." >&2
184 kill -USR1 `cat $IPSEC_STARTER_PID` 2>/dev/null && rc=0
186 echo "Reloading strongSwan IPsec failed: starter is not running" >&2
191 $IPSEC_SBINDIR/$IPSEC_SCRIPT stop
194 exec $IPSEC_SBINDIR/$IPSEC_SCRIPT start "$@"
202 echo "Usage: $IPSEC_SCRIPT $op <connection name>"
205 if [ -e $IPSEC_CHARON_PID ]
207 $IPSEC_STROKE "$op" "$1"
214 if [ -e $IPSEC_CHARON_PID ]
216 $IPSEC_STROKE rereadsecrets
223 if [ -d /var/lock/subsys ]; then
224 touch /var/lock/subsys/ipsec
226 exec $IPSEC_STARTER --daemon $DAEMON_NAME "$@"
230 # Return value is slightly different for the status command:
231 # 0 - service up and running
232 # 1 - service dead, but /var/run/ pid file exists
233 # 2 - service dead, but /var/lock/ lock file exists
234 # 3 - service not running (unused)
235 # 4 - service status unknown :-(
236 # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
240 if [ -e $IPSEC_CHARON_PID ]
245 if [ -e $IPSEC_CHARON_PID ]
247 $IPSEC_STROKE "$op" "$1"
250 if [ -e $IPSEC_STARTER_PID ]
252 kill -0 `cat $IPSEC_STARTER_PID` 2>/dev/null
258 # stopping a not-running service is considered as success
259 if [ -e $IPSEC_STARTER_PID ]
261 echo "Stopping strongSwan IPsec..." >&2
262 spid=`cat $IPSEC_STARTER_PID`
265 kill $spid 2>/dev/null
267 while [ $loop -gt 0 ] ; do
268 kill -0 $spid 2>/dev/null || break
274 kill -KILL $spid 2>/dev/null
275 rm -f $IPSEC_STARTER_PID
279 echo "Stopping strongSwan IPsec failed: starter is not running" >&2
281 if [ -d /var/lock/subsys ]; then
282 rm -f /var/lock/subsys/ipsec
290 echo "Usage: $IPSEC_SCRIPT up <connection name>"
294 if [ -e $IPSEC_CHARON_PID ]
296 $IPSEC_STROKE up "$1"
302 if [ -e $IPSEC_STARTER_PID ]
304 echo "Updating strongSwan IPsec configuration..." >&2
305 kill -HUP `cat $IPSEC_STARTER_PID`
308 echo "Updating strongSwan IPsec failed: starter is not running" >&2
313 printf "$OS_NAME $IPSEC_NAME $IPSEC_VERSION\n"
314 printf "$IPSEC_DISTRO\n"
315 printf "See '$IPSEC_SCRIPT --copyright' for copyright information.\n"
319 echo "$0: unknown option \`$1' (perhaps command name was omitted?)" >&2
327 path="$IPSEC_DIR/$cmd"
331 path="$IPSEC_DIR/$cmd"
334 echo "$0: unknown IPsec command \`$cmd' (\`$IPSEC_SCRIPT --help' for list)" >&2