Initial sources of crywrap 0.2.1.
[crywrap.git] / etc / crywrap-init.d
blob76838832abf7198b80d901506d4c120b4f77eb0a
1 #! /bin/sh
2 ## /etc/init.d/crywrap -- init script for CryWrap
3 ## (Generic, used for Debian)
4 ##
5 ## arch-tag: 95d90d0c-199e-4f43-9bf3-33706a009a19
7 set -e
9 CRYWRAP=/usr/sbin/crywrap
10 CONFFILE=/etc/default/crywrap
11 PIDDIR=/var/run/crywrap
13 test -x ${CRYWRAP} || exit 0
15 ## Ignore starts here..
16 # crywrap_map_add dest listen
17 crywrap_map_add ()
19 SRC_PORT="$(echo $1 | sed -e 's,^.*/,,g')"
20 SRC_IP="$(echo $1 | sed -e 's,/.*,,g')"
21 DST_PORT="$(echo $2 | sed -e 's,^.*/,,g')"
22 DST_IP="$(echo $2 | sed -e 's,/.*,,g')"
24 CRYWRAP_MAP="${CRYWRAP_MAP}-d ${SRC_IP}/${SRC_PORT} -l ${DST_IP}/${DST_PORT}|"
26 CRYWRAP_MAP=
27 ## Unignore starts here :)
29 [ -e ${CONFFILE} ] && . ${CONFFILE}
31 crywrap_start ()
33 install -d -m 1777 ${PIDDIR}
34 cnt=0
35 IFS_SAVE="${IFS}"
36 IFS="|"
37 set -- ${CRYWRAP_MAP}
38 while [ "$#" -gt 0 ]; do
39 PC=""; PK=""
40 if [ ! -z "${CRYWRAP_CERTFILE}" ]; then
41 PC="cert=${CRYWRAP_CERTFILE}"
43 if [ ! -z "${CRYWRAP_KEYFILE}" ]; then
44 PK="key=${CRYWRAP_KEYFILE}"
46 P="${PC}${PC:+,}${PK}"
47 P="${P:+-p ${P}}"
48 CMDLINE="$1 -P ${PIDDIR}/crywrap-${cnt}.pid ${P} \
49 ${CRYWRAP_USER:+-u ${CRYWRAP_USER}} \
50 ${CRYWRAP_OPTIONS}"
51 cnt=$(expr ${cnt} + 1)
52 eval ${CRYWRAP} ${CMDLINE}
53 echo -n "."
54 shift
55 done
56 IFS="${IFS_SAVE}"
57 if [ "$cnt" -eq 0 ]; then
58 echo " - not started"
59 else
60 echo " done."
64 crywrap_stop ()
66 for PIDFILE in ${PIDDIR}/*; do
67 if [ -e ${PIDFILE} ]; then
68 PID=$(cat ${PIDFILE})
69 if [ ! -z "${PID}" ]; then
70 if kill -15 ${PID} >/dev/null 2>&1; then
71 echo -n "."
75 rm -f ${PIDFILE}
76 done
77 rm -rf ${PIDDIR}
80 case $1 in
81 start)
82 echo -n "Starting TLS wrapper: crywrap"
83 crywrap_start;;
84 stop)
85 echo -n "Stopping TLS wrapper: crywrap"
86 crywrap_stop
87 echo ".";;
88 restart|force-reload)
89 $0 stop
90 sleep 2
91 $0 start;;
93 echo "Usage: /etc/init.d/crywrap {start|stop|restart|force-reload}"
94 exit 1;;
95 esac
97 exit 0