add init scripts for hostapd, firewall and dnsmasq

This commit is contained in:
Calin Crisan 2017-12-21 21:56:35 +02:00
parent 246e788328
commit e0487db0b5
4 changed files with 197 additions and 1 deletions

View File

@ -25,6 +25,7 @@ rm -f $TARGET/etc/udev/hwdb.d/20-pci-vendor-model.hwdb
rm -f $TARGET/etc/motion-dist.conf
rm -f $TARGET/etc/hostname
rm -f $TARGET/etc/os-release
rm -f $TARGET/etc/hostapd.conf
# /usr/share stuff
rm -rf $TARGET/usr/share/bash-completion/
@ -182,12 +183,13 @@ rm -rf $TARGET/usr/lib/python2.7/ensurepip/
rm -f $TARGET/etc/init.d/S01logging
rm -f $TARGET/etc/init.d/S10udev
rm -f $TARGET/etc/init.d/S15watchdog
rm -f $TARGET/etc/init.d/S20urandom
rm -f $TARGET/etc/init.d/S49ntp
rm -f $TARGET/etc/init.d/S50sshd
rm -f $TARGET/etc/init.d/S50proftpd
rm -f $TARGET/etc/init.d/S20urandom
rm -f $TARGET/etc/init.d/S80dhcp-relay
rm -f $TARGET/etc/init.d/S80dhcp-server
rm -f $TARGET/etc/init.d/S80dnsmasq
rm -f $TARGET/etc/init.d/S91smb
# other unwanted dirs

View File

@ -0,0 +1,96 @@
#!/bin/bash
sys_conf="/etc/hostapd.conf"
boot_conf="/boot/hostapd.conf"
conf="/data/etc/hostapd.conf"
log="/var/log/hostapd.log"
prog="/usr/sbin/hostapd"
watch_conf="/data/etc/watch.conf"
link_watch=yes
link_watch_timeout=20
test -f $watch_conf && source $watch_conf
if ! [ -f $conf ]; then
if [ -f $boot_conf ]; then
cp $boot_conf $conf
elif [ -f $sys_conf ]; then
cp $sys_conf $conf
fi
fi
test -f $conf || exit 0
test -n "$os_version" || source /etc/init.d/base
running() {
killall -0 hostapd &> /dev/null
}
watch() {
while true; do
sleep 5
if ! running; then
logger -t hostapd -s "dead, rebooting"
reboot
break
fi
done
}
start() {
msg_begin "Starting hostapd"
# wait up to 5 seconds for interface
count=0
while ! ifconfig $iface >/dev/null 2>&1; do
sleep 1
count=$(($count + 1))
if [ $count -ge 5 ]; then
msg_fail "no device"
return 1
fi
done
iface=$(cat $conf | grep interface | cut -d '=' -f 2)
module=$(basename $(readlink /sys/class/net/$iface/device/driver/module 2>/dev/null) 2>/dev/null)
iwconfig $iface power off &> /dev/null
$prog $conf &> $log &
if [ "$link_watch" == "yes" ]; then
watch &
fi
test -n "$module" && msg_done "done ($module)"|| msg_done
}
stop() {
msg_begin "Stopping hostpad"
killall hostapd &>/dev/null
ps | grep hostapd | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill
msg_done
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac

View File

@ -0,0 +1,39 @@
#!/bin/bash
sys_conf="/etc/firewall.sh"
boot_conf="/boot/firewall.sh"
conf="/data/etc/firewall.sh"
if ! [ -f $conf ]; then
if [ -f $boot_conf ]; then
cp $boot_conf $conf
elif [ -f $sys_conf ]; then
cp $sys_conf $conf
fi
fi
test -f $conf || exit 0
test -n "$os_version" || source /etc/init.d/base
start() {
msg_begin "Starting firewall"
bash $conf
test $? == 0 && msg_done || msg_fail
}
case "$1" in
start)
start
;;
stop)
;;
*)
echo "Usage: $0 {start}"
exit 1
esac

View File

@ -0,0 +1,59 @@
#!/bin/bash
sys_conf="/etc/dnsmasq.conf"
boot_conf="/boot/dnsmasq.conf"
conf="/data/etc/dnsmasq.conf"
log="/var/log/dnsmasq.log"
prog="/usr/sbin/dnsmasq"
if ! [ -f $conf ]; then
if [ -f $boot_conf ]; then
cp $boot_conf $conf
elif [ -f $sys_conf ]; then
cp $sys_conf $conf
fi
fi
test -f $conf || exit 0
test -n "$os_version" || source /etc/init.d/base
start() {
msg_begin "Starting dnsmasq"
iface=$(cat $conf | grep interface | cut -d '=' -f 2)
ip=$(cat $conf | grep range | cut -d '=' -f 2 | cut -d '.' -f 1,2,3).1
ifconfig $iface $ip
$prog -C $conf --log-facility=$log
test $? == 0 && msg_done || msg_fail
}
stop() {
msg_begin "Stopping dnsmasq"
killall dnsmasq &>/dev/null
test $? == 0 && msg_done || msg_fail
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac