From 5eca1169a020f0d082a08ff282375f2ae2915503 Mon Sep 17 00:00:00 2001 From: nbd Date: Sun, 15 Oct 2006 21:03:30 +0000 Subject: init script cleanup, use /etc/rc.d/ for enabled scripts, /etc/init.d/ (enable|disable) manages symlinks git-svn-id: svn://svn.openwrt.org/openwrt/trunk@5128 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/ar7-2.4/etc/init.d/S00adam2 | 12 --- package/base-files/ar7-2.4/etc/init.d/adam2 | 13 ++++ .../base-files/brcm-2.4/etc/init.d/S05netconfig | 86 --------------------- package/base-files/brcm-2.4/etc/init.d/netconfig | 88 ++++++++++++++++++++++ .../base-files/brcm-2.6/etc/init.d/S05netconfig | 86 --------------------- package/base-files/brcm-2.6/etc/init.d/netconfig | 87 +++++++++++++++++++++ package/base-files/default/etc/init.d/S10boot | 25 ------ package/base-files/default/etc/init.d/S40network | 13 ---- package/base-files/default/etc/init.d/S50httpd | 10 --- package/base-files/default/etc/init.d/S50telnet | 10 --- package/base-files/default/etc/init.d/S60cron | 12 --- package/base-files/default/etc/init.d/boot | 26 +++++++ package/base-files/default/etc/init.d/cron | 12 +++ package/base-files/default/etc/init.d/httpd | 10 +++ package/base-files/default/etc/init.d/network | 14 ++++ package/base-files/default/etc/init.d/rcS | 4 +- package/base-files/default/etc/init.d/telnet | 10 +++ package/base-files/default/etc/rc.common | 16 +++- 18 files changed, 275 insertions(+), 259 deletions(-) delete mode 100755 package/base-files/ar7-2.4/etc/init.d/S00adam2 create mode 100755 package/base-files/ar7-2.4/etc/init.d/adam2 delete mode 100755 package/base-files/brcm-2.4/etc/init.d/S05netconfig create mode 100755 package/base-files/brcm-2.4/etc/init.d/netconfig delete mode 100755 package/base-files/brcm-2.6/etc/init.d/S05netconfig create mode 100755 package/base-files/brcm-2.6/etc/init.d/netconfig delete mode 100755 package/base-files/default/etc/init.d/S10boot delete mode 100755 package/base-files/default/etc/init.d/S40network delete mode 100755 package/base-files/default/etc/init.d/S50httpd delete mode 100755 package/base-files/default/etc/init.d/S50telnet delete mode 100755 package/base-files/default/etc/init.d/S60cron create mode 100755 package/base-files/default/etc/init.d/boot create mode 100755 package/base-files/default/etc/init.d/cron create mode 100755 package/base-files/default/etc/init.d/httpd create mode 100755 package/base-files/default/etc/init.d/network create mode 100755 package/base-files/default/etc/init.d/telnet (limited to 'package/base-files') diff --git a/package/base-files/ar7-2.4/etc/init.d/S00adam2 b/package/base-files/ar7-2.4/etc/init.d/S00adam2 deleted file mode 100755 index 5f5b3504c2..0000000000 --- a/package/base-files/ar7-2.4/etc/init.d/S00adam2 +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh /etc/rc.common -# ADAM2 patcher for Netgear DG834 and compatible -# Copyright (C) 2006 OpenWrt.org - -start() { - MD5="$(md5sum /dev/mtdblock/0 | awk '{print $1}')" - [ "$MD5" = "0530bfdf00ec155f4182afd70da028c1" ] && { - mtd unlock adam2 - /sbin/adam2patcher /dev/mtdblock/0 - } - rm -f /etc/init.d/S00adam2 /sbin/adam2patcher >&- 2>&- -} diff --git a/package/base-files/ar7-2.4/etc/init.d/adam2 b/package/base-files/ar7-2.4/etc/init.d/adam2 new file mode 100755 index 0000000000..425bc15d69 --- /dev/null +++ b/package/base-files/ar7-2.4/etc/init.d/adam2 @@ -0,0 +1,13 @@ +#!/bin/sh /etc/rc.common +# ADAM2 patcher for Netgear DG834 and compatible +# Copyright (C) 2006 OpenWrt.org + +START=00 +start() { + MD5="$(md5sum /dev/mtdblock/0 | awk '{print $1}')" + [ "$MD5" = "0530bfdf00ec155f4182afd70da028c1" ] && { + mtd unlock adam2 + /sbin/adam2patcher /dev/mtdblock/0 + } + rm -f /etc/init.d/S00adam2 /sbin/adam2patcher >&- 2>&- +} diff --git a/package/base-files/brcm-2.4/etc/init.d/S05netconfig b/package/base-files/brcm-2.4/etc/init.d/S05netconfig deleted file mode 100755 index 7c36183896..0000000000 --- a/package/base-files/brcm-2.4/etc/init.d/S05netconfig +++ /dev/null @@ -1,86 +0,0 @@ -#!/bin/sh /etc/rc.common -# Copyright (C) 2006 OpenWrt.org - -start() { - [ -e /etc/config/network ] && exit 0 - - mkdir -p /etc/config - - ( - if grep -E 'mtd0: 000(6|a)0000' /proc/mtd 2>&- >&-; then - # WGT634u - echo boardtype=wgt634u - else - strings /dev/mtdblock/3 - fi - ) | awk ' - function p(cfgname, name) { - if (c[name] != "") print " option " cfgname " \"" c[name] "\"" - } - - BEGIN { - FS="=" - c["lan_ifname"]="eth0.0" - c["wan_ifname"]="eth0.1" - c["vlan0ports"]="1 2 3 4 5*" - c["vlan1ports"]="0 5" - } - - ($1 == "boardnum") || ($1 == "boardtype") || ($1 == "boardflags") { - nvram[$1] = $2 - } - - END { - # v1 hardware - if (nvram["boardtype"] == "bcm94710dev") { - # Asus WL-500g - if (nvram["boardnum"] == "asusX") { - c["lan_ifname"]="eth0 eth1" # FIXME - c["wan_ifname"]="" - } - } - if (nvram["boardtype"] == "wgt634u") { - c["vlan0ports"] = "0 1 2 3 5*" - c["vlan1ports"] = "4 5" - } - if ((nvram["boardtype"] == "0x0467") || (nvram["boardtype"] == "0x042f")) { - c["vlan0ports"] = "0 1 2 3 5*" - c["vlan1ports"] = "4 5" - } - - # WAP54G - if ((nvram["boardnum"] == "2") || \ - (nvram["boardnum"] == "1024")) { - c["lan_ifname"]="eth0" - c["wan_ifname"]="" - } - - print "#### VLAN configuration " - print "config switch eth0" - p("vlan0", "vlan0ports") - p("vlan1", "vlan1ports") - print "" - print "" - print "#### Loopback configuration" - print "config interface loopback" - print " option ifname \"lo\"" - print " option proto static" - print " option ipaddr 127.0.0.1" - print " option netmask 255.0.0.0" - print "" - print "" - print "#### LAN configuration" - print "config interface lan" - print " option type bridge" - p("ifname", "lan_ifname") - print " option proto static" - print " option ipaddr 192.168.1.1" - print " option netmask 255.255.255.0" - print "" - print "" - print "#### WAN configuration" - print "config interface wan" - p("ifname", "wan_ifname") - print " option proto dhcp" - }' > /etc/config/network -} diff --git a/package/base-files/brcm-2.4/etc/init.d/netconfig b/package/base-files/brcm-2.4/etc/init.d/netconfig new file mode 100755 index 0000000000..ca52ee7c59 --- /dev/null +++ b/package/base-files/brcm-2.4/etc/init.d/netconfig @@ -0,0 +1,88 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2006 OpenWrt.org + +START=05 + +start() { + [ -e /etc/config/network ] && exit 0 + + mkdir -p /etc/config + + ( + if grep -E 'mtd0: 000(6|a)0000' /proc/mtd 2>&- >&-; then + # WGT634u + echo boardtype=wgt634u + else + strings /dev/mtdblock/3 + fi + ) | awk ' + function p(cfgname, name) { + if (c[name] != "") print " option " cfgname " \"" c[name] "\"" + } + + BEGIN { + FS="=" + c["lan_ifname"]="eth0.0" + c["wan_ifname"]="eth0.1" + c["vlan0ports"]="1 2 3 4 5*" + c["vlan1ports"]="0 5" + } + + ($1 == "boardnum") || ($1 == "boardtype") || ($1 == "boardflags") { + nvram[$1] = $2 + } + + END { + # v1 hardware + if (nvram["boardtype"] == "bcm94710dev") { + # Asus WL-500g + if (nvram["boardnum"] == "asusX") { + c["lan_ifname"]="eth0 eth1" # FIXME + c["wan_ifname"]="" + } + } + if (nvram["boardtype"] == "wgt634u") { + c["vlan0ports"] = "0 1 2 3 5*" + c["vlan1ports"] = "4 5" + } + if ((nvram["boardtype"] == "0x0467") || (nvram["boardtype"] == "0x042f")) { + c["vlan0ports"] = "0 1 2 3 5*" + c["vlan1ports"] = "4 5" + } + + # WAP54G + if ((nvram["boardnum"] == "2") || \ + (nvram["boardnum"] == "1024")) { + c["lan_ifname"]="eth0" + c["wan_ifname"]="" + } + + print "#### VLAN configuration " + print "config switch eth0" + p("vlan0", "vlan0ports") + p("vlan1", "vlan1ports") + print "" + print "" + print "#### Loopback configuration" + print "config interface loopback" + print " option ifname \"lo\"" + print " option proto static" + print " option ipaddr 127.0.0.1" + print " option netmask 255.0.0.0" + print "" + print "" + print "#### LAN configuration" + print "config interface lan" + print " option type bridge" + p("ifname", "lan_ifname") + print " option proto static" + print " option ipaddr 192.168.1.1" + print " option netmask 255.255.255.0" + print "" + print "" + print "#### WAN configuration" + print "config interface wan" + p("ifname", "wan_ifname") + print " option proto dhcp" + }' > /etc/config/network +} diff --git a/package/base-files/brcm-2.6/etc/init.d/S05netconfig b/package/base-files/brcm-2.6/etc/init.d/S05netconfig deleted file mode 100755 index 846562690e..0000000000 --- a/package/base-files/brcm-2.6/etc/init.d/S05netconfig +++ /dev/null @@ -1,86 +0,0 @@ -#!/bin/sh /etc/rc.common -# Copyright (C) 2006 OpenWrt.org - -start() { - [ -e /etc/config/network ] && exit 0 - - mkdir -p /etc/config - - ( - if grep -E 'mtd0: 000(6|a)0000' /proc/mtd 2>&- >&-; then - # WGT634u - echo boardtype=wgt634u - else - strings /dev/mtdblock/3 - fi - ) | awk ' - function p(cfgname, name) { - if (c[name] != "") print " option " cfgname " \"" c[name] "\"" - } - - BEGIN { - FS="=" - c["lan_ifname"]="eth0.0" - c["wan_ifname"]="eth0.1" - c["vlan0ports"]="1 2 3 4 5*" - c["vlan1ports"]="0 5" - } - - ($1 == "boardnum") || ($1 == "boardtype") || ($1 == "boardflags") { - nvram[$1] = $2 - } - - END { - # v1 hardware - if (nvram["boardtype"] == "bcm94710dev") { - # Asus WL-500g - if (nvram["boardnum"] == "asusX") { - c["lan_ifname"]="eth0 eth1" # FIXME - c["wan_ifname"]="" - } - } - if (nvram["boardtype"] == "wgt634u") { - c["vlan0ports"] = "0 1 2 3 5*" - c["vlan1ports"] = "4 5" - } - if ((nvram["boardtype"] == "0x0467") || (nvram["boardtype"] == "0x042f")) { - c["vlan0ports"] = "0 1 2 3 5*" - c["vlan1ports"] = "4 5" - } - - # WAP54G - if ((nvram["boardnum"] == "2") || \ - (nvram["boardnum"] == "1024")) { - c["lan_ifname"]="eth0" - c["wan_ifname"]="" - } - - print "#### VLAN configuration " - print "config switch eth0" - p("vlan0", "vlan0ports") - p("vlan1", "vlan1ports") - print "" - print "" - print "#### Loopback configuration" - print "config interface loopback" - print " option ifname \"lo\"" - print " option proto static" - print " option ipaddr 127.0.0.1" - print " option netmask 255.0.0.0" - print "" - print "" - print "#### LAN configuration" - print "config interface lan" - print " option type bridge" - p("ifname", "lan_ifname") - print " option proto static" - print " option ipaddr 192.168.1.1" - print " option netmask 255.255.255.0" - print "" - print "" - print "#### WAN configuration" - print "config interface wan" - p("ifname", "wan_ifname") - print " option proto dhcp" - }' > /etc/config/network -} diff --git a/package/base-files/brcm-2.6/etc/init.d/netconfig b/package/base-files/brcm-2.6/etc/init.d/netconfig new file mode 100755 index 0000000000..7a818dc5dd --- /dev/null +++ b/package/base-files/brcm-2.6/etc/init.d/netconfig @@ -0,0 +1,87 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2006 OpenWrt.org + +START=05 +start() { + [ -e /etc/config/network ] && exit 0 + + mkdir -p /etc/config + + ( + if grep -E 'mtd0: 000(6|a)0000' /proc/mtd 2>&- >&-; then + # WGT634u + echo boardtype=wgt634u + else + strings /dev/mtdblock/3 + fi + ) | awk ' + function p(cfgname, name) { + if (c[name] != "") print " option " cfgname " \"" c[name] "\"" + } + + BEGIN { + FS="=" + c["lan_ifname"]="eth0.0" + c["wan_ifname"]="eth0.1" + c["vlan0ports"]="1 2 3 4 5*" + c["vlan1ports"]="0 5" + } + + ($1 == "boardnum") || ($1 == "boardtype") || ($1 == "boardflags") { + nvram[$1] = $2 + } + + END { + # v1 hardware + if (nvram["boardtype"] == "bcm94710dev") { + # Asus WL-500g + if (nvram["boardnum"] == "asusX") { + c["lan_ifname"]="eth0 eth1" # FIXME + c["wan_ifname"]="" + } + } + if (nvram["boardtype"] == "wgt634u") { + c["vlan0ports"] = "0 1 2 3 5*" + c["vlan1ports"] = "4 5" + } + if ((nvram["boardtype"] == "0x0467") || (nvram["boardtype"] == "0x042f")) { + c["vlan0ports"] = "0 1 2 3 5*" + c["vlan1ports"] = "4 5" + } + + # WAP54G + if ((nvram["boardnum"] == "2") || \ + (nvram["boardnum"] == "1024")) { + c["lan_ifname"]="eth0" + c["wan_ifname"]="" + } + + print "#### VLAN configuration " + print "config switch eth0" + p("vlan0", "vlan0ports") + p("vlan1", "vlan1ports") + print "" + print "" + print "#### Loopback configuration" + print "config interface loopback" + print " option ifname \"lo\"" + print " option proto static" + print " option ipaddr 127.0.0.1" + print " option netmask 255.0.0.0" + print "" + print "" + print "#### LAN configuration" + print "config interface lan" + print " option type bridge" + p("ifname", "lan_ifname") + print " option proto static" + print " option ipaddr 192.168.1.1" + print " option netmask 255.255.255.0" + print "" + print "" + print "#### WAN configuration" + print "config interface wan" + p("ifname", "wan_ifname") + print " option proto dhcp" + }' > /etc/config/network +} diff --git a/package/base-files/default/etc/init.d/S10boot b/package/base-files/default/etc/init.d/S10boot deleted file mode 100755 index 77b5ca72d5..0000000000 --- a/package/base-files/default/etc/init.d/S10boot +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh /etc/rc.common -# Copyright (C) 2006 OpenWrt.org - -start() { - [ -f /proc/mounts ] || /sbin/mount_root - [ -f /proc/jffs2_bbc ] && echo "S" > /proc/jffs2_bbc - vconfig set_name_type DEV_PLUS_VID_NO_PAD - - HOSTNAME=${wan_hostname%%.*} - echo ${HOSTNAME:=OpenWrt}>/proc/sys/kernel/hostname - - mkdir -p /var/run - mkdir -p /var/log - mkdir -p /var/lock - touch /var/log/wtmp - touch /var/log/lastlog - [ "$FAILSAFE" = "true" ] && touch /tmp/.failsafe - - # manually trigger hotplug before loading modules - for iface in $(awk -F: '/:/ {print $1}' /proc/net/dev); do - /usr/bin/env -i ACTION=add INTERFACE="$iface" /sbin/hotplug net - done - - load_modules /etc/modules /etc/modules.d/* -} diff --git a/package/base-files/default/etc/init.d/S40network b/package/base-files/default/etc/init.d/S40network deleted file mode 100755 index c7720369fd..0000000000 --- a/package/base-files/default/etc/init.d/S40network +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh /etc/rc.common -# Copyright (C) 2006 OpenWrt.org - -start() { - setup_switch() { return 0; } - - include /lib/network - setup_switch - [ -e /etc/config/wireless ] || \ - /sbin/wifi detect > /etc/config/wireless - /sbin/wifi up -} - diff --git a/package/base-files/default/etc/init.d/S50httpd b/package/base-files/default/etc/init.d/S50httpd deleted file mode 100755 index a05b10c094..0000000000 --- a/package/base-files/default/etc/init.d/S50httpd +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh /etc/rc.common -# Copyright (C) 2006 OpenWrt.org - -start() { - [ -d /www ] && httpd -p 80 -h /www -r OpenWrt -} - -stop() { - killall httpd -} diff --git a/package/base-files/default/etc/init.d/S50telnet b/package/base-files/default/etc/init.d/S50telnet deleted file mode 100755 index 228eac2b62..0000000000 --- a/package/base-files/default/etc/init.d/S50telnet +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh /etc/rc.common -# Copyright (C) 2006 OpenWrt.org - -start() { - if awk -F: '/^root:/ && $2 !~ /\!/ {exit 1}' /etc/passwd 2>/dev/null; then telnetd -l /bin/login; fi -} - -stop() { - killall telnetd -} diff --git a/package/base-files/default/etc/init.d/S60cron b/package/base-files/default/etc/init.d/S60cron deleted file mode 100755 index a450c36dd2..0000000000 --- a/package/base-files/default/etc/init.d/S60cron +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh /etc/rc.common -# Copyright (C) 2006 OpenWrt.org - -start () { - mkdir -p /var/spool/cron - ln -s /etc/crontabs /var/spool/cron/crontabs - crond -c /etc/crontabs -} - -stop() { - killall crond -} diff --git a/package/base-files/default/etc/init.d/boot b/package/base-files/default/etc/init.d/boot new file mode 100755 index 0000000000..a5c8603a5d --- /dev/null +++ b/package/base-files/default/etc/init.d/boot @@ -0,0 +1,26 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2006 OpenWrt.org + +START=10 +start() { + [ -f /proc/mounts ] || /sbin/mount_root + [ -f /proc/jffs2_bbc ] && echo "S" > /proc/jffs2_bbc + vconfig set_name_type DEV_PLUS_VID_NO_PAD + + HOSTNAME=${wan_hostname%%.*} + echo ${HOSTNAME:=OpenWrt}>/proc/sys/kernel/hostname + + mkdir -p /var/run + mkdir -p /var/log + mkdir -p /var/lock + touch /var/log/wtmp + touch /var/log/lastlog + [ "$FAILSAFE" = "true" ] && touch /tmp/.failsafe + + # manually trigger hotplug before loading modules + for iface in $(awk -F: '/:/ {print $1}' /proc/net/dev); do + /usr/bin/env -i ACTION=add INTERFACE="$iface" /sbin/hotplug net + done + + load_modules /etc/modules /etc/modules.d/* +} diff --git a/package/base-files/default/etc/init.d/cron b/package/base-files/default/etc/init.d/cron new file mode 100755 index 0000000000..a450c36dd2 --- /dev/null +++ b/package/base-files/default/etc/init.d/cron @@ -0,0 +1,12 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2006 OpenWrt.org + +start () { + mkdir -p /var/spool/cron + ln -s /etc/crontabs /var/spool/cron/crontabs + crond -c /etc/crontabs +} + +stop() { + killall crond +} diff --git a/package/base-files/default/etc/init.d/httpd b/package/base-files/default/etc/init.d/httpd new file mode 100755 index 0000000000..a05b10c094 --- /dev/null +++ b/package/base-files/default/etc/init.d/httpd @@ -0,0 +1,10 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2006 OpenWrt.org + +start() { + [ -d /www ] && httpd -p 80 -h /www -r OpenWrt +} + +stop() { + killall httpd +} diff --git a/package/base-files/default/etc/init.d/network b/package/base-files/default/etc/init.d/network new file mode 100755 index 0000000000..45d5311a7a --- /dev/null +++ b/package/base-files/default/etc/init.d/network @@ -0,0 +1,14 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2006 OpenWrt.org + +START=40 +start() { + setup_switch() { return 0; } + + include /lib/network + setup_switch + [ -e /etc/config/wireless ] || \ + /sbin/wifi detect > /etc/config/wireless + /sbin/wifi up +} + diff --git a/package/base-files/default/etc/init.d/rcS b/package/base-files/default/etc/init.d/rcS index 7fae7f5b05..27bc34b220 100755 --- a/package/base-files/default/etc/init.d/rcS +++ b/package/base-files/default/etc/init.d/rcS @@ -11,8 +11,8 @@ syslogd -C 16 #${log_ipaddr:+-L -R $log_ipaddr} klogd ( - for i in /etc/init.d/S*; do - $i start 2>&1 + for i in /etc/rc.d/S*; do + $i boot 2>&1 done sysctl -p >&- diff --git a/package/base-files/default/etc/init.d/telnet b/package/base-files/default/etc/init.d/telnet new file mode 100755 index 0000000000..228eac2b62 --- /dev/null +++ b/package/base-files/default/etc/init.d/telnet @@ -0,0 +1,10 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2006 OpenWrt.org + +start() { + if awk -F: '/^root:/ && $2 !~ /\!/ {exit 1}' /etc/passwd 2>/dev/null; then telnetd -l /bin/login; fi +} + +stop() { + killall telnetd +} diff --git a/package/base-files/default/etc/rc.common b/package/base-files/default/etc/rc.common index 20d1efa402..a08f5e523c 100755 --- a/package/base-files/default/etc/rc.common +++ b/package/base-files/default/etc/rc.common @@ -1,5 +1,9 @@ #!/bin/sh -. /etc/functions.sh +# Copyright (C) 2006 OpenWrt.org + +. $IPKG_INSTROOT/etc/functions.sh + +START=50 start() { return 0 @@ -27,12 +31,14 @@ shutdown() { } disable() { - rm -f /etc/rc.d/${initscript##*/} + name="$(basename "${initscript}")" + rm -f "$IPKG_INSTROOT/etc/rc.d/S??$name" } enable() { + name="$(basename "${initscript}")" disable - ln -s /etc/init.d/${initscript##*/} /etc/rc.d/${initscript##*/} + ln -s "/etc/init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" } depends() { @@ -48,6 +54,8 @@ Available commands: stop Stop the service restart Restart the service reload Reload configuration files (or restart if that fails) + enable Enable service autostart + disable Disable service autostart $EXTRA_HELP EOF } @@ -68,6 +76,8 @@ eval "case \"\$action\" in restart) restart;; boot) boot;; shutdown) shutdown;; + enable) enable;; + disable) disable;; $cmds *) help;; esac" -- cgit v1.2.3