]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
freifunk: Split freifunk initscript into separate ones
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 4 Dec 2014 01:39:36 +0000 (02:39 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 9 Mar 2015 15:39:08 +0000 (16:39 +0100)
config/rootfiles/common/armv5tel/initscripts
config/rootfiles/common/i586/initscripts
html/cgi-bin/freifunk.cgi
src/initscripts/init.d/alfred [new file with mode: 0755]
src/initscripts/init.d/fastd [new file with mode: 0755]
src/initscripts/init.d/freifunk
src/initscripts/init.d/lib-freifunk [new file with mode: 0755]

index 50a99eac442a24ebb91f4f04b730177dcdbb8b18..b2d29334a642e16557ae13c20a630270adf8a35b 100644 (file)
@@ -3,6 +3,7 @@
 etc/rc.d/helper/getdnsfromdhcpc.pl
 etc/rc.d/helper/writeipac.pl
 #etc/rc.d/init.d
+etc/rc.d/init.d/alfred
 #etc/rc.d/init.d/alsa
 #etc/rc.d/init.d/amavisd
 etc/rc.d/init.d/apache
@@ -26,6 +27,7 @@ etc/rc.d/init.d/console
 etc/rc.d/init.d/dhcp
 etc/rc.d/init.d/dhcrelay
 etc/rc.d/init.d/dnsmasq
+etc/rc.d/init.d/fastd
 etc/rc.d/init.d/fcron
 #etc/rc.d/init.d/fetchmail
 etc/rc.d/init.d/fireinfo
@@ -44,6 +46,7 @@ etc/rc.d/init.d/ipsec
 #etc/rc.d/init.d/lcdproc
 #etc/rc.d/init.d/lcr
 etc/rc.d/init.d/leds
+etc/rc.d/init.d/lib-freifunk
 etc/rc.d/init.d/localnet
 etc/rc.d/init.d/mISDN
 #etc/rc.d/init.d/mediatomb
index fc15c2e1c2d68ea9ec20d6c76e99f28d0a5a4a8d..876208d4bc4bfed8d5c3ac75b94816fa3dd03dc1 100644 (file)
@@ -4,6 +4,7 @@ etc/rc.d/helper/getdnsfromdhcpc.pl
 etc/rc.d/helper/writeipac.pl
 #etc/rc.d/init.d
 etc/rc.d/init.d/acpid
+etc/rc.d/init.d/alfred
 #etc/rc.d/init.d/alsa
 #etc/rc.d/init.d/amavisd
 etc/rc.d/init.d/apache
@@ -28,6 +29,7 @@ etc/rc.d/init.d/console
 etc/rc.d/init.d/dhcp
 etc/rc.d/init.d/dhcrelay
 etc/rc.d/init.d/dnsmasq
+etc/rc.d/init.d/fastd
 etc/rc.d/init.d/fcron
 #etc/rc.d/init.d/fetchmail
 etc/rc.d/init.d/fireinfo
@@ -46,6 +48,7 @@ etc/rc.d/init.d/ipsec
 #etc/rc.d/init.d/lcdproc
 #etc/rc.d/init.d/lcr
 etc/rc.d/init.d/leds
+etc/rc.d/init.d/lib-freifunk
 etc/rc.d/init.d/localnet
 etc/rc.d/init.d/mISDN
 #etc/rc.d/init.d/mediatomb
index 1a7c84d6ad221d92df4b84c1436fd09cc6dc23d9..a9b9d6ae3298e59d5bafe2e05edb1c96520915aa 100755 (executable)
@@ -289,7 +289,7 @@ sub BuildConfiguration() {
 
        print FILE "# Hooks\n";
        foreach my $hook ("pre-up", "up") {
-               print FILE "on $hook \"/etc/rc.d/init.d/freifunk on-$hook\";\n";
+               print FILE "on $hook \"/etc/init.d/fastd on-$hook\";\n";
        }
 
        close(FILE);
diff --git a/src/initscripts/init.d/alfred b/src/initscripts/init.d/alfred
new file mode 100755 (executable)
index 0000000..08b7887
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/sh
+########################################################################
+# Begin $rc_base/init.d/alfred
+#
+# Description : alfred initscript
+#
+########################################################################
+
+. /etc/sysconfig/rc
+. ${rc_functions}
+
+. /etc/rc.d/init.d/lib-freifunk
+
+case "${1}" in
+       start)
+               # Do nothing if Freifunk is not enabled
+               freifunk_is_enabled || exit 0
+
+               boot_mesg "Starting A.L.F.R.E.D. on ${FREIFUNK_BRIDGE}..."
+
+               # Enable IPv6 (for multicasts) on the bridge interface
+               freifunk_ipv6_enable "${FREIFUNK_BRIDGE}"
+
+               /usr/sbin/alfred -i "${FREIFUNK_BRIDGE}" &>/dev/null &
+               evaluate_retval
+               ;;
+
+       stop)
+               boot_mesg "Stopping A.L.F.R.E.D. on ${FREIFUNK_BRIDGE}..."
+               killproc /usr/sbin/alfred
+               ;;
+
+       restart)
+               ${0} stop
+               sleep 1
+               ${0} start
+               ;;
+
+       status)
+               statusproc /usr/sbin/alfred
+               ;;
+
+       *)
+               echo "Usage: ${0} {start|stop|restart|status}"
+               exit 1
+               ;;
+esac
+
+# End $rc_base/init.d/alfred
diff --git a/src/initscripts/init.d/fastd b/src/initscripts/init.d/fastd
new file mode 100755 (executable)
index 0000000..06ad6ed
--- /dev/null
@@ -0,0 +1,73 @@
+#!/bin/sh
+########################################################################
+# Begin $rc_base/init.d/fastd
+#
+# Description : fastd initscript
+#
+########################################################################
+
+. /etc/sysconfig/rc
+. ${rc_functions}
+
+. /etc/rc.d/init.d/lib-freifunk
+
+FASTD_CONF="/var/ipfire/freifunk/fastd.conf"
+
+case "${1}" in
+       start)
+               # Do nothing if the fastd configuration file does not exist
+               # or if it is empty
+               [ -s "${FASTD_CONF}" ] || exit 0
+
+               boot_mesg "Starting fastd..."
+
+               # Loading required kernel modules
+               modprobe tun
+
+               loadproc /usr/bin/fastd --daemon --config "${FASTD_CONF}"
+               ;;
+
+       stop)
+               boot_mesg "Stopping fastd..."
+               killproc /usr/bin/fastd
+               ;;
+
+       restart)
+               ${0} stop
+               sleep 1
+               ${0} start
+               ;;
+
+       status)
+               statusproc /usr/bin/fastd
+               ;;
+
+       # Hidden commands used by fastd
+       on-up)
+               # INTERFACE must be set
+               [ -z "${INTERFACE}" ] && exit 2
+
+               # Bring up the device
+               ip link set "${INTERFACE}" up
+
+               # Add the VPN device to the BATMAN network
+               freifunk_batman_attach "${INTERFACE}"
+
+               # Bring up all the rest of Freifunk
+               freifunk_start
+
+               exit 0
+               ;;
+
+       on-*)
+               # Nothing to do, yet
+               exit 0
+               ;;
+
+       *)
+               echo "Usage: ${0} {start|stop|restart|status}"
+               exit 1
+               ;;
+esac
+
+# End $rc_base/init.d/fastd
index 3199a1e43bb505c35e51bdd1c1b792ba66f22faf..fb25e9fc51ff96e42f903df146ebdf588910cc4a 100755 (executable)
@@ -9,30 +9,24 @@
 . /etc/sysconfig/rc
 . ${rc_functions}
 
