Initial commit
This commit is contained in:
202
package/base-files/Makefile
Normal file
202
package/base-files/Makefile
Normal file
@@ -0,0 +1,202 @@
|
||||
#
|
||||
# Copyright (C) 2007-2016 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
include $(INCLUDE_DIR)/kernel.mk
|
||||
include $(INCLUDE_DIR)/version.mk
|
||||
include $(INCLUDE_DIR)/feeds.mk
|
||||
|
||||
PKG_NAME:=base-files
|
||||
PKG_RELEASE:=194.3
|
||||
PKG_FLAGS:=nonshared
|
||||
|
||||
PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
|
||||
PKG_BUILD_DEPENDS:=usign/host
|
||||
PKG_LICENSE:=GPL-2.0
|
||||
|
||||
# Extend depends from version.mk
|
||||
PKG_CONFIG_DEPENDS += \
|
||||
CONFIG_SIGNED_PACKAGES CONFIG_TARGET_INIT_PATH CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE \
|
||||
CONFIG_NAND_SUPPORT \
|
||||
CONFIG_CLEAN_IPKG \
|
||||
CONFIG_PER_FEED_REPO \
|
||||
$(foreach feed,$(FEEDS_AVAILABLE),CONFIG_FEED_$(feed))
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
ifneq ($(DUMP),1)
|
||||
STAMP_CONFIGURED:=$(strip $(STAMP_CONFIGURED))_$(shell echo $(CONFIG_TARGET_INIT_PATH) | mkhash md5)
|
||||
TARGET:=-$(BOARD)
|
||||
endif
|
||||
|
||||
define Package/base-files
|
||||
SECTION:=base
|
||||
CATEGORY:=Base system
|
||||
DEPENDS:=+netifd +libc +procd +jsonfilter +SIGNED_PACKAGES:usign +SIGNED_PACKAGES:openwrt-keyring +NAND_SUPPORT:ubi-utils +fstools +fwtool
|
||||
TITLE:=Base filesystem for OpenWrt
|
||||
URL:=http://openwrt.org/
|
||||
VERSION:=$(PKG_RELEASE)-$(REVISION)
|
||||
endef
|
||||
|
||||
define Package/base-files/conffiles
|
||||
/etc/config/
|
||||
/etc/config/network
|
||||
/etc/config/system
|
||||
/etc/crontabs/
|
||||
/etc/dropbear/
|
||||
/etc/ethers
|
||||
/etc/group
|
||||
/etc/hosts
|
||||
/etc/inittab
|
||||
/etc/iproute2/rt_protos
|
||||
/etc/iproute2/rt_tables
|
||||
/etc/passwd
|
||||
/etc/profile
|
||||
/etc/profile.d
|
||||
/etc/protocols
|
||||
/etc/rc.local
|
||||
/etc/services
|
||||
/etc/shadow
|
||||
/etc/shells
|
||||
/etc/sysctl.conf
|
||||
/etc/sysupgrade.conf
|
||||
$(call $(TARGET)/conffiles)
|
||||
endef
|
||||
|
||||
define Package/base-files/description
|
||||
This package contains a base filesystem and system scripts for OpenWrt.
|
||||
endef
|
||||
|
||||
define ImageConfigOptions
|
||||
mkdir -p $(1)/lib/preinit
|
||||
echo 'pi_suppress_stderr="$(CONFIG_TARGET_PREINIT_SUPPRESS_STDERR)"' >$(1)/lib/preinit/00_preinit.conf
|
||||
echo 'fs_failsafe_wait_timeout=$(if $(CONFIG_TARGET_PREINIT_TIMEOUT),$(CONFIG_TARGET_PREINIT_TIMEOUT),2)' >>$(1)/lib/preinit/00_preinit.conf
|
||||
echo 'pi_init_path="$(TARGET_INIT_PATH)"' >>$(1)/lib/preinit/00_preinit.conf
|
||||
echo 'pi_init_env=$(if $(CONFIG_TARGET_INIT_ENV),$(CONFIG_TARGET_INIT_ENV),"")' >>$(1)/lib/preinit/00_preinit.conf
|
||||
echo 'pi_init_cmd=$(if $(CONFIG_TARGET_INIT_CMD),$(CONFIG_TARGET_INIT_CMD),"/sbin/init")' >>$(1)/lib/preinit/00_preinit.conf
|
||||
echo 'pi_init_suppress_stderr="$(CONFIG_TARGET_INIT_SUPPRESS_STDERR)"' >>$(1)/lib/preinit/00_preinit.conf
|
||||
echo 'pi_ifname=$(if $(CONFIG_TARGET_PREINIT_IFNAME),$(CONFIG_TARGET_PREINIT_IFNAME),"")' >>$(1)/lib/preinit/00_preinit.conf
|
||||
echo 'pi_ip=$(if $(CONFIG_TARGET_PREINIT_IP),$(CONFIG_TARGET_PREINIT_IP),"192.168.1.1")' >>$(1)/lib/preinit/00_preinit.conf
|
||||
echo 'pi_netmask=$(if $(CONFIG_TARGET_PREINIT_NETMASK),$(CONFIG_TARGET_PREINIT_NETMASK),"255.255.255.0")' >>$(1)/lib/preinit/00_preinit.conf
|
||||
echo 'pi_broadcast=$(if $(CONFIG_TARGET_PREINIT_BROADCAST),$(CONFIG_TARGET_PREINIT_BROADCAST),"192.168.1.255")' >>$(1)/lib/preinit/00_preinit.conf
|
||||
echo 'pi_preinit_net_messages="$(CONFIG_TARGET_PREINIT_SHOW_NETMSG)"' >>$(1)/lib/preinit/00_preinit.conf
|
||||
echo 'pi_preinit_no_failsafe_netmsg="$(CONFIG_TARGET_PREINIT_SUPPRESS_FAILSAFE_NETMSG)"' >>$(1)/lib/preinit/00_preinit.conf
|
||||
echo 'pi_preinit_no_failsafe="$(CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE)"' >>$(1)/lib/preinit/00_preinit.conf
|
||||
endef
|
||||
|
||||
define Build/Prepare
|
||||
mkdir -p $(PKG_BUILD_DIR)
|
||||
endef
|
||||
|
||||
define Build/Compile/Default
|
||||
|
||||
endef
|
||||
Build/Compile = $(Build/Compile/Default)
|
||||
|
||||
ifdef CONFIG_SIGNED_PACKAGES
|
||||
define Build/Configure
|
||||
[ -s $(BUILD_KEY) -a -s $(BUILD_KEY).pub ] || \
|
||||
$(STAGING_DIR_HOST)/bin/usign -G -s $(BUILD_KEY) -p $(BUILD_KEY).pub -c "Local build key"
|
||||
|
||||
endef
|
||||
|
||||
define Package/base-files/install-key
|
||||
mkdir -p $(1)/etc/opkg/keys
|
||||
$(CP) $(BUILD_KEY).pub $(1)/etc/opkg/keys/`$(STAGING_DIR_HOST)/bin/usign -F -p $(BUILD_KEY).pub`
|
||||
|
||||
endef
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NAND_SUPPORT),)
|
||||
define Package/base-files/nand-support
|
||||
rm -f $(1)/lib/upgrade/nand.sh
|
||||
endef
|
||||
endif
|
||||
|
||||
define Package/base-files/install
|
||||
$(CP) ./files/* $(1)/
|
||||
$(Package/base-files/install-key)
|
||||
$(Package/base-files/nand-support)
|
||||
if [ -d $(GENERIC_PLATFORM_DIR)/base-files/. ]; then \
|
||||
$(CP) $(GENERIC_PLATFORM_DIR)/base-files/* $(1)/; \
|
||||
fi
|
||||
if [ -d $(PLATFORM_DIR)/base-files/. ]; then \
|
||||
$(CP) $(PLATFORM_DIR)/base-files/* $(1)/; \
|
||||
fi
|
||||
$(if $(filter-out $(PLATFORM_DIR),$(PLATFORM_SUBDIR)), \
|
||||
if [ -d $(PLATFORM_SUBDIR)/base-files/. ]; then \
|
||||
$(CP) $(PLATFORM_SUBDIR)/base-files/* $(1)/; \
|
||||
fi; \
|
||||
)
|
||||
|
||||
$(VERSION_SED_SCRIPT) \
|
||||
$(1)/etc/banner \
|
||||
$(1)/etc/openwrt_version \
|
||||
$(1)/usr/lib/os-release
|
||||
|
||||
$(VERSION_SED_SCRIPT) \
|
||||
$(1)/etc/openwrt_release \
|
||||
$(1)/etc/device_info \
|
||||
$(1)/usr/lib/os-release
|
||||
|
||||
$(SED) "s#%PATH%#$(TARGET_INIT_PATH)#g" \
|
||||
$(1)/sbin/hotplug-call \
|
||||
$(1)/etc/preinit \
|
||||
$(1)/etc/profile
|
||||
|
||||
mkdir -p $(1)/CONTROL
|
||||
mkdir -p $(1)/dev
|
||||
mkdir -p $(1)/etc/config
|
||||
mkdir -p $(1)/etc/crontabs
|
||||
mkdir -p $(1)/etc/rc.d
|
||||
mkdir -p $(1)/overlay
|
||||
mkdir -p $(1)/lib/firmware
|
||||
$(if $(LIB_SUFFIX),-$(LN) lib $(1)/lib$(LIB_SUFFIX))
|
||||
mkdir -p $(1)/mnt
|
||||
mkdir -p $(1)/proc
|
||||
mkdir -p $(1)/tmp
|
||||
mkdir -p $(1)/usr/lib
|
||||
$(if $(LIB_SUFFIX),-$(LN) lib $(1)/usr/lib$(LIB_SUFFIX))
|
||||
mkdir -p $(1)/usr/bin
|
||||
mkdir -p $(1)/sys
|
||||
mkdir -p $(1)/www
|
||||
mkdir -p $(1)/root
|
||||
$(LN) /proc/mounts $(1)/etc/mtab
|
||||
rm -f $(1)/var
|
||||
$(LN) tmp $(1)/var
|
||||
mkdir -p $(1)/etc
|
||||
$(LN) /tmp/resolv.conf /tmp/TZ /tmp/localtime $(1)/etc/
|
||||
|
||||
chmod 0600 $(1)/etc/shadow
|
||||
chmod 1777 $(1)/tmp
|
||||
|
||||
$(call ImageConfigOptions,$(1))
|
||||
$(call Package/base-files/install-target,$(1))
|
||||
for conffile in $(1)/etc/config/*; do \
|
||||
if [ -f "$$$$conffile" ]; then \
|
||||
grep "$$$${conffile##$(1)}" $(1)/CONTROL/conffiles || \
|
||||
echo "$$$${conffile##$(1)}" >> $(1)/CONTROL/conffiles; \
|
||||
fi \
|
||||
done
|
||||
|
||||
$(if $(CONFIG_INCLUDE_CONFIG), \
|
||||
echo -e "# Build configuration for board $(BOARD)/$(SUBTARGET)/$(PROFILE)\n" >$(1)/etc/build.config; \
|
||||
cat $(BIN_DIR)/config.seed >>$(1)/etc/build.config)
|
||||
|
||||
$(if $(CONFIG_CLEAN_IPKG),, \
|
||||
mkdir -p $(1)/etc/opkg; \
|
||||
$(call FeedSourcesAppend,$(1)/etc/opkg/distfeeds.conf); \
|
||||
$(VERSION_SED_SCRIPT) $(1)/etc/opkg/distfeeds.conf)
|
||||
endef
|
||||
|
||||
ifneq ($(DUMP),1)
|
||||
-include $(PLATFORM_DIR)/base-files.mk
|
||||
-include $(PLATFORM_SUBDIR)/base-files.mk
|
||||
endif
|
||||
|
||||
$(eval $(call BuildPackage,base-files))
|
||||
14
package/base-files/files/bin/board_detect
Executable file
14
package/base-files/files/bin/board_detect
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
CFG=$1
|
||||
|
||||
[ -n "$CFG" ] || CFG=/etc/board.json
|
||||
|
||||
[ -d "/etc/board.d/" -a ! -s "$CFG" ] && {
|
||||
for a in `ls /etc/board.d/*`; do
|
||||
[ -x $a ] || continue;
|
||||
$(. $a)
|
||||
done
|
||||
}
|
||||
|
||||
[ -s "$CFG" ] || return 1
|
||||
449
package/base-files/files/bin/config_generate
Executable file
449
package/base-files/files/bin/config_generate
Executable file
@@ -0,0 +1,449 @@
|
||||
#!/bin/sh
|
||||
|
||||
CFG=/etc/board.json
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
[ -s $CFG ] || /bin/board_detect || exit 1
|
||||
[ -s /etc/config/network -a -s /etc/config/system ] && exit 0
|
||||
|
||||
generate_static_network() {
|
||||
uci -q batch <<-EOF
|
||||
delete network.loopback
|
||||
set network.loopback='interface'
|
||||
set network.loopback.ifname='lo'
|
||||
set network.loopback.proto='static'
|
||||
set network.loopback.ipaddr='127.0.0.1'
|
||||
set network.loopback.netmask='255.0.0.0'
|
||||
EOF
|
||||
[ -e /proc/sys/net/ipv6 ] && {
|
||||
uci -q batch <<-EOF
|
||||
delete network.globals
|
||||
set network.globals='globals'
|
||||
set network.globals.ula_prefix='auto'
|
||||
EOF
|
||||
}
|
||||
|
||||
if json_is_a dsl object; then
|
||||
json_select dsl
|
||||
if json_is_a atmbridge object; then
|
||||
json_select atmbridge
|
||||
local vpi vci encaps payload nameprefix
|
||||
json_get_vars vpi vci encaps payload nameprefix
|
||||
uci -q batch <<-EOF
|
||||
delete network.atm
|
||||
set network.atm='atm-bridge'
|
||||
set network.atm.vpi='$vpi'
|
||||
set network.atm.vci='$vci'
|
||||
set network.atm.encaps='$encaps'
|
||||
set network.atm.payload='$payload'
|
||||
set network.atm.nameprefix='$nameprefix'
|
||||
EOF
|
||||
json_select ..
|
||||
fi
|
||||
|
||||
if json_is_a modem object; then
|
||||
json_select modem
|
||||
local type annex firmware tone xfer_mode
|
||||
json_get_vars type annex firmware tone xfer_mode
|
||||
uci -q batch <<-EOF
|
||||
delete network.dsl
|
||||
set network.dsl='dsl'
|
||||
set network.dsl.annex='$annex'
|
||||
set network.dsl.firmware='$firmware'
|
||||
set network.dsl.tone='$tone'
|
||||
set network.dsl.xfer_mode='$xfer_mode'
|
||||
EOF
|
||||
json_select ..
|
||||
fi
|
||||
json_select ..
|
||||
fi
|
||||
}
|
||||
|
||||
addr_offset=2
|
||||
generate_network() {
|
||||
local ifname macaddr protocol type ipaddr netmask
|
||||
|
||||
json_select network
|
||||
json_select "$1"
|
||||
json_get_vars ifname macaddr protocol ipaddr netmask
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
[ -n "$ifname" ] || return
|
||||
|
||||
# force bridge for multi-interface devices (and lan)
|
||||
case "$1:$ifname" in
|
||||
*\ * | lan:*) type="bridge" ;;
|
||||
esac
|
||||
|
||||
uci -q batch <<-EOF
|
||||
delete network.$1
|
||||
set network.$1='interface'
|
||||
set network.$1.type='$type'
|
||||
set network.$1.ifname='$ifname'
|
||||
set network.$1.proto='none'
|
||||
EOF
|
||||
|
||||
if [ -n "$macaddr" ]; then
|
||||
for name in $ifname; do
|
||||
uci -q batch <<-EOF
|
||||
delete network.$1_${name/./_}_dev
|
||||
set network.$1_${name/./_}_dev='device'
|
||||
set network.$1_${name/./_}_dev.name='$name'
|
||||
set network.$1_${name/./_}_dev.macaddr='$macaddr'
|
||||
EOF
|
||||
done
|
||||
fi
|
||||
|
||||
case "$protocol" in
|
||||
static)
|
||||
local ipad
|
||||
case "$1" in
|
||||
lan) ipad=${ipaddr:-"192.168.1.1"} ;;
|
||||
*) ipad=${ipaddr:-"192.168.$((addr_offset++)).1"} ;;
|
||||
esac
|
||||
|
||||
netm=${netmask:-"255.255.255.0"}
|
||||
|
||||
uci -q batch <<-EOF
|
||||
set network.$1.proto='static'
|
||||
set network.$1.ipaddr='$ipad'
|
||||
set network.$1.netmask='$netm'
|
||||
EOF
|
||||
[ -e /proc/sys/net/ipv6 ] && uci set network.$1.ip6assign='60'
|
||||
;;
|
||||
|
||||
dhcp)
|
||||
# fixup IPv6 slave interface if parent is a bridge
|
||||
[ "$type" = "bridge" ] && ifname="br-$1"
|
||||
|
||||
uci set network.$1.proto='dhcp'
|
||||
[ -e /proc/sys/net/ipv6 ] && {
|
||||
uci -q batch <<-EOF
|
||||
delete network.${1}6
|
||||
set network.${1}6='interface'
|
||||
set network.${1}6.ifname='$ifname'
|
||||
set network.${1}6.proto='dhcpv6'
|
||||
EOF
|
||||
}
|
||||
;;
|
||||
|
||||
pppoe)
|
||||
uci -q batch <<-EOF
|
||||
set network.$1.proto='pppoe'
|
||||
set network.$1.username='username'
|
||||
set network.$1.password='password'
|
||||
EOF
|
||||
[ -e /proc/sys/net/ipv6 ] && {
|
||||
uci -q batch <<-EOF
|
||||
set network.$1.ipv6='1'
|
||||
delete network.${1}6
|
||||
set network.${1}6='interface'
|
||||
set network.${1}6.ifname='@${1}'
|
||||
set network.${1}6.proto='dhcpv6'
|
||||
EOF
|
||||
}
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
generate_switch_vlans_ports() {
|
||||
local switch="$1"
|
||||
local port ports role roles num attr val
|
||||
|
||||
#
|
||||
# autogenerate vlans
|
||||
#
|
||||
|
||||
if json_is_a roles array; then
|
||||
json_get_keys roles roles
|
||||
json_select roles
|
||||
|
||||
for role in $roles; do
|
||||
json_select "$role"
|
||||
json_get_vars ports
|
||||
json_select ..
|
||||
|
||||
uci -q batch <<-EOF
|
||||
add network switch_vlan
|
||||
set network.@switch_vlan[-1].device='$switch'
|
||||
set network.@switch_vlan[-1].vlan='$role'
|
||||
set network.@switch_vlan[-1].ports='$ports'
|
||||
EOF
|
||||
done
|
||||
|
||||
json_select ..
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# write port specific settings
|
||||
#
|
||||
|
||||
if json_is_a ports array; then
|
||||
json_get_keys ports ports
|
||||
json_select ports
|
||||
|
||||
for port in $ports; do
|
||||
json_select "$port"
|
||||
json_get_vars num
|
||||
|
||||
if json_is_a attr object; then
|
||||
json_get_keys attr attr
|
||||
json_select attr
|
||||
uci -q batch <<-EOF
|
||||
add network switch_port
|
||||
set network.@switch_port[-1].device='$switch'
|
||||
set network.@switch_port[-1].port=$num
|
||||
EOF
|
||||
|
||||
for attr in $attr; do
|
||||
json_get_var val "$attr"
|
||||
uci -q set network.@switch_port[-1].$attr="$val"
|
||||
done
|
||||
json_select ..
|
||||
fi
|
||||
json_select ..
|
||||
done
|
||||
|
||||
json_select ..
|
||||
fi
|
||||
}
|
||||
|
||||
generate_switch() {
|
||||
local key="$1"
|
||||
local vlans
|
||||
|
||||
json_select switch
|
||||
json_select "$key"
|
||||
json_get_vars enable reset blinkrate cpu_port
|
||||
|
||||
uci -q batch <<-EOF
|
||||
add network switch
|
||||
set network.@switch[-1].name='$key'
|
||||
set network.@switch[-1].reset='$reset'
|
||||
set network.@switch[-1].enable_vlan='$enable'
|
||||
set network.@switch[-1].blinkrate='$blinkrate'
|
||||
EOF
|
||||
|
||||
generate_switch_vlans_ports "$1"
|
||||
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
|
||||
generate_static_system() {
|
||||
uci -q batch <<-EOF
|
||||
delete system.@system[0]
|
||||
add system system
|
||||
set system.@system[-1].hostname='OpenWrt'
|
||||
set system.@system[-1].timezone='UTC'
|
||||
set system.@system[-1].ttylogin='0'
|
||||
set system.@system[-1].log_size='64'
|
||||
set system.@system[-1].urandom_seed='0'
|
||||
|
||||
delete system.ntp
|
||||
set system.ntp='timeserver'
|
||||
set system.ntp.enabled='1'
|
||||
set system.ntp.enable_server='0'
|
||||
add_list system.ntp.server='0.openwrt.pool.ntp.org'
|
||||
add_list system.ntp.server='1.openwrt.pool.ntp.org'
|
||||
add_list system.ntp.server='2.openwrt.pool.ntp.org'
|
||||
add_list system.ntp.server='3.openwrt.pool.ntp.org'
|
||||
EOF
|
||||
|
||||
if json_is_a system object; then
|
||||
json_select system
|
||||
local hostname
|
||||
if json_get_var hostname hostname; then
|
||||
uci -q set "system.@system[-1].hostname=$hostname"
|
||||
fi
|
||||
|
||||
if json_is_a ntpserver array; then
|
||||
local keys key
|
||||
json_get_keys keys ntpserver
|
||||
json_select ntpserver
|
||||
uci -q delete "system.ntp.server"
|
||||
|
||||
for key in $keys; do
|
||||
local server
|
||||
if json_get_var server "$key"; then
|
||||
uci -q add_list "system.ntp.server=$server"
|
||||
fi
|
||||
done
|
||||
json_select ..
|
||||
fi
|
||||
json_select ..
|
||||
fi
|
||||
}
|
||||
|
||||
generate_rssimon() {
|
||||
local key="$1"
|
||||
local cfg="rssid_$key"
|
||||
local refresh threshold
|
||||
|
||||
json_select rssimon
|
||||
json_select "$key"
|
||||
json_get_vars refresh threshold
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
uci -q batch <<-EOF
|
||||
delete system.$cfg
|
||||
set system.$cfg='rssid'
|
||||
set system.$cfg.dev='$key'
|
||||
set system.$cfg.refresh='$refresh'
|
||||
set system.$cfg.threshold='$threshold'
|
||||
EOF
|
||||
}
|
||||
|
||||
generate_led() {
|
||||
local key="$1"
|
||||
local cfg="led_$key"
|
||||
|
||||
json_select led
|
||||
json_select "$key"
|
||||
json_get_vars name sysfs type trigger default
|
||||
|
||||
uci -q batch <<-EOF
|
||||
delete system.$cfg
|
||||
set system.$cfg='led'
|
||||
set system.$cfg.name='$name'
|
||||
set system.$cfg.sysfs='$sysfs'
|
||||
set system.$cfg.trigger='$trigger'
|
||||
set system.$cfg.default='$default'
|
||||
EOF
|
||||
|
||||
case "$type" in
|
||||
gpio)
|
||||
local gpio inverted
|
||||
json_get_vars gpio inverted
|
||||
uci -q batch <<-EOF
|
||||
set system.$cfg.trigger='gpio'
|
||||
set system.$cfg.gpio='$gpio'
|
||||
set system.$cfg.inverted='$inverted'
|
||||
EOF
|
||||
;;
|
||||
|
||||
netdev)
|
||||
local device mode
|
||||
json_get_vars device mode
|
||||
uci -q batch <<-EOF
|
||||
set system.$cfg.trigger='netdev'
|
||||
set system.$cfg.mode='$mode'
|
||||
set system.$cfg.dev='$device'
|
||||
EOF
|
||||
;;
|
||||
|
||||
usb)
|
||||
local device
|
||||
json_get_vars device
|
||||
uci -q batch <<-EOF
|
||||
set system.$cfg.trigger='usbdev'
|
||||
set system.$cfg.interval='50'
|
||||
set system.$cfg.dev='$device'
|
||||
EOF
|
||||
;;
|
||||
|
||||
usbport)
|
||||
local ports port
|
||||
json_get_values ports ports
|
||||
uci set system.$cfg.trigger='usbport'
|
||||
for port in $ports; do
|
||||
uci add_list system.$cfg.port=$port
|
||||
done
|
||||
;;
|
||||
|
||||
rssi)
|
||||
local iface minq maxq offset factor
|
||||
json_get_vars iface minq maxq offset factor
|
||||
uci -q batch <<-EOF
|
||||
set system.$cfg.trigger='rssi'
|
||||
set system.$cfg.iface='rssid_$iface'
|
||||
set system.$cfg.minq='$minq'
|
||||
set system.$cfg.maxq='$maxq'
|
||||
set system.$cfg.offset='$offset'
|
||||
set system.$cfg.factor='$factor'
|
||||
EOF
|
||||
;;
|
||||
|
||||
switch)
|
||||
local port_mask speed_mask
|
||||
json_get_vars port_mask speed_mask
|
||||
uci -q batch <<-EOF
|
||||
set system.$cfg.port_mask='$port_mask'
|
||||
set system.$cfg.speed_mask='$speed_mask'
|
||||
EOF
|
||||
;;
|
||||
|
||||
portstate)
|
||||
local port_state
|
||||
json_get_vars port_state
|
||||
uci -q batch <<-EOF
|
||||
set system.$cfg.port_state='$port_state'
|
||||
EOF
|
||||
;;
|
||||
|
||||
timer|oneshot)
|
||||
local delayon delayoff
|
||||
json_get_vars delayon delayoff
|
||||
uci -q batch <<-EOF
|
||||
set system.$cfg.trigger='$type'
|
||||
set system.$cfg.delayon='$delayon'
|
||||
set system.$cfg.delayoff='$delayoff'
|
||||
EOF
|
||||
;;
|
||||
esac
|
||||
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
generate_gpioswitch() {
|
||||
local cfg="$1"
|
||||
|
||||
json_select gpioswitch
|
||||
json_select "$cfg"
|
||||
local name pin default
|
||||
json_get_vars name pin default
|
||||
uci -q batch <<-EOF
|
||||
delete system.$cfg
|
||||
set system.$cfg='gpio_switch'
|
||||
set system.$cfg.name='$name'
|
||||
set system.$cfg.gpio_pin='$pin'
|
||||
set system.$cfg.value='$default'
|
||||
EOF
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
json_init
|
||||
json_load "$(cat ${CFG})"
|
||||
|
||||
if [ ! -s /etc/config/network ]; then
|
||||
touch /etc/config/network
|
||||
generate_static_network
|
||||
|
||||
json_get_keys keys network
|
||||
for key in $keys; do generate_network $key; done
|
||||
|
||||
json_get_keys keys switch
|
||||
for key in $keys; do generate_switch $key; done
|
||||
fi
|
||||
|
||||
if [ ! -s /etc/config/system ]; then
|
||||
touch /etc/config/system
|
||||
generate_static_system
|
||||
|
||||
json_get_keys keys rssimon
|
||||
for key in $keys; do generate_rssimon $key; done
|
||||
|
||||
json_get_keys keys gpioswitch
|
||||
for key in $keys; do generate_gpioswitch $key; done
|
||||
|
||||
json_get_keys keys led
|
||||
for key in $keys; do generate_led $key; done
|
||||
fi
|
||||
uci commit
|
||||
71
package/base-files/files/bin/ipcalc.sh
Executable file
71
package/base-files/files/bin/ipcalc.sh
Executable file
@@ -0,0 +1,71 @@
|
||||
#!/bin/sh
|
||||
|
||||
awk -f - $* <<EOF
|
||||
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 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
|
||||
}
|
||||
|
||||
function compl32(v) {
|
||||
ret=xor(v, 0xffffffff)
|
||||
return ret
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
slpos=index(ARGV[1],"/")
|
||||
if (slpos == 0) {
|
||||
ipaddr=ip2int(ARGV[1])
|
||||
dotpos=index(ARGV[2],".")
|
||||
if (dotpos == 0)
|
||||
netmask=compl32(2**(32-int(ARGV[2]))-1)
|
||||
else
|
||||
netmask=ip2int(ARGV[2])
|
||||
} else {
|
||||
ipaddr=ip2int(substr(ARGV[1],0,slpos-1))
|
||||
netmask=compl32(2**(32-int(substr(ARGV[1],slpos+1)))-1)
|
||||
ARGV[4]=ARGV[3]
|
||||
ARGV[3]=ARGV[2]
|
||||
}
|
||||
|
||||
network=and(ipaddr,netmask)
|
||||
broadcast=or(network,compl32(netmask))
|
||||
|
||||
start=or(network,and(ip2int(ARGV[3]),compl32(netmask)))
|
||||
limit=network+1
|
||||
if (start<limit) start=limit
|
||||
|
||||
end=start+ARGV[4]
|
||||
limit=or(network,compl32(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(compl32(netmask))
|
||||
|
||||
# range calculations:
|
||||
# ipcalc <ip> <netmask> <start> <num>
|
||||
|
||||
if (ARGC > 3) {
|
||||
print "START="int2ip(start)
|
||||
print "END="int2ip(end)
|
||||
}
|
||||
}
|
||||
EOF
|
||||
8
package/base-files/files/etc/banner
Normal file
8
package/base-files/files/etc/banner
Normal file
@@ -0,0 +1,8 @@
|
||||
_______ ________ __
|
||||
| |.-----.-----.-----.| | | |.----.| |_
|
||||
| - || _ | -__| || | | || _|| _|
|
||||
|_______|| __|_____|__|__||________||__| |____|
|
||||
|__| W I R E L E S S F R E E D O M
|
||||
-----------------------------------------------------
|
||||
%D %V, %C
|
||||
-----------------------------------------------------
|
||||
15
package/base-files/files/etc/banner.failsafe
Normal file
15
package/base-files/files/etc/banner.failsafe
Normal file
@@ -0,0 +1,15 @@
|
||||
================= FAILSAFE MODE active ================
|
||||
special commands:
|
||||
* firstboot reset settings to factory defaults
|
||||
* mount_root mount root-partition with config files
|
||||
|
||||
after mount_root:
|
||||
* passwd change root's password
|
||||
* /etc/config directory with config files
|
||||
|
||||
for more help see:
|
||||
https://openwrt.org/docs/guide-user/troubleshooting/
|
||||
- failsafe_and_factory_reset
|
||||
- root_password_reset
|
||||
=======================================================
|
||||
|
||||
17
package/base-files/files/etc/board.d/99-default_network
Executable file
17
package/base-files/files/etc/board.d/99-default_network
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2013-2015 OpenWrt.org
|
||||
#
|
||||
|
||||
. /lib/functions/uci-defaults.sh
|
||||
|
||||
board_config_update
|
||||
|
||||
json_is_a network object && exit 0
|
||||
|
||||
ucidef_set_interface_lan 'eth0'
|
||||
[ -d /sys/class/net/eth1 ] && ucidef_set_interface_wan 'eth1'
|
||||
|
||||
board_config_flush
|
||||
|
||||
exit 0
|
||||
4
package/base-files/files/etc/device_info
Normal file
4
package/base-files/files/etc/device_info
Normal file
@@ -0,0 +1,4 @@
|
||||
DEVICE_MANUFACTURER='%M'
|
||||
DEVICE_MANUFACTURER_URL='%m'
|
||||
DEVICE_PRODUCT='%P'
|
||||
DEVICE_REVISION='%h'
|
||||
4
package/base-files/files/etc/diag.sh
Normal file
4
package/base-files/files/etc/diag.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006-2009 OpenWrt.org
|
||||
|
||||
set_state() { :; }
|
||||
6
package/base-files/files/etc/ethers
Normal file
6
package/base-files/files/etc/ethers
Normal file
@@ -0,0 +1,6 @@
|
||||
#
|
||||
# Lookup man 5 ethers for syntax documentation
|
||||
#
|
||||
# Examples :
|
||||
# 02:00:11:22:33:44 OpenWrt.lan
|
||||
# 02:00:11:22:33:44 192.168.1.1
|
||||
1
package/base-files/files/etc/fstab
Normal file
1
package/base-files/files/etc/fstab
Normal file
@@ -0,0 +1 @@
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
11
package/base-files/files/etc/group
Normal file
11
package/base-files/files/etc/group
Normal file
@@ -0,0 +1,11 @@
|
||||
root:x:0:
|
||||
daemon:x:1:
|
||||
adm:x:4:
|
||||
tty:x:5:
|
||||
mail:x:8:
|
||||
audio:x:29:
|
||||
www-data:x:33:
|
||||
ftp:x:55:
|
||||
users:x:100:
|
||||
network:x:101:
|
||||
nogroup:x:65534:
|
||||
5
package/base-files/files/etc/hosts
Normal file
5
package/base-files/files/etc/hosts
Normal file
@@ -0,0 +1,5 @@
|
||||
127.0.0.1 localhost
|
||||
|
||||
::1 localhost ip6-localhost ip6-loopback
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
9
package/base-files/files/etc/hotplug.d/net/00-sysctl
Normal file
9
package/base-files/files/etc/hotplug.d/net/00-sysctl
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ "$ACTION" = add ]; then
|
||||
for CONF in /etc/sysctl.d/*.conf /etc/sysctl.conf; do
|
||||
[ ! -f "$CONF" ] && continue;
|
||||
sed -ne "/^[[:space:]]*net\..*\.$DEVICENAME\./p" "$CONF" | \
|
||||
sysctl -e -p - | logger -t sysctl
|
||||
done
|
||||
fi
|
||||
51
package/base-files/files/etc/init.d/boot
Executable file
51
package/base-files/files/etc/init.d/boot
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2006-2011 OpenWrt.org
|
||||
|
||||
START=10
|
||||
STOP=98
|
||||
|
||||
uci_apply_defaults() {
|
||||
. /lib/functions/system.sh
|
||||
|
||||
cd /etc/uci-defaults || return 0
|
||||
files="$(ls)"
|
||||
[ -z "$files" ] && return 0
|
||||
mkdir -p /tmp/.uci
|
||||
for file in $files; do
|
||||
( . "./$(basename $file)" ) && rm -f "$file"
|
||||
done
|
||||
uci commit
|
||||
}
|
||||
|
||||
boot() {
|
||||
[ -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 /var/tmp
|
||||
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 && /bin/mount -o noatime -t debugfs debugfs /sys/kernel/debug
|
||||
[ "$FAILSAFE" = "true" ] && touch /tmp/.failsafe
|
||||
|
||||
/sbin/kmodloader
|
||||
|
||||
[ ! -f /etc/config/wireless ] && {
|
||||
# compat for brcm47xx and mvebu
|
||||
sleep 1
|
||||
}
|
||||
|
||||
/bin/config_generate
|
||||
uci_apply_defaults
|
||||
|
||||
# temporary hack until configd exists
|
||||
/sbin/reload_config
|
||||
}
|
||||
17
package/base-files/files/etc/init.d/done
Executable file
17
package/base-files/files/etc/init.d/done
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
|
||||
START=95
|
||||
boot() {
|
||||
mount_root done
|
||||
rm -f /sysupgrade.tgz
|
||||
|
||||
# process user commands
|
||||
[ -f /etc/rc.local ] && {
|
||||
sh /etc/rc.local
|
||||
}
|
||||
|
||||
# set leds to normal state
|
||||
. /etc/diag.sh
|
||||
set_state done
|
||||
}
|
||||
48
package/base-files/files/etc/init.d/gpio_switch
Executable file
48
package/base-files/files/etc/init.d/gpio_switch
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2015 OpenWrt.org
|
||||
|
||||
START=94
|
||||
STOP=10
|
||||
USE_PROCD=1
|
||||
|
||||
|
||||
load_gpio_switch()
|
||||
{
|
||||
local name
|
||||
local gpio_pin
|
||||
local value
|
||||
|
||||
config_get gpio_pin "$1" gpio_pin
|
||||
config_get name "$1" name
|
||||
config_get value "$1" value 0
|
||||
|
||||
local gpio_path="/sys/class/gpio/gpio${gpio_pin}"
|
||||
# export GPIO pin for access
|
||||
[ -d "$gpio_path" ] || {
|
||||
echo "$gpio_pin" >/sys/class/gpio/export
|
||||
# we need to wait a bit until the GPIO appears
|
||||
[ -d "$gpio_path" ] || sleep 1
|
||||
}
|
||||
|
||||
# direction attribute only exists if the kernel supports changing the
|
||||
# direction of a GPIO
|
||||
if [ -e "${gpio_path}/direction" ]; then
|
||||
# set the pin to output with high or low pin value
|
||||
{ [ "$value" = "0" ] && echo "low" || echo "high"; } >"$gpio_path/direction"
|
||||
else
|
||||
{ [ "$value" = "0" ] && echo "0" || echo "1"; } >"$gpio_path/value"
|
||||
fi
|
||||
}
|
||||
|
||||
service_triggers()
|
||||
{
|
||||
procd_add_reload_trigger "system"
|
||||
}
|
||||
|
||||
start_service()
|
||||
{
|
||||
[ -e /sys/class/gpio/ ] && {
|
||||
config_load system
|
||||
config_foreach load_gpio_switch gpio_switch
|
||||
}
|
||||
}
|
||||
135
package/base-files/files/etc/init.d/led
Executable file
135
package/base-files/files/etc/init.d/led
Executable file
@@ -0,0 +1,135 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2008 OpenWrt.org
|
||||
|
||||
START=96
|
||||
|
||||
load_led() {
|
||||
local name
|
||||
local sysfs
|
||||
local trigger
|
||||
local dev
|
||||
local ports
|
||||
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 ports $1 port
|
||||
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
|
||||
config_get delay $1 delay "150"
|
||||
config_get message $1 message ""
|
||||
config_get gpio $1 gpio "0"
|
||||
config_get inverted $1 inverted "0"
|
||||
|
||||
if [ "$trigger" = "rssi" ]; then
|
||||
# handled by rssileds userspace process
|
||||
return
|
||||
fi
|
||||
|
||||
[ "$trigger" = "usbdev" ] && {
|
||||
# Backward compatibility: translate to the new trigger
|
||||
trigger="usbport"
|
||||
# Translate port of root hub, e.g. 4-1 -> usb4-port1
|
||||
ports=$(echo "$dev" | sed -n 's/^\([0-9]*\)-\([0-9]*\)$/usb\1-port\2/p')
|
||||
# Translate port of extra hub, e.g. 2-2.4 -> 2-2-port4
|
||||
[ -z "$ports" ] && ports=$(echo "$dev" | sed -n 's/\./-port/p')
|
||||
}
|
||||
|
||||
[ -e /sys/class/leds/${sysfs}/brightness ] && {
|
||||
echo "setting up led ${name}"
|
||||
|
||||
printf "%s %s %d\n" \
|
||||
"$sysfs" \
|
||||
"$(sed -ne 's/^.*\[\(.*\)\].*$/\1/p' /sys/class/leds/${sysfs}/trigger)" \
|
||||
"$(cat /sys/class/leds/${sysfs}/brightness)" \
|
||||
>> /var/run/led.state
|
||||
|
||||
[ "$default" = 0 ] &&
|
||||
echo 0 >/sys/class/leds/${sysfs}/brightness
|
||||
|
||||
echo $trigger > /sys/class/leds/${sysfs}/trigger 2> /dev/null
|
||||
ret="$?"
|
||||
|
||||
[ $default = 1 ] &&
|
||||
cat /sys/class/leds/${sysfs}/max_brightness > /sys/class/leds/${sysfs}/brightness
|
||||
|
||||
[ $ret = 0 ] || {
|
||||
echo >&2 "Skipping trigger '$trigger' for led '$name' due to missing kernel module"
|
||||
return 1
|
||||
}
|
||||
case "$trigger" in
|
||||
"netdev")
|
||||
[ -n "$dev" ] && {
|
||||
echo $dev > /sys/class/leds/${sysfs}/device_name
|
||||
echo $mode > /sys/class/leds/${sysfs}/mode
|
||||
echo $interval > /sys/class/leds/${sysfs}/interval
|
||||
}
|
||||
;;
|
||||
|
||||
"timer"|"oneshot")
|
||||
[ -n "$delayon" ] && \
|
||||
echo $delayon > /sys/class/leds/${sysfs}/delay_on
|
||||
[ -n "$delayoff" ] && \
|
||||
echo $delayoff > /sys/class/leds/${sysfs}/delay_off
|
||||
;;
|
||||
|
||||
"usbport")
|
||||
local p
|
||||
|
||||
for p in $ports; do
|
||||
echo 1 > /sys/class/leds/${sysfs}/ports/$p
|
||||
done
|
||||
;;
|
||||
|
||||
"port_state")
|
||||
[ -n "$port_state" ] && \
|
||||
echo $port_state > /sys/class/leds/${sysfs}/port_state
|
||||
;;
|
||||
|
||||
"gpio")
|
||||
echo $gpio > /sys/class/leds/${sysfs}/gpio
|
||||
echo $inverted > /sys/class/leds/${sysfs}/inverted
|
||||
;;
|
||||
|
||||
switch[0-9]*)
|
||||
local port_mask speed_mask
|
||||
|
||||
config_get port_mask $1 port_mask
|
||||
[ -n "$port_mask" ] && \
|
||||
echo $port_mask > /sys/class/leds/${sysfs}/port_mask
|
||||
config_get speed_mask $1 speed_mask
|
||||
[ -n "$speed_mask" ] && \
|
||||
echo $speed_mask > /sys/class/leds/${sysfs}/speed_mask
|
||||
;;
|
||||
esac
|
||||
}
|
||||
}
|
||||
|
||||
start() {
|
||||
[ -e /sys/class/leds/ ] && {
|
||||
[ -s /var/run/led.state ] && {
|
||||
local led trigger brightness
|
||||
while read led trigger brightness; do
|
||||
[ -e "/sys/class/leds/$led/trigger" ] && \
|
||||
echo "$trigger" > "/sys/class/leds/$led/trigger"
|
||||
|
||||
[ -e "/sys/class/leds/$led/brightness" ] && \
|
||||
echo "$brightness" > "/sys/class/leds/$led/brightness"
|
||||
done < /var/run/led.state
|
||||
rm /var/run/led.state
|
||||
}
|
||||
|
||||
config_load system
|
||||
config_foreach load_led led
|
||||
}
|
||||
}
|
||||
44
package/base-files/files/etc/init.d/sysctl
Executable file
44
package/base-files/files/etc/init.d/sysctl
Executable file
@@ -0,0 +1,44 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
|
||||
START=11
|
||||
|
||||
apply_defaults() {
|
||||
local mem="$(awk '/^MemTotal:/ {print $2}' /proc/meminfo)"
|
||||
local min_free frag_low_thresh frag_high_thresh
|
||||
|
||||
if [ "$mem" -gt 65536 ]; then # 128M
|
||||
min_free=16384
|
||||
elif [ "$mem" -gt 32768 ]; then # 64M
|
||||
min_free=8192
|
||||
else
|
||||
min_free=1024
|
||||
frag_low_thresh=393216
|
||||
frag_high_thresh=524288
|
||||
fi
|
||||
|
||||
sysctl -qw vm.min_free_kbytes="$min_free"
|
||||
|
||||
[ "$frag_low_thresh" ] && sysctl -qw \
|
||||
net.ipv4.ipfrag_low_thresh="$frag_low_thresh" \
|
||||
net.ipv4.ipfrag_high_thresh="$frag_high_thresh" \
|
||||
net.ipv6.ip6frag_low_thresh="$frag_low_thresh" \
|
||||
net.ipv6.ip6frag_high_thresh="$frag_high_thresh" \
|
||||
net.netfilter.nf_conntrack_frag6_low_thresh="$frag_low_thresh" \
|
||||
net.netfilter.nf_conntrack_frag6_high_thresh="$frag_high_thresh"
|
||||
|
||||
# first set default, then all interfaces to avoid races with appearing interfaces
|
||||
if [ -d /proc/sys/net/ipv6/conf ]; then
|
||||
echo 0 > /proc/sys/net/ipv6/conf/default/accept_ra
|
||||
for iface in /proc/sys/net/ipv6/conf/*/accept_ra; do
|
||||
echo 0 > "$iface"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
start() {
|
||||
apply_defaults
|
||||
for CONF in /etc/sysctl.d/*.conf /etc/sysctl.conf; do
|
||||
[ -f "$CONF" ] && sysctl -e -p "$CONF" >&-
|
||||
done
|
||||
}
|
||||
34
package/base-files/files/etc/init.d/sysfixtime
Executable file
34
package/base-files/files/etc/init.d/sysfixtime
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2013-2014 OpenWrt.org
|
||||
|
||||
START=00
|
||||
STOP=90
|
||||
|
||||
RTC_DEV=/dev/rtc0
|
||||
HWCLOCK=/sbin/hwclock
|
||||
|
||||
boot() {
|
||||
start && exit 0
|
||||
|
||||
local maxtime="$(maxtime)"
|
||||
local curtime="$(date +%s)"
|
||||
[ $curtime -lt $maxtime ] && date -s @$maxtime
|
||||
}
|
||||
|
||||
start() {
|
||||
[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s -u -f $RTC_DEV
|
||||
}
|
||||
|
||||
stop() {
|
||||
[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -w -u -f $RTC_DEV && \
|
||||
logger -t sysfixtime "saved '$(date)' to $RTC_DEV"
|
||||
}
|
||||
|
||||
maxtime() {
|
||||
local file newest
|
||||
|
||||
for file in $( find /etc -type f ) ; do
|
||||
[ -z "$newest" -o "$newest" -ot "$file" ] && newest=$file
|
||||
done
|
||||
[ "$newest" ] && date -r "$newest" +%s
|
||||
}
|
||||
50
package/base-files/files/etc/init.d/system
Executable file
50
package/base-files/files/etc/init.d/system
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2014 OpenWrt.org
|
||||
|
||||
START=10
|
||||
USE_PROCD=1
|
||||
|
||||
validate_system_section()
|
||||
{
|
||||
uci_validate_section system system "${1}" \
|
||||
'hostname:string:OpenWrt' \
|
||||
'conloglevel:uinteger' \
|
||||
'buffersize:uinteger' \
|
||||
'timezone:string:UTC' \
|
||||
'zonename:string'
|
||||
}
|
||||
|
||||
system_config() {
|
||||
local cfg="$1"
|
||||
|
||||
local hostname conloglevel buffersize timezone zonename
|
||||
|
||||
validate_system_section "${1}" || {
|
||||
echo "validation failed"
|
||||
return 1
|
||||
}
|
||||
|
||||
echo "$hostname" > /proc/sys/kernel/hostname
|
||||
[ -z "$conloglevel" -a -z "$buffersize" ] || dmesg ${conloglevel:+-n $conloglevel} ${buffersize:+-s $buffersize}
|
||||
echo "$timezone" > /tmp/TZ
|
||||
[ -n "$zonename" ] && [ -f "/usr/share/zoneinfo/$zonename" ] && \
|
||||
ln -sf "/usr/share/zoneinfo/$zonename" /tmp/localtime && rm -f /tmp/TZ
|
||||
|
||||
# apply timezone to kernel
|
||||
date -k
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
config_load system
|
||||
config_foreach system_config system
|
||||
}
|
||||
|
||||
service_triggers()
|
||||
{
|
||||
procd_add_reload_trigger "system"
|
||||
procd_add_validation validate_system_section
|
||||
}
|
||||
|
||||
start_service() {
|
||||
reload_service
|
||||
}
|
||||
8
package/base-files/files/etc/init.d/umount
Executable file
8
package/base-files/files/etc/init.d/umount
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
|
||||
STOP=99
|
||||
stop() {
|
||||
sync
|
||||
/bin/umount -a -d -r
|
||||
}
|
||||
12
package/base-files/files/etc/init.d/urandom_seed
Executable file
12
package/base-files/files/etc/init.d/urandom_seed
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=99
|
||||
USE_PROCD=1
|
||||
|
||||
start_service() {
|
||||
procd_open_instance "urandom_seed"
|
||||
procd_set_param command "/sbin/urandom_seed"
|
||||
procd_set_param stdout 1
|
||||
procd_set_param stderr 1
|
||||
procd_close_instance
|
||||
}
|
||||
3
package/base-files/files/etc/inittab
Normal file
3
package/base-files/files/etc/inittab
Normal file
@@ -0,0 +1,3 @@
|
||||
::sysinit:/etc/init.d/rcS S boot
|
||||
::shutdown:/etc/init.d/rcS K shutdown
|
||||
::askconsole:/usr/libexec/login.sh
|
||||
8
package/base-files/files/etc/iproute2/ematch_map
Normal file
8
package/base-files/files/etc/iproute2/ematch_map
Normal file
@@ -0,0 +1,8 @@
|
||||
# lookup table for ematch kinds
|
||||
1 cmp
|
||||
2 nbyte
|
||||
3 u32
|
||||
4 meta
|
||||
7 canid
|
||||
8 ipset
|
||||
9 ipt
|
||||
18
package/base-files/files/etc/iproute2/rt_protos
Normal file
18
package/base-files/files/etc/iproute2/rt_protos
Normal file
@@ -0,0 +1,18 @@
|
||||
#
|
||||
# Reserved protocols.
|
||||
#
|
||||
0 unspec
|
||||
1 redirect
|
||||
2 kernel
|
||||
3 boot
|
||||
4 static
|
||||
8 gated
|
||||
9 ra
|
||||
10 mrt
|
||||
11 zebra
|
||||
12 bird
|
||||
13 dnrouted
|
||||
14 xorp
|
||||
15 ntk
|
||||
16 dhcp
|
||||
42 babel
|
||||
12
package/base-files/files/etc/iproute2/rt_tables
Normal file
12
package/base-files/files/etc/iproute2/rt_tables
Normal file
@@ -0,0 +1,12 @@
|
||||
#
|
||||
# reserved values
|
||||
#
|
||||
128 prelocal
|
||||
255 local
|
||||
254 main
|
||||
253 default
|
||||
0 unspec
|
||||
#
|
||||
# local
|
||||
#
|
||||
#1 inr.ruhep
|
||||
7
package/base-files/files/etc/openwrt_release
Normal file
7
package/base-files/files/etc/openwrt_release
Normal file
@@ -0,0 +1,7 @@
|
||||
DISTRIB_ID='%D'
|
||||
DISTRIB_RELEASE='%V'
|
||||
DISTRIB_REVISION='%R'
|
||||
DISTRIB_TARGET='%S'
|
||||
DISTRIB_ARCH='%A'
|
||||
DISTRIB_DESCRIPTION='%D %V %C'
|
||||
DISTRIB_TAINTS='%t'
|
||||
1
package/base-files/files/etc/openwrt_version
Normal file
1
package/base-files/files/etc/openwrt_version
Normal file
@@ -0,0 +1 @@
|
||||
%C
|
||||
1
package/base-files/files/etc/os-release
Symbolic link
1
package/base-files/files/etc/os-release
Symbolic link
@@ -0,0 +1 @@
|
||||
../usr/lib/os-release
|
||||
5
package/base-files/files/etc/passwd
Normal file
5
package/base-files/files/etc/passwd
Normal file
@@ -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
|
||||
29
package/base-files/files/etc/preinit
Executable file
29
package/base-files/files/etc/preinit
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006-2016 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
[ -z "$PREINIT" ] && exec /sbin/init
|
||||
|
||||
export PATH="%PATH%"
|
||||
|
||||
. /lib/functions.sh
|
||||
. /lib/functions/preinit.sh
|
||||
. /lib/functions/system.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
|
||||
59
package/base-files/files/etc/profile
Normal file
59
package/base-files/files/etc/profile
Normal file
@@ -0,0 +1,59 @@
|
||||
#!/bin/sh
|
||||
[ -e /tmp/.failsafe ] && export FAILSAFE=1
|
||||
|
||||
[ -f /etc/banner ] && cat /etc/banner
|
||||
[ -n "$FAILSAFE" ] && cat /etc/banner.failsafe
|
||||
|
||||
fgrep -sq '/ overlay ro,' /proc/mounts && {
|
||||
echo 'Your JFFS2-partition seems full and overlayfs is mounted read-only.'
|
||||
echo 'Please try to remove files from /overlay/upper/... and reboot!'
|
||||
}
|
||||
|
||||
export PATH="%PATH%"
|
||||
export HOME=$(grep -e "^${USER:-root}:" /etc/passwd | cut -d ":" -f 6)
|
||||
export HOME=${HOME:-/root}
|
||||
export PS1='\u@\h:\w\$ '
|
||||
|
||||
case "$TERM" in
|
||||
xterm*|rxvt*)
|
||||
export PS1='\[\e]0;\u@\h: \w\a\]'$PS1
|
||||
;;
|
||||
esac
|
||||
|
||||
[ -x /bin/more ] || alias more=less
|
||||
[ -x /usr/bin/vim ] && alias vi=vim || alias vim=vi
|
||||
|
||||
alias ll='ls -alF --color=auto'
|
||||
|
||||
[ -z "$KSH_VERSION" -o \! -s /etc/mkshrc ] || . /etc/mkshrc
|
||||
|
||||
[ -x /usr/bin/arp -o -x /sbin/arp ] || arp() { cat /proc/net/arp; }
|
||||
[ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }
|
||||
|
||||
[ -n "$FAILSAFE" ] || {
|
||||
for FILE in /etc/profile.d/*.sh; do
|
||||
[ -e "$FILE" ] && . "$FILE"
|
||||
done
|
||||
unset FILE
|
||||
}
|
||||
|
||||
if ( grep -qs '^root::' /etc/shadow && \
|
||||
[ -z "$FAILSAFE" ] )
|
||||
then
|
||||
cat << EOF
|
||||
=== WARNING! =====================================
|
||||
There is no root password defined on this device!
|
||||
Use the "passwd" command to set up a new password
|
||||
in order to prevent unauthorized SSH logins.
|
||||
--------------------------------------------------
|
||||
EOF
|
||||
fi
|
||||
|
||||
service() {
|
||||
[ -f "/etc/init.d/$1" ] || {
|
||||
echo "service "'"'"$1"'"'" not found, the following services are available:"
|
||||
ls "/etc/init.d"
|
||||
return 1
|
||||
}
|
||||
/etc/init.d/$@
|
||||
}
|
||||
57
package/base-files/files/etc/protocols
Normal file
57
package/base-files/files/etc/protocols
Normal file
@@ -0,0 +1,57 @@
|
||||
# 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]
|
||||
dccp 33 DCCP # Datagram Congestion Control Protocol [RFC4340]
|
||||
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
|
||||
|
||||
5
package/base-files/files/etc/rc.button/failsafe
Executable file
5
package/base-files/files/etc/rc.button/failsafe
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ "${TYPE}" = "switch" ] || echo ${BUTTON} > /tmp/failsafe_button
|
||||
|
||||
return 0
|
||||
7
package/base-files/files/etc/rc.button/power
Executable file
7
package/base-files/files/etc/rc.button/power
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ "${ACTION}" = "released" ] || exit 0
|
||||
|
||||
exec /sbin/poweroff
|
||||
|
||||
return 0
|
||||
31
package/base-files/files/etc/rc.button/reset
Executable file
31
package/base-files/files/etc/rc.button/reset
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
|
||||
OVERLAY="$( grep ' /overlay ' /proc/mounts )"
|
||||
|
||||
case "$ACTION" in
|
||||
pressed)
|
||||
[ -z "$OVERLAY" ] && return 0
|
||||
|
||||
return 5
|
||||
;;
|
||||
timeout)
|
||||
. /etc/diag.sh
|
||||
set_state failsafe
|
||||
;;
|
||||
released)
|
||||
if [ "$SEEN" -lt 1 ]
|
||||
then
|
||||
echo "REBOOT" > /dev/console
|
||||
sync
|
||||
reboot
|
||||
elif [ "$SEEN" -ge 5 -a -n "$OVERLAY" ]
|
||||
then
|
||||
echo "FACTORY RESET" > /dev/console
|
||||
jffs2reset -y && reboot &
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
return 0
|
||||
32
package/base-files/files/etc/rc.button/rfkill
Executable file
32
package/base-files/files/etc/rc.button/rfkill
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ "${ACTION}" = "released" -o -n "${TYPE}" ] || exit 0
|
||||
|
||||
. /lib/functions.sh
|
||||
|
||||
rfkill_state=0
|
||||
|
||||
wifi_rfkill_set() {
|
||||
uci set wireless.$1.disabled=$rfkill_state
|
||||
}
|
||||
|
||||
wifi_rfkill_check() {
|
||||
local disabled
|
||||
config_get disabled $1 disabled
|
||||
[ "$disabled" = "1" ] || rfkill_state=1
|
||||
}
|
||||
|
||||
config_load wireless
|
||||
case "${TYPE}" in
|
||||
"switch")
|
||||
[ "${ACTION}" = "released" ] && rfkill_state=1
|
||||
;;
|
||||
*)
|
||||
config_foreach wifi_rfkill_check wifi-device
|
||||
;;
|
||||
esac
|
||||
config_foreach wifi_rfkill_set wifi-device
|
||||
uci commit wireless
|
||||
wifi up
|
||||
|
||||
return 0
|
||||
152
package/base-files/files/etc/rc.common
Executable file
152
package/base-files/files/etc/rc.common
Executable file
@@ -0,0 +1,152 @@
|
||||
#!/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() {
|
||||
restart
|
||||
}
|
||||
|
||||
restart() {
|
||||
trap '' TERM
|
||||
stop "$@"
|
||||
trap - TERM
|
||||
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() {
|
||||
err=1
|
||||
name="$(basename "${initscript}")"
|
||||
[ "$START" ] && \
|
||||
ln -sf "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" && \
|
||||
err=0
|
||||
[ "$STOP" ] && \
|
||||
ln -sf "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}" && \
|
||||
err=0
|
||||
return $err
|
||||
}
|
||||
|
||||
enabled() {
|
||||
name="$(basename "${initscript}")"
|
||||
[ -x "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ]
|
||||
}
|
||||
|
||||
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 service does not implement reload)
|
||||
enable Enable service autostart
|
||||
disable Disable service autostart
|
||||
$EXTRA_HELP
|
||||
EOF
|
||||
}
|
||||
|
||||
# for procd
|
||||
start_service() {
|
||||
return 0
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
return 0
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
return 0
|
||||
}
|
||||
|
||||
service_data() {
|
||||
return 0
|
||||
}
|
||||
|
||||
service_running() {
|
||||
return 0
|
||||
}
|
||||
|
||||
${INIT_TRACE:+set -x}
|
||||
|
||||
. "$initscript"
|
||||
|
||||
[ -n "$USE_PROCD" ] && {
|
||||
EXTRA_COMMANDS="${EXTRA_COMMANDS} running trace"
|
||||
|
||||
. $IPKG_INSTROOT/lib/functions/procd.sh
|
||||
basescript=$(readlink "$initscript")
|
||||
rc_procd() {
|
||||
local method="set"
|
||||
[ -n "$2" ] && method="add"
|
||||
procd_open_service "$(basename ${basescript:-$initscript})" "$initscript"
|
||||
"$@"
|
||||
procd_close_service "$method"
|
||||
}
|
||||
|
||||
start() {
|
||||
rc_procd start_service "$@"
|
||||
if eval "type service_started" 2>/dev/null >/dev/null; then
|
||||
service_started
|
||||
fi
|
||||
}
|
||||
|
||||
trace() {
|
||||
TRACE_SYSCALLS=1
|
||||
start "$@"
|
||||
}
|
||||
|
||||
stop() {
|
||||
procd_lock
|
||||
stop_service "$@"
|
||||
procd_kill "$(basename ${basescript:-$initscript})" "$1"
|
||||
}
|
||||
|
||||
reload() {
|
||||
if eval "type reload_service" 2>/dev/null >/dev/null; then
|
||||
procd_lock
|
||||
reload_service "$@"
|
||||
else
|
||||
start
|
||||
fi
|
||||
}
|
||||
|
||||
running() {
|
||||
service_running "$@"
|
||||
}
|
||||
}
|
||||
|
||||
ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}"
|
||||
list_contains ALL_COMMANDS "$action" || action=help
|
||||
$action "$@"
|
||||
4
package/base-files/files/etc/rc.local
Normal file
4
package/base-files/files/etc/rc.local
Normal file
@@ -0,0 +1,4 @@
|
||||
# Put your custom commands here that should be executed once
|
||||
# the system init finished. By default this file does nothing.
|
||||
|
||||
exit 0
|
||||
173
package/base-files/files/etc/services
Normal file
173
package/base-files/files/etc/services
Normal file
@@ -0,0 +1,173 @@
|
||||
echo 7/tcp
|
||||
echo 7/udp
|
||||
discard 9/tcp
|
||||
discard 9/udp
|
||||
daytime 13/tcp
|
||||
daytime 13/udp
|
||||
netstat 15/tcp
|
||||
chargen 19/tcp
|
||||
chargen 19/udp
|
||||
ftp-data 20/tcp
|
||||
ftp 21/tcp
|
||||
ssh 22/tcp
|
||||
ssh 22/udp
|
||||
telnet 23/tcp
|
||||
smtp 25/tcp
|
||||
time 37/tcp
|
||||
time 37/udp
|
||||
whois 43/tcp
|
||||
domain 53/tcp
|
||||
domain 53/udp
|
||||
bootps 67/tcp
|
||||
bootps 67/udp
|
||||
bootpc 68/tcp
|
||||
bootpc 68/udp
|
||||
tftp 69/udp
|
||||
finger 79/tcp
|
||||
www 80/tcp http
|
||||
kerberos 88/tcp kerberos5 krb5 kerberos-sec
|
||||
kerberos 88/udp kerberos5 krb5 kerberos-sec
|
||||
pop3 110/tcp
|
||||
pop3 110/udp
|
||||
sunrpc 111/tcp rpcbind
|
||||
sunrpc 111/udp rpcbind
|
||||
auth 113/tcp ident
|
||||
sftp 115/tcp
|
||||
nntp 119/tcp
|
||||
ntp 123/tcp
|
||||
ntp 123/udp
|
||||
netbios-ns 137/tcp
|
||||
netbios-ns 137/udp
|
||||
netbios-dgm 138/tcp
|
||||
netbios-dgm 138/udp
|
||||
netbios-ssn 139/tcp
|
||||
netbios-ssn 139/udp
|
||||
imap2 143/tcp imap
|
||||
imap2 143/udp imap
|
||||
snmp 161/tcp
|
||||
snmp 161/udp
|
||||
snmp-trap 162/tcp snmptrap
|
||||
snmp-trap 162/udp snmptrap
|
||||
xdmcp 177/tcp
|
||||
xdmcp 177/udp
|
||||
bgp 179/tcp
|
||||
bgp 179/udp
|
||||
imap3 220/tcp
|
||||
imap3 220/udp
|
||||
ldap 389/tcp
|
||||
ldap 389/udp
|
||||
https 443/tcp
|
||||
https 443/udp
|
||||
microsoft-ds 445/tcp
|
||||
microsoft-ds 445/udp
|
||||
isakmp 500/tcp
|
||||
isakmp 500/udp
|
||||
rtsp 554/tcp
|
||||
rtsp 554/udp
|
||||
ipp 631/tcp
|
||||
ipp 631/udp
|
||||
syslog 514/udp
|
||||
printer 515/tcp spooler
|
||||
dhcpv6-client 546/tcp
|
||||
dhcpv6-client 546/udp
|
||||
dhcpv6-server 547/tcp
|
||||
dhcpv6-server 547/udp
|
||||
afpovertcp 548/tcp
|
||||
afpovertcp 548/udp
|
||||
nntps 563/tcp snntp
|
||||
nntps 563/udp snntp
|
||||
submission 587/tcp
|
||||
submission 587/udp
|
||||
ldaps 636/tcp
|
||||
ldaps 636/udp
|
||||
tinc 655/tcp
|
||||
tinc 655/udp
|
||||
rsync 873/tcp
|
||||
rsync 873/udp
|
||||
ftps-data 989/tcp
|
||||
ftps 990/tcp
|
||||
imaps 993/tcp
|
||||
imaps 993/udp
|
||||
ircs 994/tcp
|
||||
ircs 994/udp
|
||||
pop3s 995/tcp
|
||||
pop3s 995/udp
|
||||
socks 1080/tcp
|
||||
socks 1080/udp
|
||||
openvpn 1194/tcp
|
||||
openvpn 1194/udp
|
||||
l2f 1701/tcp l2tp
|
||||
l2f 1701/udp l2tp
|
||||
radius 1812/tcp
|
||||
radius 1812/udp
|
||||
radius-acct 1813/tcp radacct
|
||||
radius-acct 1813/udp radacct
|
||||
nfs 2049/tcp
|
||||
nfs 2049/udp
|
||||
dict 2628/tcp
|
||||
dict 2628/udp
|
||||
gpsd 2947/tcp
|
||||
gpsd 2947/udp
|
||||
icpv2 3130/tcp icp
|
||||
icpv2 3130/udp icp
|
||||
mysql 3306/tcp
|
||||
mysql 3306/udp
|
||||
nut 3493/tcp
|
||||
nut 3493/udp
|
||||
distcc 3632/tcp
|
||||
distcc 3632/udp
|
||||
daap 3689/tcp
|
||||
daap 3689/udp
|
||||
svn 3690/tcp subversion
|
||||
svn 3690/udp subversion
|
||||
epmd 4369/tcp
|
||||
epmd 4369/udp
|
||||
iax 4569/tcp
|
||||
iax 4569/udp
|
||||
mtn 4691/tcp
|
||||
mtn 4691/udp
|
||||
munin 4949/tcp
|
||||
sip 5060/tcp
|
||||
sip 5060/udp
|
||||
sip-tls 5061/tcp
|
||||
sip-tls 5061/udp
|
||||
xmpp-client 5222/tcp jabber-client
|
||||
xmpp-client 5222/udp jabber-client
|
||||
xmpp-server 5269/tcp jabber-server
|
||||
xmpp-server 5269/udp jabber-server
|
||||
mdns 5353/tcp
|
||||
mdns 5353/udp
|
||||
postgresql 5432/tcp postgres
|
||||
postgresql 5432/udp postgres
|
||||
x11 6000/tcp
|
||||
x11 6000/udp
|
||||
mysql-proxy 6446/tcp
|
||||
mysql-proxy 6446/udp
|
||||
bacula-dir 9101/tcp
|
||||
bacula-dir 9101/udp
|
||||
bacula-fd 9102/tcp
|
||||
bacula-fd 9102/udp
|
||||
bacula-sd 9103/tcp
|
||||
bacula-sd 9103/udp
|
||||
nbd 10809/tcp
|
||||
zabbix-agent 10050/tcp
|
||||
zabbix-agent 10050/udp
|
||||
zabbix-trapper 10051/tcp
|
||||
zabbix-trapper 10051/udp
|
||||
hkp 11371/tcp
|
||||
hkp 11371/udp
|
||||
ssmtp 465/tcp smtps
|
||||
spamd 783/tcp
|
||||
zebrasrv 2600/tcp
|
||||
zebra 2601/tcp
|
||||
ripd 2602/tcp
|
||||
ripngd 2603/tcp
|
||||
ospfd 2604/tcp
|
||||
bgpd 2605/tcp
|
||||
ospf6d 2606/tcp
|
||||
ospfapi 2607/tcp
|
||||
isisd 2608/tcp
|
||||
sane-port 6566/tcp sane saned
|
||||
ircd 6667/tcp
|
||||
git 9418/tcp
|
||||
|
||||
5
package/base-files/files/etc/shadow
Normal file
5
package/base-files/files/etc/shadow
Normal file
@@ -0,0 +1,5 @@
|
||||
root::0:0:99999:7:::
|
||||
daemon:*:0:0:99999:7:::
|
||||
ftp:*:0:0:99999:7:::
|
||||
network:*:0:0:99999:7:::
|
||||
nobody:*:0:0:99999:7:::
|
||||
1
package/base-files/files/etc/shells
Normal file
1
package/base-files/files/etc/shells
Normal file
@@ -0,0 +1 @@
|
||||
/bin/ash
|
||||
1
package/base-files/files/etc/sysctl.conf
Normal file
1
package/base-files/files/etc/sysctl.conf
Normal file
@@ -0,0 +1 @@
|
||||
# Defaults are configured in /etc/sysctl.d/* and can be customized in this file
|
||||
25
package/base-files/files/etc/sysctl.d/10-default.conf
Normal file
25
package/base-files/files/etc/sysctl.d/10-default.conf
Normal file
@@ -0,0 +1,25 @@
|
||||
# Do not edit, changes to this file will be lost on upgrades
|
||||
# /etc/sysctl.conf can be used to customize sysctl settings
|
||||
|
||||
kernel.panic=3
|
||||
kernel.core_pattern=/tmp/%e.%t.%p.%s.core
|
||||
fs.suid_dumpable=2
|
||||
|
||||
fs.protected_hardlinks=1
|
||||
fs.protected_symlinks=1
|
||||
|
||||
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.igmp_max_memberships=100
|
||||
net.ipv4.tcp_fin_timeout=30
|
||||
net.ipv4.tcp_keepalive_time=120
|
||||
net.ipv4.tcp_syncookies=1
|
||||
net.ipv4.tcp_timestamps=1
|
||||
net.ipv4.tcp_sack=1
|
||||
net.ipv4.tcp_dsack=1
|
||||
|
||||
net.ipv6.conf.default.forwarding=1
|
||||
net.ipv6.conf.all.forwarding=1
|
||||
5
package/base-files/files/etc/sysupgrade.conf
Normal file
5
package/base-files/files/etc/sysupgrade.conf
Normal file
@@ -0,0 +1,5 @@
|
||||
## This file contains files and directories that should
|
||||
## be preserved during an upgrade.
|
||||
|
||||
# /etc/example.conf
|
||||
# /etc/openvpn/
|
||||
12
package/base-files/files/etc/uci-defaults/10_migrate-shadow
Normal file
12
package/base-files/files/etc/uci-defaults/10_migrate-shadow
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
ppwd="$(sed -ne '/^root:/s/^root:\([^:]*\):.*$/\1/p' /etc/passwd)"
|
||||
spwd="$(sed -ne '/^root:/s/^root:\([^:]*\):.*$/\1/p' /etc/shadow)"
|
||||
|
||||
if [ -n "${ppwd#[\!x]}" ] && [ -z "${spwd#[\!x]}" ]; then
|
||||
logger -t migrate-shadow "Moving root password hash into shadow database"
|
||||
sed -i -e "s:^root\:[^\:]*\::root\:x\::" /etc/passwd
|
||||
sed -i -e "s:^root\:[^\:]*\::root\:$ppwd\::" /etc/shadow
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ "$(uci -q get network.globals.ula_prefix)" != "auto" ] && exit 0
|
||||
|
||||
r1=$(dd if=/dev/urandom bs=1 count=1 |hexdump -e '1/1 "%02x"')
|
||||
r2=$(dd if=/dev/urandom bs=2 count=1 |hexdump -e '2/1 "%02x"')
|
||||
r3=$(dd if=/dev/urandom bs=2 count=1 |hexdump -e '2/1 "%02x"')
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set network.globals.ula_prefix=fd$r1:$r2:$r3::/48
|
||||
commit network
|
||||
EOF
|
||||
|
||||
exit 0
|
||||
|
||||
11
package/base-files/files/etc/uci-defaults/13_fix_group_user
Normal file
11
package/base-files/files/etc/uci-defaults/13_fix_group_user
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
|
||||
for file in `grep -sl Require-User /usr/lib/opkg/info/*.control`; do
|
||||
file="${file##*/}"
|
||||
file="${file%.control}"
|
||||
add_group_and_user "${file}"
|
||||
done
|
||||
|
||||
exit 0
|
||||
354
package/base-files/files/lib/functions.sh
Executable file
354
package/base-files/files/lib/functions.sh
Executable file
@@ -0,0 +1,354 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006-2014 OpenWrt.org
|
||||
# Copyright (C) 2006 Fokus Fraunhofer <carsten.tittel@fokus.fraunhofer.de>
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
|
||||
debug () {
|
||||
${DEBUG:-:} "$@"
|
||||
}
|
||||
|
||||
# newline
|
||||
N="
|
||||
"
|
||||
|
||||
_C=0
|
||||
NO_EXPORT=1
|
||||
LOAD_STATE=1
|
||||
LIST_SEP=" "
|
||||
|
||||
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" ]
|
||||
}
|
||||
|
||||
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"
|
||||
export ${NO_EXPORT:+-n} CONFIG_SECTION="$name"
|
||||
config_set "$CONFIG_SECTION" "TYPE" "${cfgtype}"
|
||||
[ -n "$NO_CALLBACK" ] || config_cb "$cfgtype" "$name"
|
||||
}
|
||||
|
||||
option () {
|
||||
local varname="$1"; shift
|
||||
local value="$*"
|
||||
|
||||
config_set "$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"
|
||||
[ -n "$NO_CALLBACK" ] || list_cb "$varname" "$*"
|
||||
}
|
||||
|
||||
config_unset() {
|
||||
config_set "$1" "$2" ""
|
||||
}
|
||||
|
||||
# config_get <variable> <section> <option> [<default>]
|
||||
# config_get <section> <option>
|
||||
config_get() {
|
||||
case "$3" in
|
||||
"") eval echo "\"\${CONFIG_${1}_${2}:-\${4}}\"";;
|
||||
*) eval export ${NO_EXPORT:+-n} -- "${1}=\${CONFIG_${2}_${3}:-\${4}}";;
|
||||
esac
|
||||
}
|
||||
|
||||
# config_get_bool <variable> <section> <option> [<default>]
|
||||
config_get_bool() {
|
||||
local _tmp
|
||||
config_get _tmp "$2" "$3" "$4"
|
||||
case "$_tmp" in
|
||||
1|on|true|yes|enabled) _tmp=1;;
|
||||
0|off|false|no|disabled) _tmp=0;;
|
||||
*) _tmp="$4";;
|
||||
esac
|
||||
export ${NO_EXPORT:+-n} "$1=$_tmp"
|
||||
}
|
||||
|
||||
config_set() {
|
||||
local section="$1"
|
||||
local option="$2"
|
||||
local value="$3"
|
||||
|
||||
export ${NO_EXPORT:+-n} "CONFIG_${section}_${option}=${value}"
|
||||
}
|
||||
|
||||
config_foreach() {
|
||||
local ___function="$1"
|
||||
[ "$#" -ge 1 ] && shift
|
||||
local ___type="$1"
|
||||
[ "$#" -ge 1 ] && shift
|
||||
local section cfgtype
|
||||
|
||||
[ -z "$CONFIG_SECTIONS" ] && return 0
|
||||
for section in ${CONFIG_SECTIONS}; do
|
||||
config_get cfgtype "$section" TYPE
|
||||
[ -n "$___type" -a "x$cfgtype" != "x$___type" ] && continue
|
||||
eval "$___function \"\$section\" \"\$@\""
|
||||
done
|
||||
}
|
||||
|
||||
config_list_foreach() {
|
||||
[ "$#" -ge 3 ] || return 0
|
||||
local section="$1"; shift
|
||||
local option="$1"; shift
|
||||
local function="$1"; shift
|
||||
local val
|
||||
local len
|
||||
local c=1
|
||||
|
||||
config_get len "${section}" "${option}_LENGTH"
|
||||
[ -z "$len" ] && return 0
|
||||
while [ $c -le "$len" ]; do
|
||||
config_get val "${section}" "${option}_ITEM$c"
|
||||
eval "$function \"\$val\" \"\$@\""
|
||||
c="$(($c + 1))"
|
||||
done
|
||||
}
|
||||
|
||||
default_prerm() {
|
||||
local root="${IPKG_INSTROOT}"
|
||||
local pkgname="$(basename ${1%.*})"
|
||||
local ret=0
|
||||
|
||||
if [ -f "$root/usr/lib/opkg/info/${pkgname}.prerm-pkg" ]; then
|
||||
( . "$root/usr/lib/opkg/info/${pkgname}.prerm-pkg" )
|
||||
ret=$?
|
||||
fi
|
||||
|
||||
local shell="$(which bash)"
|
||||
for i in $(grep -s "^/etc/init.d/" "$root/usr/lib/opkg/info/${pkgname}.list"); do
|
||||
if [ -n "$root" ]; then
|
||||
${shell:-/bin/sh} "$root/etc/rc.common" "$root$i" disable
|
||||
else
|
||||
if [ "$PKG_UPGRADE" != "1" ]; then
|
||||
"$i" disable
|
||||
fi
|
||||
"$i" stop
|
||||
fi
|
||||
done
|
||||
|
||||
return $ret
|
||||
}
|
||||
|
||||
add_group_and_user() {
|
||||
local pkgname="$1"
|
||||
local rusers="$(sed -ne 's/^Require-User: *//p' $root/usr/lib/opkg/info/${pkgname}.control 2>/dev/null)"
|
||||
|
||||
if [ -n "$rusers" ]; then
|
||||
local tuple oIFS="$IFS"
|
||||
for tuple in $rusers; do
|
||||
local uid gid uname gname
|
||||
|
||||
IFS=":"
|
||||
set -- $tuple; uname="$1"; gname="$2"
|
||||
IFS="="
|
||||
set -- $uname; uname="$1"; uid="$2"
|
||||
set -- $gname; gname="$1"; gid="$2"
|
||||
IFS="$oIFS"
|
||||
|
||||
if [ -n "$gname" ] && [ -n "$gid" ]; then
|
||||
group_exists "$gname" || group_add "$gname" "$gid"
|
||||
elif [ -n "$gname" ]; then
|
||||
gid="$(group_add_next "$gname")"
|
||||
fi
|
||||
|
||||
if [ -n "$uname" ]; then
|
||||
user_exists "$uname" || user_add "$uname" "$uid" "$gid"
|
||||
fi
|
||||
|
||||
if [ -n "$uname" ] && [ -n "$gname" ]; then
|
||||
group_add_user "$gname" "$uname"
|
||||
fi
|
||||
|
||||
unset uid gid uname gname
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
default_postinst() {
|
||||
local root="${IPKG_INSTROOT}"
|
||||
local pkgname="$(basename ${1%.*})"
|
||||
local ret=0
|
||||
|
||||
add_group_and_user "${pkgname}"
|
||||
|
||||
if [ -f "$root/usr/lib/opkg/info/${pkgname}.postinst-pkg" ]; then
|
||||
( . "$root/usr/lib/opkg/info/${pkgname}.postinst-pkg" )
|
||||
ret=$?
|
||||
fi
|
||||
|
||||
if [ -d "$root/rootfs-overlay" ]; then
|
||||
cp -R $root/rootfs-overlay/. $root/
|
||||
rm -fR $root/rootfs-overlay/
|
||||
fi
|
||||
|
||||
if [ -z "$root" ] && grep -q -s "^/etc/modules.d/" "/usr/lib/opkg/info/${pkgname}.list"; then
|
||||
kmodloader
|
||||
fi
|
||||
|
||||
if [ -z "$root" ] && grep -q -s "^/etc/uci-defaults/" "/usr/lib/opkg/info/${pkgname}.list"; then
|
||||
. /lib/functions/system.sh
|
||||
[ -d /tmp/.uci ] || mkdir -p /tmp/.uci
|
||||
for i in $(grep -s "^/etc/uci-defaults/" "/usr/lib/opkg/info/${pkgname}.list"); do
|
||||
( [ -f "$i" ] && cd "$(dirname $i)" && . "$i" ) && rm -f "$i"
|
||||
done
|
||||
uci commit
|
||||
fi
|
||||
|
||||
[ -n "$root" ] || rm -f /tmp/luci-indexcache 2>/dev/null
|
||||
|
||||
local shell="$(which bash)"
|
||||
for i in $(grep -s "^/etc/init.d/" "$root/usr/lib/opkg/info/${pkgname}.list"); do
|
||||
if [ -n "$root" ]; then
|
||||
${shell:-/bin/sh} "$root/etc/rc.common" "$root$i" enable
|
||||
else
|
||||
if [ "$PKG_UPGRADE" != "1" ]; then
|
||||
"$i" enable
|
||||
fi
|
||||
"$i" start
|
||||
fi
|
||||
done
|
||||
|
||||
return $ret
|
||||
}
|
||||
|
||||
include() {
|
||||
local file
|
||||
|
||||
for file in $(ls $1/*.sh 2>/dev/null); do
|
||||
. $file
|
||||
done
|
||||
}
|
||||
|
||||
find_mtd_index() {
|
||||
local PART="$(grep "\"$1\"" /proc/mtd | awk -F: '{print $1}')"
|
||||
local INDEX="${PART##mtd}"
|
||||
|
||||
echo ${INDEX}
|
||||
}
|
||||
|
||||
find_mtd_part() {
|
||||
local INDEX=$(find_mtd_index "$1")
|
||||
local PREFIX=/dev/mtdblock
|
||||
|
||||
[ -d /dev/mtdblock ] && PREFIX=/dev/mtdblock/
|
||||
echo "${INDEX:+$PREFIX$INDEX}"
|
||||
}
|
||||
|
||||
group_add() {
|
||||
local name="$1"
|
||||
local gid="$2"
|
||||
local rc
|
||||
[ -f "${IPKG_INSTROOT}/etc/group" ] || return 1
|
||||
[ -n "$IPKG_INSTROOT" ] || lock /var/lock/group
|
||||
echo "${name}:x:${gid}:" >> ${IPKG_INSTROOT}/etc/group
|
||||
[ -n "$IPKG_INSTROOT" ] || lock -u /var/lock/group
|
||||
}
|
||||
|
||||
group_exists() {
|
||||
grep -qs "^${1}:" ${IPKG_INSTROOT}/etc/group
|
||||
}
|
||||
|
||||
group_add_next() {
|
||||
local gid gids
|
||||
gid=$(grep -s "^${1}:" ${IPKG_INSTROOT}/etc/group | cut -d: -f3)
|
||||
if [ -n "$gid" ]; then
|
||||
echo $gid
|
||||
return
|
||||
fi
|
||||
gids=$(cat ${IPKG_INSTROOT}/etc/group | cut -d: -f3)
|
||||
gid=65536
|
||||
while [ -n "$(echo "$gids" | grep "^$gid$")" ] ; do
|
||||
gid=$((gid + 1))
|
||||
done
|
||||
group_add $1 $gid
|
||||
echo $gid
|
||||
}
|
||||
|
||||
group_add_user() {
|
||||
local grp delim=","
|
||||
grp=$(grep -s "^${1}:" ${IPKG_INSTROOT}/etc/group)
|
||||
[ -z "$(echo $grp | cut -d: -f4 | grep $2)" ] || return
|
||||
[ -n "$(echo $grp | grep ":$")" ] && delim=""
|
||||
[ -n "$IPKG_INSTROOT" ] || lock /var/lock/passwd
|
||||
sed -i "s/$grp/$grp$delim$2/g" ${IPKG_INSTROOT}/etc/group
|
||||
[ -n "$IPKG_INSTROOT" ] || lock -u /var/lock/passwd
|
||||
}
|
||||
|
||||
user_add() {
|
||||
local name="${1}"
|
||||
local uid="${2}"
|
||||
local gid="${3}"
|
||||
local desc="${4:-$1}"
|
||||
local home="${5:-/var/run/$1}"
|
||||
local shell="${6:-/bin/false}"
|
||||
local rc
|
||||
[ -z "$uid" ] && {
|
||||
uids=$(cat ${IPKG_INSTROOT}/etc/passwd | cut -d: -f3)
|
||||
uid=65536
|
||||
while [ -n "$(echo "$uids" | grep "^$uid$")" ] ; do
|
||||
uid=$((uid + 1))
|
||||
done
|
||||
}
|
||||
[ -z "$gid" ] && gid=$uid
|
||||
[ -f "${IPKG_INSTROOT}/etc/passwd" ] || return 1
|
||||
[ -n "$IPKG_INSTROOT" ] || lock /var/lock/passwd
|
||||
echo "${name}:x:${uid}:${gid}:${desc}:${home}:${shell}" >> ${IPKG_INSTROOT}/etc/passwd
|
||||
echo "${name}:x:0:0:99999:7:::" >> ${IPKG_INSTROOT}/etc/shadow
|
||||
[ -n "$IPKG_INSTROOT" ] || lock -u /var/lock/passwd
|
||||
}
|
||||
|
||||
user_exists() {
|
||||
grep -qs "^${1}:" ${IPKG_INSTROOT}/etc/passwd
|
||||
}
|
||||
|
||||
board_name() {
|
||||
[ -e /tmp/sysinfo/board_name ] && cat /tmp/sysinfo/board_name || echo "generic"
|
||||
}
|
||||
|
||||
[ -z "$IPKG_INSTROOT" -a -f /lib/config/uci.sh ] && . /lib/config/uci.sh
|
||||
75
package/base-files/files/lib/functions/leds.sh
Normal file
75
package/base-files/files/lib/functions/leds.sh
Normal file
@@ -0,0 +1,75 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2013 OpenWrt.org
|
||||
|
||||
get_dt_led() {
|
||||
local label
|
||||
local ledpath
|
||||
local basepath="/proc/device-tree"
|
||||
local nodepath="$basepath/aliases/led-$1"
|
||||
|
||||
[ -f "$nodepath" ] && ledpath=$(cat "$nodepath")
|
||||
[ -n "$ledpath" ] && \
|
||||
label=$(cat "$basepath$ledpath/label" 2>/dev/null) || \
|
||||
label=$(cat "$basepath$ledpath/chan-name" 2>/dev/null)
|
||||
|
||||
echo "$label"
|
||||
}
|
||||
|
||||
led_set_attr() {
|
||||
[ -f "/sys/class/leds/$1/$2" ] && echo "$3" > "/sys/class/leds/$1/$2"
|
||||
}
|
||||
|
||||
led_timer() {
|
||||
led_set_attr $1 "trigger" "timer"
|
||||
led_set_attr $1 "delay_on" "$2"
|
||||
led_set_attr $1 "delay_off" "$3"
|
||||
}
|
||||
|
||||
led_on() {
|
||||
led_set_attr $1 "trigger" "none"
|
||||
led_set_attr $1 "brightness" 255
|
||||
}
|
||||
|
||||
led_off() {
|
||||
led_set_attr $1 "trigger" "none"
|
||||
led_set_attr $1 "brightness" 0
|
||||
}
|
||||
|
||||
status_led_set_timer() {
|
||||
led_timer $status_led "$1" "$2"
|
||||
[ -n "$status_led2" ] && led_timer $status_led2 "$1" "$2"
|
||||
}
|
||||
|
||||
status_led_set_heartbeat() {
|
||||
led_set_attr $status_led "trigger" "heartbeat"
|
||||
}
|
||||
|
||||
status_led_on() {
|
||||
led_on $status_led
|
||||
[ -n "$status_led2" ] && led_on $status_led2
|
||||
}
|
||||
|
||||
status_led_off() {
|
||||
led_off $status_led
|
||||
[ -n "$status_led2" ] && led_off $status_led2
|
||||
}
|
||||
|
||||
status_led_blink_slow() {
|
||||
led_timer $status_led 1000 1000
|
||||
}
|
||||
|
||||
status_led_blink_fast() {
|
||||
led_timer $status_led 100 100
|
||||
}
|
||||
|
||||
status_led_blink_preinit() {
|
||||
led_timer $status_led 100 100
|
||||
}
|
||||
|
||||
status_led_blink_failsafe() {
|
||||
led_timer $status_led 50 50
|
||||
}
|
||||
|
||||
status_led_blink_preinit_regular() {
|
||||
led_timer $status_led 200 200
|
||||
}
|
||||
306
package/base-files/files/lib/functions/network.sh
Normal file
306
package/base-files/files/lib/functions/network.sh
Normal file
@@ -0,0 +1,306 @@
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
# 3: path
|
||||
# 4: separator
|
||||
# 5: limit
|
||||
__network_ifstatus() {
|
||||
local __tmp
|
||||
|
||||
[ -z "$__NETWORK_CACHE" ] && {
|
||||
__tmp="$(ubus call network.interface dump 2>&1)"
|
||||
case "$?" in
|
||||
4) : ;;
|
||||
0) export __NETWORK_CACHE="$__tmp" ;;
|
||||
*) echo "$__tmp" >&2 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
__tmp="$(jsonfilter ${4:+-F "$4"} ${5:+-l "$5"} -s "${__NETWORK_CACHE:-{}}" -e "$1=@.interface${2:+[@.interface='$2']}$3")"
|
||||
|
||||
[ -z "$__tmp" ] && \
|
||||
unset "$1" && \
|
||||
return 1
|
||||
|
||||
eval "$__tmp"
|
||||
}
|
||||
|
||||
# determine first IPv4 address of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_ipaddr() {
|
||||
__network_ifstatus "$1" "$2" "['ipv4-address'][0].address";
|
||||
}
|
||||
|
||||
# determine first IPv6 address of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_ipaddr6() {
|
||||
__network_ifstatus "$1" "$2" "['ipv6-address'][0].address" || \
|
||||
__network_ifstatus "$1" "$2" "['ipv6-prefix-assignment'][0]['local-address'].address" || \
|
||||
return 1
|
||||
}
|
||||
|
||||
# determine first IPv4 subnet of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_subnet() {
|
||||
__network_ifstatus "$1" "$2" "['ipv4-address'][0]['address','mask']" "/"
|
||||
}
|
||||
|
||||
# determine first IPv6 subnet of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_subnet6() {
|
||||
local __nets __addr
|
||||
|
||||
if network_get_subnets6 __nets "$2"; then
|
||||
# Attempt to return first non-fe80::/10, non-fc::/7 range
|
||||
for __addr in $__nets; do
|
||||
case "$__addr" in fe[8ab]?:*|f[cd]??:*)
|
||||
continue
|
||||
esac
|
||||
export "$1=$__addr"
|
||||
return 0
|
||||
done
|
||||
|
||||
# Attempt to return first non-fe80::/10 range
|
||||
for __addr in $__nets; do
|
||||
case "$__addr" in fe[8ab]?:*)
|
||||
continue
|
||||
esac
|
||||
export "$1=$__addr"
|
||||
return 0
|
||||
done
|
||||
|
||||
# Return first item
|
||||
for __addr in $__nets; do
|
||||
export "$1=$__addr"
|
||||
return 0
|
||||
done
|
||||
fi
|
||||
|
||||
unset "$1"
|
||||
return 1
|
||||
}
|
||||
|
||||
# determine first IPv6 prefix of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_prefix6() {
|
||||
__network_ifstatus "$1" "$2" "['ipv6-prefix'][0]['address','mask']" "/"
|
||||
}
|
||||
|
||||
# determine all IPv4 addresses of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_ipaddrs() {
|
||||
__network_ifstatus "$1" "$2" "['ipv4-address'][*].address"
|
||||
}
|
||||
|
||||
# determine all IPv6 addresses of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_ipaddrs6() {
|
||||
local __addr
|
||||
local __list=""
|
||||
|
||||
if __network_ifstatus "__addr" "$2" "['ipv6-address'][*].address"; then
|
||||
for __addr in $__addr; do
|
||||
__list="${__list:+$__list }${__addr}"
|
||||
done
|
||||
fi
|
||||
|
||||
if __network_ifstatus "__addr" "$2" "['ipv6-prefix-assignment'][*]['local-address'].address"; then
|
||||
for __addr in $__addr; do
|
||||
__list="${__list:+$__list }${__addr}"
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -n "$__list" ]; then
|
||||
export "$1=$__list"
|
||||
return 0
|
||||
fi
|
||||
|
||||
unset "$1"
|
||||
return 1
|
||||
}
|
||||
|
||||
# determine all IP addresses of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_ipaddrs_all() {
|
||||
local __addr __addr6
|
||||
|
||||
network_get_ipaddrs __addr "$2"
|
||||
network_get_ipaddrs6 __addr6 "$2"
|
||||
|
||||
if [ -n "$__addr" -o -n "$__addr6" ]; then
|
||||
export "$1=${__addr:+$__addr }$__addr6"
|
||||
return 0
|
||||
fi
|
||||
|
||||
unset "$1"
|
||||
return 1
|
||||
}
|
||||
|
||||
# determine all IPv4 subnets of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_subnets() {
|
||||
__network_ifstatus "$1" "$2" "['ipv4-address'][*]['address','mask']" "/ "
|
||||
}
|
||||
|
||||
# determine all IPv6 subnets of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_subnets6() {
|
||||
local __addr __mask
|
||||
local __list=""
|
||||
|
||||
if __network_ifstatus "__addr" "$2" "['ipv6-address'][*]['address','mask']" "/ "; then
|
||||
for __addr in $__addr; do
|
||||
__list="${__list:+$__list }${__addr}"
|
||||
done
|
||||
fi
|
||||
|
||||
if __network_ifstatus "__addr" "$2" "['ipv6-prefix-assignment'][*]['local-address'].address" && \
|
||||
__network_ifstatus "__mask" "$2" "['ipv6-prefix-assignment'][*].mask"; then
|
||||
for __addr in $__addr; do
|
||||
__list="${__list:+$__list }${__addr}/${__mask%% *}"
|
||||
__mask="${__mask#* }"
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -n "$__list" ]; then
|
||||
export "$1=$__list"
|
||||
return 0
|
||||
fi
|
||||
|
||||
unset "$1"
|
||||
return 1
|
||||
}
|
||||
|
||||
# determine all IPv6 prefixes of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_prefixes6() {
|
||||
__network_ifstatus "$1" "$2" "['ipv6-prefix'][*]['address','mask']" "/ "
|
||||
}
|
||||
|
||||
# determine IPv4 gateway of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
# 3: consider inactive gateway if "true" (optional)
|
||||
network_get_gateway() {
|
||||
__network_ifstatus "$1" "$2" ".route[@.target='0.0.0.0' && !@.table].nexthop" "" 1 && \
|
||||
return 0
|
||||
|
||||
[ "$3" = 1 -o "$3" = "true" ] && \
|
||||
__network_ifstatus "$1" "$2" ".inactive.route[@.target='0.0.0.0' && !@.table].nexthop" "" 1
|
||||
}
|
||||
|
||||
# determine IPv6 gateway of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
# 3: consider inactive gateway if "true" (optional)
|
||||
network_get_gateway6() {
|
||||
__network_ifstatus "$1" "$2" ".route[@.target='::' && !@.table].nexthop" "" 1 && \
|
||||
return 0
|
||||
|
||||
[ "$3" = 1 -o "$3" = "true" ] && \
|
||||
__network_ifstatus "$1" "$2" ".inactive.route[@.target='::' && !@.table].nexthop" "" 1
|
||||
}
|
||||
|
||||
# determine the DNS servers of the given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
# 3: consider inactive servers if "true" (optional)
|
||||
network_get_dnsserver() {
|
||||
__network_ifstatus "$1" "$2" "['dns-server'][*]" && return 0
|
||||
|
||||
[ "$3" = 1 -o "$3" = "true" ] && \
|
||||
__network_ifstatus "$1" "$2" ".inactive['dns-server'][*]"
|
||||
}
|
||||
|
||||
# determine the domains of the given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
# 3: consider inactive domains if "true" (optional)
|
||||
network_get_dnssearch() {
|
||||
__network_ifstatus "$1" "$2" "['dns-search'][*]" && return 0
|
||||
|
||||
[ "$3" = 1 -o "$3" = "true" ] && \
|
||||
__network_ifstatus "$1" "$2" ".inactive['dns-search'][*]"
|
||||
}
|
||||
|
||||
|
||||
# 1: destination variable
|
||||
# 2: addr
|
||||
# 3: inactive
|
||||
__network_wan()
|
||||
{
|
||||
__network_ifstatus "$1" "" \
|
||||
"[@.route[@.target='$2' && !@.table]].interface" "" 1 && \
|
||||
return 0
|
||||
|
||||
[ "$3" = 1 -o "$3" = "true" ] && \
|
||||
__network_ifstatus "$1" "" \
|
||||
"[@.inactive.route[@.target='$2' && !@.table]].interface" "" 1
|
||||
}
|
||||
|
||||
# find the logical interface which holds the current IPv4 default route
|
||||
# 1: destination variable
|
||||
# 2: consider inactive default routes if "true" (optional)
|
||||
network_find_wan() { __network_wan "$1" "0.0.0.0" "$2"; }
|
||||
|
||||
# find the logical interface which holds the current IPv6 default route
|
||||
# 1: destination variable
|
||||
# 2: consider inactive dafault routes if "true" (optional)
|
||||
network_find_wan6() { __network_wan "$1" "::" "$2"; }
|
||||
|
||||
# test whether the given logical interface is running
|
||||
# 1: interface
|
||||
network_is_up()
|
||||
{
|
||||
local __up
|
||||
__network_ifstatus "__up" "$1" ".up" && [ "$__up" = 1 ]
|
||||
}
|
||||
|
||||
# determine the protocol of the given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_protocol() { __network_ifstatus "$1" "$2" ".proto"; }
|
||||
|
||||
# determine the metric of the given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_metric() { __network_ifstatus "$1" "$2" ".metric"; }
|
||||
|
||||
# determine the layer 3 linux network device of the given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_device() { __network_ifstatus "$1" "$2" ".l3_device"; }
|
||||
|
||||
# determine the layer 2 linux network device of the given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_physdev() { __network_ifstatus "$1" "$2" ".device"; }
|
||||
|
||||
# defer netifd actions on the given linux network device
|
||||
# 1: device name
|
||||
network_defer_device()
|
||||
{
|
||||
ubus call network.device set_state \
|
||||
"$(printf '{ "name": "%s", "defer": true }' "$1")" 2>/dev/null
|
||||
}
|
||||
|
||||
# continue netifd actions on the given linux network device
|
||||
# 1: device name
|
||||
network_ready_device()
|
||||
{
|
||||
ubus call network.device set_state \
|
||||
"$(printf '{ "name": "%s", "defer": false }' "$1")" 2>/dev/null
|
||||
}
|
||||
|
||||
# flush the internal value cache to force re-reading values from ubus
|
||||
network_flush_cache() { unset __NETWORK_CACHE; }
|
||||
88
package/base-files/files/lib/functions/preinit.sh
Normal file
88
package/base-files/files/lib/functions/preinit.sh
Normal file
@@ -0,0 +1,88 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006-2013 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
boot_hook_splice_start() {
|
||||
export -n PI_HOOK_SPLICE=1
|
||||
}
|
||||
|
||||
boot_hook_splice_finish() {
|
||||
local hook
|
||||
for hook in $PI_STACK_LIST; do
|
||||
local v; eval "v=\${${hook}_splice:+\$${hook}_splice }$hook"
|
||||
export -n "${hook}=${v% }"
|
||||
export -n "${hook}_splice="
|
||||
done
|
||||
export -n PI_HOOK_SPLICE=
|
||||
}
|
||||
|
||||
boot_hook_init() {
|
||||
local hook="${1}_hook"
|
||||
export -n "PI_STACK_LIST=${PI_STACK_LIST:+$PI_STACK_LIST }$hook"
|
||||
export -n "$hook="
|
||||
}
|
||||
|
||||
boot_hook_add() {
|
||||
local hook="${1}_hook${PI_HOOK_SPLICE:+_splice}"
|
||||
local func="${2}"
|
||||
|
||||
[ -n "$func" ] && {
|
||||
local v; eval "v=\$$hook"
|
||||
export -n "$hook=${v:+$v }$func"
|
||||
}
|
||||
}
|
||||
|
||||
boot_hook_shift() {
|
||||
local hook="${1}_hook"
|
||||
local rvar="${2}"
|
||||
|
||||
local v; eval "v=\$$hook"
|
||||
[ -n "$v" ] && {
|
||||
local first="${v%% *}"
|
||||
|
||||
[ "$v" != "${v#* }" ] && \
|
||||
export -n "$hook=${v#* }" || \
|
||||
export -n "$hook="
|
||||
|
||||
export -n "$rvar=$first"
|
||||
return 0
|
||||
}
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
boot_run_hook() {
|
||||
local hook="$1"
|
||||
local func
|
||||
|
||||
while boot_hook_shift "$hook" func; do
|
||||
local ran; eval "ran=\$PI_RAN_$func"
|
||||
[ -n "$ran" ] || {
|
||||
export -n "PI_RAN_$func=1"
|
||||
$func "$1" "$2"
|
||||
}
|
||||
done
|
||||
}
|
||||
|
||||
pivot() { # <new_root> <old_root>
|
||||
/bin/mount -o noatime,move /proc $1/proc && \
|
||||
pivot_root $1 $1$2 && {
|
||||
/bin/mount -o noatime,move $2/dev /dev
|
||||
/bin/mount -o noatime,move $2/tmp /tmp
|
||||
/bin/mount -o noatime,move $2/sys /sys 2>&-
|
||||
/bin/mount -o noatime,move $2/overlay /overlay 2>&-
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
fopivot() { # <rw_root> <work_dir> <ro_root> <dupe?>
|
||||
/bin/mount -o noatime,lowerdir=/,upperdir=$1,workdir=$2 -t overlay "overlayfs:$1" /mnt
|
||||
pivot /mnt $3
|
||||
}
|
||||
|
||||
ramoverlay() {
|
||||
mkdir -p /tmp/root
|
||||
/bin/mount -t tmpfs -o noatime,mode=0755 root /tmp/root
|
||||
mkdir -p /tmp/root/root /tmp/root/work
|
||||
fopivot /tmp/root/root /tmp/root/work /rom 1
|
||||
}
|
||||
103
package/base-files/files/lib/functions/service.sh
Normal file
103
package/base-files/files/lib/functions/service.sh
Normal file
@@ -0,0 +1,103 @@
|
||||
#
|
||||
# service: simple wrapper around start-stop-daemon
|
||||
#
|
||||
# Usage: service ACTION EXEC ARGS...
|
||||
#
|
||||
# Action:
|
||||
# -C check if EXEC is alive
|
||||
# -S start EXEC, passing it ARGS as its arguments
|
||||
# -K kill EXEC, sending it a TERM signal if not specified otherwise
|
||||
#
|
||||
# Environment variables exposed:
|
||||
# SERVICE_DAEMONIZE run EXEC in background
|
||||
# SERVICE_WRITE_PID create a pid-file and use it for matching
|
||||
# SERVICE_MATCH_EXEC use EXEC command-line for matching (default)
|
||||
# SERVICE_MATCH_NAME use EXEC process name for matching
|
||||
# SERVICE_USE_PID assume EXEC create its own pid-file and use it for matching
|
||||
# SERVICE_NAME process name to use (default to EXEC file part)
|
||||
# SERVICE_PID_FILE pid file to use (default to /var/run/$SERVICE_NAME.pid)
|
||||
# SERVICE_SIG signal to send when using -K
|
||||
# SERVICE_SIG_RELOAD default signal used when reloading
|
||||
# SERVICE_SIG_STOP default signal used when stopping
|
||||
# SERVICE_STOP_TIME time to wait for a process to stop gracefully before killing it
|
||||
# SERVICE_UID user EXEC should be run as
|
||||
# SERVICE_GID group EXEC should be run as
|
||||
#
|
||||
# SERVICE_DEBUG don't do anything, but show what would be done
|
||||
# SERVICE_QUIET don't print anything
|
||||
#
|
||||
|
||||
SERVICE_QUIET=1
|
||||
SERVICE_SIG_RELOAD="HUP"
|
||||
SERVICE_SIG_STOP="TERM"
|
||||
SERVICE_STOP_TIME=5
|
||||
SERVICE_MATCH_EXEC=1
|
||||
|
||||
service() {
|
||||
local ssd
|
||||
local exec
|
||||
local name
|
||||
local start
|
||||
ssd="${SERVICE_DEBUG:+echo }start-stop-daemon${SERVICE_QUIET:+ -q}"
|
||||
case "$1" in
|
||||
-C)
|
||||
ssd="$ssd -K -t"
|
||||
;;
|
||||
-S)
|
||||
ssd="$ssd -S${SERVICE_DAEMONIZE:+ -b}${SERVICE_WRITE_PID:+ -m}"
|
||||
start=1
|
||||
;;
|
||||
-K)
|
||||
ssd="$ssd -K${SERVICE_SIG:+ -s $SERVICE_SIG}"
|
||||
;;
|
||||
*)
|
||||
echo "service: unknown ACTION '$1'" 1>&2
|
||||
return 1
|
||||
esac
|
||||
shift
|
||||
exec="$1"
|
||||
[ -n "$exec" ] || {
|
||||
echo "service: missing argument" 1>&2
|
||||
return 1
|
||||
}
|
||||
[ -x "$exec" ] || {
|
||||
echo "service: file '$exec' is not executable" 1>&2
|
||||
return 1
|
||||
}
|
||||
name="${SERVICE_NAME:-${exec##*/}}"
|
||||
[ -z "$SERVICE_USE_PID$SERVICE_WRITE_PID$SERVICE_PID_FILE" ] \
|
||||
|| ssd="$ssd -p ${SERVICE_PID_FILE:-/var/run/$name.pid}"
|
||||
[ -z "$SERVICE_MATCH_NAME" ] || ssd="$ssd -n $name"
|
||||
ssd="$ssd${SERVICE_UID:+ -c $SERVICE_UID${SERVICE_GID:+:$SERVICE_GID}}"
|
||||
[ -z "$SERVICE_MATCH_EXEC$start" ] || ssd="$ssd -x $exec"
|
||||
shift
|
||||
$ssd${1:+ -- "$@"}
|
||||
}
|
||||
|
||||
service_check() {
|
||||
service -C "$@"
|
||||
}
|
||||
|
||||
service_signal() {
|
||||
SERVICE_SIG="${SERVICE_SIG:-USR1}" service -K "$@"
|
||||
}
|
||||
|
||||
service_start() {
|
||||
service -S "$@"
|
||||
}
|
||||
|
||||
service_stop() {
|
||||
local try
|
||||
SERVICE_SIG="${SERVICE_SIG:-$SERVICE_SIG_STOP}" service -K "$@" || return 1
|
||||
while [ $((try++)) -lt $SERVICE_STOP_TIME ]; do
|
||||
service -C "$@" || return 0
|
||||
sleep 1
|
||||
done
|
||||
SERVICE_SIG="KILL" service -K "$@"
|
||||
sleep 1
|
||||
! service -C "$@"
|
||||
}
|
||||
|
||||
service_reload() {
|
||||
SERVICE_SIG="${SERVICE_SIG:-$SERVICE_SIG_RELOAD}" service -K "$@"
|
||||
}
|
||||
155
package/base-files/files/lib/functions/system.sh
Normal file
155
package/base-files/files/lib/functions/system.sh
Normal file
@@ -0,0 +1,155 @@
|
||||
# Copyright (C) 2006-2013 OpenWrt.org
|
||||
|
||||
get_mac_binary() {
|
||||
local path="$1"
|
||||
local offset="$2"
|
||||
|
||||
if ! [ -e "$path" ]; then
|
||||
echo "get_mac_binary: file $path not found!" >&2
|
||||
return
|
||||
fi
|
||||
|
||||
hexdump -v -n 6 -s $offset -e '5/1 "%02x:" 1/1 "%02x"' $path 2>/dev/null
|
||||
}
|
||||
|
||||
find_mtd_chardev() {
|
||||
local INDEX=$(find_mtd_index "$1")
|
||||
local PREFIX=/dev/mtd
|
||||
|
||||
[ -d /dev/mtd ] && PREFIX=/dev/mtd/
|
||||
echo "${INDEX:+$PREFIX$INDEX}"
|
||||
}
|
||||
|
||||
mtd_get_mac_ascii() {
|
||||
local mtdname="$1"
|
||||
local key="$2"
|
||||
local part
|
||||
local mac_dirty
|
||||
|
||||
part=$(find_mtd_part "$mtdname")
|
||||
if [ -z "$part" ]; then
|
||||
echo "mtd_get_mac_ascii: partition $mtdname not found!" >&2
|
||||
return
|
||||
fi
|
||||
|
||||
mac_dirty=$(strings "$part" | sed -n 's/^'"$key"'=//p')
|
||||
|
||||
# "canonicalize" mac
|
||||
[ -n "$mac_dirty" ] && macaddr_canonicalize "$mac_dirty"
|
||||
}
|
||||
|
||||
mtd_get_mac_text() {
|
||||
local mtdname=$1
|
||||
local offset=$2
|
||||
local part
|
||||
local mac_dirty
|
||||
|
||||
part=$(find_mtd_part "$mtdname")
|
||||
if [ -z "$part" ]; then
|
||||
echo "mtd_get_mac_text: partition $mtdname not found!" >&2
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -z "$offset" ]; then
|
||||
echo "mtd_get_mac_text: offset missing!" >&2
|
||||
return
|
||||
fi
|
||||
|
||||
mac_dirty=$(dd if="$part" bs=1 skip="$offset" count=17 2>/dev/null)
|
||||
|
||||
# "canonicalize" mac
|
||||
[ -n "$mac_dirty" ] && macaddr_canonicalize "$mac_dirty"
|
||||
}
|
||||
|
||||
mtd_get_mac_binary() {
|
||||
local mtdname="$1"
|
||||
local offset="$2"
|
||||
local part
|
||||
|
||||
part=$(find_mtd_part "$mtdname")
|
||||
get_mac_binary "$part" "$offset"
|
||||
}
|
||||
|
||||
mtd_get_mac_binary_ubi() {
|
||||
local mtdname="$1"
|
||||
local offset="$2"
|
||||
|
||||
. /lib/upgrade/nand.sh
|
||||
|
||||
local ubidev=$(nand_find_ubi $CI_UBIPART)
|
||||
local part=$(nand_find_volume $ubidev $1)
|
||||
|
||||
if [ -z "$part" ]; then
|
||||
echo "mtd_get_mac_binary: ubi volume $mtdname not found!" >&2
|
||||
return
|
||||
fi
|
||||
|
||||
hexdump -v -n 6 -s $offset -e '5/1 "%02x:" 1/1 "%02x"' /dev/$part 2>/dev/null
|
||||
}
|
||||
|
||||
mtd_get_part_size() {
|
||||
local part_name=$1
|
||||
local first dev size erasesize name
|
||||
while read dev size erasesize name; do
|
||||
name=${name#'"'}; name=${name%'"'}
|
||||
if [ "$name" = "$part_name" ]; then
|
||||
echo $((0x$size))
|
||||
break
|
||||
fi
|
||||
done < /proc/mtd
|
||||
}
|
||||
|
||||
macaddr_add() {
|
||||
local mac=$1
|
||||
local val=$2
|
||||
local oui=${mac%:*:*:*}
|
||||
local nic=${mac#*:*:*:}
|
||||
|
||||
nic=$(printf "%06x" $((0x${nic//:/} + $val & 0xffffff)) | sed 's/^\(.\{2\}\)\(.\{2\}\)\(.\{2\}\)/\1:\2:\3/')
|
||||
echo $oui:$nic
|
||||
}
|
||||
|
||||
macaddr_setbit_la() {
|
||||
local mac=$1
|
||||
|
||||
printf "%02x:%s" $((0x${mac%%:*} | 0x02)) ${mac#*:}
|
||||
}
|
||||
|
||||
macaddr_2bin() {
|
||||
local mac=$1
|
||||
|
||||
echo -ne \\x${mac//:/\\x}
|
||||
}
|
||||
|
||||
macaddr_canonicalize() {
|
||||
local mac="$1"
|
||||
local canon=""
|
||||
|
||||
mac=$(echo -n $mac | tr -d \")
|
||||
[ ${#mac} -gt 17 ] && return
|
||||
[ -n "${mac//[a-fA-F0-9\.: -]/}" ] && return
|
||||
|
||||
for octet in ${mac//[\.:-]/ }; do
|
||||
case "${#octet}" in
|
||||
1)
|
||||
octet="0${octet}"
|
||||
;;
|
||||
2)
|
||||
;;
|
||||
4)
|
||||
octet="${octet:0:2} ${octet:2:2}"
|
||||
;;
|
||||
12)
|
||||
octet="${octet:0:2} ${octet:2:2} ${octet:4:2} ${octet:6:2} ${octet:8:2} ${octet:10:2}"
|
||||
;;
|
||||
*)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
canon=${canon}${canon:+ }${octet}
|
||||
done
|
||||
|
||||
[ ${#canon} -ne 17 ] && return
|
||||
|
||||
printf "%02x:%02x:%02x:%02x:%02x:%02x" 0x${canon// / 0x} 2>/dev/null
|
||||
}
|
||||
617
package/base-files/files/lib/functions/uci-defaults.sh
Executable file
617
package/base-files/files/lib/functions/uci-defaults.sh
Executable file
@@ -0,0 +1,617 @@
|
||||
#!/bin/ash
|
||||
|
||||
. /lib/functions.sh
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
json_select_array() {
|
||||
local _json_no_warning=1
|
||||
|
||||
json_select "$1"
|
||||
[ $? = 0 ] && return
|
||||
|
||||
json_add_array "$1"
|
||||
json_close_array
|
||||
|
||||
json_select "$1"
|
||||
}
|
||||
|
||||
json_select_object() {
|
||||
local _json_no_warning=1
|
||||
|
||||
json_select "$1"
|
||||
[ $? = 0 ] && return
|
||||
|
||||
json_add_object "$1"
|
||||
json_close_object
|
||||
|
||||
json_select "$1"
|
||||
}
|
||||
|
||||
_ucidef_set_interface() {
|
||||
local name="$1"
|
||||
local iface="$2"
|
||||
local proto="$3"
|
||||
|
||||
json_select_object "$name"
|
||||
json_add_string ifname "$iface"
|
||||
|
||||
if ! json_is_a protocol string || [ -n "$proto" ]; then
|
||||
case "$proto" in
|
||||
static|dhcp|none|pppoe) : ;;
|
||||
*)
|
||||
case "$name" in
|
||||
lan) proto="static" ;;
|
||||
wan) proto="dhcp" ;;
|
||||
*) proto="none" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
json_add_string protocol "$proto"
|
||||
fi
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_board_id() {
|
||||
json_select_object model
|
||||
json_add_string id "$1"
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_model_name() {
|
||||
json_select_object model
|
||||
json_add_string name "$1"
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_interface_lan() {
|
||||
json_select_object network
|
||||
_ucidef_set_interface lan "$@"
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_interface_wan() {
|
||||
json_select_object network
|
||||
_ucidef_set_interface wan "$@"
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_interfaces_lan_wan() {
|
||||
local lan_if="$1"
|
||||
local wan_if="$2"
|
||||
|
||||
json_select_object network
|
||||
_ucidef_set_interface lan "$lan_if"
|
||||
_ucidef_set_interface wan "$wan_if"
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_interface_raw() {
|
||||
json_select_object network
|
||||
_ucidef_set_interface "$@"
|
||||
json_select ..
|
||||
}
|
||||
|
||||
_ucidef_add_switch_port() {
|
||||
# inherited: $num $device $need_tag $want_untag $role $index $prev_role
|
||||
# inherited: $n_cpu $n_ports $n_vlan $cpu0 $cpu1 $cpu2 $cpu3 $cpu4 $cpu5
|
||||
|
||||
n_ports=$((n_ports + 1))
|
||||
|
||||
json_select_array ports
|
||||
json_add_object
|
||||
json_add_int num "$num"
|
||||
[ -n "$device" ] && json_add_string device "$device"
|
||||
[ -n "$need_tag" ] && json_add_boolean need_tag "$need_tag"
|
||||
[ -n "$want_untag" ] && json_add_boolean want_untag "$want_untag"
|
||||
[ -n "$role" ] && json_add_string role "$role"
|
||||
[ -n "$index" ] && json_add_int index "$index"
|
||||
json_close_object
|
||||
json_select ..
|
||||
|
||||
# record pointer to cpu entry for lookup in _ucidef_finish_switch_roles()
|
||||
[ -n "$device" ] && {
|
||||
export "cpu$n_cpu=$n_ports"
|
||||
n_cpu=$((n_cpu + 1))
|
||||
}
|
||||
|
||||
# create/append object to role list
|
||||
[ -n "$role" ] && {
|
||||
json_select_array roles
|
||||
|
||||
if [ "$role" != "$prev_role" ]; then
|
||||
json_add_object
|
||||
json_add_string role "$role"
|
||||
json_add_string ports "$num"
|
||||
json_close_object
|
||||
|
||||
prev_role="$role"
|
||||
n_vlan=$((n_vlan + 1))
|
||||
else
|
||||
json_select_object "$n_vlan"
|
||||
json_get_var port ports
|
||||
json_add_string ports "$port $num"
|
||||
json_select ..
|
||||
fi
|
||||
|
||||
json_select ..
|
||||
}
|
||||
}
|
||||
|
||||
_ucidef_finish_switch_roles() {
|
||||
# inherited: $name $n_cpu $n_vlan $cpu0 $cpu1 $cpu2 $cpu3 $cpu4 $cpu5
|
||||
local index role roles num device need_tag want_untag port ports
|
||||
|
||||
json_select switch
|
||||
json_select "$name"
|
||||
json_get_keys roles roles
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
for index in $roles; do
|
||||
eval "port=\$cpu$(((index - 1) % n_cpu))"
|
||||
|
||||
json_select switch
|
||||
json_select "$name"
|
||||
json_select ports
|
||||
json_select "$port"
|
||||
json_get_vars num device need_tag want_untag
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
if [ ${need_tag:-0} -eq 1 -o ${want_untag:-0} -ne 1 ]; then
|
||||
num="${num}t"
|
||||
device="${device}.${index}"
|
||||
fi
|
||||
|
||||
json_select roles
|
||||
json_select "$index"
|
||||
json_get_vars role ports
|
||||
json_add_string ports "$ports $num"
|
||||
json_add_string device "$device"
|
||||
json_select ..
|
||||
json_select ..
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
json_select_object network
|
||||
local devices
|
||||
|
||||
json_select_object "$role"
|
||||
# attach previous interfaces (for multi-switch devices)
|
||||
json_get_var devices ifname
|
||||
if ! list_contains devices "$device"; then
|
||||
devices="${devices:+$devices }$device"
|
||||
fi
|
||||
json_select ..
|
||||
|
||||
_ucidef_set_interface "$role" "$devices"
|
||||
json_select ..
|
||||
done
|
||||
}
|
||||
|
||||
ucidef_add_switch() {
|
||||
local name="$1"; shift
|
||||
local port num role device index need_tag prev_role
|
||||
local cpu0 cpu1 cpu2 cpu3 cpu4 cpu5
|
||||
local n_cpu=0 n_vlan=0 n_ports=0
|
||||
|
||||
json_select_object switch
|
||||
json_select_object "$name"
|
||||
json_add_boolean enable 1
|
||||
json_add_boolean reset 1
|
||||
|
||||
for port in "$@"; do
|
||||
case "$port" in
|
||||
[0-9]*@*)
|
||||
num="${port%%@*}"
|
||||
device="${port##*@}"
|
||||
need_tag=0
|
||||
want_untag=0
|
||||
[ "${num%t}" != "$num" ] && {
|
||||
num="${num%t}"
|
||||
need_tag=1
|
||||
}
|
||||
[ "${num%u}" != "$num" ] && {
|
||||
num="${num%u}"
|
||||
want_untag=1
|
||||
}
|
||||
;;
|
||||
[0-9]*:*:[0-9]*)
|
||||
num="${port%%:*}"
|
||||
index="${port##*:}"
|
||||
role="${port#[0-9]*:}"; role="${role%:*}"
|
||||
;;
|
||||
[0-9]*:*)
|
||||
num="${port%%:*}"
|
||||
role="${port##*:}"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -n "$num" ] && [ -n "$device$role" ]; then
|
||||
_ucidef_add_switch_port
|
||||
fi
|
||||
|
||||
unset num device role index need_tag want_untag
|
||||
done
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
_ucidef_finish_switch_roles
|
||||
}
|
||||
|
||||
ucidef_add_switch_attr() {
|
||||
local name="$1"
|
||||
local key="$2"
|
||||
local val="$3"
|
||||
|
||||
json_select_object switch
|
||||
json_select_object "$name"
|
||||
|
||||
case "$val" in
|
||||
true|false) [ "$val" != "true" ]; json_add_boolean "$key" $? ;;
|
||||
[0-9]) json_add_int "$key" "$val" ;;
|
||||
*) json_add_string "$key" "$val" ;;
|
||||
esac
|
||||
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_add_switch_port_attr() {
|
||||
local name="$1"
|
||||
local port="$2"
|
||||
local key="$3"
|
||||
local val="$4"
|
||||
local ports i num
|
||||
|
||||
json_select_object switch
|
||||
json_select_object "$name"
|
||||
|
||||
json_get_keys ports ports
|
||||
json_select_array ports
|
||||
|
||||
for i in $ports; do
|
||||
json_select "$i"
|
||||
json_get_var num num
|
||||
|
||||
if [ -n "$num" ] && [ $num -eq $port ]; then
|
||||
json_select_object attr
|
||||
|
||||
case "$val" in
|
||||
true|false) [ "$val" != "true" ]; json_add_boolean "$key" $? ;;
|
||||
[0-9]) json_add_int "$key" "$val" ;;
|
||||
*) json_add_string "$key" "$val" ;;
|
||||
esac
|
||||
|
||||
json_select ..
|
||||
fi
|
||||
|
||||
json_select ..
|
||||
done
|
||||
|
||||
json_select ..
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_interface_macaddr() {
|
||||
local network="$1"
|
||||
local macaddr="$2"
|
||||
|
||||
json_select_object network
|
||||
|
||||
json_select "$network"
|
||||
[ $? -eq 0 ] || {
|
||||
json_select ..
|
||||
return
|
||||
}
|
||||
|
||||
json_add_string macaddr "$macaddr"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_add_atm_bridge() {
|
||||
local vpi="$1"
|
||||
local vci="$2"
|
||||
local encaps="$3"
|
||||
local payload="$4"
|
||||
local nameprefix="$5"
|
||||
|
||||
json_select_object dsl
|
||||
json_select_object atmbridge
|
||||
json_add_int vpi "$vpi"
|
||||
json_add_int vci "$vci"
|
||||
json_add_string encaps "$encaps"
|
||||
json_add_string payload "$payload"
|
||||
json_add_string nameprefix "$nameprefix"
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_add_adsl_modem() {
|
||||
local annex="$1"
|
||||
local firmware="$2"
|
||||
|
||||
json_select_object dsl
|
||||
json_select_object modem
|
||||
json_add_string type "adsl"
|
||||
json_add_string annex "$annex"
|
||||
json_add_string firmware "$firmware"
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_add_vdsl_modem() {
|
||||
local annex="$1"
|
||||
local tone="$2"
|
||||
local xfer_mode="$3"
|
||||
|
||||
json_select_object dsl
|
||||
json_select_object modem
|
||||
json_add_string type "vdsl"
|
||||
json_add_string annex "$annex"
|
||||
json_add_string tone "$tone"
|
||||
json_add_string xfer_mode "$xfer_mode"
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_ataport() {
|
||||
_ucidef_set_led_trigger "$1" "$2" "$3" ata"$4"
|
||||
}
|
||||
|
||||
_ucidef_set_led_common() {
|
||||
local cfg="led_$1"
|
||||
local name="$2"
|
||||
local sysfs="$3"
|
||||
|
||||
json_select_object led
|
||||
|
||||
json_select_object "$1"
|
||||
json_add_string name "$name"
|
||||
json_add_string sysfs "$sysfs"
|
||||
}
|
||||
|
||||
ucidef_set_led_default() {
|
||||
local default="$4"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string default "$default"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_gpio() {
|
||||
local gpio="$4"
|
||||
local inverted="$5"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string trigger "$trigger"
|
||||
json_add_string type gpio
|
||||
json_add_int gpio "$gpio"
|
||||
json_add_boolean inverted "$inverted"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_ide() {
|
||||
_ucidef_set_led_trigger "$1" "$2" "$3" ide-disk
|
||||
}
|
||||
|
||||
ucidef_set_led_netdev() {
|
||||
local dev="$4"
|
||||
local mode="${5:-link tx rx}"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string type netdev
|
||||
json_add_string device "$dev"
|
||||
json_add_string mode "$mode"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_oneshot() {
|
||||
_ucidef_set_led_timer $1 $2 $3 "oneshot" $4 $5
|
||||
}
|
||||
|
||||
ucidef_set_led_portstate() {
|
||||
local port_state="$4"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string trigger port_state
|
||||
json_add_string type portstate
|
||||
json_add_string port_state "$port_state"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_rssi() {
|
||||
local iface="$4"
|
||||
local minq="$5"
|
||||
local maxq="$6"
|
||||
local offset="${7:-0}"
|
||||
local factor="${8:-1}"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string type rssi
|
||||
json_add_string name "$name"
|
||||
json_add_string iface "$iface"
|
||||
json_add_string minq "$minq"
|
||||
json_add_string maxq "$maxq"
|
||||
json_add_string offset "$offset"
|
||||
json_add_string factor "$factor"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_switch() {
|
||||
local trigger_name="$4"
|
||||
local port_mask="$5"
|
||||
local speed_mask="$6"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string trigger "$trigger_name"
|
||||
json_add_string type switch
|
||||
json_add_string port_mask "$port_mask"
|
||||
json_add_string speed_mask "$speed_mask"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
_ucidef_set_led_timer() {
|
||||
local trigger_name="$4"
|
||||
local delayon="$5"
|
||||
local delayoff="$6"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string type "$trigger_name"
|
||||
json_add_string trigger "$trigger_name"
|
||||
json_add_int delayon "$delayon"
|
||||
json_add_int delayoff "$delayoff"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_timer() {
|
||||
_ucidef_set_led_timer $1 $2 $3 "timer" $4 $5
|
||||
}
|
||||
|
||||
_ucidef_set_led_trigger() {
|
||||
local trigger_name="$4"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string trigger "$trigger_name"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_usbdev() {
|
||||
local dev="$4"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string type usb
|
||||
json_add_string device "$dev"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_usbhost() {
|
||||
_ucidef_set_led_trigger "$1" "$2" "$3" usb-host
|
||||
}
|
||||
|
||||
ucidef_set_led_usbport() {
|
||||
local obj="$1"
|
||||
local name="$2"
|
||||
local sysfs="$3"
|
||||
shift
|
||||
shift
|
||||
shift
|
||||
|
||||
_ucidef_set_led_common "$obj" "$name" "$sysfs"
|
||||
|
||||
json_add_string type usbport
|
||||
json_select_array ports
|
||||
for port in "$@"; do
|
||||
json_add_string port "$port"
|
||||
done
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_wlan() {
|
||||
_ucidef_set_led_trigger "$1" "$2" "$3" "$4"
|
||||
}
|
||||
|
||||
ucidef_set_rssimon() {
|
||||
local dev="$1"
|
||||
local refresh="$2"
|
||||
local threshold="$3"
|
||||
|
||||
json_select_object rssimon
|
||||
|
||||
json_select_object "$dev"
|
||||
[ -n "$refresh" ] && json_add_int refresh "$refresh"
|
||||
[ -n "$threshold" ] && json_add_int threshold "$threshold"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_add_gpio_switch() {
|
||||
local cfg="$1"
|
||||
local name="$2"
|
||||
local pin="$3"
|
||||
local default="${4:-0}"
|
||||
|
||||
json_select_object gpioswitch
|
||||
json_select_object "$cfg"
|
||||
json_add_string name "$name"
|
||||
json_add_int pin "$pin"
|
||||
json_add_int default "$default"
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_hostname() {
|
||||
local hostname="$1"
|
||||
|
||||
json_select_object system
|
||||
json_add_string hostname "$hostname"
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_ntpserver() {
|
||||
local server
|
||||
|
||||
json_select_object system
|
||||
json_select_array ntpserver
|
||||
for server in "$@"; do
|
||||
json_add_string "" "$server"
|
||||
done
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
board_config_update() {
|
||||
json_init
|
||||
[ -f ${CFG} ] && json_load "$(cat ${CFG})"
|
||||
|
||||
# auto-initialize model id and name if applicable
|
||||
if ! json_is_a model object; then
|
||||
json_select_object model
|
||||
[ -f "/tmp/sysinfo/board_name" ] && \
|
||||
json_add_string id "$(cat /tmp/sysinfo/board_name)"
|
||||
[ -f "/tmp/sysinfo/model" ] && \
|
||||
json_add_string name "$(cat /tmp/sysinfo/model)"
|
||||
json_select ..
|
||||
fi
|
||||
}
|
||||
|
||||
board_config_flush() {
|
||||
json_dump -i > /tmp/.board.json
|
||||
mv /tmp/.board.json ${CFG}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
define_default_set_state() {
|
||||
. /etc/diag.sh
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main define_default_set_state
|
||||
10
package/base-files/files/lib/preinit/02_sysinfo
Normal file
10
package/base-files/files/lib/preinit/02_sysinfo
Normal file
@@ -0,0 +1,10 @@
|
||||
do_sysinfo_generic() {
|
||||
[ -d /proc/device-tree ] || return
|
||||
mkdir -p /tmp/sysinfo
|
||||
[ -e /tmp/sysinfo/board_name ] || \
|
||||
echo "$(strings /proc/device-tree/compatible | head -1)" > /tmp/sysinfo/board_name
|
||||
[ ! -e /tmp/sysinfo/model -a -e /proc/device-tree/model ] && \
|
||||
echo "$(cat /proc/device-tree/model)" > /tmp/sysinfo/model
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main do_sysinfo_generic
|
||||
18
package/base-files/files/lib/preinit/10_indicate_failsafe
Normal file
18
package/base-files/files/lib/preinit/10_indicate_failsafe
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
# commands for emitting messages to network in failsafe mode
|
||||
|
||||
indicate_failsafe_led () {
|
||||
set_state failsafe
|
||||
}
|
||||
|
||||
indicate_failsafe() {
|
||||
[ "$pi_preinit_no_failsafe" = "y" ] && return
|
||||
echo "- failsafe -"
|
||||
preinit_net_echo "Entering Failsafe!\n"
|
||||
indicate_failsafe_led
|
||||
}
|
||||
|
||||
boot_hook_add failsafe indicate_failsafe
|
||||
155
package/base-files/files/lib/preinit/10_indicate_preinit
Normal file
155
package/base-files/files/lib/preinit/10_indicate_preinit
Normal file
@@ -0,0 +1,155 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
preinit_ip_config() {
|
||||
local netdev vid
|
||||
|
||||
netdev=${1%\.*}
|
||||
vid=${1#*\.}
|
||||
|
||||
if [ "$vid" = "$netdev" ]; then
|
||||
vid=
|
||||
fi
|
||||
|
||||
grep -q "$netdev" /proc/net/dev || return
|
||||
|
||||
if [ -n "$vid" ]; then
|
||||
ip link add link $netdev name $1 type vlan id $vid
|
||||
fi
|
||||
|
||||
ip link set dev $netdev up
|
||||
ip -4 address add $pi_ip/$pi_netmask broadcast $pi_broadcast dev $1
|
||||
}
|
||||
|
||||
preinit_config_switch() {
|
||||
local role roles ports device enable reset
|
||||
|
||||
local name=$1
|
||||
local lan_if=$2
|
||||
|
||||
json_select switch
|
||||
json_select $name
|
||||
|
||||
json_get_vars enable reset
|
||||
|
||||
if json_is_a roles array; then
|
||||
json_get_keys roles roles
|
||||
json_select roles
|
||||
|
||||
for role in $roles; do
|
||||
json_select "$role"
|
||||
json_get_vars ports device
|
||||
json_select ..
|
||||
|
||||
if [ "$device" = "$lan_if" ]; then
|
||||
if [ "$reset" -eq "1" ]; then
|
||||
swconfig dev $name set reset
|
||||
fi
|
||||
|
||||
swconfig dev $name set enable_vlan $enable
|
||||
swconfig dev $name vlan $role set ports "$ports"
|
||||
swconfig dev $name set apply
|
||||
fi
|
||||
done
|
||||
|
||||
json_select ..
|
||||
fi
|
||||
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
preinit_config_board() {
|
||||
/bin/board_detect /tmp/board.json
|
||||
|
||||
[ -f "/tmp/board.json" ] || return
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
json_init
|
||||
json_load "$(cat /tmp/board.json)"
|
||||
|
||||
json_select network
|
||||
json_select "lan"
|
||||
json_get_vars ifname
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
[ -n "$ifname" ] || return
|
||||
|
||||
# only use the first one
|
||||
ifname=${ifname%% *}
|
||||
|
||||
if [ -x /sbin/swconfig ]; then
|
||||
# configure the switch, if present
|
||||
|
||||
json_get_keys keys switch
|
||||
for key in $keys; do
|
||||
preinit_config_switch $key $ifname
|
||||
done
|
||||
else
|
||||
# trim any vlan ids
|
||||
ifname=${ifname%\.*}
|
||||
fi
|
||||
|
||||
pi_ifname=$ifname
|
||||
|
||||
preinit_ip_config $pi_ifname
|
||||
}
|
||||
|
||||
preinit_ip() {
|
||||
[ "$pi_preinit_no_failsafe" = "y" ] && return
|
||||
|
||||
# if the preinit interface isn't specified and ifname is set in
|
||||
# preinit.arch use that interface
|
||||
if [ -z "$pi_ifname" ]; then
|
||||
pi_ifname=$ifname
|
||||
fi
|
||||
|
||||
if [ -n "$pi_ifname" ]; then
|
||||
preinit_ip_config $pi_ifname
|
||||
elif [ -d "/etc/board.d/" ]; then
|
||||
preinit_config_board
|
||||
fi
|
||||
|
||||
preinit_net_echo "Doing OpenWrt Preinit\n"
|
||||
}
|
||||
|
||||
preinit_ip_deconfig() {
|
||||
[ -n "$pi_ifname" ] && grep -q "$pi_ifname" /proc/net/dev && {
|
||||
local netdev vid
|
||||
|
||||
netdev=${pi_ifname%\.*}
|
||||
vid=${pi_ifname#*\.}
|
||||
|
||||
if [ "$vid" = "$netdev" ]; then
|
||||
vid=
|
||||
fi
|
||||
|
||||
ip -4 address flush dev $pi_ifname
|
||||
ip link set dev $netdev down
|
||||
|
||||
if [ -n "$vid" ]; then
|
||||
ip link delete $pi_ifname
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
preinit_net_echo() {
|
||||
[ -n "$pi_ifname" ] && grep -q "$pi_ifname" /proc/net/dev && {
|
||||
{
|
||||
[ "$pi_preinit_net_messages" = "y" ] || {
|
||||
[ "$pi_failsafe_net_message" = "true" ] &&
|
||||
[ "$pi_preinit_no_failsafe_netmsg" != "y" ]
|
||||
}
|
||||
} && netmsg $pi_broadcast "$1"
|
||||
}
|
||||
}
|
||||
|
||||
pi_indicate_preinit() {
|
||||
set_state preinit
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main preinit_ip
|
||||
boot_hook_add preinit_main pi_indicate_preinit
|
||||
100
package/base-files/files/lib/preinit/30_failsafe_wait
Normal file
100
package/base-files/files/lib/preinit/30_failsafe_wait
Normal file
@@ -0,0 +1,100 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006-2010 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
fs_wait_for_key () {
|
||||
local timeout=$3
|
||||
local timer
|
||||
local do_keypress
|
||||
local keypress_true="$(mktemp)"
|
||||
local keypress_wait="$(mktemp)"
|
||||
local keypress_sec="$(mktemp)"
|
||||
if [ -z "$keypress_wait" ]; then
|
||||
keypress_wait=/tmp/.keypress_wait
|
||||
touch $keypress_wait
|
||||
fi
|
||||
if [ -z "$keypress_true" ]; then
|
||||
keypress_true=/tmp/.keypress_true
|
||||
touch $keypress_true
|
||||
fi
|
||||
if [ -z "$keypress_sec" ]; then
|
||||
keypress_sec=/tmp/.keypress_sec
|
||||
touch $keypress_sec
|
||||
fi
|
||||
|
||||
trap "echo 'true' >$keypress_true; lock -u $keypress_wait ; rm -f $keypress_wait" INT
|
||||
trap "echo 'true' >$keypress_true; lock -u $keypress_wait ; rm -f $keypress_wait" USR1
|
||||
|
||||
[ -n "$timeout" ] || timeout=1
|
||||
[ $timeout -ge 1 ] || timeout=1
|
||||
timer=$timeout
|
||||
lock $keypress_wait
|
||||
{
|
||||
while [ $timer -gt 0 ]; do
|
||||
echo "$timer" >$keypress_sec
|
||||
timer=$(($timer - 1))
|
||||
sleep 1
|
||||
done
|
||||
lock -u $keypress_wait
|
||||
rm -f $keypress_wait
|
||||
} &
|
||||
|
||||
[ "$pi_preinit_no_failsafe" != "y" ] && echo "Press the [$1] key and hit [enter] $2"
|
||||
echo "Press the [1], [2], [3] or [4] key and hit [enter] to select the debug level"
|
||||
# if we're on the console we wait for input
|
||||
{
|
||||
while [ -r $keypress_wait ]; do
|
||||
timer="$(cat $keypress_sec)"
|
||||
|
||||
[ -n "$timer" ] || timer=1
|
||||
timer="${timer%%\ *}"
|
||||
[ $timer -ge 1 ] || timer=1
|
||||
do_keypress=""
|
||||
{
|
||||
read -t "$timer" do_keypress
|
||||
case "$do_keypress" in
|
||||
$1)
|
||||
echo "true" >$keypress_true
|
||||
;;
|
||||
1 | 2 | 3 | 4)
|
||||
echo "$do_keypress" >/tmp/debug_level
|
||||
;;
|
||||
*)
|
||||
continue;
|
||||
;;
|
||||
esac
|
||||
lock -u $keypress_wait
|
||||
rm -f $keypress_wait
|
||||
}
|
||||
done
|
||||
}
|
||||
lock -w $keypress_wait
|
||||
|
||||
keypressed=1
|
||||
[ "$(cat $keypress_true)" = "true" ] && keypressed=0
|
||||
|
||||
rm -f $keypress_true
|
||||
rm -f $keypress_wait
|
||||
rm -f $keypress_sec
|
||||
|
||||
return $keypressed
|
||||
}
|
||||
|
||||
failsafe_wait() {
|
||||
FAILSAFE=
|
||||
[ "$pi_preinit_no_failsafe" == "y" ] && {
|
||||
fs_wait_for_key "" "" $fs_failsafe_wait_timeout
|
||||
return
|
||||
}
|
||||
grep -q 'failsafe=' /proc/cmdline && FAILSAFE=true && export FAILSAFE
|
||||
if [ "$FAILSAFE" != "true" ]; then
|
||||
pi_failsafe_net_message=true
|
||||
preinit_net_echo "Please press button now to enter failsafe"
|
||||
pi_failsafe_net_message=false
|
||||
fs_wait_for_key f 'to enter failsafe mode' $fs_failsafe_wait_timeout && FAILSAFE=true
|
||||
[ -f "/tmp/failsafe_button" ] && FAILSAFE=true && echo "- failsafe button "`cat /tmp/failsafe_button`" was pressed -"
|
||||
[ "$FAILSAFE" = "true" ] && export FAILSAFE && touch /tmp/failsafe
|
||||
fi
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main failsafe_wait
|
||||
17
package/base-files/files/lib/preinit/40_run_failsafe_hook
Normal file
17
package/base-files/files/lib/preinit/40_run_failsafe_hook
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006-2010 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
run_failsafe_hook() {
|
||||
[ "$pi_preinit_no_failsafe" = "y" ] && return
|
||||
if [ "$FAILSAFE" = "true" ]; then
|
||||
lock /tmp/.failsafe
|
||||
boot_run_hook failsafe
|
||||
while [ ! -e /tmp/sysupgrade ]; do
|
||||
lock -w /tmp/.failsafe
|
||||
done
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main run_failsafe_hook
|
||||
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
indicate_regular_preinit() {
|
||||
preinit_net_echo "Continuing with Regular Preinit\n"
|
||||
set_state preinit_regular
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main indicate_regular_preinit
|
||||
13
package/base-files/files/lib/preinit/70_initramfs_test
Normal file
13
package/base-files/files/lib/preinit/70_initramfs_test
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
initramfs_test() {
|
||||
if [ -n "$INITRAMFS" ]; then
|
||||
boot_run_hook initramfs
|
||||
preinit_ip_deconfig
|
||||
break
|
||||
fi
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main initramfs_test
|
||||
15
package/base-files/files/lib/preinit/80_mount_root
Normal file
15
package/base-files/files/lib/preinit/80_mount_root
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
do_mount_root() {
|
||||
mount_root
|
||||
boot_run_hook preinit_mount_root
|
||||
[ -f /sysupgrade.tgz ] && {
|
||||
echo "- config restore -"
|
||||
cd /
|
||||
tar xzf /sysupgrade.tgz
|
||||
}
|
||||
}
|
||||
|
||||
[ "$INITRAMFS" = "1" ] || boot_hook_add preinit_main do_mount_root
|
||||
24
package/base-files/files/lib/preinit/81_urandom_seed
Normal file
24
package/base-files/files/lib/preinit/81_urandom_seed
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
|
||||
log_urandom_seed() {
|
||||
echo "urandom-seed: $1" > /dev/kmsg
|
||||
}
|
||||
|
||||
_do_urandom_seed() {
|
||||
[ -f "$1" ] || { log_urandom_seed "Seed file not found ($1)"; return; }
|
||||
[ -O "$1" -a -G "$1" -a ! -x "$1" ] || { log_urandom_seed "Wrong owner / permissions for $1"; return; }
|
||||
|
||||
log_urandom_seed "Seeding with $1"
|
||||
cat "$1" > /dev/urandom
|
||||
}
|
||||
|
||||
do_urandom_seed() {
|
||||
[ -c /dev/urandom ] || { log_urandom_seed "Something is wrong with /dev/urandom"; return; }
|
||||
|
||||
_do_urandom_seed "/etc/urandom.seed"
|
||||
|
||||
SEED="$(uci -q get system.@system[0].urandom_seed)"
|
||||
[ "${SEED:0:1}" == "/" -a "$SEED" != "/etc/urandom.seed" ] && _do_urandom_seed "$SEED"
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main do_urandom_seed
|
||||
21
package/base-files/files/lib/preinit/99_10_failsafe_login
Normal file
21
package/base-files/files/lib/preinit/99_10_failsafe_login
Normal file
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006-2015 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
failsafe_netlogin () {
|
||||
dropbearkey -t rsa -s 1024 -f /tmp/dropbear_failsafe_host_key
|
||||
dropbear -r /tmp/dropbear_failsafe_host_key <> /dev/null 2>&1
|
||||
}
|
||||
|
||||
failsafe_shell() {
|
||||
local console="$(sed -e 's/ /\n/g' /proc/cmdline | grep '^console=' | head -1 | sed -e 's/^console=//' -e 's/,.*//')"
|
||||
[ -n "$console" ] || console=console
|
||||
[ -c "/dev/$console" ] || return 0
|
||||
while true; do
|
||||
ash --login <"/dev/$console" >"/dev/$console" 2>"/dev/$console"
|
||||
sleep 1
|
||||
done &
|
||||
}
|
||||
|
||||
boot_hook_add failsafe failsafe_netlogin
|
||||
boot_hook_add failsafe failsafe_shell
|
||||
9
package/base-files/files/lib/preinit/99_10_run_init
Normal file
9
package/base-files/files/lib/preinit/99_10_run_init
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
run_init() {
|
||||
preinit_ip_deconfig
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main run_init
|
||||
250
package/base-files/files/lib/upgrade/common.sh
Normal file
250
package/base-files/files/lib/upgrade/common.sh
Normal file
@@ -0,0 +1,250 @@
|
||||
#!/bin/sh
|
||||
|
||||
RAM_ROOT=/tmp/root
|
||||
|
||||
[ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }
|
||||
libs() { ldd $* 2>/dev/null | sed -r 's/(.* => )?(.*) .*/\2/'; }
|
||||
|
||||
install_file() { # <file> [ <file> ... ]
|
||||
local target dest dir
|
||||
for file in "$@"; do
|
||||
if [ -L "$file" ]; then
|
||||
target="$(readlink -f "$file")"
|
||||
dest="$RAM_ROOT/$file"
|
||||
[ ! -f "$dest" ] && {
|
||||
dir="$(dirname "$dest")"
|
||||
mkdir -p "$dir"
|
||||
ln -s "$target" "$dest"
|
||||
}
|
||||
file="$target"
|
||||
fi
|
||||
dest="$RAM_ROOT/$file"
|
||||
[ -f "$file" -a ! -f "$dest" ] && {
|
||||
dir="$(dirname "$dest")"
|
||||
mkdir -p "$dir"
|
||||
cp "$file" "$dest"
|
||||
}
|
||||
done
|
||||
}
|
||||
|
||||
install_bin() {
|
||||
local src files
|
||||
src=$1
|
||||
files=$1
|
||||
[ -x "$src" ] && files="$src $(libs $src)"
|
||||
install_file $files
|
||||
}
|
||||
|
||||
run_hooks() {
|
||||
local arg="$1"; shift
|
||||
for func in "$@"; do
|
||||
eval "$func $arg"
|
||||
done
|
||||
}
|
||||
|
||||
ask_bool() {
|
||||
local default="$1"; shift;
|
||||
local answer="$default"
|
||||
|
||||
[ "$INTERACTIVE" -eq 1 ] && {
|
||||
case "$default" in
|
||||
0) echo -n "$* (y/N): ";;
|
||||
*) echo -n "$* (Y/n): ";;
|
||||
esac
|
||||
read answer
|
||||
case "$answer" in
|
||||
y*) answer=1;;
|
||||
n*) answer=0;;
|
||||
*) answer="$default";;
|
||||
esac
|
||||
}
|
||||
[ "$answer" -gt 0 ]
|
||||
}
|
||||
|
||||
v() {
|
||||
[ "$VERBOSE" -ge 1 ] && echo "$@"
|
||||
}
|
||||
|
||||
json_string() {
|
||||
local v="$1"
|
||||
v="${v//\\/\\\\}"
|
||||
v="${v//\"/\\\"}"
|
||||
echo "\"$v\""
|
||||
}
|
||||
|
||||
rootfs_type() {
|
||||
/bin/mount | awk '($3 ~ /^\/$/) && ($5 !~ /rootfs/) { print $5 }'
|
||||
}
|
||||
|
||||
get_image() { # <source> [ <command> ]
|
||||
local from="$1"
|
||||
local cmd="$2"
|
||||
|
||||
if [ -z "$cmd" ]; then
|
||||
local magic="$(dd if="$from" bs=2 count=1 2>/dev/null | hexdump -n 2 -e '1/1 "%02x"')"
|
||||
case "$magic" in
|
||||
1f8b) cmd="zcat";;
|
||||
425a) cmd="bzcat";;
|
||||
*) cmd="cat";;
|
||||
esac
|
||||
fi
|
||||
|
||||
cat "$from" 2>/dev/null | $cmd
|
||||
}
|
||||
|
||||
get_magic_word() {
|
||||
(get_image "$@" | dd bs=2 count=1 | hexdump -v -n 2 -e '1/1 "%02x"') 2>/dev/null
|
||||
}
|
||||
|
||||
get_magic_long() {
|
||||
(get_image "$@" | dd bs=4 count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2>/dev/null
|
||||
}
|
||||
|
||||
export_bootdevice() {
|
||||
local cmdline uuid disk uevent line
|
||||
local MAJOR MINOR DEVNAME DEVTYPE
|
||||
|
||||
if read cmdline < /proc/cmdline; then
|
||||
case "$cmdline" in
|
||||
*block2mtd=*)
|
||||
disk="${cmdline##*block2mtd=}"
|
||||
disk="${disk%%,*}"
|
||||
;;
|
||||
*root=*)
|
||||
disk="${cmdline##*root=}"
|
||||
disk="${disk%% *}"
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$disk" in
|
||||
PARTUUID=[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]-02)
|
||||
uuid="${disk#PARTUUID=}"
|
||||
uuid="${uuid%-02}"
|
||||
for disk in $(find /dev -type b); do
|
||||
set -- $(dd if=$disk bs=1 skip=440 count=4 2>/dev/null | hexdump -v -e '4/1 "%02x "')
|
||||
if [ "$4$3$2$1" = "$uuid" ]; then
|
||||
uevent="/sys/class/block/${disk##*/}/uevent"
|
||||
break
|
||||
fi
|
||||
done
|
||||
;;
|
||||
/dev/*)
|
||||
uevent="/sys/class/block/${disk##*/}/uevent"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -e "$uevent" ]; then
|
||||
while read line; do
|
||||
export -n "$line"
|
||||
done < "$uevent"
|
||||
export BOOTDEV_MAJOR=$MAJOR
|
||||
export BOOTDEV_MINOR=$MINOR
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
export_partdevice() {
|
||||
local var="$1" offset="$2"
|
||||
local uevent line MAJOR MINOR DEVNAME DEVTYPE
|
||||
|
||||
for uevent in /sys/class/block/*/uevent; do
|
||||
while read line; do
|
||||
export -n "$line"
|
||||
done < "$uevent"
|
||||
if [ $BOOTDEV_MAJOR = $MAJOR -a $(($BOOTDEV_MINOR + $offset)) = $MINOR -a -b "/dev/$DEVNAME" ]; then
|
||||
export "$var=$DEVNAME"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
hex_le32_to_cpu() {
|
||||
[ "$(echo 01 | hexdump -v -n 2 -e '/2 "%x"')" == "3031" ] && {
|
||||
echo "${1:0:2}${1:8:2}${1:6:2}${1:4:2}${1:2:2}"
|
||||
return
|
||||
}
|
||||
echo "$@"
|
||||
}
|
||||
|
||||
get_partitions() { # <device> <filename>
|
||||
local disk="$1"
|
||||
local filename="$2"
|
||||
|
||||
if [ -b "$disk" -o -f "$disk" ]; then
|
||||
v "Reading partition table from $filename..."
|
||||
|
||||
local magic=$(dd if="$disk" bs=2 count=1 skip=255 2>/dev/null)
|
||||
if [ "$magic" != $'\x55\xAA' ]; then
|
||||
v "Invalid partition table on $disk"
|
||||
exit
|
||||
fi
|
||||
|
||||
rm -f "/tmp/partmap.$filename"
|
||||
|
||||
local part
|
||||
for part in 1 2 3 4; do
|
||||
set -- $(hexdump -v -n 12 -s "$((0x1B2 + $part * 16))" -e '3/4 "0x%08X "' "$disk")
|
||||
|
||||
local type="$(( $(hex_le32_to_cpu $1) % 256))"
|
||||
local lba="$(( $(hex_le32_to_cpu $2) ))"
|
||||
local num="$(( $(hex_le32_to_cpu $3) ))"
|
||||
|
||||
[ $type -gt 0 ] || continue
|
||||
|
||||
printf "%2d %5d %7d\n" $part $lba $num >> "/tmp/partmap.$filename"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
jffs2_copy_config() {
|
||||
if grep rootfs_data /proc/mtd >/dev/null; then
|
||||
# squashfs+jffs2
|
||||
mtd -e rootfs_data jffs2write "$CONF_TAR" rootfs_data
|
||||
else
|
||||
# jffs2
|
||||
mtd jffs2write "$CONF_TAR" rootfs
|
||||
fi
|
||||
}
|
||||
|
||||
# Flash firmware to MTD partition
|
||||
#
|
||||
# $(1): path to image
|
||||
# $(2): (optional) pipe command to extract firmware, e.g. dd bs=n skip=m
|
||||
default_do_upgrade() {
|
||||
sync
|
||||
if [ "$SAVE_CONFIG" -eq 1 ]; then
|
||||
get_image "$1" "$2" | mtd $MTD_CONFIG_ARGS -j "$CONF_TAR" write - "${PART_NAME:-image}"
|
||||
else
|
||||
get_image "$1" "$2" | mtd write - "${PART_NAME:-image}"
|
||||
fi
|
||||
[ $? -ne 0 ] && exit 1
|
||||
}
|
||||
|
||||
do_upgrade_stage2() {
|
||||
v "Performing system upgrade..."
|
||||
if [ -n "$do_upgrade" ]; then
|
||||
eval "$do_upgrade"
|
||||
elif type 'platform_do_upgrade' >/dev/null 2>/dev/null; then
|
||||
platform_do_upgrade "$IMAGE"
|
||||
else
|
||||
default_do_upgrade "$IMAGE"
|
||||
fi
|
||||
|
||||
if [ "$SAVE_CONFIG" -eq 1 ] && type 'platform_copy_config' >/dev/null 2>/dev/null; then
|
||||
platform_copy_config
|
||||
fi
|
||||
|
||||
v "Upgrade completed"
|
||||
sleep 1
|
||||
|
||||
v "Rebooting system..."
|
||||
umount -a
|
||||
reboot -f
|
||||
sleep 5
|
||||
echo b 2>/dev/null >/proc/sysrq-trigger
|
||||
}
|
||||
39
package/base-files/files/lib/upgrade/fwtool.sh
Normal file
39
package/base-files/files/lib/upgrade/fwtool.sh
Normal file
@@ -0,0 +1,39 @@
|
||||
fwtool_check_image() {
|
||||
[ $# -gt 1 ] && return 1
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
if ! fwtool -q -i /tmp/sysupgrade.meta "$1"; then
|
||||
echo "Image metadata not found"
|
||||
[ "$REQUIRE_IMAGE_METADATA" = 1 -a "$FORCE" != 1 ] && {
|
||||
echo "Use sysupgrade -F to override this check when downgrading or flashing to vendor firmware"
|
||||
}
|
||||
[ "$REQUIRE_IMAGE_METADATA" = 1 ] && return 1
|
||||
return 0
|
||||
fi
|
||||
|
||||
json_load "$(cat /tmp/sysupgrade.meta)" || {
|
||||
echo "Invalid image metadata"
|
||||
return 1
|
||||
}
|
||||
|
||||
device="$(cat /tmp/sysinfo/board_name)"
|
||||
|
||||
json_select supported_devices || return 1
|
||||
|
||||
json_get_keys dev_keys
|
||||
for k in $dev_keys; do
|
||||
json_get_var dev "$k"
|
||||
[ "$dev" = "$device" ] && return 0
|
||||
done
|
||||
|
||||
echo "Device $device not supported by this image"
|
||||
echo -n "Supported devices:"
|
||||
for k in $dev_keys; do
|
||||
json_get_var dev "$k"
|
||||
echo -n " $dev"
|
||||
done
|
||||
echo
|
||||
|
||||
return 1
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
# Essential files that will be always kept
|
||||
/etc/hosts
|
||||
/etc/inittab
|
||||
/etc/group
|
||||
/etc/passwd
|
||||
/etc/profile
|
||||
/etc/shadow
|
||||
/etc/shells
|
||||
/etc/sysctl.conf
|
||||
/etc/rc.local
|
||||
329
package/base-files/files/lib/upgrade/nand.sh
Normal file
329
package/base-files/files/lib/upgrade/nand.sh
Normal file
@@ -0,0 +1,329 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2014 OpenWrt.org
|
||||
#
|
||||
|
||||
. /lib/functions.sh
|
||||
|
||||
# 'kernel' partition on NAND contains the kernel
|
||||
CI_KERNPART="${CI_KERNPART:-kernel}"
|
||||
|
||||
# 'ubi' partition on NAND contains UBI
|
||||
CI_UBIPART="${CI_UBIPART:-ubi}"
|
||||
|
||||
ubi_mknod() {
|
||||
local dir="$1"
|
||||
local dev="/dev/$(basename $dir)"
|
||||
|
||||
[ -e "$dev" ] && return 0
|
||||
|
||||
local devid="$(cat $dir/dev)"
|
||||
local major="${devid%%:*}"
|
||||
local minor="${devid##*:}"
|
||||
mknod "$dev" c $major $minor
|
||||
}
|
||||
|
||||
nand_find_volume() {
|
||||
local ubidevdir ubivoldir
|
||||
ubidevdir="/sys/devices/virtual/ubi/$1"
|
||||
[ ! -d "$ubidevdir" ] && return 1
|
||||
for ubivoldir in $ubidevdir/${1}_*; do
|
||||
[ ! -d "$ubivoldir" ] && continue
|
||||
if [ "$( cat $ubivoldir/name )" = "$2" ]; then
|
||||
basename $ubivoldir
|
||||
ubi_mknod "$ubivoldir"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
nand_find_ubi() {
|
||||
local ubidevdir ubidev mtdnum
|
||||
mtdnum="$( find_mtd_index $1 )"
|
||||
[ ! "$mtdnum" ] && return 1
|
||||
for ubidevdir in /sys/devices/virtual/ubi/ubi*; do
|
||||
[ ! -d "$ubidevdir" ] && continue
|
||||
cmtdnum="$( cat $ubidevdir/mtd_num )"
|
||||
[ ! "$mtdnum" ] && continue
|
||||
if [ "$mtdnum" = "$cmtdnum" ]; then
|
||||
ubidev=$( basename $ubidevdir )
|
||||
ubi_mknod "$ubidevdir"
|
||||
echo $ubidev
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
nand_get_magic_long() {
|
||||
dd if="$1" skip=$2 bs=4 count=1 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
|
||||
}
|
||||
|
||||
get_magic_long_tar() {
|
||||
( tar xf $1 $2 -O | dd bs=4 count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2> /dev/null
|
||||
}
|
||||
|
||||
identify_magic() {
|
||||
local magic=$1
|
||||
case "$magic" in
|
||||
"55424923")
|
||||
echo "ubi"
|
||||
;;
|
||||
"31181006")
|
||||
echo "ubifs"
|
||||
;;
|
||||
"68737173")
|
||||
echo "squashfs"
|
||||
;;
|
||||
"d00dfeed")
|
||||
echo "fit"
|
||||
;;
|
||||
"4349"*)
|
||||
echo "combined"
|
||||
;;
|
||||
*)
|
||||
echo "unknown $magic"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
identify() {
|
||||
identify_magic $(nand_get_magic_long "$1" "${2:-0}")
|
||||
}
|
||||
|
||||
identify_tar() {
|
||||
identify_magic $(get_magic_long_tar "$1" "$2")
|
||||
}
|
||||
|
||||
nand_restore_config() {
|
||||
sync
|
||||
local ubidev=$( nand_find_ubi $CI_UBIPART )
|
||||
local ubivol="$( nand_find_volume $ubidev rootfs_data )"
|
||||
[ ! "$ubivol" ] &&
|
||||
ubivol="$( nand_find_volume $ubidev rootfs )"
|
||||
mkdir /tmp/new_root
|
||||
if ! mount -t ubifs /dev/$ubivol /tmp/new_root; then
|
||||
echo "mounting ubifs $ubivol failed"
|
||||
rmdir /tmp/new_root
|
||||
return 1
|
||||
fi
|
||||
mv "$1" "/tmp/new_root/sysupgrade.tgz"
|
||||
umount /tmp/new_root
|
||||
sync
|
||||
rmdir /tmp/new_root
|
||||
}
|
||||
|
||||
nand_upgrade_prepare_ubi() {
|
||||
local rootfs_length="$1"
|
||||
local rootfs_type="$2"
|
||||
local has_kernel="${3:-0}"
|
||||
local has_env="${4:-0}"
|
||||
|
||||
local mtdnum="$( find_mtd_index "$CI_UBIPART" )"
|
||||
if [ ! "$mtdnum" ]; then
|
||||
echo "cannot find ubi mtd partition $CI_UBIPART"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
||||
if [ ! "$ubidev" ]; then
|
||||
ubiattach -m "$mtdnum"
|
||||
sync
|
||||
ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
||||
fi
|
||||
|
||||
if [ ! "$ubidev" ]; then
|
||||
ubiformat /dev/mtd$mtdnum -y
|
||||
ubiattach -m "$mtdnum"
|
||||
sync
|
||||
ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
||||
[ "$has_env" -gt 0 ] && {
|
||||
ubimkvol /dev/$ubidev -n 0 -N ubootenv -s 1MiB
|
||||
ubimkvol /dev/$ubidev -n 1 -N ubootenv2 -s 1MiB
|
||||
}
|
||||
fi
|
||||
|
||||
local kern_ubivol="$( nand_find_volume $ubidev $CI_KERNPART )"
|
||||
local root_ubivol="$( nand_find_volume $ubidev rootfs )"
|
||||
local data_ubivol="$( nand_find_volume $ubidev rootfs_data )"
|
||||
|
||||
# remove ubiblock device of rootfs
|
||||
local root_ubiblk="ubiblock${root_ubivol:3}"
|
||||
if [ "$root_ubivol" -a -e "/dev/$root_ubiblk" ]; then
|
||||
echo "removing $root_ubiblk"
|
||||
if ! ubiblock -r /dev/$root_ubivol; then
|
||||
echo "cannot remove $root_ubiblk"
|
||||
return 1;
|
||||
fi
|
||||
fi
|
||||
|
||||
# kill volumes
|
||||
[ "$kern_ubivol" ] && ubirmvol /dev/$ubidev -N $CI_KERNPART || true
|
||||
[ "$root_ubivol" ] && ubirmvol /dev/$ubidev -N rootfs || true
|
||||
[ "$data_ubivol" ] && ubirmvol /dev/$ubidev -N rootfs_data || true
|
||||
|
||||
# update kernel
|
||||
if [ "$has_kernel" = "1" ]; then
|
||||
if ! ubimkvol /dev/$ubidev -N $CI_KERNPART -s $kernel_length; then
|
||||
echo "cannot create kernel volume"
|
||||
return 1;
|
||||
fi
|
||||
fi
|
||||
|
||||
# update rootfs
|
||||
local root_size_param
|
||||
if [ "$rootfs_type" = "ubifs" ]; then
|
||||
root_size_param="-m"
|
||||
else
|
||||
root_size_param="-s $rootfs_length"
|
||||
fi
|
||||
if ! ubimkvol /dev/$ubidev -N rootfs $root_size_param; then
|
||||
echo "cannot create rootfs volume"
|
||||
return 1;
|
||||
fi
|
||||
|
||||
# create rootfs_data for non-ubifs rootfs
|
||||
if [ "$rootfs_type" != "ubifs" ]; then
|
||||
if ! ubimkvol /dev/$ubidev -N rootfs_data -m; then
|
||||
echo "cannot initialize rootfs_data volume"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
sync
|
||||
return 0
|
||||
}
|
||||
|
||||
nand_do_upgrade_success() {
|
||||
local conf_tar="/tmp/sysupgrade.tgz"
|
||||
|
||||
sync
|
||||
[ -f "$conf_tar" ] && nand_restore_config "$conf_tar"
|
||||
echo "sysupgrade successful"
|
||||
umount -a
|
||||
reboot -f
|
||||
}
|
||||
|
||||
# Flash the UBI image to MTD partition
|
||||
nand_upgrade_ubinized() {
|
||||
local ubi_file="$1"
|
||||
local mtdnum="$(find_mtd_index "$CI_UBIPART")"
|
||||
|
||||
[ ! "$mtdnum" ] && {
|
||||
CI_UBIPART="rootfs"
|
||||
mtdnum="$(find_mtd_index "$CI_UBIPART")"
|
||||
}
|
||||
|
||||
if [ ! "$mtdnum" ]; then
|
||||
echo "cannot find mtd device $CI_UBIPART"
|
||||
umount -a
|
||||
reboot -f
|
||||
fi
|
||||
|
||||
local mtddev="/dev/mtd${mtdnum}"
|
||||
ubidetach -p "${mtddev}" || true
|
||||
sync
|
||||
ubiformat "${mtddev}" -y -f "${ubi_file}"
|
||||
ubiattach -p "${mtddev}"
|
||||
nand_do_upgrade_success
|
||||
}
|
||||
|
||||
# Write the UBIFS image to UBI volume
|
||||
nand_upgrade_ubifs() {
|
||||
local rootfs_length=`(cat $1 | wc -c) 2> /dev/null`
|
||||
|
||||
nand_upgrade_prepare_ubi "$rootfs_length" "ubifs" "0" "0"
|
||||
|
||||
local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
||||
local root_ubivol="$(nand_find_volume $ubidev rootfs)"
|
||||
ubiupdatevol /dev/$root_ubivol -s $rootfs_length $1
|
||||
|
||||
nand_do_upgrade_success
|
||||
}
|
||||
|
||||
nand_upgrade_tar() {
|
||||
local tar_file="$1"
|
||||
local kernel_mtd="$(find_mtd_index $CI_KERNPART)"
|
||||
|
||||
local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
|
||||
board_dir=${board_dir%/}
|
||||
|
||||
local kernel_length=`(tar xf $tar_file ${board_dir}/kernel -O | wc -c) 2> /dev/null`
|
||||
local rootfs_length=`(tar xf $tar_file ${board_dir}/root -O | wc -c) 2> /dev/null`
|
||||
|
||||
local rootfs_type="$(identify_tar "$tar_file" ${board_dir}/root)"
|
||||
|
||||
local has_kernel=1
|
||||
local has_env=0
|
||||
|
||||
[ "$kernel_length" != 0 -a -n "$kernel_mtd" ] && {
|
||||
tar xf $tar_file ${board_dir}/kernel -O | mtd write - $CI_KERNPART
|
||||
}
|
||||
[ "$kernel_length" = 0 -o ! -z "$kernel_mtd" ] && has_kernel=0
|
||||
|
||||
nand_upgrade_prepare_ubi "$rootfs_length" "$rootfs_type" "$has_kernel" "$has_env"
|
||||
|
||||
local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
||||
[ "$has_kernel" = "1" ] && {
|
||||
local kern_ubivol="$(nand_find_volume $ubidev $CI_KERNPART)"
|
||||
tar xf $tar_file ${board_dir}/kernel -O | \
|
||||
ubiupdatevol /dev/$kern_ubivol -s $kernel_length -
|
||||
}
|
||||
|
||||
local root_ubivol="$(nand_find_volume $ubidev rootfs)"
|
||||
tar xf $tar_file ${board_dir}/root -O | \
|
||||
ubiupdatevol /dev/$root_ubivol -s $rootfs_length -
|
||||
|
||||
nand_do_upgrade_success
|
||||
}
|
||||
|
||||
# Recognize type of passed file and start the upgrade process
|
||||
nand_do_upgrade() {
|
||||
if [ -n "$IS_PRE_UPGRADE" ]; then
|
||||
# Previously, nand_do_upgrade was called from the platform_pre_upgrade
|
||||
# hook; this piece of code handles scripts that haven't been
|
||||
# updated. All scripts should gradually move to call nand_do_upgrade
|
||||
# from platform_do_upgrade instead.
|
||||
export do_upgrade="nand_do_upgrade '$1'"
|
||||
return
|
||||
fi
|
||||
|
||||
local file_type=$(identify $1)
|
||||
|
||||
if type 'platform_nand_pre_upgrade' >/dev/null 2>/dev/null; then
|
||||
platform_nand_pre_upgrade "$1"
|
||||
fi
|
||||
|
||||
[ ! "$(find_mtd_index "$CI_UBIPART")" ] && CI_UBIPART="rootfs"
|
||||
|
||||
case "$file_type" in
|
||||
"ubi") nand_upgrade_ubinized $1;;
|
||||
"ubifs") nand_upgrade_ubifs $1;;
|
||||
*) nand_upgrade_tar $1;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Check if passed file is a valid one for NAND sysupgrade. Currently it accepts
|
||||
# 3 types of files:
|
||||
# 1) UBI - should contain an ubinized image, header is checked for the proper
|
||||
# MAGIC
|
||||
# 2) UBIFS - should contain UBIFS partition that will replace "rootfs" volume,
|
||||
# header is checked for the proper MAGIC
|
||||
# 3) TAR - archive has to include "sysupgrade-BOARD" directory with a non-empty
|
||||
# "CONTROL" file (at this point its content isn't verified)
|
||||
#
|
||||
# You usually want to call this function in platform_check_image.
|
||||
#
|
||||
# $(1): board name, used in case of passing TAR file
|
||||
# $(2): file to be checked
|
||||
nand_do_platform_check() {
|
||||
local board_name="$1"
|
||||
local tar_file="$2"
|
||||
local control_length=`(tar xf $tar_file sysupgrade-$board_name/CONTROL -O | wc -c) 2> /dev/null`
|
||||
local file_type="$(identify $2)"
|
||||
|
||||
[ "$control_length" = 0 -a "$file_type" != "ubi" -a "$file_type" != "ubifs" ] && {
|
||||
echo "Invalid sysupgrade file."
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
150
package/base-files/files/lib/upgrade/stage2
Executable file
150
package/base-files/files/lib/upgrade/stage2
Executable file
@@ -0,0 +1,150 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
. /lib/functions/system.sh
|
||||
|
||||
export IMAGE="$1"
|
||||
COMMAND="$2"
|
||||
|
||||
export ARGV="$IMAGE"
|
||||
export ARGC=1
|
||||
|
||||
export SAVE_CONFIG=1
|
||||
export SAVE_PARTITIONS=1
|
||||
|
||||
export INTERACTIVE=0
|
||||
export VERBOSE=1
|
||||
export CONFFILES=/tmp/sysupgrade.conffiles
|
||||
export CONF_TAR=/tmp/sysupgrade.tgz
|
||||
|
||||
RAMFS_COPY_BIN= # extra programs for temporary ramfs root
|
||||
RAMFS_COPY_DATA= # extra data files
|
||||
|
||||
|
||||
[ -f "$CONF_TAR" ] || export SAVE_CONFIG=0
|
||||
[ -f /tmp/sysupgrade.always.overwrite.bootdisk.partmap ] && export SAVE_PARTITIONS=0
|
||||
|
||||
include /lib/upgrade
|
||||
|
||||
|
||||
supivot() { # <new_root> <old_root>
|
||||
/bin/mount | grep "on $1 type" 2>&- 1>&- || /bin/mount -o bind $1 $1
|
||||
mkdir -p $1$2 $1/proc $1/sys $1/dev $1/tmp $1/overlay && \
|
||||
/bin/mount -o noatime,move /proc $1/proc && \
|
||||
pivot_root $1 $1$2 || {
|
||||
/bin/umount -l $1 $1
|
||||
return 1
|
||||
}
|
||||
|
||||
/bin/mount -o noatime,move $2/sys /sys
|
||||
/bin/mount -o noatime,move $2/dev /dev
|
||||
/bin/mount -o noatime,move $2/tmp /tmp
|
||||
/bin/mount -o noatime,move $2/overlay /overlay 2>&-
|
||||
return 0
|
||||
}
|
||||
|
||||
switch_to_ramfs() {
|
||||
for binary in \
|
||||
/bin/busybox /bin/ash /bin/sh /bin/mount /bin/umount \
|
||||
pivot_root mount_root reboot sync kill sleep \
|
||||
md5sum hexdump cat zcat bzcat dd tar \
|
||||
ls basename find cp mv rm mkdir rmdir mknod touch chmod \
|
||||
'[' printf wc grep awk sed cut \
|
||||
mtd partx losetup mkfs.ext4 \
|
||||
ubiupdatevol ubiattach ubiblock ubiformat \
|
||||
ubidetach ubirsvol ubirmvol ubimkvol \
|
||||
snapshot snapshot_tool \
|
||||
$RAMFS_COPY_BIN
|
||||
do
|
||||
local file="$(which "$binary" 2>/dev/null)"
|
||||
[ -n "$file" ] && install_bin "$file"
|
||||
done
|
||||
install_file /etc/resolv.conf /lib/*.sh /lib/functions/*.sh /lib/upgrade/*.sh $RAMFS_COPY_DATA
|
||||
|
||||
[ -L "/lib64" ] && ln -s /lib $RAM_ROOT/lib64
|
||||
|
||||
supivot $RAM_ROOT /mnt || {
|
||||
echo "Failed to switch over to ramfs. Please reboot."
|
||||
exit 1
|
||||
}
|
||||
|
||||
/bin/mount -o remount,ro /mnt
|
||||
/bin/umount -l /mnt
|
||||
|
||||
grep /overlay /proc/mounts > /dev/null && {
|
||||
/bin/mount -o noatime,remount,ro /overlay
|
||||
/bin/umount -l /overlay
|
||||
}
|
||||
}
|
||||
|
||||
kill_remaining() { # [ <signal> [ <loop> ] ]
|
||||
local loop_limit=10
|
||||
|
||||
local sig="${1:-TERM}"
|
||||
local loop="${2:-0}"
|
||||
local run=true
|
||||
local stat
|
||||
local proc_ppid=$(cut -d' ' -f4 /proc/$$/stat)
|
||||
|
||||
echo -n "Sending $sig to remaining processes ... "
|
||||
|
||||
while $run; do
|
||||
run=false
|
||||
for stat in /proc/[0-9]*/stat; do
|
||||
[ -f "$stat" ] || continue
|
||||
|
||||
local pid name state ppid rest
|
||||
read pid name state ppid rest < $stat
|
||||
name="${name#(}"; name="${name%)}"
|
||||
|
||||
# Skip PID1, our parent, ourself and our children
|
||||
[ $pid -ne 1 -a $pid -ne $proc_ppid -a $pid -ne $$ -a $ppid -ne $$ ] || continue
|
||||
|
||||
local cmdline
|
||||
read cmdline < /proc/$pid/cmdline
|
||||
|
||||
# Skip kernel threads
|
||||
[ -n "$cmdline" ] || continue
|
||||
|
||||
echo -n "$name "
|
||||
kill -$sig $pid 2>/dev/null
|
||||
|
||||
[ $loop -eq 1 ] && run=true
|
||||
done
|
||||
|
||||
let loop_limit--
|
||||
[ $loop_limit -eq 0 ] && {
|
||||
echo
|
||||
echo "Failed to kill all processes."
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
echo
|
||||
}
|
||||
|
||||
|
||||
killall -9 telnetd
|
||||
killall -9 dropbear
|
||||
killall -9 ash
|
||||
|
||||
kill_remaining TERM
|
||||
sleep 3
|
||||
kill_remaining KILL 1
|
||||
|
||||
sleep 1
|
||||
|
||||
|
||||
if [ -n "$IMAGE" ] && type 'platform_pre_upgrade' >/dev/null 2>/dev/null; then
|
||||
IS_PRE_UPGRADE=1 platform_pre_upgrade "$IMAGE"
|
||||
|
||||
# Needs to be unset again because of busybox weirdness ...
|
||||
IS_PRE_UPGRADE=
|
||||
fi
|
||||
|
||||
if [ -n "$(rootfs_type)" ]; then
|
||||
echo "Switching to ramdisk..."
|
||||
switch_to_ramfs
|
||||
fi
|
||||
|
||||
# Exec new shell from ramfs
|
||||
exec /bin/busybox ash -c "$COMMAND"
|
||||
3
package/base-files/files/rom/note
Normal file
3
package/base-files/files/rom/note
Normal file
@@ -0,0 +1,3 @@
|
||||
SQUASHFS USERS:
|
||||
After firstboot has been run, / will be jffs2 and /rom will be squashfs
|
||||
(* except when in failsafe)
|
||||
3
package/base-files/files/sbin/firstboot
Executable file
3
package/base-files/files/sbin/firstboot
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
/sbin/jffs2reset $@
|
||||
18
package/base-files/files/sbin/hotplug-call
Executable file
18
package/base-files/files/sbin/hotplug-call
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006-2016 OpenWrt.org
|
||||
|
||||
export HOTPLUG_TYPE="$1"
|
||||
|
||||
. /lib/functions.sh
|
||||
|
||||
PATH="%PATH%"
|
||||
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
|
||||
}
|
||||
25
package/base-files/files/sbin/led.sh
Executable file
25
package/base-files/files/sbin/led.sh
Executable file
@@ -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
|
||||
}
|
||||
289
package/base-files/files/sbin/sysupgrade
Executable file
289
package/base-files/files/sbin/sysupgrade
Executable file
@@ -0,0 +1,289 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
. /lib/functions/system.sh
|
||||
|
||||
# initialize defaults
|
||||
export MTD_CONFIG_ARGS=""
|
||||
export INTERACTIVE=0
|
||||
export VERBOSE=1
|
||||
export SAVE_CONFIG=1
|
||||
export SAVE_OVERLAY=0
|
||||
export SAVE_PARTITIONS=1
|
||||
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;;
|
||||
-v) export VERBOSE="$(($VERBOSE + 1))";;
|
||||
-q) export VERBOSE="$(($VERBOSE - 1))";;
|
||||
-n) export SAVE_CONFIG=0;;
|
||||
-c) export SAVE_OVERLAY=1;;
|
||||
-p) export SAVE_PARTITIONS=0;;
|
||||
-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
|
||||
|
||||
IMAGE="$1"
|
||||
|
||||
[ -z "$IMAGE" -a -z "$NEED_IMAGE" -o $HELP -gt 0 ] && {
|
||||
cat <<EOF
|
||||
Usage: $0 [<upgrade-option>...] <image file or URL>
|
||||
$0 [-q] [-i] <backup-command> <file>
|
||||
|
||||
upgrade-option:
|
||||
-f <config> 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
|
||||
-p do not attempt to restore the partition table after flash.
|
||||
-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 <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.
|
||||
-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 "$IMAGE" -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
|
||||
|
||||
|
||||
list_conffiles() {
|
||||
awk '
|
||||
BEGIN { conffiles = 0 }
|
||||
/^Conffiles:/ { conffiles = 1; next }
|
||||
!/^ / { conffiles = 0; next }
|
||||
conffiles == 1 { print }
|
||||
' /usr/lib/opkg/status
|
||||
}
|
||||
|
||||
list_changed_conffiles() {
|
||||
# Cannot handle spaces in filenames - but opkg cannot either...
|
||||
list_conffiles | while read file csum; do
|
||||
[ -r "$file" ] || continue
|
||||
|
||||
echo "${csum} ${file}" | sha256sum -sc - || echo "$file"
|
||||
done
|
||||
}
|
||||
|
||||
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;
|
||||
list_changed_conffiles ) | sort -u > "$file"
|
||||
return 0
|
||||
}
|
||||
|
||||
add_overlayfiles() {
|
||||
local file="$1"
|
||||
find /overlay/upper/etc/ -type f -o -type l | sed \
|
||||
-e 's,^/overlay\/upper/,/,' \
|
||||
-e '\,/META_[a-zA-Z0-9]*$,d' \
|
||||
-e '\,/functions.sh$,d' \
|
||||
-e '\,/[^/]*-opkg$,d' \
|
||||
> "$file"
|
||||
return 0
|
||||
}
|
||||
|
||||
# hooks
|
||||
sysupgrade_image_check="fwtool_check_image platform_check_image"
|
||||
sysupgrade_pre_upgrade=""
|
||||
|
||||
if [ $SAVE_OVERLAY = 1 ]; then
|
||||
[ ! -d /overlay/upper/etc ] && {
|
||||
echo "Cannot find '/overlay/upper/etc', required for '-c'"
|
||||
exit 1
|
||||
}
|
||||
sysupgrade_init_conffiles="add_overlayfiles"
|
||||
else
|
||||
sysupgrade_init_conffiles="add_uci_conffiles"
|
||||
fi
|
||||
|
||||
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
|
||||
rm -f "$conf_tar"
|
||||
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 [ "$?" -ne 0 ]; then
|
||||
echo "Failed to create the configuration backup."
|
||||
rm -f "$conf_tar"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -f "$CONFFILES"
|
||||
}
|
||||
|
||||
if [ $CONF_BACKUP_LIST -eq 1 ]; then
|
||||
run_hooks "$CONFFILES" $sysupgrade_init_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
|
||||
}
|
||||
|
||||
case "$IMAGE" in
|
||||
http://*|\
|
||||
https://*)
|
||||
wget -O/tmp/sysupgrade.img "$IMAGE"
|
||||
IMAGE=/tmp/sysupgrade.img
|
||||
;;
|
||||
esac
|
||||
|
||||
IMAGE="$(readlink -f "$IMAGE")"
|
||||
|
||||
case "$IMAGE" in
|
||||
'')
|
||||
echo "Image file not found."
|
||||
exit 1
|
||||
;;
|
||||
/tmp/*) ;;
|
||||
*)
|
||||
v "Image not in /tmp, copying..."
|
||||
cp -f "$IMAGE" /tmp/sysupgrade.img
|
||||
IMAGE=/tmp/sysupgrade.img
|
||||
;;
|
||||
esac
|
||||
|
||||
export ARGV="$IMAGE"
|
||||
export ARGC=1
|
||||
|
||||
for check in $sysupgrade_image_check; do
|
||||
( $check "$IMAGE" ) || {
|
||||
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
|
||||
[ $TEST -eq 1 ] || rm -f "$CONF_TAR"
|
||||
export SAVE_CONFIG=0
|
||||
fi
|
||||
|
||||
if [ $TEST -eq 1 ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ $SAVE_PARTITIONS -eq 0 ]; then
|
||||
touch /tmp/sysupgrade.always.overwrite.bootdisk.partmap
|
||||
else
|
||||
rm -f /tmp/sysupgrade.always.overwrite.bootdisk.partmap
|
||||
fi
|
||||
|
||||
run_hooks "" $sysupgrade_pre_upgrade
|
||||
|
||||
install_bin /sbin/upgraded
|
||||
v "Commencing upgrade. Closing all shell sessions."
|
||||
|
||||
COMMAND='. /lib/functions.sh; include /lib/upgrade; do_upgrade_stage2'
|
||||
|
||||
if [ -n "$FAILSAFE" ]; then
|
||||
printf '%s\x00%s\x00%s' "$RAM_ROOT" "$IMAGE" "$COMMAND" >/tmp/sysupgrade
|
||||
lock -u /tmp/.failsafe
|
||||
else
|
||||
ubus call system sysupgrade "{
|
||||
\"prefix\": $(json_string "$RAM_ROOT"),
|
||||
\"path\": $(json_string "$IMAGE"),
|
||||
\"command\": $(json_string "$COMMAND")
|
||||
}"
|
||||
fi
|
||||
20
package/base-files/files/sbin/urandom_seed
Executable file
20
package/base-files/files/sbin/urandom_seed
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
trap '[ "$?" -eq 0 ] || echo "An error occured" >&2' EXIT
|
||||
|
||||
save() {
|
||||
touch "$1.tmp"
|
||||
chown root:root "$1.tmp"
|
||||
chmod 600 "$1.tmp"
|
||||
getrandom 512 > "$1.tmp"
|
||||
mv "$1.tmp" "$1"
|
||||
echo "Seed saved ($1)"
|
||||
}
|
||||
|
||||
SEED="$(uci -q get system.@system[0].urandom_seed || true)"
|
||||
[ "${SEED:0:1}" == "/" ] && save "$SEED"
|
||||
|
||||
SEED=/etc/urandom.seed
|
||||
[ ! -f $SEED ] && save "$SEED"
|
||||
true
|
||||
246
package/base-files/files/sbin/wifi
Executable file
246
package/base-files/files/sbin/wifi
Executable file
@@ -0,0 +1,246 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
|
||||
. /lib/functions.sh
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $0 [config|up|down|reload|status]
|
||||
enables (default), disables or configures devices not yet configured.
|
||||
EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
ubus_wifi_cmd() {
|
||||
local cmd="$1"
|
||||
local dev="$2"
|
||||
|
||||
json_init
|
||||
[ -n "$2" ] && json_add_string device "$2"
|
||||
ubus call network.wireless "$1" "$(json_dump)"
|
||||
}
|
||||
|
||||
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() {
|
||||
for device in ${2:-$DEVICES}; do (
|
||||
config_get disabled "$device" disabled
|
||||
[ "$disabled" = "1" ] && {
|
||||
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"
|
||||
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_notice() {
|
||||
>&2 echo "WARNING: Wifi detect is deprecated. Use wifi config instead"
|
||||
>&2 echo "For more information, see commit 5f8f8a366136a07df661e31decce2458357c167a"
|
||||
exit 1
|
||||
}
|
||||
|
||||
wifi_config() {
|
||||
[ ! -f /etc/config/wireless ] && touch /etc/config/wireless
|
||||
|
||||
for driver in $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_notice ;;
|
||||
config) wifi_config ;;
|
||||
status) ubus_wifi_cmd "status" "$2";;
|
||||
reload) wifi_reload "$2";;
|
||||
reload_legacy) wifi_reload_legacy "$2";;
|
||||
--help|help) usage;;
|
||||
''|up) ubus call network reload; wifi_updown "enable" "$2";;
|
||||
*) usage; exit 1;;
|
||||
esac
|
||||
18
package/base-files/files/usr/lib/os-release
Normal file
18
package/base-files/files/usr/lib/os-release
Normal file
@@ -0,0 +1,18 @@
|
||||
NAME="%D"
|
||||
VERSION="%V"
|
||||
ID="%d"
|
||||
ID_LIKE="lede openwrt"
|
||||
PRETTY_NAME="%D %V"
|
||||
VERSION_ID="%v"
|
||||
HOME_URL="%u"
|
||||
BUG_URL="%b"
|
||||
SUPPORT_URL="%s"
|
||||
BUILD_ID="%R"
|
||||
LEDE_BOARD="%S"
|
||||
LEDE_ARCH="%A"
|
||||
LEDE_TAINTS="%t"
|
||||
LEDE_DEVICE_MANUFACTURER="%M"
|
||||
LEDE_DEVICE_MANUFACTURER_URL="%m"
|
||||
LEDE_DEVICE_PRODUCT="%P"
|
||||
LEDE_DEVICE_REVISION="%h"
|
||||
LEDE_RELEASE="%D %V %C"
|
||||
5
package/base-files/files/usr/libexec/login.sh
Executable file
5
package/base-files/files/usr/libexec/login.sh
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ "$(uci -q get system.@system[0].ttylogin)" == 1 ] || exec /bin/ash --login
|
||||
|
||||
exec /bin/login
|
||||
277
package/base-files/image-config.in
Normal file
277
package/base-files/image-config.in
Normal file
@@ -0,0 +1,277 @@
|
||||
# Copyright (C) 2006-2012 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
menuconfig PREINITOPT
|
||||
bool "Preinit configuration options" if IMAGEOPT
|
||||
default n
|
||||
help
|
||||
These options are used to control the environment used to initialize
|
||||
the system before running init (which typically mean /sbin/init which
|
||||
switches to multiuser mode).
|
||||
|
||||
config TARGET_PREINIT_SUPPRESS_STDERR
|
||||
bool "Suppress stderr messages during preinit" if PREINITOPT
|
||||
default y
|
||||
help
|
||||
Sends stderr to null during preinit. This is the default behaviour
|
||||
in previous versions of OpenWrt. This also prevents init process
|
||||
itself from displaying stderr, however processes launched by init
|
||||
in multiuser through inittab will use the current terminal (e.g.
|
||||
the ash shell launched by inittab will display stderr). That's
|
||||
the same behaviour as seen in previous version of OpenWrt.
|
||||
|
||||
config TARGET_PREINIT_DISABLE_FAILSAFE
|
||||
bool
|
||||
prompt "Disable failsafe" if PREINITOPT
|
||||
default n
|
||||
help
|
||||
Disable failsafe mode. While it is very handy while
|
||||
experimenting or developing it really ought to be
|
||||
disabled in production environments as it is a major
|
||||
security loophole.
|
||||
|
||||
config TARGET_PREINIT_TIMEOUT
|
||||
int
|
||||
prompt "Failsafe/Debug wait timeout" if PREINITOPT
|
||||
default 2
|
||||
help
|
||||
How long to wait for failsafe mode to be entered or for
|
||||
a debug option to be pressed before continuing with a
|
||||
regular boot.
|
||||
|
||||
config TARGET_PREINIT_SHOW_NETMSG
|
||||
bool
|
||||
prompt "Show all preinit network messages" if PREINITOPT
|
||||
default n
|
||||
help
|
||||
Show preinit all network messages (via netmsg broadcast), not only
|
||||
the message indicating to press reset to enter failsafe. Note that
|
||||
if the architecture doesn't define an interface, and there is no
|
||||
'Preinit network interface' defined, then no messages will be
|
||||
emitted, even if this is set.
|
||||
|
||||
config TARGET_PREINIT_SUPPRESS_FAILSAFE_NETMSG
|
||||
bool
|
||||
prompt "Suppress network message indicating failsafe" if ( PREINITOPT && !TARGET_PREINIT_SHOW_NETMSG && !TARGET_PREINIT_DISABLE_FAILSAFE )
|
||||
default n
|
||||
help
|
||||
If "Show all preinit network messages" above is not set, then
|
||||
setting this option suppresses the only message that would be
|
||||
emitted otherwise, name the network message to enter failsafe
|
||||
(via netmsg).
|
||||
|
||||
config TARGET_PREINIT_IFNAME
|
||||
string
|
||||
prompt "Preinit network interface" if PREINITOPT
|
||||
default ""
|
||||
help
|
||||
Interface for sending preinit messages to network, and any other
|
||||
default networking in failsafe or preinit. If empty
|
||||
uses $ifname (if defined in /etc/preinit.arch).
|
||||
|
||||
config TARGET_PREINIT_IP
|
||||
string
|
||||
prompt "IP address for preinit network messages" if PREINITOPT
|
||||
default "192.168.1.1"
|
||||
help
|
||||
IP address used to configure interface for preinit network
|
||||
messages, including failsafe messages
|
||||
|
||||
config TARGET_PREINIT_NETMASK
|
||||
string
|
||||
prompt "Netmask for preinit network messages" if PREINITOPT
|
||||
default "255.255.255.0"
|
||||
help
|
||||
Netmask used to configure interface for preinit network
|
||||
messages, including failsafes messages
|
||||
|
||||
config TARGET_PREINIT_BROADCAST
|
||||
string
|
||||
prompt "Broadcast address for preinit network messages" if PREINITOPT
|
||||
default "192.168.1.255"
|
||||
help
|
||||
Broadcast address to which to send preinit network messages, as
|
||||
as failsafe messages
|
||||
|
||||
|
||||
menuconfig INITOPT
|
||||
bool "Init configuration options" if IMAGEOPT
|
||||
default n
|
||||
help
|
||||
These option choose the command that will run as the 'init' command
|
||||
(that is which is responsible for controlling the system once preinit
|
||||
transfers control to it) as well as some options controlling its
|
||||
behaviour. Normally init is /sbin/init.
|
||||
|
||||
config TARGET_INIT_PATH
|
||||
string
|
||||
prompt "PATH for regular boot" if INITOPT
|
||||
default "/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
help
|
||||
Default PATH used during normal operation
|
||||
|
||||
config TARGET_INIT_ENV
|
||||
string
|
||||
prompt "Environment variables to set when starting init (start with none)" if INITOPT
|
||||
default ""
|
||||
help
|
||||
Should be a space seperated list of variable assignments. These
|
||||
variables will be present in the environment. Spaces may not be
|
||||
present (including through expansion) even in a quoted string
|
||||
(env doesn't understanding quoting).
|
||||
|
||||
config TARGET_INIT_CMD
|
||||
string
|
||||
prompt "Init command" if INITOPT
|
||||
default "/sbin/init"
|
||||
help
|
||||
The executable to run as the init process. Is 'exec'd by
|
||||
preinit (which is the init that the kernel launches on boot).
|
||||
|
||||
config TARGET_INIT_SUPPRESS_STDERR
|
||||
bool
|
||||
prompt "Suppress stderr messages of init" if INITOPT
|
||||
default y
|
||||
help
|
||||
Prevents showing stderr messages for init command if not already
|
||||
suppressed during preinit. This is the default behaviour in
|
||||
previous versions of OpenWrt. Removing this does nothing if
|
||||
stderr is suppressed during preinit (which is the default).
|
||||
|
||||
|
||||
menuconfig VERSIONOPT
|
||||
bool "Version configuration options" if IMAGEOPT
|
||||
default n
|
||||
help
|
||||
These options allow to override the version information embedded in
|
||||
the /etc/openwrt_version, /etc/openwrt_release, /etc/banner,
|
||||
/etc/opkg.conf, and /etc/os-release files. Usually there is no need
|
||||
to set these, but they're useful for release builds or custom OpenWrt
|
||||
redistributions that should carry custom version tags.
|
||||
|
||||
if VERSIONOPT
|
||||
|
||||
config VERSION_DIST
|
||||
string
|
||||
prompt "Release distribution"
|
||||
default "OpenWrt"
|
||||
help
|
||||
This is the name of the release distribution.
|
||||
If unspecified, it defaults to OpenWrt.
|
||||
|
||||
config VERSION_NUMBER
|
||||
string
|
||||
prompt "Release version number"
|
||||
help
|
||||
This is the release version number embedded in the image.
|
||||
If unspecified, it defaults to SNAPSHOT for the master branch
|
||||
or to ##.##-SNAPSHOT on release branches.
|
||||
|
||||
config VERSION_CODE
|
||||
string
|
||||
prompt "Release version code"
|
||||
help
|
||||
This is the release version code embedded in the image.
|
||||
If unspecified, it defaults to a revision number describing the
|
||||
repository version of the source, e.g. the number of commits
|
||||
since a branch point or a short Git commit ID.
|
||||
|
||||
config VERSION_REPO
|
||||
string
|
||||
prompt "Release repository"
|
||||
default "http://downloads.openwrt.org/releases/18.06-SNAPSHOT"
|
||||
help
|
||||
This is the repository address embedded in the image, it defaults
|
||||
to the trunk snapshot repo; the url may contain the following placeholders:
|
||||
%R .. Repository revision ID
|
||||
%V .. Configured release version number or "SNAPSHOT", uppercase
|
||||
%v .. Configured release version number or "snapshot", lowercase
|
||||
%C .. Configured release revision code or value of %R, uppercase
|
||||
%c .. Configured release revision code or value of %R, lowercase
|
||||
%D .. Distribution name or "OpenWrt", uppercase
|
||||
%d .. Distribution name or "openwrt", lowercase
|
||||
%T .. Target name
|
||||
%S .. Target/Subtarget name
|
||||
%A .. Package architecture
|
||||
%t .. Build taint flags, e.g. "no-all busybox"
|
||||
%M .. Manufacturer name or "OpenWrt"
|
||||
%P .. Product name or "Generic"
|
||||
%h .. Hardware revision or "v0"
|
||||
|
||||
config VERSION_HOME_URL
|
||||
string
|
||||
prompt "Release Homepage"
|
||||
help
|
||||
This is the release version homepage
|
||||
|
||||
config VERSION_MANUFACTURER
|
||||
string
|
||||
prompt "Manufacturer name"
|
||||
help
|
||||
This is the manufacturer name embedded in /etc/device_info
|
||||
Useful for OEMs building OpenWrt based firmware
|
||||
|
||||
config VERSION_MANUFACTURER_URL
|
||||
string
|
||||
prompt "Manufacturer URL"
|
||||
help
|
||||
This is an URL to the manufacturer's website embedded in /etc/device_info
|
||||
Useful for OEMs building OpenWrt based firmware
|
||||
|
||||
config VERSION_BUG_URL
|
||||
string
|
||||
prompt "Bug reporting URL"
|
||||
help
|
||||
This is an URL to provide users for providing bug reports
|
||||
|
||||
config VERSION_SUPPORT_URL
|
||||
string
|
||||
prompt "Support URL"
|
||||
help
|
||||
This an URL to provide users seeking support
|
||||
|
||||
config VERSION_PRODUCT
|
||||
string
|
||||
prompt "Product name"
|
||||
help
|
||||
This is the product name embedded in /etc/device_info
|
||||
Useful for OEMs building OpenWrt based firmware
|
||||
|
||||
config VERSION_HWREV
|
||||
string
|
||||
prompt "Hardware revision"
|
||||
help
|
||||
This is the hardware revision string embedded in /etc/device_info
|
||||
Useful for OEMs building OpenWrt based firmware
|
||||
|
||||
config VERSION_FILENAMES
|
||||
bool
|
||||
prompt "Version number in filenames"
|
||||
default y
|
||||
help
|
||||
Enable this to include the version number in firmware image, SDK-
|
||||
and Image Builder archive file names
|
||||
|
||||
config VERSION_CODE_FILENAMES
|
||||
bool
|
||||
prompt "Revision code in filenames"
|
||||
default y
|
||||
help
|
||||
Enable this to include the revision identifier or the configured
|
||||
version code into the firmware image, SDK- and Image Builder archive
|
||||
file names
|
||||
endif
|
||||
|
||||
|
||||
menuconfig PER_FEED_REPO
|
||||
bool "Separate feed repositories" if IMAGEOPT
|
||||
default y
|
||||
help
|
||||
If set, a separate repository is generated within bin/*/packages/
|
||||
for the core packages and each enabled feed.
|
||||
|
||||
source "tmp/.config-feeds.in"
|
||||
Reference in New Issue
Block a user