From 5c105d9f3fd086aff195d3849dcf847d6b0bd927 Mon Sep 17 00:00:00 2001 From: blogic Date: Fri, 5 Oct 2012 10:12:53 +0000 Subject: branch Attitude Adjustment git-svn-id: svn://svn.openwrt.org/openwrt/branches/attitude_adjustment@33625 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/files/bin/ipcalc.sh | 62 ++++ package/base-files/files/bin/login.sh | 19 ++ package/base-files/files/etc/banner | 16 + package/base-files/files/etc/config/network | 14 + package/base-files/files/etc/config/system | 10 + package/base-files/files/etc/diag.sh | 4 + package/base-files/files/etc/functions.sh | 1 + package/base-files/files/etc/group | 10 + package/base-files/files/etc/hosts | 1 + .../files/etc/hotplug.d/ieee1394/10-ieee1394 | 13 + package/base-files/files/etc/hotplug.d/usb/10-usb | 13 + package/base-files/files/etc/hotplug2-common.rules | 43 +++ package/base-files/files/etc/hotplug2-init.rules | 5 + package/base-files/files/etc/init.d/boot | 103 +++++++ package/base-files/files/etc/init.d/done | 20 ++ package/base-files/files/etc/init.d/led | 80 +++++ package/base-files/files/etc/init.d/rcS | 26 ++ package/base-files/files/etc/init.d/sysctl | 7 + package/base-files/files/etc/init.d/sysntpd | 37 +++ package/base-files/files/etc/init.d/umount | 8 + package/base-files/files/etc/init.d/usb | 9 + package/base-files/files/etc/init.d/watchdog | 13 + package/base-files/files/etc/inittab | 4 + package/base-files/files/etc/openwrt_release | 6 + package/base-files/files/etc/openwrt_version | 1 + package/base-files/files/etc/passwd | 5 + package/base-files/files/etc/preinit | 44 +++ package/base-files/files/etc/profile | 15 + package/base-files/files/etc/protocols | 56 ++++ package/base-files/files/etc/rc.common | 85 ++++++ package/base-files/files/etc/rc.local | 4 + package/base-files/files/etc/services | 171 +++++++++++ package/base-files/files/etc/shadow | 5 + package/base-files/files/etc/shells | 1 + package/base-files/files/etc/sysctl.conf | 27 ++ package/base-files/files/etc/sysupgrade.conf | 5 + .../files/etc/uci-defaults/migrate-shadow | 12 + .../files/etc/uci-defaults/migrate-sysctl | 17 ++ .../files/lib/firstboot/05_firstboot_skip | 10 + .../files/lib/firstboot/10_determine_parts | 46 +++ .../files/lib/firstboot/10_no_fo_clear_overlay | 17 ++ .../files/lib/firstboot/10_reset_has_mini_fo | 12 + .../base-files/files/lib/firstboot/20_has_mini_fo | 13 + .../files/lib/firstboot/20_no_fo_mount_jffs | 15 + .../files/lib/firstboot/20_reset_clear_jffs | 14 + .../files/lib/firstboot/30_is_rootfs_mounted | 10 + .../base-files/files/lib/firstboot/30_no_fo_pivot | 11 + .../files/lib/firstboot/30_reset_copy_rom | 13 + .../files/lib/firstboot/40_copy_ramoverlay | 15 + .../files/lib/firstboot/40_no_fo_copy_ramoverlay | 14 + package/base-files/files/lib/firstboot/50_pivot | 17 ++ .../files/lib/firstboot/99_10_no_fo_cleanup | 13 + .../files/lib/firstboot/99_10_with_fo_cleanup | 25 ++ package/base-files/files/lib/functions.sh | 340 +++++++++++++++++++++ package/base-files/files/lib/functions/boot.sh | 150 +++++++++ package/base-files/files/lib/functions/network.sh | 170 +++++++++++ package/base-files/files/lib/functions/service.sh | 129 ++++++++ .../base-files/files/lib/functions/uci-defaults.sh | 230 ++++++++++++++ .../files/lib/preinit/02_default_set_state | 7 + package/base-files/files/lib/preinit/05_mount_skip | 13 + .../base-files/files/lib/preinit/10_check_for_mtd | 20 ++ .../base-files/files/lib/preinit/10_essential_fs | 25 ++ .../files/lib/preinit/10_indicate_failsafe | 18 ++ .../files/lib/preinit/10_indicate_preinit | 52 ++++ .../files/lib/preinit/20_check_jffs2_ready | 19 ++ .../files/lib/preinit/20_device_fs_mount | 37 +++ .../files/lib/preinit/30_device_fs_daemons | 36 +++ .../base-files/files/lib/preinit/30_failsafe_wait | 85 ++++++ package/base-files/files/lib/preinit/40_init_shm | 10 + .../base-files/files/lib/preinit/40_mount_devpts | 15 + .../base-files/files/lib/preinit/40_mount_jffs2 | 26 ++ .../files/lib/preinit/40_run_failsafe_hook | 13 + .../files/lib/preinit/41_merge_overlay_hooks | 24 ++ .../base-files/files/lib/preinit/50_choose_console | 31 ++ .../files/lib/preinit/50_indicate_regular_preinit | 12 + .../base-files/files/lib/preinit/60_init_hotplug | 10 + .../base-files/files/lib/preinit/70_initramfs_test | 14 + .../files/lib/preinit/70_pivot_jffs2_root | 14 + package/base-files/files/lib/preinit/80_mount_root | 10 + .../base-files/files/lib/preinit/90_init_console | 14 + .../base-files/files/lib/preinit/90_mount_no_jffs2 | 12 + .../base-files/files/lib/preinit/90_restore_config | 17 ++ .../files/lib/preinit/99_10_failsafe_login | 18 ++ .../files/lib/preinit/99_10_mount_no_mtd | 12 + .../base-files/files/lib/preinit/99_10_run_init | 16 + package/base-files/files/lib/upgrade/common.sh | 230 ++++++++++++++ .../files/lib/upgrade/keep.d/base-files-essential | 9 + package/base-files/files/rom/note | 3 + package/base-files/files/sbin/firstboot | 34 +++ package/base-files/files/sbin/hotplug-call | 17 ++ package/base-files/files/sbin/led.sh | 25 ++ package/base-files/files/sbin/mount_root | 26 ++ package/base-files/files/sbin/sysupgrade | 187 ++++++++++++ package/base-files/files/sbin/wifi | 204 +++++++++++++ 94 files changed, 3551 insertions(+) create mode 100755 package/base-files/files/bin/ipcalc.sh create mode 100755 package/base-files/files/bin/login.sh create mode 100644 package/base-files/files/etc/banner create mode 100644 package/base-files/files/etc/config/network create mode 100644 package/base-files/files/etc/config/system create mode 100644 package/base-files/files/etc/diag.sh create mode 120000 package/base-files/files/etc/functions.sh create mode 100644 package/base-files/files/etc/group create mode 100644 package/base-files/files/etc/hosts create mode 100644 package/base-files/files/etc/hotplug.d/ieee1394/10-ieee1394 create mode 100644 package/base-files/files/etc/hotplug.d/usb/10-usb create mode 100644 package/base-files/files/etc/hotplug2-common.rules create mode 100644 package/base-files/files/etc/hotplug2-init.rules create mode 100755 package/base-files/files/etc/init.d/boot create mode 100755 package/base-files/files/etc/init.d/done create mode 100755 package/base-files/files/etc/init.d/led create mode 100755 package/base-files/files/etc/init.d/rcS create mode 100755 package/base-files/files/etc/init.d/sysctl create mode 100755 package/base-files/files/etc/init.d/sysntpd create mode 100755 package/base-files/files/etc/init.d/umount create mode 100755 package/base-files/files/etc/init.d/usb create mode 100755 package/base-files/files/etc/init.d/watchdog create mode 100644 package/base-files/files/etc/inittab create mode 100644 package/base-files/files/etc/openwrt_release create mode 100644 package/base-files/files/etc/openwrt_version create mode 100644 package/base-files/files/etc/passwd create mode 100755 package/base-files/files/etc/preinit create mode 100644 package/base-files/files/etc/profile create mode 100644 package/base-files/files/etc/protocols create mode 100755 package/base-files/files/etc/rc.common create mode 100644 package/base-files/files/etc/rc.local create mode 100644 package/base-files/files/etc/services create mode 100644 package/base-files/files/etc/shadow create mode 100644 package/base-files/files/etc/shells create mode 100644 package/base-files/files/etc/sysctl.conf create mode 100644 package/base-files/files/etc/sysupgrade.conf create mode 100644 package/base-files/files/etc/uci-defaults/migrate-shadow create mode 100644 package/base-files/files/etc/uci-defaults/migrate-sysctl create mode 100644 package/base-files/files/lib/firstboot/05_firstboot_skip create mode 100644 package/base-files/files/lib/firstboot/10_determine_parts create mode 100644 package/base-files/files/lib/firstboot/10_no_fo_clear_overlay create mode 100644 package/base-files/files/lib/firstboot/10_reset_has_mini_fo create mode 100644 package/base-files/files/lib/firstboot/20_has_mini_fo create mode 100644 package/base-files/files/lib/firstboot/20_no_fo_mount_jffs create mode 100644 package/base-files/files/lib/firstboot/20_reset_clear_jffs create mode 100644 package/base-files/files/lib/firstboot/30_is_rootfs_mounted create mode 100644 package/base-files/files/lib/firstboot/30_no_fo_pivot create mode 100644 package/base-files/files/lib/firstboot/30_reset_copy_rom create mode 100644 package/base-files/files/lib/firstboot/40_copy_ramoverlay create mode 100644 package/base-files/files/lib/firstboot/40_no_fo_copy_ramoverlay create mode 100644 package/base-files/files/lib/firstboot/50_pivot create mode 100644 package/base-files/files/lib/firstboot/99_10_no_fo_cleanup create mode 100644 package/base-files/files/lib/firstboot/99_10_with_fo_cleanup create mode 100755 package/base-files/files/lib/functions.sh create mode 100644 package/base-files/files/lib/functions/boot.sh create mode 100644 package/base-files/files/lib/functions/network.sh create mode 100644 package/base-files/files/lib/functions/service.sh create mode 100644 package/base-files/files/lib/functions/uci-defaults.sh create mode 100644 package/base-files/files/lib/preinit/02_default_set_state create mode 100644 package/base-files/files/lib/preinit/05_mount_skip create mode 100644 package/base-files/files/lib/preinit/10_check_for_mtd create mode 100644 package/base-files/files/lib/preinit/10_essential_fs create mode 100644 package/base-files/files/lib/preinit/10_indicate_failsafe create mode 100644 package/base-files/files/lib/preinit/10_indicate_preinit create mode 100644 package/base-files/files/lib/preinit/20_check_jffs2_ready create mode 100644 package/base-files/files/lib/preinit/20_device_fs_mount create mode 100644 package/base-files/files/lib/preinit/30_device_fs_daemons create mode 100644 package/base-files/files/lib/preinit/30_failsafe_wait create mode 100644 package/base-files/files/lib/preinit/40_init_shm create mode 100644 package/base-files/files/lib/preinit/40_mount_devpts create mode 100644 package/base-files/files/lib/preinit/40_mount_jffs2 create mode 100644 package/base-files/files/lib/preinit/40_run_failsafe_hook create mode 100644 package/base-files/files/lib/preinit/41_merge_overlay_hooks create mode 100644 package/base-files/files/lib/preinit/50_choose_console create mode 100644 package/base-files/files/lib/preinit/50_indicate_regular_preinit create mode 100644 package/base-files/files/lib/preinit/60_init_hotplug create mode 100644 package/base-files/files/lib/preinit/70_initramfs_test create mode 100644 package/base-files/files/lib/preinit/70_pivot_jffs2_root create mode 100644 package/base-files/files/lib/preinit/80_mount_root create mode 100644 package/base-files/files/lib/preinit/90_init_console create mode 100644 package/base-files/files/lib/preinit/90_mount_no_jffs2 create mode 100644 package/base-files/files/lib/preinit/90_restore_config create mode 100644 package/base-files/files/lib/preinit/99_10_failsafe_login create mode 100644 package/base-files/files/lib/preinit/99_10_mount_no_mtd create mode 100644 package/base-files/files/lib/preinit/99_10_run_init create mode 100644 package/base-files/files/lib/upgrade/common.sh create mode 100644 package/base-files/files/lib/upgrade/keep.d/base-files-essential create mode 100644 package/base-files/files/rom/note create mode 100755 package/base-files/files/sbin/firstboot create mode 100755 package/base-files/files/sbin/hotplug-call create mode 100755 package/base-files/files/sbin/led.sh create mode 100755 package/base-files/files/sbin/mount_root create mode 100755 package/base-files/files/sbin/sysupgrade create mode 100755 package/base-files/files/sbin/wifi (limited to 'package/base-files/files') diff --git a/package/base-files/files/bin/ipcalc.sh b/package/base-files/files/bin/ipcalc.sh new file mode 100755 index 000000000..d6ef16870 --- /dev/null +++ b/package/base-files/files/bin/ipcalc.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +awk -f - $* <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 + + if (ARGC > 3) { + print "START="int2ip(start) + print "END="int2ip(end) + } +} +EOF diff --git a/package/base-files/files/bin/login.sh b/package/base-files/files/bin/login.sh new file mode 100755 index 000000000..04b3fe250 --- /dev/null +++ b/package/base-files/files/bin/login.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# Copyright (C) 2006-2011 OpenWrt.org + +if ( ! grep -qs '^root:[!x]\?:' /etc/shadow || \ + ! grep -qs '^root:[!x]\?:' /etc/passwd ) && \ + [ -z "$FAILSAFE" ] +then + echo "Login failed." + exit 0 +else +cat << EOF + === IMPORTANT ============================ + Use 'passwd' to set your login password + this will disable telnet and enable SSH + ------------------------------------------ +EOF +fi + +exec /bin/ash --login diff --git a/package/base-files/files/etc/banner b/package/base-files/files/etc/banner new file mode 100644 index 000000000..058cb5573 --- /dev/null +++ b/package/base-files/files/etc/banner @@ -0,0 +1,16 @@ + _______ ________ __ + | |.-----.-----.-----.| | | |.----.| |_ + | - || _ | -__| || | | || _|| _| + |_______|| __|_____|__|__||________||__| |____| + |__| W I R E L E S S F R E E D O M + ----------------------------------------------------- + ATTITUDE ADJUSTMENT (%C, %R) + ----------------------------------------------------- + * 1/4 oz Vodka Pour all ingredients into mixing + * 1/4 oz Gin tin with ice, strain into glass. + * 1/4 oz Amaretto + * 1/4 oz Triple sec + * 1/4 oz Peach schnapps + * 1/4 oz Sour mix + * 1 splash Cranberry juice + ----------------------------------------------------- diff --git a/package/base-files/files/etc/config/network b/package/base-files/files/etc/config/network new file mode 100644 index 000000000..a35fd2ef9 --- /dev/null +++ b/package/base-files/files/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 ifname eth0 + option type bridge + option proto static + option ipaddr 192.168.1.1 + option netmask 255.255.255.0 diff --git a/package/base-files/files/etc/config/system b/package/base-files/files/etc/config/system new file mode 100644 index 000000000..d2124e417 --- /dev/null +++ b/package/base-files/files/etc/config/system @@ -0,0 +1,10 @@ +config system + option hostname OpenWrt + option timezone UTC + +config timeserver ntp + list server 0.openwrt.pool.ntp.org + list server 1.openwrt.pool.ntp.org + list server 2.openwrt.pool.ntp.org + list server 3.openwrt.pool.ntp.org + option enable_server 0 diff --git a/package/base-files/files/etc/diag.sh b/package/base-files/files/etc/diag.sh new file mode 100644 index 000000000..8726a4398 --- /dev/null +++ b/package/base-files/files/etc/diag.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# Copyright (C) 2006-2009 OpenWrt.org + +set_state() { :; } diff --git a/package/base-files/files/etc/functions.sh b/package/base-files/files/etc/functions.sh new file mode 120000 index 000000000..13b3190e7 --- /dev/null +++ b/package/base-files/files/etc/functions.sh @@ -0,0 +1 @@ +../lib/functions.sh \ No newline at end of file diff --git a/package/base-files/files/etc/group b/package/base-files/files/etc/group new file mode 100644 index 000000000..d36685139 --- /dev/null +++ b/package/base-files/files/etc/group @@ -0,0 +1,10 @@ +root:x:0: +daemon:x:1: +adm:x:4: +mail:x:8: +audio:x:29: +www-data:x:33: +ftp:x:55: +users:x:100: +network:x:101: +nogroup:x:65534: diff --git a/package/base-files/files/etc/hosts b/package/base-files/files/etc/hosts new file mode 100644 index 000000000..75721cd5a --- /dev/null +++ b/package/base-files/files/etc/hosts @@ -0,0 +1 @@ +127.0.0.1 localhost diff --git a/package/base-files/files/etc/hotplug.d/ieee1394/10-ieee1394 b/package/base-files/files/etc/hotplug.d/ieee1394/10-ieee1394 new file mode 100644 index 000000000..7e142a211 --- /dev/null +++ b/package/base-files/files/etc/hotplug.d/ieee1394/10-ieee1394 @@ -0,0 +1,13 @@ +#!/bin/sh + +# Copyright (C) 2009 OpenWrt.org + +case "$ACTION" in + add) + # update LEDs + ;; + remove) + # update LEDs + ;; +esac + diff --git a/package/base-files/files/etc/hotplug.d/usb/10-usb b/package/base-files/files/etc/hotplug.d/usb/10-usb new file mode 100644 index 000000000..7e142a211 --- /dev/null +++ b/package/base-files/files/etc/hotplug.d/usb/10-usb @@ -0,0 +1,13 @@ +#!/bin/sh + +# Copyright (C) 2009 OpenWrt.org + +case "$ACTION" in + add) + # update LEDs + ;; + remove) + # update LEDs + ;; +esac + diff --git a/package/base-files/files/etc/hotplug2-common.rules b/package/base-files/files/etc/hotplug2-common.rules new file mode 100644 index 000000000..c284f8f3f --- /dev/null +++ b/package/base-files/files/etc/hotplug2-common.rules @@ -0,0 +1,43 @@ + +# uncomment me to log hotplug events +# DEVPATH is set { +# exec logger -s -t hotplug -p daemon.info "name=%DEVNAME%, path=%DEVPATH%" +# } + +$include /etc/hotplug2-platform.rules + +DEVNAME ~~ (^null$|^full$|^ptmx$|^zero$|^gpio|^hvc) { + makedev /dev/%DEVNAME% 0666 + next-event +} + +DEVNAME == mapper/control { + makedev /dev/%DEVNAME% 0600 + next-event +} + +ACTION == add, DEVPATH is set { + makedev /dev/%DEVNAME% 0644 +} + +ACTION == add, DEVPATH is set, DEVNAME ~~ ^tty { + chmod 0666 /dev/%DEVNAME% +} + +ACTION == add, DEVPATH is set, DEVNAME ~~ ^ppp { + chmod 0600 /dev/%DEVNAME% +} + +ACTION == remove, DEVPATH is set, MAJOR is set, MINOR is set { + remove /dev/%DEVNAME% +} + +FIRMWARE is set, ACTION == add { + exec /sbin/hotplug-call firmware + load-firmware /lib/firmware + next-event +} + +SUBSYSTEM == platform { + exec /sbin/hotplug-call %SUBSYSTEM% +} diff --git a/package/base-files/files/etc/hotplug2-init.rules b/package/base-files/files/etc/hotplug2-init.rules new file mode 100644 index 000000000..f01169776 --- /dev/null +++ b/package/base-files/files/etc/hotplug2-init.rules @@ -0,0 +1,5 @@ +$include /etc/hotplug2-common.rules + +SUBSYSTEM == button { + exec kill -USR1 1 +} diff --git a/package/base-files/files/etc/init.d/boot b/package/base-files/files/etc/init.d/boot new file mode 100755 index 000000000..43837a80f --- /dev/null +++ b/package/base-files/files/etc/init.d/boot @@ -0,0 +1,103 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2006-2011 OpenWrt.org + +START=10 +STOP=98 + +system_config() { + local cfg="$1" + + local hostname conloglevel timezone + + config_get hostname "$cfg" hostname 'OpenWrt' + echo "$hostname" > /proc/sys/kernel/hostname + + config_get conloglevel "$cfg" conloglevel + config_get buffersize "$cfg" buffersize + [ -z "$conloglevel" -a -z "$buffersize" ] || dmesg ${conloglevel:+-n $conloglevel} ${buffersize:+-s $buffersize} + + config_get timezone "$cfg" timezone 'UTC' + echo "$timezone" > /tmp/TZ + + config_get zonename "$cfg" zonename + [ -n "$zonename" ] && [ -f "/usr/share/zoneinfo/$zonename" ] && ln -s "/usr/share/zoneinfo/$zonename" /tmp/localtime + + # apply timezone to kernel + date -k + + if [ -x /sbin/syslogd ]; then + local args log_ip log_size log_port log_type log_file + config_get log_ip "$cfg" log_ip + config_get log_size "$cfg" log_size 16 + config_get log_port "$cfg" log_port 514 + config_get log_type "$cfg" log_type circular + config_get log_file "$cfg" log_file "/var/log/messages" + args="${log_ip:+-L -R ${log_ip}:${log_port}} ${conloglevel:+-l $conloglevel}" + if [ "$log_type" = "file" ]; then + args="$args -s $log_size -O $log_file -S" + else + args="$args -C${log_size}" + fi + service_start /sbin/syslogd $args + fi + if [ -x /sbin/klogd ]; then + config_get klogconloglevel "$cfg" klogconloglevel + args="${klogconloglevel:+-c $klogconloglevel}" + service_start /sbin/klogd $args + fi +} + +apply_uci_config() { + sh -c '. /lib/functions.sh; include /lib/config; uci_apply_defaults' +} + +start() { + [ -f /proc/mounts ] || /sbin/mount_root + [ -f /proc/jffs2_bbc ] && echo "S" > /proc/jffs2_bbc + [ -f /proc/net/vlan/config ] && vconfig set_name_type DEV_PLUS_VID_NO_PAD + + mkdir -p /var/run + mkdir -p /var/log + mkdir -p /var/lock + mkdir -p /var/state + mkdir -p /tmp/.uci + chmod 0700 /tmp/.uci + touch /var/log/wtmp + touch /var/log/lastlog + touch /tmp/resolv.conf.auto + ln -sf /tmp/resolv.conf.auto /tmp/resolv.conf + grep -q debugfs /proc/filesystems && mount -t debugfs debugfs /sys/kernel/debug + [ "$FAILSAFE" = "true" ] && touch /tmp/.failsafe + + load_modules /etc/modules.d/* + + # allow wifi modules time to settle + sleep 1 + + /sbin/wifi detect > /tmp/wireless.tmp + [ -s /tmp/wireless.tmp ] && { + cat /tmp/wireless.tmp >> /etc/config/wireless + } + rm -f /tmp/wireless.tmp + + apply_uci_config + config_load system + config_foreach system_config system + + killall -q hotplug2 + [ -x /sbin/hotplug2 ] && /sbin/hotplug2 --override --persistent \ + --set-rules-file /etc/hotplug2.rules \ + --set-coldplug-cmd /sbin/udevtrigger \ + --max-children 1 >/dev/null 2>&1 & + + # create /dev/root if it doesn't exist + [ -e /dev/root -o -h /dev/root ] || { + rootdev=$(awk 'BEGIN { RS=" "; FS="="; } $1 == "root" { print $2 }' < /proc/cmdline) + [ -n "$rootdev" ] && ln -s "$rootdev" /dev/root + } +} + +stop() { + service_stop /sbin/klogd + service_stop /sbin/syslogd +} diff --git a/package/base-files/files/etc/init.d/done b/package/base-files/files/etc/init.d/done new file mode 100755 index 000000000..827866912 --- /dev/null +++ b/package/base-files/files/etc/init.d/done @@ -0,0 +1,20 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2006 OpenWrt.org + +START=95 +boot() { + [ -d /tmp/root ] && { + lock /tmp/.switch2jffs + firstboot switch2jffs + lock -u /tmp/.switch2jffs + } + + # process user commands + [ -f /etc/rc.local ] && { + sh /etc/rc.local + } + + # set leds to normal state + . /etc/diag.sh + set_state done +} diff --git a/package/base-files/files/etc/init.d/led b/package/base-files/files/etc/init.d/led new file mode 100755 index 000000000..43964bf0b --- /dev/null +++ b/package/base-files/files/etc/init.d/led @@ -0,0 +1,80 @@ +#!/bin/sh /etc/rc.common +# (C) 2008 openwrt.org + +START=96 + +load_led() { + local name + local sysfs + local trigger + local dev + local mode + local default + local delayon + local delayoff + local interval + + config_get sysfs $1 sysfs + config_get name $1 name "$sysfs" + config_get trigger $1 trigger "none" + config_get dev $1 dev + config_get mode $1 mode "link" + config_get_bool default $1 default "nil" + config_get delayon $1 delayon + config_get delayoff $1 delayoff + config_get interval $1 interval "50" + config_get port_state $1 port_state + + [ -e /sys/class/leds/${sysfs}/brightness ] && { + echo "setting up led ${name}" + [ "$default" != nil ] && { + [ $default -eq 1 ] && + echo 1 >/sys/class/leds/${sysfs}/brightness + [ $default -eq 1 ] || + echo 0 >/sys/class/leds/${sysfs}/brightness + } + echo $trigger > /sys/class/leds/${sysfs}/trigger + case "$trigger" in + "netdev") + [ -n "$dev" ] && { + echo $dev > /sys/class/leds/${sysfs}/device_name + echo $mode > /sys/class/leds/${sysfs}/mode + } + ;; + + "timer") + [ -n "$delayon" ] && \ + echo $delayon > /sys/class/leds/${sysfs}/delay_on + [ -n "$delayoff" ] && \ + echo $delayoff > /sys/class/leds/${sysfs}/delay_off + ;; + + "usbdev") + [ -n "$dev" ] && { + echo $dev > /sys/class/leds/${sysfs}/device_name + echo $interval > /sys/class/leds/${sysfs}/activity_interval + } + ;; + + "port_state") + [ -n "$port_state" ] && \ + echo $port_state > /sys/class/leds/${sysfs}/port_state + ;; + + switch[0-9]*) + local port_mask + + config_get port_mask $1 port_mask + [ -n "$port_mask" ] && \ + echo $port_mask > /sys/class/leds/${sysfs}/port_mask + ;; + esac + } +} + +start() { + [ -e /sys/class/leds/ ] && { + config_load system + config_foreach load_led led + } +} diff --git a/package/base-files/files/etc/init.d/rcS b/package/base-files/files/etc/init.d/rcS new file mode 100755 index 000000000..3ec9bfef6 --- /dev/null +++ b/package/base-files/files/etc/init.d/rcS @@ -0,0 +1,26 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +run_scripts() { + for i in /etc/rc.d/$1*; do + [ -x $i ] && $i $2 2>&1 + done | $LOGGER +} + +system_config() { + config_get_bool foreground $1 foreground 0 +} + +LOGGER="cat" +[ -x /usr/bin/logger ] && LOGGER="logger -s -p 6 -t sysinit" + +. /lib/functions.sh + +config_load system +config_foreach system_config system + +if [ "$1" = "S" -a "$foreground" != "1" ]; then + run_scripts "$1" "$2" & +else + run_scripts "$1" "$2" +fi diff --git a/package/base-files/files/etc/init.d/sysctl b/package/base-files/files/etc/init.d/sysctl new file mode 100755 index 000000000..239779055 --- /dev/null +++ b/package/base-files/files/etc/init.d/sysctl @@ -0,0 +1,7 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2006 OpenWrt.org + +START=99 +start() { + [ -f /etc/sysctl.conf ] && sysctl -p -e >&- +} diff --git a/package/base-files/files/etc/init.d/sysntpd b/package/base-files/files/etc/init.d/sysntpd new file mode 100755 index 000000000..bb42ef7d3 --- /dev/null +++ b/package/base-files/files/etc/init.d/sysntpd @@ -0,0 +1,37 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2011 OpenWrt.org + +START=98 + +SERVICE_DAEMONIZE=1 +SERVICE_WRITE_PID=1 +SERVICE_PID_FILE=/var/run/sysntpd.pid + +start() { + local peers + local args="-n" + local enable_server + + config_load system + config_get peers ntp server + config_get_bool enable_server ntp enable_server 0 + + if [ $enable_server -ne 0 ]; then + append args "-l" + fi + + if [ -n "$peers" ]; then + local peer + for peer in $peers; do + append args "-p $peer" + done + fi + + if [ "$args" != "-n" ]; then + service_start /usr/sbin/ntpd $args + fi +} + +stop() { + service_stop /usr/sbin/ntpd +} diff --git a/package/base-files/files/etc/init.d/umount b/package/base-files/files/etc/init.d/umount new file mode 100755 index 000000000..5a750b93c --- /dev/null +++ b/package/base-files/files/etc/init.d/umount @@ -0,0 +1,8 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2006 OpenWrt.org + +STOP=99 +stop() { + sync + umount -a -d -r +} diff --git a/package/base-files/files/etc/init.d/usb b/package/base-files/files/etc/init.d/usb new file mode 100755 index 000000000..7b443b651 --- /dev/null +++ b/package/base-files/files/etc/init.d/usb @@ -0,0 +1,9 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2006 OpenWrt.org + +START=39 +start() { + [ -d /proc/bus/usb ] && { + /bin/mount -t usbfs none /proc/bus/usb + } +} diff --git a/package/base-files/files/etc/init.d/watchdog b/package/base-files/files/etc/init.d/watchdog new file mode 100755 index 000000000..299c89142 --- /dev/null +++ b/package/base-files/files/etc/init.d/watchdog @@ -0,0 +1,13 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2008-2011 OpenWrt.org + +START=97 + +start() { + [ -c /dev/watchdog ] || return 1 + [ -x /sbin/watchdog ] || return 1 + service_start /sbin/watchdog -t 5 /dev/watchdog +} +stop() { + service_stop /sbin/watchdog +} diff --git a/package/base-files/files/etc/inittab b/package/base-files/files/etc/inittab new file mode 100644 index 000000000..ca90fd8a2 --- /dev/null +++ b/package/base-files/files/etc/inittab @@ -0,0 +1,4 @@ +::sysinit:/etc/init.d/rcS S boot +::shutdown:/etc/init.d/rcS K shutdown +ttyS0::askfirst:/bin/ash --login +tty1::askfirst:/bin/ash --login diff --git a/package/base-files/files/etc/openwrt_release b/package/base-files/files/etc/openwrt_release new file mode 100644 index 000000000..8ad2d9d4f --- /dev/null +++ b/package/base-files/files/etc/openwrt_release @@ -0,0 +1,6 @@ +DISTRIB_ID="%D" +DISTRIB_RELEASE="%C" +DISTRIB_REVISION="%R" +DISTRIB_CODENAME="%n" +DISTRIB_TARGET="%S" +DISTRIB_DESCRIPTION="%D %N %V" diff --git a/package/base-files/files/etc/openwrt_version b/package/base-files/files/etc/openwrt_version new file mode 100644 index 000000000..4b14f596f --- /dev/null +++ b/package/base-files/files/etc/openwrt_version @@ -0,0 +1 @@ +%V diff --git a/package/base-files/files/etc/passwd b/package/base-files/files/etc/passwd new file mode 100644 index 000000000..1d06a8036 --- /dev/null +++ b/package/base-files/files/etc/passwd @@ -0,0 +1,5 @@ +root:x:0:0:root:/root:/bin/ash +daemon:*:1:1:daemon:/var:/bin/false +ftp:*:55:55:ftp:/home/ftp:/bin/false +network:*:101:101:network:/var:/bin/false +nobody:*:65534:65534:nobody:/var:/bin/false diff --git a/package/base-files/files/etc/preinit b/package/base-files/files/etc/preinit new file mode 100755 index 000000000..0fdfa8cf8 --- /dev/null +++ b/package/base-files/files/etc/preinit @@ -0,0 +1,44 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +export PATH=/bin:/sbin:/usr/bin:/usr/sbin + +pi_ifname= +pi_ip=192.168.1.1 +pi_broadcast=192.168.1.255 +pi_netmask=255.255.255.0 + +fs_failsafe_ifname= +fs_failsafe_ip=192.168.1.1 +fs_failsafe_broadcast=192.168.1.255 +fs_failsafe_netmask=255.255.255.0 + +fs_failsafe_wait_timeout=2 + +pi_suppress_stderr="y" +pi_init_suppress_stderr="y" +pi_init_path="/bin:/sbin:/usr/bin:/usr/sbin" +pi_init_cmd="/sbin/init" + +. /lib/functions.sh +. /lib/functions/boot.sh + +boot_hook_init preinit_essential +boot_hook_init preinit_main +boot_hook_init failsafe +boot_hook_init initramfs +boot_hook_init preinit_mount_root + +for pi_source_file in /lib/preinit/*; do + . $pi_source_file +done + +boot_run_hook preinit_essential + +pi_mount_skip_next=false +pi_jffs2_mount_success=false +pi_failsafe_net_message=false + +boot_run_hook preinit_main + diff --git a/package/base-files/files/etc/profile b/package/base-files/files/etc/profile new file mode 100644 index 000000000..171adc18e --- /dev/null +++ b/package/base-files/files/etc/profile @@ -0,0 +1,15 @@ +#!/bin/sh +[ -f /etc/banner ] && cat /etc/banner + +export PATH=/bin:/sbin:/usr/bin:/usr/sbin +export HOME=$(grep -e "^${USER:-root}:" /etc/passwd | cut -d ":" -f 6) +export HOME=${HOME:-/root} +export PS1='\u@\h:\w\$ ' + +[ -x /bin/more ] || alias more=less +[ -x /usr/bin/vim ] && alias vi=vim || alias vim=vi + +[ -z "$KSH_VERSION" -o \! -s /etc/mkshrc ] || . /etc/mkshrc + +[ -x /usr/bin/arp ] || arp() { cat /proc/net/arp; } +[ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; } diff --git a/package/base-files/files/etc/protocols b/package/base-files/files/etc/protocols new file mode 100644 index 000000000..53fecb6d3 --- /dev/null +++ b/package/base-files/files/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/files/etc/rc.common b/package/base-files/files/etc/rc.common new file mode 100755 index 000000000..fa2df6cd2 --- /dev/null +++ b/package/base-files/files/etc/rc.common @@ -0,0 +1,85 @@ +#!/bin/sh +# Copyright (C) 2006-2012 OpenWrt.org + +. $IPKG_INSTROOT/lib/functions.sh +. $IPKG_INSTROOT/lib/functions/service.sh + +initscript=$1 +action=${2:-help} +shift 2 + +start() { + return 0 +} + +stop() { + return 0 +} + +reload() { + return 1 +} + +restart() { + trap '' TERM + stop "$@" + start "$@" +} + +boot() { + start "$@" +} + +shutdown() { + stop +} + +disable() { + name="$(basename "${initscript}")" + rm -f "$IPKG_INSTROOT"/etc/rc.d/S??$name + rm -f "$IPKG_INSTROOT"/etc/rc.d/K??$name +} + +enable() { + name="$(basename "${initscript}")" + disable + [ -n "$START" -o -n "$STOP" ] || { + echo "/etc/init.d/$name does not have a START or STOP value" + return 1 + } + [ "$START" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" + [ "$STOP" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}" +} + +enabled() { + name="$(basename "${initscript}")" + [ -x "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ] +} + +depends() { + return 0 +} + +help() { + cat </dev/null +} + +boot_hook_add no_fo no_fo_mount_jffs diff --git a/package/base-files/files/lib/firstboot/20_reset_clear_jffs b/package/base-files/files/lib/firstboot/20_reset_clear_jffs new file mode 100644 index 000000000..a3cd24fe9 --- /dev/null +++ b/package/base-files/files/lib/firstboot/20_reset_clear_jffs @@ -0,0 +1,14 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +reset_clear_jffs() { + [ "$reset_has_fo" = "true" ] && { + rm -rf $jffs/* 2>&- + mount -o remount $jffs / 2>&- + exit 0 + } || reset_has_fo=false +} + +boot_hook_add jffs2reset reset_clear_jffs diff --git a/package/base-files/files/lib/firstboot/30_is_rootfs_mounted b/package/base-files/files/lib/firstboot/30_is_rootfs_mounted new file mode 100644 index 000000000..e2ba01d50 --- /dev/null +++ b/package/base-files/files/lib/firstboot/30_is_rootfs_mounted @@ -0,0 +1,10 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +skip_if_rootfs_mounted() { + mount "$mtdpart" /rom/overlay -t jffs2 || exit +} + +boot_hook_add switch2jffs skip_if_rootfs_mounted diff --git a/package/base-files/files/lib/firstboot/30_no_fo_pivot b/package/base-files/files/lib/firstboot/30_no_fo_pivot new file mode 100644 index 000000000..b5c2601ee --- /dev/null +++ b/package/base-files/files/lib/firstboot/30_no_fo_pivot @@ -0,0 +1,11 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +no_fo_pivot() { + # switch to the new (empty) jffs2 + fopivot /overlay /rom 1 +} + +boot_hook_add no_fo no_fo_pivot diff --git a/package/base-files/files/lib/firstboot/30_reset_copy_rom b/package/base-files/files/lib/firstboot/30_reset_copy_rom new file mode 100644 index 000000000..d91c68947 --- /dev/null +++ b/package/base-files/files/lib/firstboot/30_reset_copy_rom @@ -0,0 +1,13 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +reset_copy_rom() { + [ "$reset_has_fo" != "true" ] && { + dupe $jffs $rom + exit 0 + } +} + +boot_hook_add jffs2reset reset_copy_rom diff --git a/package/base-files/files/lib/firstboot/40_copy_ramoverlay b/package/base-files/files/lib/firstboot/40_copy_ramoverlay new file mode 100644 index 000000000..39c2edacb --- /dev/null +++ b/package/base-files/files/lib/firstboot/40_copy_ramoverlay @@ -0,0 +1,15 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +copy_ramoverlay() { + # try to avoid fs changing while copying + mount -o remount,ro none / 2>&- + # copy ramoverlay to jffs2 + echo -n "copying files ... " + cp -a /tmp/root/* /rom/overlay 2>&- + echo "done" +} + +boot_hook_add switch2jffs copy_ramoverlay diff --git a/package/base-files/files/lib/firstboot/40_no_fo_copy_ramoverlay b/package/base-files/files/lib/firstboot/40_no_fo_copy_ramoverlay new file mode 100644 index 000000000..ced7c1b66 --- /dev/null +++ b/package/base-files/files/lib/firstboot/40_no_fo_copy_ramoverlay @@ -0,0 +1,14 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +no_fo_copy_ramoverlay() { + # copy ramoverlay to jffs2, must be done after switching + # to the new rootfs to avoid creating opaque directories + echo -n "copying files ... " + cp -a /tmp/root/* / >/dev/null 2>&1 + sync +} + +boot_hook_add no_fo no_fo_ramoverlay diff --git a/package/base-files/files/lib/firstboot/50_pivot b/package/base-files/files/lib/firstboot/50_pivot new file mode 100644 index 000000000..53801d7a8 --- /dev/null +++ b/package/base-files/files/lib/firstboot/50_pivot @@ -0,0 +1,17 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +with_fo_pivot() { + # switch back to squashfs (temporarily) + # and park the ramdisk ontop of /tmp/root + pivot /rom /mnt + mount -o move /mnt /tmp/root + + # /overlay is the overlay + # /rom is the readonly + fopivot /overlay /rom +} + +boot_hook_add switch2jffs with_fo_pivot diff --git a/package/base-files/files/lib/firstboot/99_10_no_fo_cleanup b/package/base-files/files/lib/firstboot/99_10_no_fo_cleanup new file mode 100644 index 000000000..6dedcb1e8 --- /dev/null +++ b/package/base-files/files/lib/firstboot/99_10_no_fo_cleanup @@ -0,0 +1,13 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +no_fo_cleanup() { + echo "done" + umount -l /overlay + umount -l /tmp/root + exit 0 +} + +boot_hook_add no_fo no_fo_cleanup diff --git a/package/base-files/files/lib/firstboot/99_10_with_fo_cleanup b/package/base-files/files/lib/firstboot/99_10_with_fo_cleanup new file mode 100644 index 000000000..0181b39d4 --- /dev/null +++ b/package/base-files/files/lib/firstboot/99_10_with_fo_cleanup @@ -0,0 +1,25 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +with_fo_cleanup() { + # try to get rid of /tmp/root + # this will almost always fail + umount /tmp/root 2>&- + grep -q overlay /proc/filesystems && { + cd / + ( + cd /overlay + find -type l + ) | while read FILE; do + [ -z "$FILE" ] && break + if ls -la "$FILE" 2>&- | grep -q '(overlay-whiteout)'; then + rm -f "$FILE" + fi + done + } + exit 0 +} + +boot_hook_add switch2jffs with_fo_cleanup diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh new file mode 100755 index 000000000..b3a3885f2 --- /dev/null +++ b/package/base-files/files/lib/functions.sh @@ -0,0 +1,340 @@ +#!/bin/sh +# Copyright (C) 2006-2011 OpenWrt.org +# Copyright (C) 2006 Fokus Fraunhofer + + +debug () { + ${DEBUG:-:} "$@" +} +mount() { + busybox mount "$@" +} + +# newline +N=" +" + +_C=0 +NO_EXPORT=1 +LOAD_STATE=1 +LIST_SEP=" " + +hotplug_dev() { + env -i ACTION=$1 INTERFACE=$2 /sbin/hotplug-call net +} + +append() { + local var="$1" + local value="$2" + local sep="${3:- }" + + eval "export ${NO_EXPORT:+-n} -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\"" +} + +list_contains() { + local var="$1" + local str="$2" + local val + + eval "val=\" \${$var} \"" + [ "${val%% $str *}" != "$val" ] +} + +list_remove() { + local var="$1" + local remove="$2" + local val + + eval "val=\" \${$var} \"" + val1="${val%% $remove *}" + [ "$val1" = "$val" ] && return + val2="${val##* $remove }" + [ "$val2" = "$val" ] && return + val="${val1## } ${val2%% }" + val="${val%% }" + eval "export ${NO_EXPORT:+-n} -- \"$var=\$val\"" +} + +config_load() { + [ -n "$IPKG_INSTROOT" ] && return 0 + uci_load "$@" +} + +reset_cb() { + config_cb() { return 0; } + option_cb() { return 0; } + list_cb() { return 0; } +} +reset_cb + +package() { + return 0 +} + +config () { + local cfgtype="$1" + local name="$2" + + export ${NO_EXPORT:+-n} CONFIG_NUM_SECTIONS=$(($CONFIG_NUM_SECTIONS + 1)) + name="${name:-cfg$CONFIG_NUM_SECTIONS}" + append CONFIG_SECTIONS "$name" + [ -n "$NO_CALLBACK" ] || config_cb "$cfgtype" "$name" + export ${NO_EXPORT:+-n} CONFIG_SECTION="$name" + export ${NO_EXPORT:+-n} "CONFIG_${CONFIG_SECTION}_TYPE=$cfgtype" +} + +option () { + local varname="$1"; shift + local value="$*" + + export ${NO_EXPORT:+-n} "CONFIG_${CONFIG_SECTION}_${varname}=$value" + [ -n "$NO_CALLBACK" ] || option_cb "$varname" "$*" +} + +list() { + local varname="$1"; shift + local value="$*" + local len + + config_get len "$CONFIG_SECTION" "${varname}_LENGTH" 0 + [ $len = 0 ] && append CONFIG_LIST_STATE "${CONFIG_SECTION}_${varname}" + len=$(($len + 1)) + config_set "$CONFIG_SECTION" "${varname}_ITEM$len" "$value" + config_set "$CONFIG_SECTION" "${varname}_LENGTH" "$len" + append "CONFIG_${CONFIG_SECTION}_${varname}" "$value" "$LIST_SEP" + list_cb "$varname" "$*" +} + +config_rename() { + local OLD="$1" + local NEW="$2" + local oldvar + local newvar + + [ -n "$OLD" -a -n "$NEW" ] || return + for oldvar in `set | grep ^CONFIG_${OLD}_ | \ + sed -e 's/\(.*\)=.*$/\1/'` ; do + newvar="CONFIG_${NEW}_${oldvar##CONFIG_${OLD}_}" + eval "export ${NO_EXPORT:+-n} \"$newvar=\${$oldvar}\"" + unset "$oldvar" + done + export ${NO_EXPORT:+-n} CONFIG_SECTIONS="$(echo " $CONFIG_SECTIONS " | sed -e "s, $OLD , $NEW ,")" + + [ "$CONFIG_SECTION" = "$OLD" ] && export ${NO_EXPORT:+-n} CONFIG_SECTION="$NEW" +} + +config_unset() { + config_set "$1" "$2" "" +} + +config_clear() { + local SECTION="$1" + local oldvar + + list_remove CONFIG_SECTIONS "$SECTION" + export ${NO_EXPORT:+-n} CONFIG_SECTIONS="${SECTION:+$CONFIG_SECTIONS}" + + for oldvar in `set | grep ^CONFIG_${SECTION:+${SECTION}_} | \ + sed -e 's/\(.*\)=.*$/\1/'` ; do + unset $oldvar + done +} + +# config_get