-FASTD_CONF="/var/ipfire/freifunk/fastd.conf"
-BATMAN_INTERFACE="bat0"
-
-eval $(/usr/local/bin/readhash /var/ipfire/freifunk/settings)
-
-function freifunk_is_enabled() {
-        [ "${FREIFUNK_ENABLED}" = "on" ]
-}
+. /etc/rc.d/init.d/lib-freifunk
 
 case "${1}" in
        start)
                freifunk_is_enabled || exit 0
 
                boot_mesg "Starting Freifunk network..."
+               freifunk_start; evaluate_retval
 
-               # Loading required kernel modules
-               modprobe tun
-
-               loadproc /usr/bin/fastd --daemon --config "${FASTD_CONF}"
+               # Start fastd (if required)
+               /etc/init.d/fastd start
                ;;
 
        stop)
+               /etc/init.d/fastd stop
+
                boot_mesg "Stopping Freifunk network..."
-               killproc /usr/bin/fastd
+               freifunk_stop; evaluate_retval
                ;;
 
        restart)
@@ -42,28 +36,8 @@ case "${1}" in
                ;;
 
        status)
-               statusproc /usr/bin/fastd
-               ;;
-
-       # Hidden commands used by fastd
-       on-up)
-               # INTERFACE must be set
-               [ -z "${INTERFACE}" ] && exit 2
-
-               # Load batman kernel module
-               modprobe batman-adv
-
-               # Bring up the device
-               ip link set "${INTERFACE}" up
-
-               # Add the VPN device to the BATMAN network and bring it up as well
-               echo "${BATMAN_INTERFACE}" > "/sys/class/net/${INTERFACE}/batman_adv/mesh_iface"
-               ip link set "${BATMAN_INTERFACE}" up
-               ;;
-
-       on-*)
-               # Nothing to do, yet
-               exit 0
+               /etc/init.d/alfred status
+               /etc/init.d/fastd status
                ;;
 
        *)
