From 716ca530e1c4515d8683c9d5be3d56b301758b66 Mon Sep 17 00:00:00 2001 From: James <> Date: Wed, 4 Nov 2015 11:49:21 +0000 Subject: trunk-47381 --- package/base-files/files/sbin/firstboot | 3 + package/base-files/files/sbin/hotplug-call | 18 +++ package/base-files/files/sbin/led.sh | 25 +++ package/base-files/files/sbin/sysupgrade | 240 +++++++++++++++++++++++++++++ package/base-files/files/sbin/wifi | 236 ++++++++++++++++++++++++++++ 5 files changed, 522 insertions(+) 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/sysupgrade create mode 100755 package/base-files/files/sbin/wifi (limited to 'package/base-files/files/sbin') diff --git a/package/base-files/files/sbin/firstboot b/package/base-files/files/sbin/firstboot new file mode 100755 index 0000000..d9af57d --- /dev/null +++ b/package/base-files/files/sbin/firstboot @@ -0,0 +1,3 @@ +#!/bin/sh + +/sbin/jffs2reset $@ diff --git a/package/base-files/files/sbin/hotplug-call b/package/base-files/files/sbin/hotplug-call new file mode 100755 index 0000000..743871a --- /dev/null +++ b/package/base-files/files/sbin/hotplug-call @@ -0,0 +1,18 @@ +#!/bin/sh +# Copyright (C) 2006-2010 OpenWrt.org + +export HOTPLUG_TYPE="$1" + +. /lib/functions.sh + +PATH=/usr/sbin:/usr/bin:/sbin:/bin +LOGNAME=root +USER=root +export PATH LOGNAME USER +export DEVICENAME="${DEVPATH##*/}" + +[ \! -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 0000000..d750f06 --- /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/sysupgrade b/package/base-files/files/sbin/sysupgrade new file mode 100755 index 0000000..ef83c4b --- /dev/null +++ b/package/base-files/files/sbin/sysupgrade @@ -0,0 +1,240 @@ +#!/bin/sh +. /lib/functions.sh +. /lib/functions/system.sh + +# initialize defaults +RAMFS_COPY_BIN="" # extra programs for temporary ramfs root +RAMFS_COPY_DATA="" # extra data files +export MTD_CONFIG_ARGS="" +export INTERACTIVE=0 +export VERBOSE=1 +export SAVE_CONFIG=1 +export SAVE_OVERLAY=0 +export DELAY= +export CONF_IMAGE= +export CONF_BACKUP_LIST=0 +export CONF_BACKUP= +export CONF_RESTORE= +export NEED_IMAGE= +export HELP=0 +export FORCE=0 +export TEST=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" NEED_IMAGE=1; shift;; + -r|--restore-backup) export CONF_RESTORE="$2" NEED_IMAGE=1; shift;; + -l|--list-backup) export CONF_BACKUP_LIST=1; break;; + -f) export CONF_IMAGE="$2"; shift;; + -F|--force) export FORCE=1;; + -T|--test) export TEST=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 "$NEED_IMAGE" -o $HELP -gt 0 ] && { + cat <...] + $0 [-q] [-i] + +upgrade-option: + -d add a delay before rebooting + -f restore configuration from .tar.gz (file or url) + -i interactive mode + -c attempt to preserve all changed files in /etc/ + -n do not save configuration over reflash + -T | --test + Verify image and config .tar.gz but do not actually flash. + -F | --force + Flash image even if image checks fail, this is dangerous! + -q less verbose + -v more verbose + -h | --help display this help + +backup-command: + -b | --create-backup + 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 + restore a .tar.gz created with sysupgrade -b + then exit. Does not flash an image. If file is '-', + the archive is read from stdin. + -l | --list-backup + list the files that would be backed up when calling + sysupgrade -b. Does not create a backup file. + +EOF + exit 1 +} + +[ -n "$ARGV" -a -n "$NEED_IMAGE" ] && { + cat <<-EOF + -b|--create-backup and -r|--restore-backup do not perform a firmware upgrade. + Do not specify both -b|-r 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 -o -type l 2>/dev/null; + opkg list-changed-conffiles ) | sort -u > "$file" + return 0 +} + +add_overlayfiles() { + local file="$1" + if [ -d /overlay/upper ]; then + local overlaydir="/overlay/upper" + else + local overlaydir="/overlay" + fi + find $overlaydir/etc/ -type f -o -type l | 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 + +[ "$1" = "nand" ] && nand_upgrade_stage2 $@ + +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 + + rm -f "$CONFFILES" +} + +if [ $CONF_BACKUP_LIST -eq 1 ]; then + add_uci_conffiles "$CONFFILES" + cat "$CONFFILES" + rm -f "$CONFFILES" + exit 0 +fi + +if [ -n "$CONF_BACKUP" ]; then + do_save_conffiles "$CONF_BACKUP" + exit $? +fi + +if [ -n "$CONF_RESTORE" ]; then + if [ "$CONF_RESTORE" != "-" ] && [ ! -f "$CONF_RESTORE" ]; then + echo "Backup archive '$CONF_RESTORE' not found." + exit 1 + fi + + [ "$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 + [ $TEST -eq 1 ] || do_save_conffiles + export SAVE_CONFIG=1 +else + export SAVE_CONFIG=0 +fi + +if [ $TEST -eq 1 ]; then + exit 0 +fi + +run_hooks "" $sysupgrade_pre_upgrade + +# Some platforms/devices may want different sysupgrade process, e.g. without +# killing processes yet or calling ubus system upgrade method. +# This is needed e.g. on NAND devices where we just want to trigger stage1 at +# this point. +if type 'platform_pre_upgrade' >/dev/null 2>/dev/null; then + platform_pre_upgrade "$ARGV" +fi + +ubus call system upgrade +touch /tmp/sysupgrade + +if [ ! -f /tmp/failsafe ] ; then + kill_remaining TERM + sleep 3 + kill_remaining KILL +fi + +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 0000000..2476414 --- /dev/null +++ b/package/base-files/files/sbin/wifi @@ -0,0 +1,236 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +. /lib/functions.sh +. /usr/share/libubox/jshn.sh + +usage() { + cat </dev/null >/dev/null; then + eval "scan_$iftype '$device'" + eval "${1}_$iftype '$device'" || echo "$device($iftype): ${1} failed" + elif [ ! -f /lib/netifd/wireless/$iftype.sh ]; then + echo "$device($iftype): Interface type not supported" + fi + ); done +} + +wifi_updown() { + cmd=down + [ enable = "$1" ] && { + _wifi_updown disable "$2" + ubus_wifi_cmd "$cmd" "$2" + scan_wifi + cmd=up + } + ubus_wifi_cmd "$cmd" "$2" + _wifi_updown "$@" +} + +wifi_reload_legacy() { + _wifi_updown "disable" "$1" + scan_wifi + _wifi_updown "enable" "$1" +} + +wifi_reload() { + ubus call network reload + wifi_reload_legacy +} + +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";; + status) ubus_wifi_cmd "status" "$2";; + reload) wifi_reload "$2";; + reload_legacy) wifi_reload_legacy "$2";; + --help|help) usage;; + *) ubus call network reload; wifi_updown "enable" "$2";; +esac -- cgit v1.2.3