#!/bin/sh export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/mod/sbin:/mod/bin:/mod/usr/sbin:/mod/usr/bin export LD_LIBRARY_PATH=/mod/lib:/mod/usr/lib DAEMON=tor . /etc/init.d/modlibrc start() { mkdir -p /mod/etc/$DAEMON [ -d $TOR_DATADIRECTORY ] || mkdir $TOR_DATADIRECTORY chown tor:tor $TOR_DATADIRECTORY -R chmod 0700 $TOR_DATADIRECTORY -R touch /var/run/tor.pid chown tor:tor /var/run/tor.pid if [ "$TOR_RELAY_ENABLED" = "yes" ] && [ -e "/tmp/flash/.tor/secret_id_key" ] && [ ! -e $TOR_DATADIRECTORY/keys/secret_id_key ]; then mkdir -p $TOR_DATADIRECTORY/keys ln -s /tmp/flash/.tor/secret_id_key $TOR_DATADIRECTORY/keys/secret_id_key chown tor:tor $TOR_DATADIRECTORY/keys -R fi ( if [ -x "/tmp/flash/${DAEMON}_conf" ]; then /tmp/flash/${DAEMON}_conf else /mod/etc/default.$DAEMON/${DAEMON}_conf fi ) > /mod/etc/$DAEMON/torrc echo -n 'Starting Tor Proxy...' $DAEMON --runasdaemon 1 --log "notice syslog" --pidfile /var/run/tor.pid > /dev/null 2>&1 exitval=$? if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi } stop() { . /mod/etc/conf/$DAEMON.cfg modlib_stop if [ ! -e "/tmp/flash/.tor/secret_id_key" ] && [-e $TOR_DATADIRECTORY/keys/secret_id_key ]; then [ -d "/tmp/flash/.tor" ] || mkdir /tmp/flash/.tor cp $TOR_DATADIRECTORY/keys/secret_id_key /tmp/flash/.tor/secret_id_key /usr/bin/modsave flash fi if [ "$TOR_DATADIRPERSISTENT" = "no" ]; then rm -rf $TOR_DATADIRECTORY fi rm -rf /mod/etc/$DAEMON } case "$1" in ""|load) modlib_addgroup tor modlib_adduser tor -G tor -D -S -g "Tor Router" modreg cgi 'tor' 'Tor Onion Router' deffile='/mod/etc/default.tor/secret_id_key.def' modreg file 'secret_id_key' 'Tor: Secret ID Key' 0 "$deffile" if [ "$TOR_ENABLED" != "yes" ]; then echo "$DAEMON is disabled" 1>&2 exit 1; fi if [ -e "/var/run/$DAEMON.pid" ]; then echo "$DAEMON already started." else start fi ;; unload) stop modunreg file 'secret_id_key' modunreg cgi 'tor' ;; start) start ;; stop) stop ;; restart) stop sleep 10 start ;; status) modlib_status ;; *) echo "Usage: $0 [load|unload|start|stop|restart|status]" 1>&2 exit 1 ;; esac exit 0