diff --git a/src/initscripts/init.d/lib-freifunk b/src/initscripts/init.d/lib-freifunk
new file mode 100755 (executable)
index 0000000..2365e3c
--- /dev/null
@@ -0,0 +1,108 @@
+#!/bin/sh
+
+FREIFUNK_BRIDGE="meshbr0"
+BATMAN_INTERFACE="bat0"
+
+eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
+eval $(/usr/local/bin/readhash /var/ipfire/freifunk/settings)
+
+function freifunk_is_enabled() {
+        [ "${FREIFUNK_ENABLED}" = "on" ]
+}
+
+function freifunk_start() {
+       # Do nothing if Freifunk is not enabled
+       freifunk_is_enabled || exit 0
+
+       # Bring up the batman interface
+       freifunk_batman_create
+       freifunk_batman_attach_all
+
+       # Create the Freifunk bridge
+       freifunk_bridge_create
+       freifunk_bridge_attach "${BATMAN_INTERFACE}"
+
+       # Make sure that alfred is started
+       /etc/init.d/alfred start &>/dev/null
+}
+
+function freifunk_stop() {
+       /etc/init.d/alfred stop &>/dev/null
+
+       ip link set "${BATMAN_INTERFACE}" down &>/dev/null
+       ip link del "${BATMAN_INTERFACE}" &>/dev/null
+
+       ip link set "${FREIFUNK_BRIDGE}" down &>/dev/null
+}
+
+function freifunk_bridge_create() {
+       # Create bridge if it does not exist, yet
+       if [ ! -d "/sys/class/net/${FREIFUNK_BRIDGE}" ]; then
+               ip link add name "${FREIFUNK_BRIDGE}" type bridge
+       fi
+
+       # Bring it up
+       ip link set "${FREIFUNK_BRIDGE}" up
+}
+
+function freifunk_bridge_remove() {
+       if [ -d "/sys/class/net/${FREIFUNK_BRIDGE}" ]; then
+               ip link set "${FREIFUNK_BRIDGE}" down
+               ip link del name "${FREIFUNK_BRIDGE}"
+       fi
+}
+
+function freifunk_bridge_attach() {
+       local device="${1}"
+
+       ip link set "${device}" master "${FREIFUNK_BRIDGE}"
+       ip link set "${device}" up
+}
+
+function freifunk_bridge_detach() {
+       local device="${1}"
+
+       ip link set "${device}" nomaster
+}
+
+function freifunk_batman_create() {
+       local device="${BATMAN_INTERFACE}"
+
+       if [ ! -d "/sys/class/net/${device}" ]; then
+               ip link add name "${device}" type batadv
+       fi
+       ip link set "${BATMAN_INTERFACE}" up
+}
+
+function freifunk_batman_attach() {
+       local device="${1}"
+
+       # Make sure the batman module is loaded
+       modprobe batman-adv
+
+       echo "${BATMAN_INTERFACE}" > "/sys/class/net/${device}/batman_adv/mesh_iface"
+       ip link set "${device}" up
+}
+
+function freifunk_batman_attach_all() {
+       local dev
+
+       for dev in BATMAN1_DEV BATMAN2_DEV; do
+               [ -z "${!dev}" ] && continue
+               [ -d "/sys/class/net/${!dev}" ] || continue
+
+               freifunk_batman_attach "${!dev}"
+       done
+}
+
+function freifunk_ipv6_enable() {
+       local device="${1}"
+
+       sysctl -w "net.ipv6.conf.${device}.disable_ipv6=0" >/dev/null
+}
+
+function freifunk_ipv6_disable() {
+       local device="${1}"
+
+       sysctl -w "net.ipv6.conf.${device}.disable_ipv6=1" >/dev/null
+}