aboutsummaryrefslogtreecommitdiffstats
path: root/package/base-files/files/sbin
diff options
context:
space:
mode:
authorblogic <blogic@3c298f89-4303-0410-b956-a3cf2f4a3e73>2012-10-05 10:12:53 +0000
committerblogic <blogic@3c298f89-4303-0410-b956-a3cf2f4a3e73>2012-10-05 10:12:53 +0000
commit5c105d9f3fd086aff195d3849dcf847d6b0bd927 (patch)
tree1229a11f725bfa58aa7c57a76898553bb5f6654a /package/base-files/files/sbin
downloadopenwrt-5c105d9f3fd086aff195d3849dcf847d6b0bd927.tar.gz
openwrt-5c105d9f3fd086aff195d3849dcf847d6b0bd927.zip
branch Attitude Adjustment
git-svn-id: svn://svn.openwrt.org/openwrt/branches/attitude_adjustment@33625 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/base-files/files/sbin')
-rwxr-xr-xpackage/base-files/files/sbin/firstboot34
-rwxr-xr-xpackage/base-files/files/sbin/hotplug-call17
-rwxr-xr-xpackage/base-files/files/sbin/led.sh25
-rwxr-xr-xpackage/base-files/files/sbin/mount_root26
-rwxr-xr-xpackage/base-files/files/sbin/sysupgrade187
-rwxr-xr-xpackage/base-files/files/sbin/wifi204
6 files changed, 493 insertions, 0 deletions
diff --git a/package/base-files/files/sbin/firstboot b/package/base-files/files/sbin/firstboot
new file mode 100755
index 000000000..4da299189
--- /dev/null
+++ b/package/base-files/files/sbin/firstboot
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+switch2jffs_hook=
+jffs2reset_hook=
+no_fo_hook=
+
+. /lib/functions/boot.sh
+
+firstboot_skip_next=false
+
+for fb_source_file in /lib/firstboot/*; do
+ . $fb_source_file
+done
+
+set_mtd_part
+set_rom_part
+set_jffs_part
+
+# invoked as an executable
+if [ "${0##*/}" = "firstboot" ]; then
+ if [ "$1" = "switch2jffs" ]; then
+ boot_run_hook switch2jffs
+ elif [ -n "$jffs" ]; then
+ reset_has_fo=true
+ echo "firstboot has already been run"
+ echo "jffs2 partition is mounted, only resetting files"
+ boot_run_hook jffs2reset
+ else
+ mtd erase "$partname"
+ mount "$mtdpart" /overlay -t jffs2
+ fopivot /overlay /rom 1
+ fi
+fi
+
diff --git a/package/base-files/files/sbin/hotplug-call b/package/base-files/files/sbin/hotplug-call
new file mode 100755
index 000000000..d627becc6
--- /dev/null
+++ b/package/base-files/files/sbin/hotplug-call
@@ -0,0 +1,17 @@
+#!/bin/sh
+# Copyright (C) 2006-2010 OpenWrt.org
+
+export HOTPLUG_TYPE="$1"
+
+. /lib/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/files/sbin/led.sh b/package/base-files/files/sbin/led.sh
new file mode 100755
index 000000000..d67a0f51c
--- /dev/null
+++ b/package/base-files/files/sbin/led.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+# (C) 2008 openwrt.org
+
+. /lib/functions.sh
+ACTION=$1
+NAME=$2
+do_led() {
+ local name
+ local sysfs
+ config_get name $1 name
+ config_get sysfs $1 sysfs
+ [ "$name" == "$NAME" -o "$sysfs" = "$NAME" -a -e "/sys/class/leds/${sysfs}" ] && {
+ [ "$ACTION" == "set" ] &&
+ echo 1 >/sys/class/leds/${sysfs}/brightness \
+ || echo 0 >/sys/class/leds/${sysfs}/brightness
+ exit 0
+ }
+}
+
+[ "$1" == "clear" -o "$1" == "set" ] &&
+ [ -n "$2" ] &&{
+ config_load system
+ config_foreach do_led
+ exit 1
+ }
diff --git a/package/base-files/files/sbin/mount_root b/package/base-files/files/sbin/mount_root
new file mode 100755
index 000000000..2d73dac53
--- /dev/null
+++ b/package/base-files/files/sbin/mount_root
@@ -0,0 +1,26 @@
+#!/bin/sh
+# Copyright (C) 2006-2010 OpenWrt.org
+# Copyright (C) 2010 Vertical Communications
+
+# Initialize hook variables et by pulling in from preinit
+
+preinit_essential_hook=
+preinit_main_hook=
+failsafe_hook=
+initramfs_hook=
+preinit_mount_root=
+
+. /lib/functions/boot.sh
+
+for pi_source_file in /lib/preinit/*; do
+ . $pi_source_file
+done
+
+# Override function that doesn't apply to use of mount_root as a command rather
+# than as part of preinit
+
+preinit_echo() {
+ echo "$@"
+}
+
+boot_run_hook preinit_mount_root
diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
new file mode 100755
index 000000000..802848ade
--- /dev/null
+++ b/package/base-files/files/sbin/sysupgrade
@@ -0,0 +1,187 @@
+#!/bin/sh
+. /lib/functions.sh
+
+# initialize defaults
+RAMFS_COPY_BIN="" # extra programs for temporary ramfs root
+RAMFS_COPY_DATA="" # extra data files
+export INTERACTIVE=0
+export VERBOSE=1
+export SAVE_CONFIG=1
+export SAVE_OVERLAY=0
+export DELAY=
+export CONF_IMAGE=
+export CONF_BACKUP=
+export CONF_RESTORE=
+export HELP=0
+export FORCE=0
+
+# parse options
+while [ -n "$1" ]; do
+ case "$1" in
+ -i) export INTERACTIVE=1;;
+ -d) export DELAY="$2"; shift;;
+ -v) export VERBOSE="$(($VERBOSE + 1))";;
+ -q) export VERBOSE="$(($VERBOSE - 1))";;
+ -n) export SAVE_CONFIG=0;;
+ -c) export SAVE_OVERLAY=1;;
+ -b|--create-backup) export CONF_BACKUP="$2"; shift;;
+ -r|--restore-backup) export CONF_RESTORE="$2"; shift;;
+ -f) export CONF_IMAGE="$2"; shift;;
+ -F|--force) export FORCE=1;;
+ -h|--help) export HELP=1; break;;
+ -*)
+ echo "Invalid option: $1"
+ exit 1
+ ;;
+ *) break;;
+ esac
+ shift;
+done
+
+export CONFFILES=/tmp/sysupgrade.conffiles
+export CONF_TAR=/tmp/sysupgrade.tgz
+
+export ARGV="$*"
+export ARGC="$#"
+
+[ -z "$ARGV" -a -z "$CONF_BACKUP" -o $HELP -gt 0 ] && {
+ cat <<EOF
+Usage: $0 [options] <image file or URL>
+
+Options:
+ -d <delay> add a delay before rebooting
+ -f <config> restore configuration from .tar.gz (file or url)
+ -i interactive mode
+ -c attempt to preserve all changed files in /etc/
+ -b / --create-backup <file>
+ create .tar.gz of files specified in sysupgrade.conf
+ then exit. Does not flash an image. If file is '-',
+ i.e. stdout, verbosity is set to 0 (i.e. quiet).
+ -r / --restore-backup <file>
+ restore a .tar.gz created with sysupgrade -b
+ then exit. Does not flash an image. If file is '-',
+ the archive is read from stdin.
+ -n do not save configuration over reflash
+ -F / --force
+ Flash image even if image checks fail, this is dangerous!
+ -q less verbose
+ -v more verbose
+ -h / --help display this help
+
+EOF
+ exit 1
+}
+
+[ -n "$ARGV" -a -n "$CONF_BACKUP" ] && {
+ cat <<-EOF
+ -b/--create-backup does not perform a firmware upgrade. Do not
+ specify both -b and a firmware image.
+ EOF
+ exit 1
+}
+
+# prevent messages from clobbering the tarball when using stdout
+[ "$CONF_BACKUP" = "-" ] && export VERBOSE=0
+
+add_uci_conffiles() {
+ local file="$1"
+ ( find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' \
+ /etc/sysupgrade.conf /lib/upgrade/keep.d/* 2>/dev/null) \
+ -type f 2>/dev/null;
+ opkg list-changed-conffiles ) | sort -u > "$file"
+ return 0
+}
+
+add_overlayfiles() {
+ local file="$1"
+ find /overlay/etc/ -type f | sed \
+ -e 's,^/overlay/,/,' \
+ -e '\,/META_[a-zA-Z0-9]*$,d' \
+ -e '\,/functions.sh$,d' \
+ -e '\,/[^/]*-opkg$,d' \
+ > "$file"
+ return 0
+}
+
+# hooks
+sysupgrade_image_check="platform_check_image"
+[ $SAVE_OVERLAY = 0 -o ! -d /overlay/etc ] && \
+ sysupgrade_init_conffiles="add_uci_conffiles" || \
+ sysupgrade_init_conffiles="add_overlayfiles"
+
+include /lib/upgrade
+
+do_save_conffiles() {
+ local conf_tar="${1:-$CONF_TAR}"
+
+ [ -z "$(rootfs_type)" ] && {
+ echo "Cannot save config while running from ramdisk."
+ ask_bool 0 "Abort" && exit
+ return 0
+ }
+ run_hooks "$CONFFILES" $sysupgrade_init_conffiles
+ ask_bool 0 "Edit config file list" && vi "$CONFFILES"
+
+ v "Saving config files..."
+ [ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
+ tar c${TAR_V}zf "$conf_tar" -T "$CONFFILES" 2>/dev/null
+}
+
+if [ -n "$CONF_BACKUP" ]; then
+ do_save_conffiles "$CONF_BACKUP"
+ exit $?
+fi
+
+if [ -f "$CONF_RESTORE" ] || [ "$CONF_RESTORE" = "-" ]; then
+ [ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
+ tar -C / -x${TAR_V}zf "$CONF_RESTORE"
+ exit $?
+fi
+
+type platform_check_image >/dev/null 2>/dev/null || {
+ echo "Firmware upgrade is not implemented for this platform."
+ exit 1
+}
+
+for check in $sysupgrade_image_check; do
+ ( eval "$check \"\$ARGV\"" ) || {
+ if [ $FORCE -eq 1 ]; then
+ echo "Image check '$check' failed but --force given - will update anyway!"
+ break
+ else
+ echo "Image check '$check' failed."
+ exit 1
+ fi
+ }
+done
+
+if [ -n "$CONF_IMAGE" ]; then
+ case "$(get_magic_word $CONF_IMAGE cat)" in
+ # .gz files
+ 1f8b) ;;
+ *)
+ echo "Invalid config file. Please use only .tar.gz files"
+ exit 1
+ ;;
+ esac
+ get_image "$CONF_IMAGE" "cat" > "$CONF_TAR"
+ export SAVE_CONFIG=1
+elif ask_bool $SAVE_CONFIG "Keep config files over reflash"; then
+ do_save_conffiles
+ export SAVE_CONFIG=1
+else
+ export SAVE_CONFIG=0
+fi
+
+run_hooks "" $sysupgrade_pre_upgrade
+
+kill_remaining TERM
+sleep 3
+kill_remaining KILL
+
+if [ -n "$(rootfs_type)" ]; then
+ v "Switching to ramdisk..."
+ run_ramfs '. /lib/functions.sh; include /lib/upgrade; do_upgrade'
+else
+ do_upgrade
+fi
diff --git a/package/base-files/files/sbin/wifi b/package/base-files/files/sbin/wifi
new file mode 100755
index 000000000..ef207878b
--- /dev/null
+++ b/package/base-files/files/sbin/wifi
@@ -0,0 +1,204 @@
+#!/bin/sh
+# Copyright (C) 2006 OpenWrt.org
+
+. /lib/functions.sh
+
+usage() {
+ cat <<EOF
+Usage: $0 [down|detect]
+enables (default), disables or detects a wifi configuration.
+EOF
+ exit 1
+}
+
+find_net_config() {(
+ local vif="$1"
+ local cfg
+ local ifname
+
+ config_get cfg "$vif" network
+
+ [ -z "$cfg" ] && {
+ include /lib/network
+ scan_interfaces
+
+ config_get ifname "$vif" ifname
+
+ cfg="$(find_config "$ifname")"
+ }
+ [ -z "$cfg" ] && return 0
+ echo "$cfg"
+)}
+
+
+bridge_interface() {(
+ local cfg="$1"
+ [ -z "$cfg" ] && return 0
+
+ include /lib/network
+ scan_interfaces
+
+ for cfg in $cfg; do
+ config_get iftype "$cfg" type
+ [ "$iftype" = bridge ] && config_get "$cfg" ifname
+ prepare_interface_bridge "$cfg"
+ return $?
+ done
+)}
+
+prepare_key_wep() {
+ local key="$1"
+ local hex=1
+
+ echo -n "$key" | grep -qE "[^a-fA-F0-9]" && hex=0
+ [ "${#key}" -eq 10 -a $hex -eq 1 ] || \
+ [ "${#key}" -eq 26 -a $hex -eq 1 ] || {
+ [ "${key:0:2}" = "s:" ] && key="${key#s:}"
+ key="$(echo -n "$key" | hexdump -ve '1/1 "%02x" ""')"
+ }
+ echo "$key"
+}
+
+wifi_fixup_hwmode() {
+ local device="$1"
+ local default="$2"
+ local hwmode hwmode_11n
+
+ config_get channel "$device" channel
+ config_get hwmode "$device" hwmode
+ case "$hwmode" in
+ 11bg) hwmode=bg;;
+ 11a) hwmode=a;;
+ 11b) hwmode=b;;
+ 11g) hwmode=g;;
+ 11n*)
+ hwmode_11n="${hwmode##11n}"
+ case "$hwmode_11n" in
+ a|g) ;;
+ default) hwmode_11n="$default"
+ esac
+ config_set "$device" hwmode_11n "$hwmode_11n"
+ ;;
+ *)
+ hwmode=
+ if [ "${channel:-0}" -gt 0 ]; then
+ if [ "${channel:-0}" -gt 14 ]; then
+ hwmode=a
+ else
+ hwmode=g
+ fi
+ else
+ hwmode="$default"
+ fi
+ ;;
+ esac
+ config_set "$device" hwmode "$hwmode"
+}
+
+wifi_updown() {
+ [ enable = "$1" ] && {
+ wifi_updown disable "$2"
+ scan_wifi
+ }
+ for device in ${2:-$DEVICES}; do (
+ config_get disabled "$device" disabled
+ [ 1 == "$disabled" ] && {
+ echo "'$device' is disabled"
+ set disable
+ }
+ config_get iftype "$device" type
+ if eval "type ${1}_$iftype" 2>/dev/null >/dev/null; then
+ eval "scan_$iftype '$device'"
+ eval "${1}_$iftype '$device'" || echo "$device($iftype): ${1} failed"
+ else
+ echo "$device($iftype): Interface type not supported"
+ fi
+ ); done
+}
+
+wifi_detect() {
+ for driver in ${2:-$DRIVERS}; do (
+ if eval "type detect_$driver" 2>/dev/null >/dev/null; then
+ eval "detect_$driver" || echo "$driver: Detect failed" >&2
+ else
+ echo "$driver: Hardware detection not supported" >&2
+ fi
+ ); done
+}
+
+start_net() {(
+ local iface="$1"
+ local config="$2"
+ local vifmac="$3"
+
+ [ -f "/var/run/$iface.pid" ] && kill "$(cat /var/run/${iface}.pid)" 2>/dev/null
+ [ -z "$config" ] || {
+ include /lib/network
+ scan_interfaces
+ for config in $config; do
+ setup_interface "$iface" "$config" "" "$vifmac"
+ done
+ }
+)}
+
+set_wifi_up() {
+ local cfg="$1"
+ local ifname="$2"
+ uci_set_state wireless "$cfg" up 1
+ uci_set_state wireless "$cfg" ifname "$ifname"
+}
+
+set_wifi_down() {
+ local cfg="$1"
+ local vifs vif vifstr
+
+ [ -f "/var/run/wifi-${cfg}.pid" ] &&
+ kill "$(cat "/var/run/wifi-${cfg}.pid")" 2>/dev/null
+ uci_revert_state wireless "$cfg"
+ config_get vifs "$cfg" vifs
+ for vif in $vifs; do
+ uci_revert_state wireless "$vif"
+ done
+}
+
+scan_wifi() {
+ local cfgfile="$1"
+ DEVICES=
+ config_cb() {
+ local type="$1"
+ local section="$2"
+
+ # section start
+ case "$type" in
+ wifi-device)
+ append DEVICES "$section"
+ config_set "$section" vifs ""
+ config_set "$section" ht_capab ""
+ ;;
+ esac
+
+ # section end
+ config_get TYPE "$CONFIG_SECTION" TYPE
+ case "$TYPE" in
+ 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 "${cfgfile:-wireless}"
+}
+
+DEVICES=
+DRIVERS=
+include /lib/wifi
+scan_wifi
+
+case "$1" in
+ down) wifi_updown "disable" "$2";;
+ detect) wifi_detect "$2";;
+ --help|help) usage;;
+ *) wifi_updown "enable" "$2";;
+esac