diff options
author | Felix Fietkau <nbd@openwrt.org> | 2006-10-13 22:51:49 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2016-03-20 17:29:15 +0100 |
commit | 60c1f0f64d23003a19a07d6b9638542130f6641d (patch) | |
tree | 8fb2787f4c49baded97cd55e0c371fe1cffce2b6 /package/base-files | |
parent | d58a09110ccfa95f06c983fe796806f2e035c9d2 (diff) | |
parent | b3ce218b51746d3a576221ea542facf3a1703ab2 (diff) | |
download | mtk-20170518-60c1f0f64d23003a19a07d6b9638542130f6641d.zip mtk-20170518-60c1f0f64d23003a19a07d6b9638542130f6641d.tar.gz mtk-20170518-60c1f0f64d23003a19a07d6b9638542130f6641d.tar.bz2 |
finally move buildroot-ng to trunk
Diffstat (limited to 'package/base-files')
65 files changed, 2588 insertions, 0 deletions
diff --git a/package/base-files/Makefile b/package/base-files/Makefile new file mode 100644 index 0000000..9f6da3b --- /dev/null +++ b/package/base-files/Makefile @@ -0,0 +1,191 @@ +# +# Copyright (C) 2006 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# +# $Id$ + +include $(TOPDIR)/rules.mk +include $(INCLUDE_DIR)/kernel.mk + +PKG_NAME:=base-files +PKG_RELEASE:=8 + +PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME) + +REV:=$(shell LANG=C svn info | awk '/^Revision:/ { print$$2 }' ) +ifeq ($(REV),) + REV:=0 +endif + +include $(INCLUDE_DIR)/package.mk + +ifneq ($(DUMP),1) + TARGET:=-$(BOARD)-$(KERNEL) + UCLIBC_VERSION:=${shell cat $(STAGING_DIR)/uclibc_version 2>/dev/null} + LIBGCC_VERSION:=${shell cat $(STAGING_DIR)/gcc_version 2>/dev/null} +else + UCLIBC_VERSION:=<UCLIBC_VERSION> + LIBGCC_VERSION:=<LIBGCC_VERSION> +endif + +CONFIG_PACKAGE_base-files$(TARGET):=$(CONFIG_PACKAGE_base-files) + +define Package/base-files$(TARGET) + SECTION:=base + CATEGORY:=Base system + DEFAULT:=y + TITLE:=Base filesystem for OpenWrt + DESCRIPTION:=\ + This package contains a base filesystem and system scripts for OpenWrt. + URL:=http://openwrt.org/ + VERSION:=$(PKG_RELEASE)-$(REV) +endef + +define -ar7-2.4/conffiles +/etc/config/network +endef + +define -aruba-2.6/conffiles +/etc/config/network +endef + +define -au1000-2.6/conffiles +/etc/config/network +endef + +define -rb532-2.6/conffiles +/etc/config/network +endef + +define -sibyte-2.6/conffiles +/etc/config/network +endef + +define -x86-2.6/conffiles +/etc/config/network +endef + +define -xscale-2.6/conffiles +/etc/config/network +endef + +define Package/base-files$(TARGET)/conffiles +/etc/banner +/etc/hosts +/etc/inittab +/etc/group +/etc/passwd +/etc/profile +/etc/shells +/etc/ipkg.conf +/etc/sysctl.conf +$(call $(TARGET)/conffiles) +endef + +define Package/libgcc + SECTION:=libs + CATEGORY:=Base system + DEFAULT:=y + DEPENDS:=@!NATIVE_TOOLCHAIN + TITLE:=GCC support library + URL:=http://gcc.gnu.org/ + VERSION:=$(LIBGCC_VERSION)-$(PKG_RELEASE) +endef + +define Package/libpthread + SECTION:=libs + CATEGORY:=Libraries + DEPENDS:=@!NATIVE_TOOLCHAIN + TITLE:=POSIX thread library + URL:=http://uclibc.org/ + VERSION:=$(UCLIBC_VERSION)-$(PKG_RELEASE) +endef + +define Package/uclibc + SECTION:=libs + CATEGORY:=Base system + DEFAULT:=y + DEPENDS:=@!NATIVE_TOOLCHAIN + TITLE:=C library embedded systems + URL:=http://uclibc.org/ + VERSION:=$(UCLIBC_VERSION)-$(PKG_RELEASE) +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) +endef + +define Build/Compile/ar7 + $(TARGET_CC) -o $(PKG_BUILD_DIR)/adam2patcher src/adam2patcher.c +endef + +define Build/Compile/brcm + $(TARGET_CC) -o $(PKG_BUILD_DIR)/jffs2root src/jffs2root.c +endef + +define Build/Compile + $(call Build/Compile/$(BOARD)) +endef + + +define Package/base-files$(TARGET)/install-ar7 + mkdir -p $(1)/sbin + $(CP) $(PKG_BUILD_DIR)/adam2patcher $(1)/sbin +endef + +define Package/base-files$(TARGET)/install-brcm + rm -f $(1)/etc/config/network + mkdir -p $(1)/sbin + $(CP) $(PKG_BUILD_DIR)/jffs2root $(1)/sbin +endef + +define Package/base-files$(TARGET)/install + $(CP) ./default/* $(1)/ + if [ -d $(BOARD)-$(KERNEL) ]; then \ + $(CP) $(BOARD)-$(KERNEL)/* $(1)/; \ + fi + $(SED) 's,$$$$R,r$(REV),g' $(1)/etc/banner + $(SED) 's,$$$$S,$(BOARD)-$(KERNEL),g' $(1)/etc/ipkg.conf + mkdir -p $(1)/dev + mkdir -p $(1)/etc/crontabs + mkdir -p $(1)/jffs + mkdir -p $(1)/lib + mkdir -p $(1)/mnt + mkdir -p $(1)/proc + mkdir -p $(1)/tmp + mkdir -p $(1)/usr/lib + mkdir -p $(1)/usr/bin + mkdir -p $(1)/sys + mkdir -p $(1)/www + ln -sf /proc/mounts $(1)/etc/mtab + rm -f $(1)/var + ln -sf /tmp $(1)/var + mkdir -p $(1)/etc +$(call Package/base-files$(TARGET)/install-$(BOARD),$(1)) +endef + +define Package/libgcc/install + install -m0755 -d $(1)/lib + $(CP) $(STAGING_DIR)/lib/libgcc_s.so.* $(1)/lib/ +endef + +define Package/libpthread/install + install -m0755 -d $(1)/lib + $(CP) $(STAGING_DIR)/lib/libpthread.so.* $(1)/lib/ + $(CP) $(STAGING_DIR)/lib/libpthread-$(UCLIBC_VERSION).so $(1)/lib/ +endef + +define Package/uclibc/install + install -m0755 -d $(1)/lib + for file in ld-uClibc libc libcrypt libdl libm libnsl libresolv librt libuClibc libutil; do \ + $(CP) $(STAGING_DIR)/lib/$$$$file.so.* $(1)/lib/; \ + $(CP) $(STAGING_DIR)/lib/$$$$file-$(UCLIBC_VERSION).so $(1)/lib/; \ + done +endef + +$(eval $(call BuildPackage,base-files$(TARGET))) +$(eval $(call BuildPackage,libgcc)) +$(eval $(call BuildPackage,libpthread)) +$(eval $(call BuildPackage,uclibc)) diff --git a/package/base-files/ar7-2.4/bin/firstboot b/package/base-files/ar7-2.4/bin/firstboot new file mode 100755 index 0000000..774bbc7 --- /dev/null +++ b/package/base-files/ar7-2.4/bin/firstboot @@ -0,0 +1,89 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +rom=$(awk '/squashfs/ {print $2}' /proc/mounts) +jffs=$(awk '/jffs2/ {print $2}' /proc/mounts) + +dupe() { # <new_root> <old_root> + cd $1 + echo -n "creating directories... " + { + cd $2 + find . -xdev -type d + echo "./dev ./jffs ./mnt ./proc ./tmp ./sys" + # xdev skips mounted directories + cd $1 + } | xargs mkdir -p + echo "done" + + echo -n "setting up symlinks... " + for file in $(cd $2; find . -xdev -type f;); do + case "$file" in + ./rom/note) ;; #nothing + ./etc/config*|\ + ./etc/resolv.conf|\ + ./usr/lib/ipkg/info) cp -af $2/$file $file;; + *) ln -sf /rom/${file#./*} $file;; + esac + done + for file in $(cd $2; find . -xdev -type l;); do + cp -af $2/${file#./*} $file + done + echo "done" +} + +pivot() { # <new_root> <old_root> + mount -o move /proc $1/proc && \ + pivot_root $1 $1$2 && { + mount -o move $2/dev /dev + mount -o move $2/tmp /tmp + mount -o move $2/sys /sys + return 0 + } +} + +mountdp() { # <device> <mount_point> <ignored> <fs> + dev=$1; mnt=$2; shift 2; opt=$* + mount $dev $mnt $opt + dupe $mnt $rom + pivot $mnt /rom +} + +ramoverlay() { + mkdir -p /tmp/root + mountdp /tmp/root /mnt -o bind +} + +[ "${0##*/}" = "firstboot" ] && { + [ -z "$rom" ] && { + echo "You do not have a squashfs partition; aborting" + echo "(firstboot cannot be run on jffs2 based firmwares)" + exit 1 + } + + [ "$1" = "switch2jffs" ] && { + mtd erase OpenWrt + mount -o remount,ro none / # try to avoid fs changing while copying + mount -o bind / /mnt + mount /dev/mtdblock/4 /rom/jffs -t jffs2 + echo -n "copying files ... " + cp -a /mnt/* /rom/jffs + umount /mnt + echo "done" + pivot /rom /mnt + mount -o move /mnt /tmp/root + pivot /jffs /rom + exit 0 + } + + # script run manually + [ \! -z "$jffs" ] && { + echo "firstboot has already been run" + echo "jffs2 partition is mounted, only resetting files" + dupe $jffs $rom + exit 0 + } + + mtd erase OpenWrt + mountdp /dev/mtdblock/4 /jffs -t jffs2 +} diff --git a/package/base-files/ar7-2.4/etc/config/network b/package/base-files/ar7-2.4/etc/config/network new file mode 100644 index 0000000..911134b --- /dev/null +++ b/package/base-files/ar7-2.4/etc/config/network @@ -0,0 +1,14 @@ +# Network configuration file + +config interface loopback + option ifname lo + option proto static + option ipaddr 127.0.0.1 + option netmask 255.0.0.0 + +config interface lan + option ifname eth0 + option proto static + option ipaddr 192.168.1.1 + option netmask 255.255.255.0 + diff --git a/package/base-files/ar7-2.4/etc/init.d/S00adam2 b/package/base-files/ar7-2.4/etc/init.d/S00adam2 new file mode 100755 index 0000000..5f5b350 --- /dev/null +++ b/package/base-files/ar7-2.4/etc/init.d/S00adam2 @@ -0,0 +1,12 @@ +#!/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/preinit b/package/base-files/ar7-2.4/etc/preinit new file mode 100755 index 0000000..5b676ca --- /dev/null +++ b/package/base-files/ar7-2.4/etc/preinit @@ -0,0 +1,11 @@ +#!/bin/sh +export PATH=/bin:/sbin:/usr/bin:/usr/sbin +mount none /proc -t proc + +[ -f /etc/preinit.arch ] && . /etc/preinit.arch +[ -z "$FAILSAFE" ] || { + echo /bin/true > /proc/sys/kernel/hotplug + telnetd -l /bin/login <> /dev/null 2>&1 +} +mount_root ${FAILSAFE:+failsafe} +exec /sbin/init diff --git a/package/base-files/ar7-2.4/sbin/mount_root b/package/base-files/ar7-2.4/sbin/mount_root new file mode 100755 index 0000000..6b90bdc --- /dev/null +++ b/package/base-files/ar7-2.4/sbin/mount_root @@ -0,0 +1,28 @@ +#!/bin/sh +size=$(awk '/Mem:/ {l=5242880;print((s=$2/2)<l)?$2-l:s}' /proc/meminfo) +mount none /tmp -t tmpfs -o size=$size + +if [ "$1" != "failsafe" ]; then + mtd unlock linux + mount | grep jffs2 >&- + if [ $? = 0 ] ; then + if [ $(cat /proc/mtd | wc -l) = 6 ]; then + mtd erase OpenWrt + else + mount -o remount,rw /dev/root / + fi + else + . /bin/firstboot + echo "switching to jffs2" + mount /dev/mtdblock/4 /jffs -t jffs2 + pivot /jffs /rom || { + echo "jffs2 unusable; using ramdisk" + ramoverlay + } + fi +fi + +mount none /tmp -t tmpfs -o remount,nosuid,nodev,mode=1777 +mkdir -p /dev/pts +mount none /dev/pts -t devpts +mount -t sysfs none /sys 2>&- diff --git a/package/base-files/aruba-2.6/etc/config/network b/package/base-files/aruba-2.6/etc/config/network new file mode 100644 index 0000000..1d9b55b --- /dev/null +++ b/package/base-files/aruba-2.6/etc/config/network @@ -0,0 +1,11 @@ +# Network configuration file + +config interface loopback + option ifname lo + option proto static + option ipaddr 127.0.0.1 + option netmask 255.0.0.0 + +config interface lan + option ifname eth0 + option proto dhcp diff --git a/package/base-files/au1000-2.6/etc/config/network b/package/base-files/au1000-2.6/etc/config/network new file mode 100644 index 0000000..9b65652 --- /dev/null +++ b/package/base-files/au1000-2.6/etc/config/network @@ -0,0 +1,14 @@ +# Copyright (C) 2006 OpenWrt.org + +config interface loopback + option ifname lo + option proto static + option ipaddr 127.0.0.1 + option netmask 255.0.0.0 + +config interface lan + option type bridge + option ifname "eth0 ath0" + option proto static + option ipaddr 192.168.1.1 + option netmask 255.255.255.0 diff --git a/package/base-files/au1000-2.6/sbin/mount_root b/package/base-files/au1000-2.6/sbin/mount_root new file mode 100755 index 0000000..718394c --- /dev/null +++ b/package/base-files/au1000-2.6/sbin/mount_root @@ -0,0 +1,26 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +mount none /proc -t proc +size=$(awk '/Mem:/ {l=5242880;print((s=$2/2)<l)?$2-l:s}' /proc/meminfo) +mount none /tmp -t tmpfs -o size=$size + +if [ "$1" != "failsafe" ]; then + mtd unlock filesystem + mount | grep jffs2 >&- + if [ $? = 0 ] ; then + if [ $(cat /proc/mtd | wc -l) = 6 ]; then + mtd erase filesystem + jffs2root --move + else + mount -o remount,rw /dev/root / + fi + else + . /bin/firstboot + fi +fi + +mount none /tmp -t tmpfs -o remount,nosuid,nodev,mode=1777 +mkdir -p /dev/pts +mount none /dev/pts -t devpts +mount -t sysfs none /sys 2>&- diff --git a/package/base-files/brcm-2.4/bin/firstboot b/package/base-files/brcm-2.4/bin/firstboot new file mode 100755 index 0000000..b65d3ee --- /dev/null +++ b/package/base-files/brcm-2.4/bin/firstboot @@ -0,0 +1,90 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +rom=$(awk '/squashfs/ {print $2}' /proc/mounts) +jffs=$(awk '/jffs2/ {print $2}' /proc/mounts) + +dupe() { # <new_root> <old_root> + cd $1 + echo -n "creating directories... " + { + cd $2 + find . -xdev -type d + echo "./dev ./jffs ./mnt ./proc ./tmp ./sys" + # xdev skips mounted directories + cd $1 + } | xargs mkdir -p + echo "done" + + echo -n "setting up symlinks... " + for file in $(cd $2; find . -xdev -type f;); do + case "$file" in + ./rom/note) ;; #nothing + ./etc/config*|\ + ./etc/resolv.conf|\ + ./usr/lib/ipkg/info/*) cp -af $2/$file $file;; + *) ln -sf /rom/${file#./*} $file;; + esac + done + for file in $(cd $2; find . -xdev -type l;); do + cp -af $2/${file#./*} $file + done + echo "done" +} + +pivot() { # <new_root> <old_root> + mount -o move /proc $1/proc && \ + pivot_root $1 $1$2 && { + mount -o move $2/dev /dev + mount -o move $2/tmp /tmp + mount -o move $2/sys /sys + return 0 + } +} + +mountdp() { # <device> <mount_point> <ignored> <fs> + dev=$1; mnt=$2; shift 2; opt=$* + mount $dev $mnt $opt + dupe $mnt $rom + pivot $mnt /rom +} + +ramoverlay() { + mkdir -p /tmp/root + mountdp /tmp/root /mnt -o bind +} + +[ "${0##*/}" = "firstboot" ] && { + [ -z "$rom" ] && { + echo "You do not have a squashfs partition; aborting" + echo "(firstboot cannot be run on jffs2 based firmwares)" + exit 1 + } + + [ "$1" = "switch2jffs" ] && { + mtd erase OpenWrt + mount -o remount,ro none / # try to avoid fs changing while copying + mount -o bind / /mnt + mount /dev/mtdblock/4 /rom/jffs -t jffs2 + echo -n "copying files ... " + cp -a /mnt/* /rom/jffs + umount /mnt + echo "done" + pivot /rom /mnt + mount -o move /mnt /tmp/root + pivot /jffs /rom + jffs2root --clean + exit 0 + } + + # script run manually + [ \! -z "$jffs" ] && { + echo "firstboot has already been run" + echo "jffs2 partition is mounted, only resetting files" + dupe $jffs $rom + exit 0 + } + + mtd erase OpenWrt + mountdp /dev/mtdblock/4 /jffs -t jffs2 +} diff --git a/package/base-files/brcm-2.4/etc/config/wireless b/package/base-files/brcm-2.4/etc/config/wireless new file mode 100644 index 0000000..9dc4945 --- /dev/null +++ b/package/base-files/brcm-2.4/etc/config/wireless @@ -0,0 +1,14 @@ +# Copyright (C) 2006 OpenWrt.org + +config wifi-device wl0 + option type broadcom + option channel 5 + +config wifi-iface + option device wl0 + option mode ap + option ssid OpenWrt + option hidden 0 + option encryption none + + diff --git a/package/base-files/brcm-2.4/etc/init.d/S05netconfig b/package/base-files/brcm-2.4/etc/init.d/S05netconfig new file mode 100755 index 0000000..71092da --- /dev/null +++ b/package/base-files/brcm-2.4/etc/init.d/S05netconfig @@ -0,0 +1,87 @@ +#!/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 wl0" + 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 wl0" # FIXME + c["wan_ifname"]="" + } + } + if (nvram["boardtype"] == "wgt634u") { + c["vlan0ports"] = "0 1 2 3 5*" + c["vlan1ports"] = "4 5" + c["lan_ifname"] = "eth0.0 ath0" + } + 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 wl0" + 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/preinit b/package/base-files/brcm-2.4/etc/preinit new file mode 100755 index 0000000..fb13e10 --- /dev/null +++ b/package/base-files/brcm-2.4/etc/preinit @@ -0,0 +1,13 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +export PATH=/bin:/sbin:/usr/bin:/usr/sbin +mount none /proc -t proc + +[ -f /etc/preinit.arch ] && . /etc/preinit.arch +[ -z "$FAILSAFE" ] || { + echo /bin/true > /proc/sys/kernel/hotplug + telnetd -l /bin/login <> /dev/null 2>&1 +} +mount_root ${FAILSAFE:+failsafe} +exec /sbin/init diff --git a/package/base-files/brcm-2.4/sbin/mount_root b/package/base-files/brcm-2.4/sbin/mount_root new file mode 100755 index 0000000..ec82cd4 --- /dev/null +++ b/package/base-files/brcm-2.4/sbin/mount_root @@ -0,0 +1,34 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +is_dirty() { + grep Broadcom /proc/cpuinfo >&- || return 1 + OFFSET="$(($(hexdump -v /dev/mtdblock/1 -s 20 -n 2 -e '"%d"')-1))" + return $(hexdump -v /dev/mtdblock/1 -s $OFFSET -n 1 -e '"%d"') +} + +size=$(awk '/Mem:/ {l=5242880;print((s=$2/2)<l)?$2-l:s}' /proc/meminfo) +mount none /tmp -t tmpfs -o size=$size + +if [ "$1" != "failsafe" ]; then + mtd unlock linux + mount | grep jffs2 >&- + if [ $? = 0 ] ; then + mount -o remount,rw /dev/root / + else + . /bin/firstboot + is_dirty + [ $? != 0 ] && { + echo "switching to jffs2" + mount /dev/mtdblock/4 /jffs -t jffs2 + pivot /jffs /rom + } || { + echo "jffs2 unusable; using ramdisk" + ramoverlay + } + fi +fi + +mount none /tmp -t tmpfs -o remount,nosuid,nodev,mode=1777 +mkdir -p /dev/pts +mount none /dev/pts -t devpts diff --git a/package/base-files/brcm-2.6/bin/firstboot b/package/base-files/brcm-2.6/bin/firstboot new file mode 100755 index 0000000..d37ce4f --- /dev/null +++ b/package/base-files/brcm-2.6/bin/firstboot @@ -0,0 +1,90 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +rom=$(awk '/squashfs/ {print $2}' /proc/mounts) +jffs=$(awk '/jffs2/ {print $2}' /proc/mounts) + +dupe() { # <new_root> <old_root> + cd $1 + echo -n "creating directories... " + { + cd $2 + find . -xdev -type d + echo "./dev ./jffs ./mnt ./proc ./tmp ./sys" + # xdev skips mounted directories + cd $1 + } | xargs mkdir -p + echo "done" + + echo -n "setting up symlinks... " + for file in $(cd $2; find . -xdev -type f;); do + case "$file" in + ./rom/note) ;; #nothing + ./etc/config*|\ + ./etc/resolv.conf|\ + ./usr/lib/ipkg/info) cp -af $2/$file $file;; + *) ln -sf /rom/${file#./*} $file;; + esac + done + for file in $(cd $2; find . -xdev -type l;); do + cp -af $2/${file#./*} $file + done + echo "done" +} + +pivot() { # <new_root> <old_root> + mount -o move /proc $1/proc && \ + pivot_root $1 $1$2 && { + mount -o move $2/dev /dev + mount -o move $2/tmp /tmp + mount -o move $2/sys /sys + return 0 + } +} + +mountdp() { # <device> <mount_point> <ignored> <fs> + dev=$1; mnt=$2; shift 2; opt=$* + mount $dev $mnt $opt + dupe $mnt $rom + pivot $mnt /rom +} + +ramoverlay() { + mkdir -p /tmp/root + mountdp /tmp/root /mnt -o bind +} + +[ "${0##*/}" = "firstboot" ] && { + [ -z "$rom" ] && { + echo "You do not have a squashfs partition; aborting" + echo "(firstboot cannot be run on jffs2 based firmwares)" + exit 1 + } + + [ "$1" = "switch2jffs" ] && { + mtd erase OpenWrt + mount -o remount,ro none / # try to avoid fs changing while copying + mount -o bind / /mnt + mount /dev/mtdblock/4 /rom/jffs -t jffs2 + echo -n "copying files ... " + cp -a /mnt/* /rom/jffs + umount /mnt + echo "done" + pivot /rom /mnt + mount -o move /mnt /tmp/root + pivot /jffs /rom + jffs2root --clean + exit 0 + } + + # script run manually + [ \! -z "$jffs" ] && { + echo "firstboot has already been run" + echo "jffs2 partition is mounted, only resetting files" + dupe $jffs $rom + exit 0 + } + + mtd erase OpenWrt + mountdp /dev/mtdblock/4 /jffs -t jffs2 +} diff --git a/package/base-files/brcm-2.6/etc/init.d/S05netconfig b/package/base-files/brcm-2.6/etc/init.d/S05netconfig new file mode 100755 index 0000000..e37633e --- /dev/null +++ b/package/base-files/brcm-2.6/etc/init.d/S05netconfig @@ -0,0 +1,87 @@ +#!/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 wl0" + 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 wl0" # FIXME + c["wan_ifname"]="" + } + } + if (nvram["boardtype"] == "wgt634u") { + c["vlan0ports"] = "0 1 2 3 5*" + c["vlan1ports"] = "4 5" + c["lan_ifname"] = "eth0.0 ath0" + } + 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 wl0" + 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/preinit b/package/base-files/brcm-2.6/etc/preinit new file mode 100755 index 0000000..fb13e10 --- /dev/null +++ b/package/base-files/brcm-2.6/etc/preinit @@ -0,0 +1,13 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +export PATH=/bin:/sbin:/usr/bin:/usr/sbin +mount none /proc -t proc + +[ -f /etc/preinit.arch ] && . /etc/preinit.arch +[ -z "$FAILSAFE" ] || { + echo /bin/true > /proc/sys/kernel/hotplug + telnetd -l /bin/login <> /dev/null 2>&1 +} +mount_root ${FAILSAFE:+failsafe} +exec /sbin/init diff --git a/package/base-files/brcm-2.6/sbin/mount_root b/package/base-files/brcm-2.6/sbin/mount_root new file mode 100755 index 0000000..e3bdd36 --- /dev/null +++ b/package/base-files/brcm-2.6/sbin/mount_root @@ -0,0 +1,35 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +is_dirty() { + grep Broadcom /proc/cpuinfo >&- || return 1 + OFFSET="$(($(hexdump -v /dev/mtdblock/1 -s 20 -n 2 -e '"%d"')-1))" + return $(hexdump -v /dev/mtdblock/1 -s $OFFSET -n 1 -e '"%d"') +} + +size=$(awk '/Mem:/ {l=5242880;print((s=$2/2)<l)?$2-l:s}' /proc/meminfo) +mount none /tmp -t tmpfs -o size=$size + +if [ "$1" != "failsafe" ]; then + mtd unlock linux + mount | grep jffs2 >&- + if [ $? = 0 ] ; then + mount -o remount,rw /dev/root / + else + . /bin/firstboot + is_dirty + [ $? != 0 ] && { + echo "switching to jffs2" + mount /dev/mtdblock/4 /jffs -t jffs2 + pivot /jffs /rom + } || { + echo "jffs2 unusable; using ramdisk" + ramoverlay + } + fi +fi + +mount none /tmp -t tmpfs -o remount,nosuid,nodev,mode=1777 +mkdir -p /dev/pts +mount none /dev/pts -t devpts +mount -t sysfs none /sys 2>&- diff --git a/package/base-files/default/bin/ipcalc b/package/base-files/default/bin/ipcalc new file mode 100755 index 0000000..e8efa6b --- /dev/null +++ b/package/base-files/default/bin/ipcalc @@ -0,0 +1,32 @@ +#!/bin/sh + +awk -f /usr/lib/common.awk -f - $* <<EOF +BEGIN { + ipaddr=ip2int(ARGV[1]) + netmask=ip2int(ARGV[2]) + network=and(ipaddr,netmask) + broadcast=or(network,compl(netmask)) + + start=or(network,and(ip2int(ARGV[3]),compl(netmask))) + limit=network+1 + if (start<limit) start=limit + + end=start+ARGV[4] + limit=or(network,compl(netmask))-1 + if (end>limit) end=limit + + print "IP="int2ip(ipaddr) + print "NETMASK="int2ip(netmask) + print "BROADCAST="int2ip(broadcast) + print "NETWORK="int2ip(network) + print "PREFIX="32-bitcount(compl(netmask)) + + # range calculations: + # ipcalc <ip> <netmask> <start> <num> + + if (ARGC > 3) { + print "START="int2ip(start) + print "END="int2ip(end-1) + } +} +EOF diff --git a/package/base-files/default/bin/login b/package/base-files/default/bin/login new file mode 100755 index 0000000..ff5d366 --- /dev/null +++ b/package/base-files/default/bin/login @@ -0,0 +1,18 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +grep '^root:[^!]' /etc/passwd >&- 2>&- +[ "$?" = "0" -a -z "$FAILSAFE" ] && +{ + echo "Login failed." + exit 0 +} || { +cat << EOF + === IMPORTANT ============================ + Use 'passwd' to set your login password + this will disable telnet and enable SSH + ------------------------------------------ +EOF +} + +exec /bin/ash --login diff --git a/package/base-files/default/bin/uci b/package/base-files/default/bin/uci new file mode 100755 index 0000000..7f43549 --- /dev/null +++ b/package/base-files/default/bin/uci @@ -0,0 +1,159 @@ +#!/bin/sh +# Shell script for interacting with config files +# +# Copyright (C) 2006 by Fokus Fraunhofer <carsten.tittel@fokus.fraumhofer.de> +# Copyright (C) 2006 by Felix Fietkau <nbd@openwrt.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +. /etc/functions.sh +include /lib/config + +do_get() { + [ $# -ne 3 ] && { + uci_usage get + exit 1 + } + local PACKAGE="$1" + local CONFIG="$2" + local OPTION="$3" + + uci_load "$PACAKGE" + config_get "$CONFIG" "$OPTION" +} + +do_set() { + [ $# -ne 4 ] && { + uci_usage set + exit 1 + } + uci_set "$@" +} + +do_add() { + [ $# -ne 3 ] && { + uci_usage add + exit 1 + } + uci_add "$@" +} + +do_rename() { + [ $# -ne 3 ] && { + uci_usage rename + exit 1 + } + uci_rename "$@" +} + +do_remove() { + [ $# -ne 3 -a $# -ne 2 ] && { + uci_usage rename + exit 1 + } + uci_remove "$@" +} + +do_commit() { + [ $# -ne 1 ] && { + uci_usage commit + exit 1 + } + uci_commit "$1" +} + +do_show() { + [ $# -gt 2 -o $# -lt 1 ] && { + uci_usage show + exit 1 + } + + PACKAGE="$1" + CONFIG="$2" + SECTION="" + + config_cb() { + if [ -z "$CONFIG" -o "$CONFIG" = "$2" ]; then + append SECTION "$2" + option_cb() { + append "${CONFIG_SECTION}_VARS" "$1" + } + else + option_cb() { + return 0 + } + fi + } + + uci_load "$PACKAGE" + + for section in $SECTION; do + config_get type "$section" TYPE + [ -z "$type" ] && continue + echo "@$section=$type" + eval "VARS=\"\${${section}_VARS}\"" + for var in $VARS; do + config_get val "$section" "$var" + [ -n "$val" ] && { + echo "${section}.${var}=${val}" + config_set "$section" "$var" "" + } + done + config_set "$section" TYPE "" + done +} + +uci_usage() { + case "$1" in + show) echo "$0 show <package> [<config>]";; + get) echo "$0 get <package> <config> <option>";; + set) echo "$0 set <package> <config> <option> <value>";; + add) echo "$0 add <package> <type> <config>";; + del) echo "$0 del <package> <config> [<option>]";; + rename) echo "$0 rename <package> <config> <name>";; + commit) echo "$0 commit <package>";; + *) + echo "Syntax: $0 <command> <arguments...>" + echo + uci_usage show + uci_usage get + uci_usage set + uci_usage add + uci_usage del + uci_usage rename + uci_usage commit + echo + exit 1 + ;; + esac +} + +if [ $# -eq 0 ] ; then + uci_usage + exit 0 +fi +CMD="$1" +shift +case "$CMD" in + set) do_set "$@";; + add) do_add "$@";; + del) do_remove "$@";; + rename) do_rename "$@";; + get) do_get "$@";; + show) do_show "$@";; + commit) do_commit "$@";; + *) uci_usage;; +esac +exit 0 diff --git a/package/base-files/default/etc/banner b/package/base-files/default/etc/banner new file mode 100644 index 0000000..c2fbc12 --- /dev/null +++ b/package/base-files/default/etc/banner @@ -0,0 +1,10 @@ + _______ ________ __ + | |.-----.-----.-----.| | | |.----.| |_ + | - || _ | -__| || | | || _|| _| + |_______|| __|_____|__|__||________||__| |____| + |__| W I R E L E S S F R E E D O M + KAMIKAZE (bleeding edge, $R) ------------------- + * 10 oz Vodka Shake well with ice and strain + * 10 oz Triple sec mixture into 10 shot glasses. + * 10 oz lime juice Salute! + --------------------------------------------------- diff --git a/package/base-files/default/etc/config/network b/package/base-files/default/etc/config/network new file mode 100644 index 0000000..1d5ded3 --- /dev/null +++ b/package/base-files/default/etc/config/network @@ -0,0 +1,13 @@ +# Copyright (C) 2006 OpenWrt.org + +config interface loopback + option ifname lo + option proto static + option ipaddr 127.0.0.1 + option netmask 255.0.0.0 + +config interface lan + option ifname eth0 + option proto static + option ipaddr 192.168.1.1 + option netmask 255.255.255.0 diff --git a/package/base-files/default/etc/functions.sh b/package/base-files/default/etc/functions.sh new file mode 100755 index 0000000..9c3057e --- /dev/null +++ b/package/base-files/default/etc/functions.sh @@ -0,0 +1,119 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org +# Copyright (C) 2006 Fokus Fraunhofer <carsten.tittel@fokus.fraunhofer.de> + +alias debug=${DEBUG:-:} + +# newline +N=" +" + +_C=0 + +# valid interface? +if_valid () ( + ifconfig "$1" >&- 2>&- || + [ "${1%%[0-9]}" = "br" ] || + { debug "# missing interface '$1' ignored"; false; } +) + +hotplug_dev() { + env -i ACTION=$1 INTERFACE=$2 /sbin/hotplug net +} + +append() { + local var="$1" + local value="$2" + local sep="${3:- }" + eval "export ${var}=\"\${${var}:+\${${var}}${value:+$sep}}\$value\"" +} + +reset_cb() { + config_cb() { + return 0 + } + option_cb() { + return 0 + } +} +reset_cb + +config () { + local cfgtype="$1" + local name="$2" + _C=$(($_C + 1)) + name="${name:-cfg${_C}}" + config_cb "$cfgtype" "$name" + export CONFIG_SECTION="$name" + export CONFIG_${CONFIG_SECTION}_TYPE="$cfgtype" +} + +option () { + local varname="$1"; shift + export CONFIG_${CONFIG_SECTION}_${varname}="$*" + option_cb "$varname" "$*" +} + +config_rename() { + local OLD="$1" + local NEW="$2" + local oldsetting + local newvar + + [ -z "$OLD" -o -z "$NEW" ] && return + for oldsetting in `set | grep ^CONFIG_${OLD}_ | \ + sed -e 's/\(.*\)=.*$/\1/'` ; do + newvar="CONFIG_${NEW}_${oldsetting##CONFIG_${OLD}_}" + eval "${newvar}=\${$oldsetting}" + unset "$oldsetting" + done + [ "$CONFIG_SECTION" = "$OLD" ] && CONFIG_SECTION="$NEW" +} + +config_unset() { + config_set "$1" "$2" "" +} + +config_clear() { + [ -z "$CONFIG_SECTION" ] && return + for oldsetting in `set | grep ^CONFIG_${CONFIG_SECTION}_ | \ + sed -e 's/\(.*\)=.*$/\1/'` ; do + unset $oldsetting + done + unset CONFIG_SECTION +} + +config_load() { + local DIR="./" + _C=0 + [ \! -e "$1" -a -e "/etc/config/$1" ] && { + DIR="/etc/config/" + } + [ -e "$DIR$1" ] && { + CONFIG_FILENAME="$DIR$1" + . ${CONFIG_FILENAME} + } || return 1 + ${CD:+cd -} >/dev/null + ${CONFIG_SECTION:+config_cb} +} + +config_get() { + case "$3" in + "") eval "echo \"\${CONFIG_${1}_${2}}\"";; + *) eval "$1=\"\${CONFIG_${2}_${3}}\"";; + esac +} + +config_set() { + export CONFIG_${1}_${2}="${3}" +} + +load_modules() { + sed 's/^[^#]/insmod &/' $* | ash 2>&- || : +} + +include() { + for file in $(ls $1/*.sh 2>/dev/null); do + . $file + done +} diff --git a/package/base-files/default/etc/group b/package/base-files/default/etc/group new file mode 100644 index 0000000..c4e77f3 --- /dev/null +++ b/package/base-files/default/etc/group @@ -0,0 +1,2 @@ +root:x:0: +nogroup:x:65534: diff --git a/package/base-files/default/etc/hosts b/package/base-files/default/etc/hosts new file mode 100644 index 0000000..ce138ec --- /dev/null +++ b/package/base-files/default/etc/hosts @@ -0,0 +1 @@ +127.0.0.1 localhost OpenWrt diff --git a/package/base-files/default/etc/hotplug.d/block/01-mount b/package/base-files/default/etc/hotplug.d/block/01-mount new file mode 100755 index 0000000..b6275e5 --- /dev/null +++ b/package/base-files/default/etc/hotplug.d/block/01-mount @@ -0,0 +1,26 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +DEV=${DEVPATH##*/} +{ +echo "ACTION=$ACTION DEVPATH=$DEVPATH $0 $*" +case "$ACTION" in +add) + echo -ne "waiting for $DEV" + while [ ! -b /dev/$DEV ]; do { + echo -ne "." + sleep 1 + time=$((time+1)); [ $time -gt 10 ] && break + }; done + + [ ${DEV%%[0-9]} != ${DEV} ] && { + mkdir -p /tmp/$DEV + mount /dev/$DEV /tmp/$DEV -t auto -o sync + } + ;; +remove) + umount /tmp/$DEV + rm -rf /dev/$DEV /tmp/$DEV + ;; +esac +} 2>&1 | logger diff --git a/package/base-files/default/etc/hotplug.d/net/10-net b/package/base-files/default/etc/hotplug.d/net/10-net new file mode 100644 index 0000000..4e5c304 --- /dev/null +++ b/package/base-files/default/etc/hotplug.d/net/10-net @@ -0,0 +1,28 @@ +# Copyright (C) 2006 OpenWrt.org + +include /lib/network + +addif() { + scan_interfaces + setup_interface "$INTERFACE" + + # find all vlan configurations for this interface and set them up as well + for ifc in $interfaces; do + config_get iftype "$ifc" type + config_get ifs "$ifc" device + for dev in $ifs; do + [ "${dev%%\.*}" = "$INTERFACE" -a "$dev" != "$INTERFACE" ] && { + add_vlan "$dev" + } + done + done +} + +case "$ACTION" in + add|register) + case "$PHYSDEVDRIVER" in + natsemi) sleep 1;; + esac + addif + ;; +esac diff --git a/package/base-files/default/etc/hotplug.d/usb/01-ln b/package/base-files/default/etc/hotplug.d/usb/01-ln new file mode 100755 index 0000000..f9eda02 --- /dev/null +++ b/package/base-files/default/etc/hotplug.d/usb/01-ln @@ -0,0 +1,33 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +case "$ACTION" in +add) + [ -f /sys/${DEVPATH}/idVendor -a "$(cat /sys/${DEVPATH}/idVendor)" -ne "0000" ] && { + cd /sys/${DEVPATH} + + NUM=${DEVPATH##*/} + HOST=$(find ${NUM}:*/host* -type d) + HOST=${HOST##*/host} + + echo -ne "waiting for disk" + + while [ ! -d "/dev/scsi/host${HOST}/bus0/target0/lun0" ]; do { + echo -ne "." + sleep 1; + time=$((time+1)); [ $time -gt 10 ] && break + }; done + echo + + cd /sys/bus/scsi/devices/${HOST}\:0\:0\:0 + for BLOCK in block:* ; do { + cd ${BLOCK} + BLOCK=${BLOCK##block\:} + ln -sf /dev/scsi/host${HOST}/bus0/target0/lun0/disc /dev/${BLOCK} + for DEV in ${BLOCK}*; do { + ln -sf /dev/scsi/host${HOST}/bus0/target0/lun0/part${DEV##$BLOCK} /dev/$DEV + }; done + }; done + } 2>&1 | logger + ;; +esac diff --git a/package/base-files/default/etc/init.d/S10boot b/package/base-files/default/etc/init.d/S10boot new file mode 100755 index 0000000..77b5ca7 --- /dev/null +++ b/package/base-files/default/etc/init.d/S10boot @@ -0,0 +1,25 @@ +#!/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 new file mode 100755 index 0000000..be04504 --- /dev/null +++ b/package/base-files/default/etc/init.d/S40network @@ -0,0 +1,11 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2006 OpenWrt.org + +start() { + setup_switch() { return 0; } + + include /lib/network + setup_switch + /sbin/wifi +} + diff --git a/package/base-files/default/etc/init.d/S50httpd b/package/base-files/default/etc/init.d/S50httpd new file mode 100755 index 0000000..a05b10c --- /dev/null +++ b/package/base-files/default/etc/init.d/S50httpd @@ -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/S50telnet b/package/base-files/default/etc/init.d/S50telnet new file mode 100755 index 0000000..228eac2 --- /dev/null +++ b/package/base-files/default/etc/init.d/S50telnet @@ -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/init.d/S60cron b/package/base-files/default/etc/init.d/S60cron new file mode 100755 index 0000000..a450c36 --- /dev/null +++ b/package/base-files/default/etc/init.d/S60cron @@ -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/rcS b/package/base-files/default/etc/init.d/rcS new file mode 100755 index 0000000..7fae7f5 --- /dev/null +++ b/package/base-files/default/etc/init.d/rcS @@ -0,0 +1,26 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +${FAILSAFE:+exit} + +# FIXME: add logging configuration +#[ -f /etc/config/network ] && . /etc/config/network +#eval $(ipcalc "$log_ipaddr") +#[ "$log_ipaddr" = "$IP" ] || log_ipaddr="" +syslogd -C 16 #${log_ipaddr:+-L -R $log_ipaddr} +klogd + +( + for i in /etc/init.d/S*; do + $i start 2>&1 + done + + sysctl -p >&- + + # automagically run firstboot + { mount|grep "on / type tmpfs" 1>&-; } && { + lock /tmp/.switch2jffs + firstboot switch2jffs + lock -u /tmp/.switch2jffs + } +) | logger -s -p 6 -t '' & diff --git a/package/base-files/default/etc/inittab b/package/base-files/default/etc/inittab new file mode 100644 index 0000000..39e134c --- /dev/null +++ b/package/base-files/default/etc/inittab @@ -0,0 +1,3 @@ +::sysinit:/etc/init.d/rcS +tts/0::askfirst:/bin/ash --login +#tts/1::askfirst:/bin/ash --login diff --git a/package/base-files/default/etc/ipkg.conf b/package/base-files/default/etc/ipkg.conf new file mode 100644 index 0000000..2931d2c --- /dev/null +++ b/package/base-files/default/etc/ipkg.conf @@ -0,0 +1,3 @@ +src snapshots http://openwrt.org/downloads/snapshots/$S/packages +dest root / +dest ram /tmp diff --git a/package/base-files/default/etc/nvram.sh b/package/base-files/default/etc/nvram.sh new file mode 100644 index 0000000..ddbd88b --- /dev/null +++ b/package/base-files/default/etc/nvram.sh @@ -0,0 +1,19 @@ +#!/bin/ash +# Copyright (C) 2006 OpenWrt.org + + +# allow env to override nvram +nvram () { + if [ -x /usr/sbin/nvram ]; then + case $1 in + get) eval "echo \${$2:-\$(/usr/sbin/nvram get $2)}";; + *) /usr/sbin/nvram $*;; + esac + else + case $1 in + get) eval "echo \${$2:-\${DEFAULT_$2}}";; + *);; + esac + fi +} + diff --git a/package/base-files/default/etc/passwd b/package/base-files/default/etc/passwd new file mode 100644 index 0000000..3b660a0 --- /dev/null +++ b/package/base-files/default/etc/passwd @@ -0,0 +1,2 @@ +root:!:0:0:root:/tmp:/bin/ash +nobody:*:65534:65534:nobody:/var:/bin/false diff --git a/package/base-files/default/etc/profile b/package/base-files/default/etc/profile new file mode 100644 index 0000000..ae514b0 --- /dev/null +++ b/package/base-files/default/etc/profile @@ -0,0 +1,12 @@ +#!/bin/sh +[ -f /etc/banner ] && cat /etc/banner + +export PATH=/bin:/sbin:/usr/bin:/usr/sbin +export PS1='\u@\h:\w\$ ' + +alias more=less +[ -x /usr/bin/vim ] || alias vim=vi + +arp() { cat /proc/net/arp; } +ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; } +reboot() { ifdown wan 2>&1 >/dev/null ; /sbin/reboot; } diff --git a/package/base-files/default/etc/protocols b/package/base-files/default/etc/protocols new file mode 100644 index 0000000..53fecb6 --- /dev/null +++ b/package/base-files/default/etc/protocols @@ -0,0 +1,56 @@ +# Internet (IP) protocols +# +# Updated from http://www.iana.org/assignments/protocol-numbers and other +# sources. +# New protocols will be added on request if they have been officially +# assigned by IANA and are not historical. +# If you need a huge list of used numbers please install the nmap package. + +ip 0 IP # internet protocol, pseudo protocol number +#hopopt 0 HOPOPT # IPv6 Hop-by-Hop Option [RFC1883] +icmp 1 ICMP # internet control message protocol +igmp 2 IGMP # Internet Group Management +ggp 3 GGP # gateway-gateway protocol +ipencap 4 IP-ENCAP # IP encapsulated in IP (officially ``IP'') +st 5 ST # ST datagram mode +tcp 6 TCP # transmission control protocol +egp 8 EGP # exterior gateway protocol +igp 9 IGP # any private interior gateway (Cisco) +pup 12 PUP # PARC universal packet protocol +udp 17 UDP # user datagram protocol +hmp 20 HMP # host monitoring protocol +xns-idp 22 XNS-IDP # Xerox NS IDP +rdp 27 RDP # "reliable datagram" protocol +iso-tp4 29 ISO-TP4 # ISO Transport Protocol class 4 [RFC905] +xtp 36 XTP # Xpress Transfer Protocol +ddp 37 DDP # Datagram Delivery Protocol +idpr-cmtp 38 IDPR-CMTP # IDPR Control Message Transport +ipv6 41 IPv6 # Internet Protocol, version 6 +ipv6-route 43 IPv6-Route # Routing Header for IPv6 +ipv6-frag 44 IPv6-Frag # Fragment Header for IPv6 +idrp 45 IDRP # Inter-Domain Routing Protocol +rsvp 46 RSVP # Reservation Protocol +gre 47 GRE # General Routing Encapsulation +esp 50 IPSEC-ESP # Encap Security Payload [RFC2046] +ah 51 IPSEC-AH # Authentication Header [RFC2402] +skip 57 SKIP # SKIP +ipv6-icmp 58 IPv6-ICMP # ICMP for IPv6 +ipv6-nonxt 59 IPv6-NoNxt # No Next Header for IPv6 +ipv6-opts 60 IPv6-Opts # Destination Options for IPv6 +rspf 73 RSPF CPHB # Radio Shortest Path First (officially CPHB) +vmtp 81 VMTP # Versatile Message Transport +eigrp 88 EIGRP # Enhanced Interior Routing Protocol (Cisco) +ospf 89 OSPFIGP # Open Shortest Path First IGP +ax.25 93 AX.25 # AX.25 frames +ipip 94 IPIP # IP-within-IP Encapsulation Protocol +etherip 97 ETHERIP # Ethernet-within-IP Encapsulation [RFC3378] +encap 98 ENCAP # Yet Another IP encapsulation [RFC1241] +# 99 # any private encryption scheme +pim 103 PIM # Protocol Independent Multicast +ipcomp 108 IPCOMP # IP Payload Compression Protocol +vrrp 112 VRRP # Virtual Router Redundancy Protocol +l2tp 115 L2TP # Layer Two Tunneling Protocol [RFC2661] +isis 124 ISIS # IS-IS over IPv4 +sctp 132 SCTP # Stream Control Transmission Protocol +fc 133 FC # Fibre Channel + diff --git a/package/base-files/default/etc/rc.common b/package/base-files/default/etc/rc.common new file mode 100755 index 0000000..20d1efa --- /dev/null +++ b/package/base-files/default/etc/rc.common @@ -0,0 +1,73 @@ +#!/bin/sh +. /etc/functions.sh + +start() { + return 0 +} + +stop() { + return 0 +} + +reload() { + return 1 +} + +restart() { + stop + start +} + +boot() { + start +} + +shutdown() { + return 0 +} + +disable() { + rm -f /etc/rc.d/${initscript##*/} +} + +enable() { + disable + ln -s /etc/init.d/${initscript##*/} /etc/rc.d/${initscript##*/} +} + +depends() { + return 0 +} + +help() { + cat <<EOF +Syntax: $initscript [command] + +Available commands: + start Start the service + stop Stop the service + restart Restart the service + reload Reload configuration files (or restart if that fails) +$EXTRA_HELP +EOF +} + +initscript="$1" +action="$2" + +. "$initscript" + +cmds= +for cmd in $EXTRA_COMMANDS; do + cmds="$cmd) $cmd;;" +done +eval "case \"\$action\" in + start) start;; + stop) stop;; + reload) reload || restart;; + restart) restart;; + boot) boot;; + shutdown) shutdown;; + $cmds + *) help;; +esac" diff --git a/package/base-files/default/etc/resolv.conf b/package/base-files/default/etc/resolv.conf new file mode 100644 index 0000000..9617eac --- /dev/null +++ b/package/base-files/default/etc/resolv.conf @@ -0,0 +1,2 @@ +nameserver 127.0.0.1 +search lan diff --git a/package/base-files/default/etc/shells b/package/base-files/default/etc/shells new file mode 100644 index 0000000..006aa38 --- /dev/null +++ b/package/base-files/default/etc/shells @@ -0,0 +1 @@ +/bin/ash diff --git a/package/base-files/default/etc/sysctl.conf b/package/base-files/default/etc/sysctl.conf new file mode 100644 index 0000000..e60038c --- /dev/null +++ b/package/base-files/default/etc/sysctl.conf @@ -0,0 +1,12 @@ +kernel.panic=3 +net.ipv4.conf.default.arp_ignore=1 +net.ipv4.conf.all.arp_ignore=1 +net.ipv4.ip_forward=1 +net.ipv4.icmp_echo_ignore_broadcasts=1 +net.ipv4.icmp_ignore_bogus_error_responses=1 +net.ipv4.tcp_fin_timeout=30 +net.ipv4.tcp_keepalive_time=120 +net.ipv4.tcp_syncookies=1 +net.ipv4.tcp_timestamps=0 +net.ipv4.ip_conntrack_tcp_timeouts="300 43200 120 60 120 120 10 60 30 120" +net.ipv4.ip_conntrack_udp_timeouts="60 180" diff --git a/package/base-files/default/lib/config/uci-update.awk b/package/base-files/default/lib/config/uci-update.awk new file mode 100644 index 0000000..efa8758 --- /dev/null +++ b/package/base-files/default/lib/config/uci-update.awk @@ -0,0 +1,160 @@ +# Configuration update functions +# +# Copyright (C) 2006 by Fokus Fraunhofer <carsten.tittel@fokus.fraunhofer.de> +# Copyright (C) 2006 by Felix Fietkau <nbd@openwrt.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +function read_file(filename, result) { + while ((getline <filename) == 1) { + result = result $0 "\n" + } + gsub(/\n*$/, "", result) + return result +} + +function cmd2option(str, tmp) { + if (match(str,"=")!=0) { + res = "\toption " substr(str,1,RSTART-1) "\t'" substr(str,RSTART+1) "'" + } else { + res= "" + } + return res +} + +function cmd2config(atype, aname) { + return "config \"" atype "\" \"" aname "\"" +} + +function update_config(cfg, update, \ + lines, line, l, n, i, i2, section, scnt, remove, tmp, aidx, rest) { + scnt = 1 + linecnt=split(cfg "\n", lines, "\n") + + cfg = "" + for (n = 1; n < linecnt; n++) { + # stupid parser for quoted arguments (e.g. for the type string). + # not to be used to gather variable values (backslash escaping doesn't work) + line = lines[n] + gsub(/^[ \t]*/, "", line) + gsub(/#.*$/, "", line) + i2 = 1 + delete l + rest = line + while (length(rest)) { + if (match(rest, /[ \t\"]+/)) { + if (RSTART>1) { + l[i2] = substr(rest,1,RSTART-1) + i2++ + } + aidx=index(rest,"\"") + if (aidx>=RSTART && aidx<=RSTART+RLENGTH) { + rest=substr(rest,aidx+1) + # find the end of the string + match(rest,/\"/) + l[i2]=substr(rest,1,RSTART-1) + i2++ + } + rest=substr(rest,RSTART+RLENGTH) + } else { + l[i2] = rest + i2++ + rest = "" + } + } + line = lines[n] + + # when a command wants to set a config value for the current + # section and a blank line is encountered before an option with + # the same name, insert it here to maintain some coherency between + # manually and automatically created option lines + # if an option with the same name appears after this point, simply + # ignore it, because it is already set. + if ((section != "") && (l[1] != "option")) { + if (line ~ /^[ \t]*$/) { + if (update ~ "^" section "\\.") { + gsub("^" section ".", "", update) + cfg = cfg cmd2option(update) "\n" + gsub(/=.*$/, "", update) + update = "-" section "." update + } + } + } + + if (l[1] == "config") { + # look for all unset values + if (section != "") { + flag=0 + if (update ~ "^" section "\\.") { + flag=1 + gsub("^" section ".", "", update) + cfg = cfg cmd2option(update) "\n" + + update = "-" section "." update + } + if (flag!=0) cfg = cfg "\n" + } + + remove = "" + section = l[3] + if (!length(section)) { + section = "cfg" scnt + } + scnt++ + if (update == "-" section) { + remove = "section" + update = "" + } else if (update ~ "^@" section "=") { + update = "" + } else if (update ~ "^&" section "=") { + gsub("^&" section "=", "", update) + line = cmd2config(l[2],update) + update = "" + } + } + if (remove == "option") remove = "" + if (l[1] == "option") { + if (update ~ "^-" section "\\." l[2] "$") remove = "option" + # if a supplied config value already exists, replace the whole line + if (match(update, "^" section "." l[2] "=")) { + gsub("^" section ".", "", update) + line = cmd2option(update) + update = "" + } + } + if (remove == "") cfg = cfg line "\n" + } + + # any new options for the last section?? + if (section != "") { + if (update ~ "^" section "\\.") { + gsub("^" section ".", "", update) + cfg = cfg cmd2option(update) "\n" + + update = "-" section "." update + } + } + + if (update ~ "^@") { + # new section + section = stype = substr(update,2) + gsub(/=.*$/,"",section) + gsub(/^.*=/,"",stype) + cfg = cfg "\nconfig \"" stype "\" \"" section "\"\n" + } + + return cfg +} diff --git a/package/base-files/default/lib/config/uci.sh b/package/base-files/default/lib/config/uci.sh new file mode 100755 index 0000000..ccd6ee5 --- /dev/null +++ b/package/base-files/default/lib/config/uci.sh @@ -0,0 +1,138 @@ +#!/bin/sh +# Shell script defining macros for manipulating config files +# +# Copyright (C) 2006 by Fokus Fraunhofer <carsten.tittel@fokus.fraumhofer.de> +# Copyright (C) 2006 by Felix Fietkau <nbd@openwrt.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +uci_load() { + config_load "$PACKAGE" + local PACKAGE_BASE="$(basename "$PACKAGE")" + [ -f "/tmp/.uci/${PACKAGE_BASE}" ] && { + . "/tmp/.uci/${PACKAGE_BASE}" + config_cb + } +} + +uci_do_update() { + local FILENAME="$1" + local UPDATE="$2" + awk -f /lib/config/uci-update.awk -f - <<EOF +BEGIN { + config = read_file("$FILENAME") + $UPDATE + print config +} +EOF +} + +uci_add_update() { + local PACKAGE="$1" + local UPDATE="$2" + local PACKAGE_BASE="$(basename "$PACKAGE")" + + # FIXME: add locking? + mkdir -p "/tmp/.uci" + echo "$UPDATE" >> "/tmp/.uci/${PACKAGE_BASE}" +} + +uci_set() { + local PACKAGE="$1" + local CONFIG="$2" + local OPTION="$3" + local VALUE="$4" + + ( # spawn a subshell so you don't mess up the current environment + uci_load "$PACKAGE" + config_get type "$CONFIG" TYPE + [ -z "$type" ] + ) || uci_add_update "$PACKAGE" "CONFIG_SECTION='$CONFIG'${N}option '$OPTION' '$VALUE'" +} + +uci_add() { + local PACKAGE="$1" + local TYPE="$2" + local CONFIG="$3" + + uci_add_update "$PACKAGE" "config '$TYPE' '$CONFIG'" +} + +uci_rename() { + local PACKAGE="$1" + local CONFIG="$2" + local VALUE="$3" + + uci_add_update "$PACKAGE" "config_rename '$CONFIG' '$VALUE'" +} + +uci_remove() { + local PACKAGE="$1" + local CONFIG="$2" + local OPTION="$3" + + if [ -z "$OPTION" ]; then + uci_add_update "$PACKAGE" "config_clear '$CONFIG'" + else + uci_add_update "$PACKAGE" "config_unset '$CONFIG' '$OPTION'" + fi +} + +uci_commit() { + local PACKAGE="$1" + local PACKAGE_BASE="$(basename "$PACKAGE")" + + mkdir -p /tmp/.uci + lock "/tmp/.uci/$PACKAGE_BASE.lock" + [ -f "/tmp/.uci/$PACKAGE_BASE" ] && ( + updatestr="" + + # replace handlers + config() { + append updatestr "config = update_config(config, \"@$2=$1\")" "$N" + } + option() { + append updatestr "config = update_config(config, \"$CONFIG_SECTION.$1=$2\")" "$N" + } + config_rename() { + append updatestr "config = update_config(config, \"&$1=$2\")" "$N" + } + config_unset() { + append updatestr "config = update_config(config, \"-$1.$2\")" "$N" + } + config_clear() { + append updatestr "config = update_config(config, \"-$1\")" "$N" + } + + . "/tmp/.uci/$PACKAGE_BASE" + + # completely disable handlers so that they don't get in the way + config() { + return 0 + } + option() { + return 0 + } + + config_load "$PACKAGE" || CONFIG_FILENAME="$ROOT/etc/config/$PACKAGE_BASE" + uci_do_update "$CONFIG_FILENAME" "$updatestr" > "/tmp/.uci/$PACKAGE_BASE.new" && { + mv -f "/tmp/.uci/$PACKAGE_BASE.new" "$CONFIG_FILENAME" && \ + rm -f "/tmp/.uci/$PACKAGE_BASE" + } + ) + lock -u "/tmp/.uci/$PACKAGE_BASE.lock" +} + + diff --git a/package/base-files/default/lib/network/config.sh b/package/base-files/default/lib/network/config.sh new file mode 100755 index 0000000..18f794a --- /dev/null +++ b/package/base-files/default/lib/network/config.sh @@ -0,0 +1,143 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +# DEBUG="echo" + +find_config() { + local iftype device iface ifaces ifn + for ifn in $interfaces; do + config_get iftype "$ifn" type + config_get iface "$ifn" ifname + case "$iftype" in + bridge) config_get ifaces "$ifn" ifnames;; + esac + config_get device "$ifn" device + for ifc in $device $iface $ifaces; do + [ "$ifc" = "$1" ] && { + echo "$ifn" + return 0 + } + done + done + + return 1; +} + +scan_interfaces() { + local mode iftype iface ifname device + interfaces= + config_cb() { + config_get iftype "$CONFIG_SECTION" TYPE + case "$iftype" in + interface) + config_get proto "$CONFIG_SECTION" proto + append interfaces "$CONFIG_SECTION" + config_get iftype "$CONFIG_SECTION" type + config_get ifname "$CONFIG_SECTION" ifname + config_set "$CONFIG_SECTION" device "$ifname" + case "$iftype" in + bridge) + config_set "$CONFIG_SECTION" ifnames "$ifname" + config_set "$CONFIG_SECTION" ifname br-"$CONFIG_SECTION" + ;; + esac + ( type "scan_$proto" ) >/dev/null 2>/dev/null && eval "scan_$proto '$CONFIG_SECTION'" + ;; + esac + } + config_load network +} + +add_vlan() { + local vif="${1%\.*}" + + [ "$1" = "$vif" ] || ifconfig "$1" >/dev/null 2>/dev/null || { + ifconfig "$vif" up 2>/dev/null >/dev/null || add_vlan "$vif" + $DEBUG vconfig add "$vif" "${1##*\.}" + } +} + +setup_interface() { + local iface="$1" + local config="$2" + local proto + + [ -n "$config" ] || { + config=$(find_config "$iface") + [ "$?" = 0 ] || return 1 + } + + proto="${3:-$(config_get "$config" proto)}" + config_get iftype "$config" type + + # Setup VLAN interfaces + add_vlan "$iface" + + # Setup bridging + case "$iftype" in + bridge) + ifconfig "$iface" up 2>/dev/null >/dev/null + ifconfig "br-$config" 2>/dev/null >/dev/null && { + $DEBUG brctl addif "br-$config" "$iface" + return 0 + } || { + $DEBUG brctl addbr "br-$config" + $DEBUG brctl setfd "br-$config" 0 + $DEBUG brctl addif "br-$config" "$iface" + iface="br-$config" + } + ;; + esac + + # Interface settings + config_get mtu "$config" mtu + $DEBUG ifconfig "$iface" ${mtu:+mtu $mtu} up + + pidfile="/var/run/$iface.pid" + case "$proto" in + static) + config_get ipaddr "$config" ipaddr + config_get netmask "$config" netmask + [ -z "$ipaddr" -o -z "$netmask" ] && return 1 + + config_get ip6addr "$config" ip6addr + config_get gateway "$config" gateway + config_get dns "$config" dns + + $DEBUG ifconfig "$iface" "$ipaddr" netmask "$netmask" + [ -z "$gateway" ] || route add default gw "$gateway" + [ -z "$dns" -o -f /tmp/resolv.conf ] || { + for ns in $dns; do + echo "nameserver $ns" >> /tmp/resolv.conf + done + } + + env -i ACTION="ifup" INTERFACE="config" DEVICE="$iface" PROTO=static /sbin/hotplug "iface" & + ;; + dhcp) + pid="$(cat "$pidfile" 2>/dev/null)" + [ -n "$pid" -a -d "/proc/$pid" ] && kill -9 "$pid" + + config_get ipaddr "$config" ipaddr + config_get netmask "$config" netmask + config_get hostname "$config" hostname + config_get proto1 "$config" proto + + [ -z "$ipaddr" ] || \ + $DEBUG ifconfig "$iface" "$ipaddr" ${netmask:+netmask "$netmask"} + + # don't stay running in background if dhcp is not the main proto on the interface (e.g. when using pptp) + [ "$proto1" != "$proto" ] && dhcpopts="-n -q" + $DEBUG udhcpc -i "$iface" ${ipaddr:+-r $ipaddr} ${hostname:+-H $hostname} -b -p "$pidfile" ${dhcpopts:- -R &} + ;; + *) + if ( eval "type setup_interface_$proto" ) >/dev/null 2>/dev/null; then + eval "setup_interface_$proto '$iface' '$config' '$proto'" + else + echo "Interface type $proto not supported." + return 1 + fi + ;; + esac +} + diff --git a/package/base-files/default/rom/note b/package/base-files/default/rom/note new file mode 100644 index 0000000..1746eb0 --- /dev/null +++ b/package/base-files/default/rom/note @@ -0,0 +1,3 @@ +SQUASHFS USERS: +After firstboot has been run, / will be jffs2 and /rom will be squashfs +(* except when in failsafe) diff --git a/package/base-files/default/sbin/hotplug b/package/base-files/default/sbin/hotplug new file mode 100755 index 0000000..b1b6f97 --- /dev/null +++ b/package/base-files/default/sbin/hotplug @@ -0,0 +1,26 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +# bypass the normal hotplug path for firmware loading +# would otherwise cause problems with drivers like bcm43xx +[ "$1" = "firmware" -a "$ACTION" = "add" ] && { + [ -f "/lib/firmware/$FIRMWARE" ] && { + echo 1 > "/sys$DEVPATH/loading" + cp "/lib/firmware/$FIRMWARE" "/sys$DEVPATH/data" + echo 0 > "/sys$DEVPATH/loading" + } + exit 0 +} + +. /etc/functions.sh + +PATH=/bin:/sbin:/usr/bin:/usr/sbin +LOGNAME=root +USER=root +export PATH LOGNAME USER + +[ \! -z "$1" -a -d /etc/hotplug.d/$1 ] && { + for script in $(ls /etc/hotplug.d/$1/* 2>&-); do ( + [ -f $script ] && . $script + ); done +} diff --git a/package/base-files/default/sbin/ifdown b/package/base-files/default/sbin/ifdown new file mode 100755 index 0000000..073e80d --- /dev/null +++ b/package/base-files/default/sbin/ifdown @@ -0,0 +1,34 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +[ $# = 0 ] && { echo " $0 <group>"; exit; } +. /etc/functions.sh +include /lib/network +scan_interfaces + +cfg=$1 +debug "### ifdown $cfg ###" + +config_get proto "$cfg" proto +[ -z "$proto" ] && { echo "interface not found."; exit; } + +# kill active ppp daemon +pid="$(cat /var/run/ppp-${cfg}.pid 2>/dev/null)" +[ -n "$pid" -a -d "/proc/$pid" ] && { + kill $pid + sleep 1 + [ -d "/proc/$pid" ] && kill -9 $pid +} + +# kill any other process associated with the interface +config_get ifname "$cfg" ifname +pid="$(cat /var/run/${ifname}.pid 2>/dev/null)" +[ -n "$pid" -a -d "/proc/$pid" ] && kill -9 $pid + +config_get ifname "$cfg" ifname +ifconfig "$ifname" >/dev/null 2>/dev/null && { + ifconfig "$ifname" 0.0.0.0 down + + config_get iftype "$cfg" type + [ "$iftype" = "bridge" ] && brctl delbr "$ifname" +} diff --git a/package/base-files/default/sbin/ifup b/package/base-files/default/sbin/ifup new file mode 100755 index 0000000..c7055d4 --- /dev/null +++ b/package/base-files/default/sbin/ifup @@ -0,0 +1,14 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +. /sbin/ifdown "$@" + +config_get iftype "$1" type +case "$iftype" in + bridge) config_get ifname "$1" ifnames;; + *) config_get ifname "$1" ifname;; +esac + +for dev in $ifname; do + setup_interface "$dev" "$1" +done diff --git a/package/base-files/default/sbin/mount_root b/package/base-files/default/sbin/mount_root new file mode 100755 index 0000000..81660f0 --- /dev/null +++ b/package/base-files/default/sbin/mount_root @@ -0,0 +1,10 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +mount none /proc -t proc +size=$(awk '/Mem:/ {l=5242880;print((s=$2/2)<l)?$2-l:s}' /proc/meminfo) +mount none /tmp -t tmpfs -o size=$size,nosuid,nodev,mode=1777 +mkdir -p /dev/pts +mount none /dev/pts -t devpts +mount -t sysfs none /sys 2>&- +mount -o remount,rw /dev/root / diff --git a/package/base-files/default/sbin/wifi b/package/base-files/default/sbin/wifi new file mode 100755 index 0000000..4a3ec8c --- /dev/null +++ b/package/base-files/default/sbin/wifi @@ -0,0 +1,44 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +. /etc/functions.sh + +config_get_bool() { + local _tmp + config_get "$1" "$2" "$3" + eval "_tmp=\$$1" + case "$_tmp" in + 1|on|enabled) eval "$1=1";; + 0|off|disabled) eval "$1=0";; + *) eval "$1=${4:-0}";; + esac +} + +config_cb() { + config_get TYPE "$CONFIG_SECTION" TYPE + case "$TYPE" in + wifi-device) + append DEVICES "$CONFIG_SECTION" + ;; + wifi-iface) + config_get device "$CONFIG_SECTION" device + config_get vifs "$device" vifs + append vifs "$CONFIG_SECTION" + config_set "$device" vifs "$vifs" + ;; + esac +} + +config_load wireless +include /lib/wifi + +for device in $DEVICES; do ( + config_get iftype "$device" type + eval "type setup_$iftype" 2>/dev/null >/dev/null && { + eval "scan_$iftype '$device'" + eval "setup_$iftype '$device'" && { + # TODO: set up network settings + /bin/true + } || echo "$device($iftype): Setup failed" || true + } || echo "$device($iftype): Interface type not supported" +); done diff --git a/package/base-files/default/usr/lib/common.awk b/package/base-files/default/usr/lib/common.awk new file mode 100644 index 0000000..c5ce680 --- /dev/null +++ b/package/base-files/default/usr/lib/common.awk @@ -0,0 +1,68 @@ +# Copyright (C) 2006 OpenWrt.org + +function portstr(type, str) { + gsub(/-/, ":", str) + if (insmod_mport != 1) { + print "insmod ipt_multiport >&- 2>&-" + insmod_mport = 1 + } + if (type == "src") return " -m multiport --sports " str + else return " -m multiport --dports " str +} + +function str2ipt(str) { + str2data(str) + _cmd = "" + if (_l["src"] != "") _cmd = _cmd " -s " _l["src"] + if (_l["dest"] != "") _cmd = _cmd " -d " _l["dest"] + if (_l["proto"] != "") { + _cmd = _cmd " -p " _l["proto"] + } + # scripts need to check for proto="" and emit two rules in that case + if ((_l["proto"] == "") || (_l["proto"] == "tcp") || (_l["proto"] == "udp")) { + if (_l["sport"] != "") _cmd = _cmd portstr("src", _l["sport"]) + if (_l["dport"] != "") _cmd = _cmd portstr("dest", _l["dport"]) + } + if (_l["layer7"] != "") { + if (insmod_l7 != 1) { + print "insmod ipt_layer7 >&- 2>&-" + insmod_l7 = 1 + } + _cmd = _cmd " -m layer7 --l7proto " _l["layer7"] + } + return _cmd +} + +function str2data(str) { + delete _l + _n = split(str, _o, "[\t ]") + for (_i = 1; _i <= _n; _i++) { + _n2 = split(_o[_i], _c, "=") + if (_n2 == 2) _l[_c[1]] = _c[2] + } +} + +function bitcount(c) { + c=and(rshift(c, 1),0x55555555)+and(c,0x55555555) + c=and(rshift(c, 2),0x33333333)+and(c,0x33333333) + c=and(rshift(c, 4),0x0f0f0f0f)+and(c,0x0f0f0f0f) + c=and(rshift(c, 8),0x00ff00ff)+and(c,0x00ff00ff) + c=and(rshift(c,16),0x0000ffff)+and(c,0x0000ffff) + return c +} + +function validate_netmask(nm) { + return and(-nm,compl(nm)) +} + +function ip2int(ip) { + for (ret=0,n=split(ip,a,"\."),x=1;x<=n;x++) ret=or(lshift(ret,8),a[x]) + return ret +} + +function int2ip(ip,ret,x) { + ret=and(ip,255) + ip=rshift(ip,8) + for(;x<3;ret=and(ip,255)"."ret,ip=rshift(ip,8),x++); + return ret +} diff --git a/package/base-files/default/usr/lib/parse-config.awk b/package/base-files/default/usr/lib/parse-config.awk new file mode 100644 index 0000000..9ce32b7 --- /dev/null +++ b/package/base-files/default/usr/lib/parse-config.awk @@ -0,0 +1,42 @@ +# Copyright (C) 2006 OpenWrt.org + +{ + line=$0 + gsub(/^[ \t]*/, "") + gsub(/[ \t]*$/, "") +} + +$1 == "@define" { + v[$2] = $3 +} + +$1 == "@ifdef" { + if_open = 1 + if (v[$2] != "") noprint = 0 + else noprint = 1 +} + +$1 == "@ifndef" { + if_open = 1 + if (v[$2] != "") noprint = 1 + else noprint = 0 +} + +$1 == "@else" { + if (noprint == 1) noprint = 0 + else noprint = 1 +} + +($1 !~ /^@[a-zA-Z]/) && (noprint != 1) { + n=split(line "@@", a, /@@/) + for (i=1; i<=n; i++) { + if ((i % 2) == 1) printf a[i] + else printf v[a[i]] + } + print "" +} + +$1 == "@endif" { + if_open = 0 + noprint = 0 +} diff --git a/package/base-files/default/usr/share/udhcpc/default.script b/package/base-files/default/usr/share/udhcpc/default.script new file mode 100755 index 0000000..74e7037 --- /dev/null +++ b/package/base-files/default/usr/share/udhcpc/default.script @@ -0,0 +1,57 @@ +#!/bin/sh +[ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1 +. /etc/functions.sh +include /lib/network + +RESOLV_CONF="/tmp/resolv.conf" + +hotplug_event() { + scan_interfaces + for ifc in $interfaces; do + config_get ifname $ifc ifname + [ "$ifname" = "$interface" ] || continue + + config_get proto $ifc proto + [ "$proto" = "dhcp" ] || continue + + env -i ACTION="$1" INTERFACE="$ifname" PROTO=dhcp /sbin/hotplug iface + done +} + +case "$1" in + deconfig) + ifconfig $interface 0.0.0.0 + hotplug_event ifdown + ;; + renew|bound) + ifconfig $interface $ip \ + netmask ${subnet:-255.255.255.0} \ + broadcast ${broadcast:-+} + + if [ -n "$router" ] ; then + echo "deleting routers" + while route del default gw 0.0.0.0 dev $interface >&- 2>&- ; do :; done + + for i in $router ; do + echo "adding router $i" + route add default gw $i dev $interface + done + fi + + [ -n "$dns" ] && { + echo -n > $RESOLV_CONF + ${domain:+echo search $domain} >> $RESOLV_CONF + for i in $dns ; do + echo "adding dns $i" + echo "nameserver $i" >> $RESOLV_CONF + done + } + + hotplug_event ifup + + # user rules + [ -f /etc/udhcpc.user ] && . /etc/udhcpc.user + ;; +esac + +exit 0 diff --git a/package/base-files/rb532-2.6/etc/config/network b/package/base-files/rb532-2.6/etc/config/network new file mode 100644 index 0000000..8279690 --- /dev/null +++ b/package/base-files/rb532-2.6/etc/config/network @@ -0,0 +1,12 @@ +# Copyright (C) 2006 OpenWrt.org + +config interface loopback + option ifname lo + option proto static + option ipaddr 127.0.0.1 + option netmask 255.0.0.0 + +config interface lan + option ifname eth0 + option proto dhcp + diff --git a/package/base-files/sibyte-2.6/etc/config/network b/package/base-files/sibyte-2.6/etc/config/network new file mode 100644 index 0000000..9b65652 --- /dev/null +++ b/package/base-files/sibyte-2.6/etc/config/network @@ -0,0 +1,14 @@ +# Copyright (C) 2006 OpenWrt.org + +config interface loopback + option ifname lo + option proto static + option ipaddr 127.0.0.1 + option netmask 255.0.0.0 + +config interface lan + option type bridge + option ifname "eth0 ath0" + option proto static + option ipaddr 192.168.1.1 + option netmask 255.255.255.0 diff --git a/package/base-files/sibyte-2.6/etc/inittab b/package/base-files/sibyte-2.6/etc/inittab new file mode 100644 index 0000000..a6f4e17 --- /dev/null +++ b/package/base-files/sibyte-2.6/etc/inittab @@ -0,0 +1,5 @@ +# Copyright (C) 2006 OpenWrt.org + +::sysinit:/etc/init.d/rcS +duart/0::askfirst:/bin/ash --login +#tts/1::askfirst:/bin/ash --login diff --git a/package/base-files/src/adam2patcher.c b/package/base-files/src/adam2patcher.c new file mode 100644 index 0000000..25a7807 --- /dev/null +++ b/package/base-files/src/adam2patcher.c @@ -0,0 +1,59 @@ +/* + * patcher.c - ADAM2 patcher for Netgear DG834 (and compatible) + * + * Copyright (C) 2006 Felix Fietkau + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <stddef.h> +#include <unistd.h> +#include <fcntl.h> +#include <stdint.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <string.h> + +#include <sys/ioctl.h> + +int main(int argc, char **argv) +{ + int fd; + char *ptr; + uint32_t *i; + + if (argc != 2) { + fprintf(stderr, "Usage: %s <filename>\n", argv[0]); + exit(1); + } + + if (((fd = open(argv[1], O_RDWR)) < 0) + || ((ptr = mmap(0, 128 * 1024, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == (void *) (-1))) { + fprintf(stderr, "Can't open file\n"); + exit(1); + } + + i = (uint32_t *) &ptr[0x3944]; + if (*i == 0x0c000944) { + fprintf(stderr, "Unpatched ADAM2 detected. Patching... "); + *i = 0x00000000; + msync(i, sizeof(*i), MS_SYNC|MS_INVALIDATE); + fprintf(stderr, "done!\n"); + } else if (*i == 0x00000000) { + fprintf(stderr, "Patched ADAM2 detected.\n"); + } else { + fprintf(stderr, "Unknown ADAM2 detected. Can't patch!\n"); + } + + close(fd); +} diff --git a/package/base-files/src/jffs2root.c b/package/base-files/src/jffs2root.c new file mode 100644 index 0000000..14662fc --- /dev/null +++ b/package/base-files/src/jffs2root.c @@ -0,0 +1,133 @@ +/* + * jffs2root.c + * + * Copyright (C) 2005 Mike Baker + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <stddef.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <string.h> + +#include <sys/ioctl.h> +#include <linux/mtd/mtd.h> + +#define FILENAME "/dev/mtdblock/1" + +struct trx_header { + unsigned magic; /* "HDR0" */ + unsigned len; /* Length of file including header */ + unsigned crc32; /* 32-bit CRC from flag_version to end of file */ + unsigned flag_version; /* 0:15 flags, 16:31 version */ + unsigned offsets[3]; /* Offsets of partitions from start of header */ +}; + +unsigned long *crc32; + +void init_crc32() +{ + unsigned long crc; + unsigned long poly = 0xEDB88320L; + int n, bit; + if ((crc32 = (unsigned long *) malloc(256 * sizeof(unsigned long))) == (void *)-1) { + perror("malloc"); + exit(1); + } + for (n = 0; n < 256; n++) { + crc = (unsigned long) n; + for (bit = 0; bit < 8; bit++) + crc = (crc & 1) ? (poly ^ (crc >> 1)) : (crc >> 1); + crc32[n] = crc; + } +} + +unsigned int crc32buf(char *buf, size_t len) +{ + unsigned int crc = 0xFFFFFFFF; + for (; len; len--, buf++) + crc = crc32[(crc ^ *buf) & 0xff] ^ (crc >> 8); + return crc; +} + +int main(int argc, char **argv) +{ + int fd; + struct mtd_info_user mtdInfo; + unsigned long len; + struct trx_header *ptr; + char *buf; + + if (((fd = open(FILENAME, O_RDWR)) < 0) + || ((len = lseek(fd, 0, SEEK_END)) < 0) + || ((ptr = (struct trx_header *) mmap(0, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == (void *) (-1)) + || (ptr->magic != 0x30524448)) { + printf("Error reading trx info\n"); + exit(-1); + } + close (fd); + + if (((fd = open("/dev/mtd/1", O_RDWR)) < 0) + || (ioctl(fd, MEMGETINFO, &mtdInfo))) { + fprintf(stderr, "Could not get MTD device info from %s\n", FILENAME); + close(fd); + exit(1); + } + close(fd); + + if (argc > 1 && !strcmp(argv[1],"--move")) { + if (ptr->offsets[2] >= ptr->len) { + printf("Partition already moved outside trx\n"); + } else { + init_crc32(); + ptr->offsets[2] += (mtdInfo.erasesize - 1); + ptr->offsets[2] &= ~(mtdInfo.erasesize - 1); + ptr->len = ptr->offsets[2]; + ptr->crc32 = crc32buf((void *) &(ptr->flag_version), ptr->len - offsetof(struct trx_header, flag_version)); + msync(ptr,sizeof(struct trx_header),MS_SYNC|MS_INVALIDATE); + printf("Partition moved; please reboot\n"); + } + } else if (argc > 1 && !strcmp(argv[1], "--clean")) { + buf = (char *) ptr; + if (buf[ptr->offsets[1] - 1] == 0) { + init_crc32(); + buf[ptr->offsets[1] - 1] = 1; + ptr->crc32 = crc32buf((void *) &(ptr->flag_version), ptr->len - offsetof(struct trx_header, flag_version)); + msync(ptr,sizeof(struct trx_header),MS_SYNC|MS_INVALIDATE); + printf("Partition marked as clean\n"); + } + } else { + int x; + printf(" erase: 0x%08x\n",mtdInfo.erasesize); + printf("=== trx ===\n"); + printf("mapped: 0x%08x\n", (unsigned)ptr); + printf(" magic: 0x%08x\n", ptr->magic); + printf(" len: 0x%08x\n", ptr->len); + printf(" crc: 0x%08x\n", ptr->crc32); + for (x = 0; x < 3; x++) + printf(" offset[%d]: 0x%08x\n", x, ptr->offsets[x]); + } + + munmap((void *) ptr, len); + return 0; +} diff --git a/package/base-files/x86-2.4/etc/config/network b/package/base-files/x86-2.4/etc/config/network new file mode 100644 index 0000000..68d8e42 --- /dev/null +++ b/package/base-files/x86-2.4/etc/config/network @@ -0,0 +1,19 @@ +# Copyright (C) 2006 OpenWrt.org + +config interface loopback + option ifname lo + option proto static + option ipaddr 127.0.0.1 + option netmask 255.0.0.0 + +config interface lan + option type bridge + option ifname "eth1 eth2" + option proto static + option ipaddr 192.168.1.1 + option netmask 255.255.255.0 + +config interface wan + option ifname eth0 + option proto dhcp + diff --git a/package/base-files/x86-2.6/etc/config/network b/package/base-files/x86-2.6/etc/config/network new file mode 100644 index 0000000..68d8e42 --- /dev/null +++ b/package/base-files/x86-2.6/etc/config/network @@ -0,0 +1,19 @@ +# Copyright (C) 2006 OpenWrt.org + +config interface loopback + option ifname lo + option proto static + option ipaddr 127.0.0.1 + option netmask 255.0.0.0 + +config interface lan + option type bridge + option ifname "eth1 eth2" + option proto static + option ipaddr 192.168.1.1 + option netmask 255.255.255.0 + +config interface wan + option ifname eth0 + option proto dhcp + diff --git a/package/base-files/xscale-2.6/etc/config/network b/package/base-files/xscale-2.6/etc/config/network new file mode 100644 index 0000000..1d9b55b --- /dev/null +++ b/package/base-files/xscale-2.6/etc/config/network @@ -0,0 +1,11 @@ +# Network configuration file + +config interface loopback + option ifname lo + option proto static + option ipaddr 127.0.0.1 + option netmask 255.0.0.0 + +config interface lan + option ifname eth0 + option proto dhcp |