2012-04-14 16:22:27 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# /etc/init.d/piratebox
|
|
|
|
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: piratebox
|
2013-02-25 09:19:06 +01:00
|
|
|
# Required-Start: $all
|
|
|
|
# Required-Stop: $network $local_fs
|
2012-04-14 16:22:27 +02:00
|
|
|
# Default-Start: 2 3 4 5
|
2013-02-25 09:19:06 +01:00
|
|
|
# Default-Stop: 6 1 0
|
2012-04-14 16:22:27 +02:00
|
|
|
# Short-Description: All services around piratebox
|
|
|
|
# Description: Based on /opt/piratebox/conf/piratebox.conf starts: * DNSMASQ * HOSTAPD * DROOPY * WLAN-config * CHAT
|
|
|
|
### END INIT INFO
|
|
|
|
|
|
|
|
###
|
|
|
|
# Default start-stop script for piratebox services on a laptop
|
|
|
|
# written by Matthias Strubel (matthias.strubel@aod-rpg.de) 2011-02-22
|
|
|
|
# licenced by gpl, feel free to improve and send me comments
|
|
|
|
|
2012-04-14 18:47:27 +02:00
|
|
|
|
2012-04-14 16:22:27 +02:00
|
|
|
[ -f /etc/default/rcS ] && . /etc/default/rcS
|
|
|
|
|
|
|
|
# PATH for /opt piratebox folder
|
2013-07-02 12:21:10 +02:00
|
|
|
PATH=$PATH:/opt/piratebox/bin
|
2012-04-14 16:22:27 +02:00
|
|
|
|
2012-04-14 18:47:27 +02:00
|
|
|
PIDFILE_DROOPY=/var/run/piratebox_droopy.pid
|
2012-04-14 16:22:27 +02:00
|
|
|
PIDFILE_HOSTAPN=/var/run/piratebox_hostapn.pid
|
|
|
|
PIDFILE_DNSMASQ=/var/run/piratebox_dnsmasq.pid
|
2012-04-18 21:29:13 +02:00
|
|
|
PIDFILE_LIGHTTPD=/opt/piratebox/tmp/lighttpd.pid
|
2012-12-26 11:20:16 +01:00
|
|
|
PIDFILE_SHOUTBOX=/opt/piratebox/tmp/shoutbox_daemon.pid
|
|
|
|
|
2012-04-14 16:22:27 +02:00
|
|
|
|
|
|
|
PIRATEBOX=/opt/piratebox
|
|
|
|
CONF=$PIRATEBOX/conf/piratebox.conf
|
2012-04-14 18:47:27 +02:00
|
|
|
#CONF_DROOPY=/opt/piratebox/conf/droopy.conf #not used
|
2012-04-14 16:22:27 +02:00
|
|
|
CONF_APN=$PIRATEBOX/conf/hostapd.conf
|
|
|
|
|
|
|
|
#Some extra config files for dnsmasq
|
2012-06-09 09:55:15 +02:00
|
|
|
CONF_DNSMASQ=$PIRATEBOX/conf/dnsmasq_generated.conf
|
2012-04-14 16:22:27 +02:00
|
|
|
|
2012-04-14 19:26:42 +02:00
|
|
|
CONF_LIGHTTPD=$PIRATEBOX/conf/lighttpd/lighttpd.conf
|
2012-04-14 16:22:27 +02:00
|
|
|
|
2012-12-26 09:51:59 +01:00
|
|
|
export PYTHONPATH=:$PYTHONPATH:$PIRATEBOX_PYTHONPATH
|
2012-11-01 19:39:37 +01:00
|
|
|
|
2012-04-14 16:22:27 +02:00
|
|
|
if [ -f $CONF ] ; then
|
|
|
|
. $CONF
|
|
|
|
else
|
|
|
|
echo "Configuration file not found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-04-14 18:47:27 +02:00
|
|
|
#If you can't find this file
|
2012-06-09 15:33:50 +02:00
|
|
|
if [[ -f $PIRATEBOX/conf/init_done ]] ; then
|
2012-04-14 18:47:27 +02:00
|
|
|
INIT=OK
|
|
|
|
else
|
2012-06-15 17:59:19 +02:00
|
|
|
$PIRATEBOX/bin/hooks/hook_pre_init.sh "$CONF"
|
2012-04-14 18:47:27 +02:00
|
|
|
$PIRATEBOX/bin/install_piratebox.sh "$CONF" part2
|
2012-06-15 17:59:19 +02:00
|
|
|
$PIRATEBOX/bin/hooks/hook_post_init.sh "$CONF"
|
2012-09-28 12:01:12 +02:00
|
|
|
touch $PIRATEBOX/conf/init_done
|
2012-04-14 18:47:27 +02:00
|
|
|
fi
|
|
|
|
|
2012-06-09 09:55:15 +02:00
|
|
|
|
|
|
|
# Command Line for DNSMASQ, use extra config file generated from command above
|
2012-06-09 10:04:42 +02:00
|
|
|
CMD_DNSMASQ="-x $PIDFILE_DNSMASQ -C $CONF_DNSMASQ "
|
2012-04-14 16:22:27 +02:00
|
|
|
|
|
|
|
# Carry out specific functions when asked to by the system
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
echo "Starting script piratebox "
|
|
|
|
|
2012-06-15 18:59:31 +02:00
|
|
|
# Generate hosts & dnsmasq file
|
|
|
|
$PIRATEBOX/bin/generate_config_files.sh "$CONF"
|
|
|
|
|
|
|
|
$PIRATEBOX/bin/hooks/hook_piratebox_start.sh "$CONF"
|
2012-06-15 17:59:19 +02:00
|
|
|
|
2012-04-18 21:29:13 +02:00
|
|
|
echo "Empty tmp folder"
|
2012-04-27 06:58:32 +02:00
|
|
|
find $PIRATEBOX/tmp/ -exec rm {} \;
|
|
|
|
|
2012-04-18 21:29:13 +02:00
|
|
|
|
2012-04-14 18:47:27 +02:00
|
|
|
if [ "$DO_IW" = "yes" ] ; then
|
|
|
|
log_daemon_msg " Setting up Interface (iw) "
|
|
|
|
iw $PHY_IF interface add $INTERFACE type managed
|
|
|
|
fi
|
|
|
|
|
2013-03-22 18:06:43 +01:00
|
|
|
if [ "$PROBE_INTERFACE" = yes ] ; then
|
|
|
|
echo " Probe wlan"
|
2012-04-14 16:22:27 +02:00
|
|
|
#Setting up WLAN Interface
|
2013-03-22 18:06:43 +01:00
|
|
|
piratebox_setup_wlan.sh $CONF probe
|
2012-04-14 16:22:27 +02:00
|
|
|
fi
|
|
|
|
if [ $? -ne 0 ] ; then
|
2013-03-22 18:06:43 +01:00
|
|
|
echo "failed probing Interface"
|
2012-04-14 16:22:27 +02:00
|
|
|
else
|
|
|
|
|
|
|
|
# Only activate
|
|
|
|
if [ "$USE_APN" = "yes" ] ; then
|
|
|
|
echo "Starting hostap... "
|
|
|
|
start-stop-daemon -m -S -b -p $PIDFILE_HOSTAPN -x /usr/sbin/hostapd -- $CONF_APN
|
2012-04-14 18:47:27 +02:00
|
|
|
echo $?
|
2012-04-14 16:22:27 +02:00
|
|
|
fi
|
|
|
|
|
2013-03-22 18:06:43 +01:00
|
|
|
if [ "$DO_IFCONFIG" = yes ] ; then
|
|
|
|
echo " Setting up wlan"
|
|
|
|
#Setting up WLAN Interface
|
|
|
|
piratebox_setup_wlan.sh $CONF start
|
|
|
|
if [ $? -ne 0 ] ; then
|
|
|
|
echo "failed setting up Interface"
|
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
fi
|
2012-04-14 16:22:27 +02:00
|
|
|
#BRIDGE
|
2012-04-14 18:47:27 +02:00
|
|
|
if [ "$DO_BRIDGE" = "yes" ] ; then
|
2012-04-14 19:26:42 +02:00
|
|
|
echo "Adding $INTERFACE to bridge $BRIDGE // brctl addif $BRIDGE $INTERFACE "
|
2012-04-14 16:22:27 +02:00
|
|
|
sleep 1
|
|
|
|
BR_CMD="brctl addif $BRIDGE $INTERFACE"
|
|
|
|
( $BR_CMD ; )
|
|
|
|
if [ $? -ne 0 ] ; then
|
|
|
|
echo "failed :( "
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$USE_DNSMASQ" = "yes" ] ; then
|
|
|
|
echo "Starting dnsmasq... "
|
|
|
|
# pidfile is written by dnsmasq
|
|
|
|
start-stop-daemon -S -q -x /usr/sbin/dnsmasq -- $CMD_DNSMASQ
|
2012-04-14 18:47:27 +02:00
|
|
|
echo $?
|
|
|
|
fi
|
|
|
|
|
2012-06-15 18:09:03 +02:00
|
|
|
if [ "$DROOPY_ENABLED" = "yes" ] ; then
|
|
|
|
#Start here the PirateBox-Parts droopy i.e.
|
|
|
|
echo "Starting droopy..."
|
|
|
|
find $UPLOADFOLDER/ -iname tmp\* -exec rm {} \;
|
|
|
|
#Delete 0 Byte Files
|
|
|
|
delete_empty.sh $UPLOADFOLDER
|
|
|
|
|
|
|
|
DROOPY_USER=""
|
|
|
|
if [ "$DROOPY_USE_USER" = "yes" ] ; then
|
|
|
|
DROOPY_USER=" -c $LIGHTTPD_USER:$LIGHTTPD_GROUP "
|
|
|
|
fi
|
|
|
|
start-stop-daemon $DROOPY_USER -m -S -b -p $PIDFILE_DROOPY -x $PIRATEBOX/bin/droopy -- -H $HOST -d $UPLOADFOLDER -m "$DROOPY_TXT" -c "" $DROOPY_USERDIR $DROOPY_PORT
|
|
|
|
echo $?
|
2012-04-26 22:26:48 +02:00
|
|
|
fi
|
2012-04-14 18:47:27 +02:00
|
|
|
|
2012-11-27 20:41:22 +01:00
|
|
|
#Do shoutbox stuff
|
2012-11-04 19:59:25 +01:00
|
|
|
$PIRATEBOX/bin/shoutbox_stuff.sh $WWW_FOLDER $CONF
|
|
|
|
|
2012-04-14 16:22:27 +02:00
|
|
|
|
|
|
|
#Start here the lighttpd i.e.
|
|
|
|
echo "Starting lighttpd..."
|
2012-04-14 18:47:27 +02:00
|
|
|
start-stop-daemon -S -q -p $PIDFILE_LIGHTTPD -x /usr/sbin/lighttpd -- -f $CONF_LIGHTTPD
|
2012-04-14 16:22:27 +02:00
|
|
|
echo $?
|
2012-12-26 11:20:16 +01:00
|
|
|
|
|
|
|
#Start Global Chat daemon if needed.
|
|
|
|
if [ "$GLOBAL_CHAT" = "yes" ] ; then
|
|
|
|
echo "Starting global chat service..."
|
|
|
|
start-stop-daemon -S -m -b -p $PIDFILE_SHOUTBOX -x $PIRATEBOX/bin/shoutbox_daemon.sh -- $CONF
|
|
|
|
echo $?
|
|
|
|
fi
|
2012-04-14 16:22:27 +02:00
|
|
|
fi
|
|
|
|
|
2012-06-15 17:59:19 +02:00
|
|
|
$PIRATEBOX/bin/hooks/hook_piratebox_start_done.sh "$CONF"
|
|
|
|
|
2012-04-14 16:22:27 +02:00
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
echo "Stopping script piratebox"
|
2012-06-15 17:59:19 +02:00
|
|
|
|
|
|
|
$PIRATEBOX/bin/hooks/hook_piratebox_stop.sh "$CONF"
|
|
|
|
|
2012-04-14 16:22:27 +02:00
|
|
|
if [ "$USE_APN" = "yes" ] ; then
|
|
|
|
echo "Stopping hostap... "
|
2012-04-14 18:47:27 +02:00
|
|
|
start-stop-daemon -K -q -p $PIDFILE_HOSTAPN
|
|
|
|
echo $?
|
2012-04-14 16:22:27 +02:00
|
|
|
fi
|
|
|
|
if [ "$USE_DNSMASQ" = "yes" ] ; then
|
|
|
|
echo "Stopping dnsmasq..."
|
2012-04-14 18:47:27 +02:00
|
|
|
start-stop-daemon -K -q -p $PIDFILE_DNSMASQ
|
|
|
|
echo $?
|
2012-04-14 16:22:27 +02:00
|
|
|
fi
|
|
|
|
|
2012-06-15 18:09:03 +02:00
|
|
|
if [ "$DROOPY_ENABLED" = "yes" ] ; then
|
|
|
|
#Kill Droopy
|
|
|
|
echo "Stopping droopy... "
|
|
|
|
start-stop-daemon -s 9 -K -q -p $PIDFILE_DROOPY
|
|
|
|
echo $?
|
|
|
|
fi
|
2012-04-14 18:47:27 +02:00
|
|
|
|
2012-12-26 11:20:16 +01:00
|
|
|
#Start Global Chat daemon if needed.
|
|
|
|
if [ "$GLOBAL_CHAT" = "yes" ] ; then
|
|
|
|
echo "Stopping global chat service..."
|
|
|
|
start-stop-daemon -K -q -p $PIDFILE_SHOUTBOX
|
|
|
|
echo $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-04-14 16:22:27 +02:00
|
|
|
echo "Stopping lighttpd..."
|
|
|
|
start-stop-daemon -K -q -p $PIDFILE_LIGHTTPD
|
|
|
|
echo $?
|
|
|
|
|
|
|
|
|
2012-04-14 18:47:27 +02:00
|
|
|
if [ "$DO_IFCONFIG" = yes ] ; then
|
2012-04-14 16:22:27 +02:00
|
|
|
piratebox_setup_wlan.sh $CONF stop
|
|
|
|
fi
|
|
|
|
|
2012-04-14 18:47:27 +02:00
|
|
|
if [ "$DO_IW" = "yes" ] ; then
|
|
|
|
iw dev $INTERFACE del
|
|
|
|
fi
|
|
|
|
|
2012-04-14 16:22:27 +02:00
|
|
|
#BRIDGE
|
2012-04-14 18:47:27 +02:00
|
|
|
if [ "$DO_BRIDGE" = "yes" ] ; then
|
|
|
|
echo "Remove $INTERFACE to bridge $BRIDGE // brctl addif
|
|
|
|
$BRIDGE $INTERFACE "
|
2012-04-14 16:22:27 +02:00
|
|
|
sleep 1
|
|
|
|
BR_CMD="brctl delif $BRIDGE $INTERFACE"
|
|
|
|
( $BR_CMD ; )
|
|
|
|
if [ $? -ne 0 ] ; then
|
|
|
|
echo "failed :( "
|
|
|
|
fi
|
|
|
|
fi
|
2012-06-15 17:59:19 +02:00
|
|
|
|
|
|
|
$PIRATEBOX/bin/hooks/hook_piratebox_stop_done.sh "$CONF"
|
2012-04-14 16:22:27 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Usage: /etc/init.d/piratebox {start|stop}"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|