mirror of
https://github.com/kenzok8/small-package
synced 2025-01-05 11:36:47 +08:00
update 2023-09-26 00:24:02
This commit is contained in:
parent
dbb23020f5
commit
8d5b5ba320
249
base-files/Makefile
Normal file
249
base-files/Makefile
Normal file
@ -0,0 +1,249 @@
|
||||
#
|
||||
# Copyright (C) 2007-2021 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_FLAGS:=nonshared
|
||||
PKG_RELEASE:=$(COMMITCOUNT)
|
||||
|
||||
PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
|
||||
PKG_BUILD_DEPENDS:=usign/host ucert/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_LEGACY_SDCARD_SUPPORT \
|
||||
CONFIG_EMMC_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 +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/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/shinit
|
||||
/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
|
||||
ifeq ($(CONFIG_TARGET_DEFAULT_LAN_IP_FROM_PREINIT),y)
|
||||
mkdir -p $(1)/etc/board.d
|
||||
echo '. /lib/functions/uci-defaults.sh' >$(1)/etc/board.d/99-lan-ip
|
||||
echo 'logger -t 99-lan-ip "setting custom default LAN IP"' >>$(1)/etc/board.d/99-lan-ip
|
||||
echo 'board_config_update' >>$(1)/etc/board.d/99-lan-ip
|
||||
echo 'json_select network' >>$(1)/etc/board.d/99-lan-ip
|
||||
echo 'json_select lan' >>$(1)/etc/board.d/99-lan-ip
|
||||
echo 'json_add_string ipaddr $(if $(CONFIG_TARGET_PREINIT_IP),$(CONFIG_TARGET_PREINIT_IP),"192.168.1.1")' >>$(1)/etc/board.d/99-lan-ip
|
||||
echo 'json_add_string netmask $(if $(CONFIG_TARGET_PREINIT_NETMASK),$(CONFIG_TARGET_PREINIT_NETMASK),"255.255.255.0")' >>$(1)/etc/board.d/99-lan-ip
|
||||
echo 'json_select ..' >>$(1)/etc/board.d/99-lan-ip
|
||||
echo 'json_select ..' >>$(1)/etc/board.d/99-lan-ip
|
||||
echo 'board_config_flush' >>$(1)/etc/board.d/99-lan-ip
|
||||
endif
|
||||
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"
|
||||
|
||||
[ -s $(BUILD_KEY).ucert ] || \
|
||||
$(STAGING_DIR_HOST)/bin/ucert -I -c $(BUILD_KEY).ucert -p $(BUILD_KEY).pub -s $(BUILD_KEY)
|
||||
|
||||
endef
|
||||
|
||||
ifndef CONFIG_BUILDBOT
|
||||
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
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NAND_SUPPORT),)
|
||||
define Package/base-files/nand-support
|
||||
rm -f $(1)/lib/upgrade/nand.sh
|
||||
endef
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EMMC_SUPPORT),)
|
||||
define Package/base-files/emmc-support
|
||||
rm -f $(1)/lib/upgrade/emmc.sh
|
||||
endef
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LEGACY_SDCARD_SUPPORT),)
|
||||
define Package/base-files/legacy-sdcard-support
|
||||
rm -f $(1)/lib/upgrade/legacy-sdcard.sh
|
||||
endef
|
||||
endif
|
||||
|
||||
|
||||
define Package/base-files/install
|
||||
$(CP) ./files/* $(1)/
|
||||
$(Package/base-files/install-key)
|
||||
$(Package/base-files/nand-support)
|
||||
$(Package/base-files/legacy-sdcard-support)
|
||||
$(Package/base-files/emmc-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/device_info \
|
||||
$(1)/etc/openwrt_release \
|
||||
$(1)/etc/openwrt_version \
|
||||
$(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 \
|
||||
$(1)/dev \
|
||||
$(1)/etc/config \
|
||||
$(1)/etc/crontabs \
|
||||
$(1)/etc/rc.d \
|
||||
$(1)/overlay \
|
||||
$(1)/lib/firmware \
|
||||
$(1)/mnt \
|
||||
$(1)/proc \
|
||||
$(1)/tmp \
|
||||
$(1)/usr/lib \
|
||||
$(1)/usr/bin \
|
||||
$(1)/sys \
|
||||
$(1)/www \
|
||||
$(1)/root
|
||||
|
||||
$(LN) /proc/mounts $(1)/etc/mtab
|
||||
$(if $(LIB_SUFFIX),-$(LN) lib $(1)/lib$(LIB_SUFFIX))
|
||||
$(if $(LIB_SUFFIX),-$(LN) lib $(1)/usr/lib$(LIB_SUFFIX))
|
||||
|
||||
ifneq ($(CONFIG_TARGET_ROOTFS_PERSIST_VAR),y)
|
||||
rm -f $(1)/var
|
||||
$(LN) tmp $(1)/var
|
||||
else
|
||||
mkdir -p $(1)/var
|
||||
$(LN) /tmp/run $(1)/var/run
|
||||
endif
|
||||
$(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.buildinfo >>$(1)/etc/build.config; \
|
||||
cat $(BIN_DIR)/feeds.buildinfo >>$(1)/etc/build.feeds; \
|
||||
cat $(BIN_DIR)/version.buildinfo >>$(1)/etc/build.version)
|
||||
|
||||
$(if $(CONFIG_CLEAN_IPKG),, \
|
||||
mkdir -p $(1)/etc/opkg; \
|
||||
$(call FeedSourcesAppend,$(1)/etc/opkg/distfeeds.conf); \
|
||||
$(VERSION_SED_SCRIPT) $(1)/etc/opkg/distfeeds.conf)
|
||||
$(if $(CONFIG_IPK_FILES_CHECKSUMS),, \
|
||||
rm -f $(1)/sbin/pkg_check)
|
||||
|
||||
$(if $(CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE), \
|
||||
rm -f $(1)/etc/banner.failsafe,)
|
||||
endef
|
||||
|
||||
ifneq ($(DUMP),1)
|
||||
-include $(PLATFORM_DIR)/base-files.mk
|
||||
-include $(PLATFORM_SUBDIR)/base-files.mk
|
||||
endif
|
||||
|
||||
$(eval $(call BuildPackage,base-files))
|
14
base-files/files/bin/board_detect
Executable file
14
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
|
||||
[ -s $a ] || continue;
|
||||
$(. $a)
|
||||
done
|
||||
}
|
||||
|
||||
[ -s "$CFG" ] || return 1
|
542
base-files/files/bin/config_generate
Executable file
542
base-files/files/bin/config_generate
Executable file
@ -0,0 +1,542 @@
|
||||
#!/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_bridge() {
|
||||
local name=$1
|
||||
local macaddr=$2
|
||||
uci -q batch <<-EOF
|
||||
set network.$name=device
|
||||
set network.$name.name=$name
|
||||
set network.$name.type=bridge
|
||||
EOF
|
||||
if [ -n "$macaddr" ]; then
|
||||
uci -q batch <<-EOF
|
||||
set network.$name.macaddr=$macaddr
|
||||
EOF
|
||||
fi
|
||||
}
|
||||
|
||||
bridge_vlan_id=0
|
||||
generate_bridge_vlan() {
|
||||
local name=$1_vlan
|
||||
local device=$2
|
||||
local ports="$3"
|
||||
local vlan="$4"
|
||||
uci -q batch <<-EOF
|
||||
set network.$name=bridge-vlan
|
||||
set network.$name.device='$device'
|
||||
set network.$name.vlan='$vlan'
|
||||
set network.$name.ports='$ports'
|
||||
EOF
|
||||
}
|
||||
|
||||
generate_static_network() {
|
||||
uci -q batch <<-EOF
|
||||
delete network.loopback
|
||||
set network.loopback='interface'
|
||||
set network.loopback.device='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 ports device macaddr protocol type ipaddr netmask vlan
|
||||
local bridge=$2
|
||||
|
||||
json_select network
|
||||
json_select "$1"
|
||||
json_get_vars device macaddr metric protocol ipaddr netmask vlan
|
||||
json_get_values ports ports
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
[ -n "$device" -o -n "$ports" ] || return
|
||||
|
||||
# Force bridge for "lan" as it may have other devices (e.g. wireless)
|
||||
# bridged
|
||||
[ "$1" = "lan" -a -z "$ports" ] && {
|
||||
ports="$device"
|
||||
}
|
||||
|
||||
[ -n "$ports" -a -z "$bridge" ] && {
|
||||
uci -q batch <<-EOF
|
||||
add network device
|
||||
set network.@device[-1].name='br-$1'
|
||||
set network.@device[-1].type='bridge'
|
||||
EOF
|
||||
for port in $ports; do uci add_list network.@device[-1].ports="$port"; done
|
||||
[ -n "$macaddr" ] && {
|
||||
for port in $ports; do
|
||||
uci -q batch <<-EOF
|
||||
add network device
|
||||
set network.@device[-1].name='$port'
|
||||
set network.@device[-1].macaddr='$macaddr'
|
||||
EOF
|
||||
done
|
||||
}
|
||||
device=br-$1
|
||||
type=
|
||||
macaddr=""
|
||||
}
|
||||
|
||||
[ -n "$bridge" ] && {
|
||||
[ -z "$ports" ] && ports="$device"
|
||||
if [ -z "$vlan" ]; then
|
||||
bridge_vlan_id=$((bridge_vlan_id + 1))
|
||||
vlan=$bridge_vlan_id
|
||||
fi
|
||||
generate_bridge_vlan $1 $bridge "$ports" $vlan
|
||||
device=$bridge.$vlan
|
||||
type=""
|
||||
}
|
||||
|
||||
if [ -n "$macaddr" ]; then
|
||||
uci -q batch <<-EOF
|
||||
add network device
|
||||
set network.@device[-1].name='$device'
|
||||
set network.@device[-1].macaddr='$macaddr'
|
||||
EOF
|
||||
fi
|
||||
|
||||
uci -q batch <<-EOF
|
||||
delete network.$1
|
||||
set network.$1='interface'
|
||||
set network.$1.type='$type'
|
||||
set network.$1.device='$device'
|
||||
set network.$1.metric='$metric'
|
||||
set network.$1.proto='none'
|
||||
EOF
|
||||
|
||||
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" ] && device="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.device='$device'
|
||||
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.device='@${1}'
|
||||
set network.${1}6.proto='dhcpv6'
|
||||
EOF
|
||||
}
|
||||
;;
|
||||
|
||||
ncm|\
|
||||
qmi|\
|
||||
mbim)
|
||||
uci -q batch <<-EOF
|
||||
set network.$1.proto='${protocol}'
|
||||
set network.$1.pdptype='ipv4'
|
||||
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 \
|
||||
ar8xxx_mib_type ar8xxx_mib_poll_interval
|
||||
|
||||
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'
|
||||
set network.@switch[-1].ar8xxx_mib_type='$ar8xxx_mib_type'
|
||||
set network.@switch[-1].ar8xxx_mib_poll_interval='$ar8xxx_mib_poll_interval'
|
||||
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
|
||||
|
||||
local compat_version
|
||||
if json_get_var compat_version compat_version; then
|
||||
uci -q set "system.@system[-1].compat_version=$compat_version"
|
||||
else
|
||||
uci -q set "system.@system[-1].compat_version=1.0"
|
||||
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 mode
|
||||
json_get_vars port_mask speed_mask mode
|
||||
uci -q batch <<-EOF
|
||||
set system.$cfg.port_mask='$port_mask'
|
||||
set system.$cfg.speed_mask='$speed_mask'
|
||||
set system.$cfg.mode='$mode'
|
||||
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})"
|
||||
|
||||
umask 077
|
||||
|
||||
if [ ! -s /etc/config/network ]; then
|
||||
bridge_name=""
|
||||
touch /etc/config/network
|
||||
generate_static_network
|
||||
|
||||
json_get_vars bridge
|
||||
[ -n "$bridge" ] && {
|
||||
json_select bridge
|
||||
json_get_vars name macaddr
|
||||
generate_bridge "$name" "$macaddr"
|
||||
json_select ..
|
||||
bridge_name=$name
|
||||
}
|
||||
|
||||
json_get_keys keys network
|
||||
for key in $keys; do generate_network $key $bridge_name; 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
|
88
base-files/files/bin/ipcalc.sh
Executable file
88
base-files/files/bin/ipcalc.sh
Executable file
@ -0,0 +1,88 @@
|
||||
#!/usr/bin/awk -f
|
||||
|
||||
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) {
|
||||
ret=0
|
||||
n=split(ip,a,"\\.")
|
||||
for (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;x++) {
|
||||
ret=and(ip,255)"."ret
|
||||
ip=rshift(ip,8)
|
||||
}
|
||||
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)
|
||||
prefix=32-bitcount(compl32(netmask))
|
||||
broadcast=or(network,compl32(netmask))
|
||||
|
||||
print "IP="int2ip(ipaddr)
|
||||
print "NETMASK="int2ip(netmask)
|
||||
print "BROADCAST="int2ip(broadcast)
|
||||
print "NETWORK="int2ip(network)
|
||||
print "PREFIX="prefix
|
||||
|
||||
# range calculations:
|
||||
# ipcalc <ip> <netmask> <start> <num>
|
||||
|
||||
if (ARGC <= 3)
|
||||
exit(0)
|
||||
|
||||
start=or(network,and(ip2int(ARGV[3]),compl32(netmask)))
|
||||
limit=network+1
|
||||
if (start<limit) start=limit
|
||||
if (start==ipaddr) start=ipaddr+1
|
||||
|
||||
end=start+ARGV[4]
|
||||
limit=or(network,compl32(netmask))-1
|
||||
if (end>limit) end=limit
|
||||
if (end==ipaddr) end=ipaddr-1
|
||||
|
||||
if (start>end) {
|
||||
print "network ("int2ip(network)"/"prefix") too small" > "/dev/stderr"
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if (ipaddr > start && ipaddr < end) {
|
||||
print "warning: ipaddr inside range - this might not be supported in future releases of Openwrt" > "/dev/stderr"
|
||||
}
|
||||
|
||||
print "START="int2ip(start)
|
||||
print "END="int2ip(end)
|
||||
}
|
8
base-files/files/etc/banner
Normal file
8
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
base-files/files/etc/banner.failsafe
Normal file
15
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
|
||||
=======================================================
|
||||
|
16
base-files/files/etc/board.d/99-default_network
Normal file
16
base-files/files/etc/board.d/99-default_network
Normal file
@ -0,0 +1,16 @@
|
||||
#
|
||||
# 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
base-files/files/etc/device_info
Normal file
4
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'
|
52
base-files/files/etc/diag.sh
Normal file
52
base-files/files/etc/diag.sh
Normal file
@ -0,0 +1,52 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006-2019 OpenWrt.org
|
||||
|
||||
. /lib/functions/leds.sh
|
||||
|
||||
boot="$(get_dt_led boot)"
|
||||
failsafe="$(get_dt_led failsafe)"
|
||||
running="$(get_dt_led running)"
|
||||
upgrade="$(get_dt_led upgrade)"
|
||||
|
||||
set_led_state() {
|
||||
status_led="$boot"
|
||||
|
||||
case "$1" in
|
||||
preinit)
|
||||
status_led_blink_preinit
|
||||
;;
|
||||
failsafe)
|
||||
status_led_off
|
||||
[ -n "$running" ] && {
|
||||
status_led="$running"
|
||||
status_led_off
|
||||
}
|
||||
status_led="$failsafe"
|
||||
status_led_blink_failsafe
|
||||
;;
|
||||
preinit_regular)
|
||||
status_led_blink_preinit_regular
|
||||
;;
|
||||
upgrade)
|
||||
[ -n "$running" ] && {
|
||||
status_led="$running"
|
||||
status_led_off
|
||||
}
|
||||
status_led="$upgrade"
|
||||
status_led_blink_preinit_regular
|
||||
;;
|
||||
done)
|
||||
status_led_off
|
||||
[ "$status_led" != "$running" ] && \
|
||||
status_led_restore_trigger "boot"
|
||||
[ -n "$running" ] && {
|
||||
status_led="$running"
|
||||
status_led_on
|
||||
}
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
set_state() {
|
||||
[ -n "$boot" -o -n "$failsafe" -o -n "$running" -o -n "$upgrade" ] && set_led_state "$1"
|
||||
}
|
6
base-files/files/etc/ethers
Normal file
6
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
base-files/files/etc/fstab
Normal file
1
base-files/files/etc/fstab
Normal file
@ -0,0 +1 @@
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
11
base-files/files/etc/group
Normal file
11
base-files/files/etc/group
Normal file
@ -0,0 +1,11 @@
|
||||
root:x:0:
|
||||
daemon:x:1:
|
||||
adm:x:4:
|
||||
mail:x:8:
|
||||
dialout:x:20:
|
||||
audio:x:29:
|
||||
www-data:x:33:
|
||||
ftp:x:55:
|
||||
users:x:100:
|
||||
network:x:101:
|
||||
nogroup:x:65534:
|
5
base-files/files/etc/hosts
Normal file
5
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
base-files/files/etc/hotplug.d/net/00-sysctl
Normal file
9
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
|
55
base-files/files/etc/init.d/boot
Executable file
55
base-files/files/etc/init.d/boot
Executable file
@ -0,0 +1,55 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2006-2011 OpenWrt.org
|
||||
|
||||
START=10
|
||||
STOP=90
|
||||
|
||||
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
|
||||
|
||||
mkdir -p /var/lock
|
||||
chmod 1777 /var/lock
|
||||
mkdir -p /var/log
|
||||
mkdir -p /var/run
|
||||
mkdir -p /var/state
|
||||
mkdir -p /var/tmp
|
||||
mkdir -p /tmp/.uci
|
||||
chmod 0700 /tmp/.uci
|
||||
touch /var/log/wtmp
|
||||
touch /var/log/lastlog
|
||||
mkdir -p /tmp/resolv.conf.d
|
||||
touch /tmp/resolv.conf.d/resolv.conf.auto
|
||||
ln -sf /tmp/resolv.conf.d/resolv.conf.auto /tmp/resolv.conf
|
||||
grep -q debugfs /proc/filesystems && /bin/mount -o noatime -t debugfs debugfs /sys/kernel/debug
|
||||
grep -q bpf /proc/filesystems && /bin/mount -o nosuid,nodev,noexec,noatime,mode=0700 -t bpf bpffs /sys/fs/bpf
|
||||
grep -q pstore /proc/filesystems && /bin/mount -o noatime -t pstore pstore /sys/fs/pstore
|
||||
[ "$FAILSAFE" = "true" ] && touch /tmp/.failsafe
|
||||
|
||||
/sbin/kmodloader
|
||||
|
||||
[ ! -f /etc/config/wireless ] && {
|
||||
# compat for bcm47xx and mvebu
|
||||
sleep 1
|
||||
}
|
||||
|
||||
/bin/config_generate
|
||||
uci_apply_defaults
|
||||
sync
|
||||
|
||||
# temporary hack until configd exists
|
||||
/sbin/reload_config
|
||||
}
|
17
base-files/files/etc/init.d/done
Executable file
17
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 && sync
|
||||
|
||||
# process user commands
|
||||
[ -f /etc/rc.local ] && {
|
||||
sh /etc/rc.local
|
||||
}
|
||||
|
||||
# set leds to normal state
|
||||
. /etc/diag.sh
|
||||
set_state done
|
||||
}
|
66
base-files/files/etc/init.d/gpio_switch
Executable file
66
base-files/files/etc/init.d/gpio_switch
Executable file
@ -0,0 +1,66 @@
|
||||
#!/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
|
||||
|
||||
[ -z "$gpio_pin" ] && {
|
||||
echo >&2 "Skipping gpio_switch '$name' due to missing gpio_pin"
|
||||
return 1
|
||||
}
|
||||
|
||||
local gpio_path
|
||||
if [ -n "$(echo "$gpio_pin" | grep -E "^[0-9]+$")" ]; then
|
||||
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
|
||||
else
|
||||
gpio_path="/sys/class/gpio/${gpio_pin}"
|
||||
|
||||
[ -d "$gpio_path" ] && {
|
||||
{ [ "$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
|
||||
}
|
||||
}
|
145
base-files/files/etc/init.d/led
Executable file
145
base-files/files/etc/init.d/led
Executable file
@ -0,0 +1,145 @@
|
||||
#!/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
|
||||
config_get_bool default $1 default "0"
|
||||
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_bool inverted $1 inverted "0"
|
||||
|
||||
# execute application led trigger
|
||||
[ -f "/usr/libexec/led-trigger/${trigger}" ] && {
|
||||
. "/usr/libexec/led-trigger/${trigger}"
|
||||
return 0
|
||||
}
|
||||
|
||||
[ "$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
|
||||
"heartbeat")
|
||||
echo "${inverted}" > "/sys/class/leds/${sysfs}/invert"
|
||||
;;
|
||||
|
||||
"netdev")
|
||||
[ -n "$dev" ] && {
|
||||
echo $dev > /sys/class/leds/${sysfs}/device_name
|
||||
for m in $mode; do
|
||||
[ -e "/sys/class/leds/${sysfs}/$m" ] && \
|
||||
echo 1 > /sys/class/leds/${sysfs}/$m
|
||||
done
|
||||
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
|
||||
[ -n "$mode" ] && \
|
||||
echo "$mode" > /sys/class/leds/${sysfs}/mode
|
||||
;;
|
||||
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
base-files/files/etc/init.d/sysctl
Executable file
44
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
|
||||
}
|
44
base-files/files/etc/init.d/sysfixtime
Executable file
44
base-files/files/etc/init.d/sysfixtime
Executable file
@ -0,0 +1,44 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2013-2014 OpenWrt.org
|
||||
|
||||
START=00
|
||||
STOP=90
|
||||
|
||||
RTC_DEV=/dev/rtc0
|
||||
HWCLOCK=/sbin/hwclock
|
||||
|
||||
boot() {
|
||||
hwclock_load
|
||||
local maxtime="$(find_max_time)"
|
||||
local curtime="$(date +%s)"
|
||||
if [ $curtime -lt $maxtime ]; then
|
||||
date -s @$maxtime
|
||||
hwclock_save
|
||||
fi
|
||||
}
|
||||
|
||||
start() {
|
||||
hwclock_load
|
||||
}
|
||||
|
||||
stop() {
|
||||
hwclock_save
|
||||
}
|
||||
|
||||
hwclock_load() {
|
||||
[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s -u -f $RTC_DEV
|
||||
}
|
||||
|
||||
hwclock_save(){
|
||||
[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -w -u -f $RTC_DEV && \
|
||||
logger -t sysfixtime "saved '$(date)' to $RTC_DEV"
|
||||
}
|
||||
|
||||
find_max_time() {
|
||||
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
|
||||
}
|
45
base-files/files/etc/init.d/system
Executable file
45
base-files/files/etc/init.d/system
Executable file
@ -0,0 +1,45 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2014 OpenWrt.org
|
||||
|
||||
START=10
|
||||
USE_PROCD=1
|
||||
|
||||
validate_system_section() {
|
||||
uci_load_validate system system "$1" "$2" \
|
||||
'hostname:string:OpenWrt' \
|
||||
'conloglevel:uinteger' \
|
||||
'buffersize:uinteger' \
|
||||
'timezone:string:UTC' \
|
||||
'zonename:string'
|
||||
}
|
||||
|
||||
system_config() {
|
||||
[ "$2" = 0 ] || {
|
||||
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
|
||||
hwclock -u --systz
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
config_load system
|
||||
config_foreach validate_system_section system system_config
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "system"
|
||||
procd_add_validation validate_system_section
|
||||
}
|
||||
|
||||
start_service() {
|
||||
reload_service
|
||||
}
|
13
base-files/files/etc/init.d/umount
Executable file
13
base-files/files/etc/init.d/umount
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
|
||||
STOP=90
|
||||
|
||||
restart() {
|
||||
:
|
||||
}
|
||||
|
||||
stop() {
|
||||
sync
|
||||
/bin/umount -a -d -r
|
||||
}
|
3
base-files/files/etc/inittab
Normal file
3
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
base-files/files/etc/iproute2/ematch_map
Normal file
8
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
base-files/files/etc/iproute2/rt_protos
Normal file
18
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
base-files/files/etc/iproute2/rt_tables
Normal file
12
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
base-files/files/etc/openwrt_release
Normal file
7
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
base-files/files/etc/openwrt_version
Normal file
1
base-files/files/etc/openwrt_version
Normal file
@ -0,0 +1 @@
|
||||
%C
|
1
base-files/files/etc/os-release
Symbolic link
1
base-files/files/etc/os-release
Symbolic link
@ -0,0 +1 @@
|
||||
../usr/lib/os-release
|
5
base-files/files/etc/passwd
Normal file
5
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
base-files/files/etc/preinit
Executable file
29
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
|
40
base-files/files/etc/profile
Normal file
40
base-files/files/etc/profile
Normal file
@ -0,0 +1,40 @@
|
||||
[ -e /tmp/.failsafe ] && export FAILSAFE=1
|
||||
|
||||
[ -f /etc/banner ] && cat /etc/banner
|
||||
[ -n "$FAILSAFE" ] && cat /etc/banner.failsafe
|
||||
|
||||
grep -Fsq '/ 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\$ '
|
||||
export ENV=/etc/shinit
|
||||
|
||||
case "$TERM" in
|
||||
xterm*|rxvt*)
|
||||
export PS1='\[\e]0;\u@\h: \w\a\]'$PS1
|
||||
;;
|
||||
esac
|
||||
|
||||
[ -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
|
57
base-files/files/etc/protocols
Normal file
57
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
base-files/files/etc/rc.button/failsafe
Executable file
5
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
base-files/files/etc/rc.button/power
Executable file
7
base-files/files/etc/rc.button/power
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ "${ACTION}" = "released" ] || exit 0
|
||||
|
||||
exec /sbin/poweroff
|
||||
|
||||
return 0
|
12
base-files/files/etc/rc.button/reboot
Executable file
12
base-files/files/etc/rc.button/reboot
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ "${ACTION}" = "released" ] || exit 0
|
||||
|
||||
if [ "$SEEN" -ge 5 ]
|
||||
then
|
||||
echo "REBOOT" > /dev/console
|
||||
sync
|
||||
reboot
|
||||
fi
|
||||
|
||||
return 0
|
31
base-files/files/etc/rc.button/reset
Executable file
31
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
base-files/files/etc/rc.button/rfkill
Executable file
32
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
|
194
base-files/files/etc/rc.common
Executable file
194
base-files/files/etc/rc.common
Executable file
@ -0,0 +1,194 @@
|
||||
#!/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}")"
|
||||
name="${name##[SK][0-9][0-9]}"
|
||||
{
|
||||
[ -z "${START:-}" ] || [ -L "$IPKG_INSTROOT/etc/rc.d/S${START}$name" ]
|
||||
} && {
|
||||
[ -z "${STOP:-}" ] || [ -L "$IPKG_INSTROOT/etc/rc.d/K${STOP}$name" ]
|
||||
}
|
||||
}
|
||||
|
||||
depends() {
|
||||
return 0
|
||||
}
|
||||
|
||||
ALL_HELP=""
|
||||
ALL_COMMANDS="boot shutdown depends"
|
||||
extra_command() {
|
||||
local cmd="$1"
|
||||
local help="$2"
|
||||
|
||||
local extra="$(printf "%-16s%s" "${cmd}" "${help}")"
|
||||
ALL_HELP="${ALL_HELP}\t${extra}\n"
|
||||
ALL_COMMANDS="${ALL_COMMANDS} ${cmd}"
|
||||
}
|
||||
|
||||
help() {
|
||||
cat <<EOF
|
||||
Syntax: $initscript [command]
|
||||
|
||||
Available commands:
|
||||
EOF
|
||||
echo -e "$ALL_HELP"
|
||||
}
|
||||
|
||||
# for procd
|
||||
start_service() {
|
||||
return 0
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
return 0
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
return 0
|
||||
}
|
||||
|
||||
service_data() {
|
||||
return 0
|
||||
}
|
||||
|
||||
service_running() {
|
||||
local instance="${1:-*}"
|
||||
|
||||
procd_running "$(basename $initscript)" "$instance"
|
||||
}
|
||||
|
||||
${INIT_TRACE:+set -x}
|
||||
|
||||
extra_command "start" "Start the service"
|
||||
extra_command "stop" "Stop the service"
|
||||
extra_command "restart" "Restart the service"
|
||||
extra_command "reload" "Reload configuration files (or restart if service does not implement reload)"
|
||||
extra_command "enable" "Enable service autostart"
|
||||
extra_command "disable" "Disable service autostart"
|
||||
extra_command "enabled" "Check if service is started on boot"
|
||||
|
||||
. "$initscript"
|
||||
|
||||
[ -n "$USE_PROCD" ] && {
|
||||
extra_command "running" "Check if service is running"
|
||||
extra_command "status" "Service status"
|
||||
extra_command "trace" "Start with syscall trace"
|
||||
extra_command "info" "Dump procd service info"
|
||||
|
||||
. $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 "$@"
|
||||
}
|
||||
|
||||
info() {
|
||||
json_init
|
||||
json_add_string name "$(basename ${basescript:-$initscript})"
|
||||
json_add_boolean verbose "1"
|
||||
_procd_ubus_call list
|
||||
}
|
||||
|
||||
stop() {
|
||||
procd_lock
|
||||
stop_service "$@"
|
||||
procd_kill "$(basename ${basescript:-$initscript})" "$1"
|
||||
if eval "type service_stopped" 2>/dev/null >/dev/null; then
|
||||
service_stopped
|
||||
fi
|
||||
}
|
||||
|
||||
reload() {
|
||||
if eval "type reload_service" 2>/dev/null >/dev/null; then
|
||||
procd_lock
|
||||
reload_service "$@"
|
||||
else
|
||||
start
|
||||
fi
|
||||
}
|
||||
|
||||
running() {
|
||||
service_running "$@"
|
||||
}
|
||||
|
||||
status() {
|
||||
if eval "type status_service" 2>/dev/null >/dev/null; then
|
||||
status_service "$@"
|
||||
else
|
||||
_procd_status "$(basename ${basescript:-$initscript})" "$1"
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
ALL_COMMANDS="${ALL_COMMANDS} ${EXTRA_COMMANDS}"
|
||||
ALL_HELP="${ALL_HELP}${EXTRA_HELP}"
|
||||
list_contains ALL_COMMANDS "$action" || action=help
|
||||
$action "$@"
|
4
base-files/files/etc/rc.local
Normal file
4
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
base-files/files/etc/services
Normal file
173
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
base-files/files/etc/shadow
Normal file
5
base-files/files/etc/shadow
Normal file
@ -0,0 +1,5 @@
|
||||
root:::0:99999:7:::
|
||||
daemon:*:0:0:99999:7:::
|
||||
ftp:*:0:0:99999:7:::
|
||||
network:*:0:0:99999:7:::
|
||||
nobody:*:0:0:99999:7:::
|
1
base-files/files/etc/shells
Normal file
1
base-files/files/etc/shells
Normal file
@ -0,0 +1 @@
|
||||
/bin/ash
|
12
base-files/files/etc/shinit
Normal file
12
base-files/files/etc/shinit
Normal file
@ -0,0 +1,12 @@
|
||||
[ -x /bin/more ] || [ -x /usr/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 "$KSH_VERSION" -o \! -s "$HOME/.shinit" ] || . "$HOME/.shinit"
|
||||
[ -z "$KSH_VERSION" -o \! -s "$HOME/.mkshrc" ] || . "$HOME/.mkshrc"
|
1
base-files/files/etc/sysctl.conf
Normal file
1
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
|
28
base-files/files/etc/sysctl.d/10-default.conf
Normal file
28
base-files/files/etc/sysctl.d/10-default.conf
Normal file
@ -0,0 +1,28 @@
|
||||
# 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.core.bpf_jit_enable=1
|
||||
net.core.bpf_jit_kallsyms=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
base-files/files/etc/sysupgrade.conf
Normal file
5
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/
|
10
base-files/files/etc/uci-defaults/10_migrate-shadow
Normal file
10
base-files/files/etc/uci-defaults/10_migrate-shadow
Normal file
@ -0,0 +1,10 @@
|
||||
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
|
13
base-files/files/etc/uci-defaults/12_network-generate-ula
Normal file
13
base-files/files/etc/uci-defaults/12_network-generate-ula
Normal file
@ -0,0 +1,13 @@
|
||||
[ "$(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
|
||||
|
9
base-files/files/etc/uci-defaults/13_fix-group-user
Normal file
9
base-files/files/etc/uci-defaults/13_fix-group-user
Normal file
@ -0,0 +1,9 @@
|
||||
. /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
|
436
base-files/files/lib/functions.sh
Normal file
436
base-files/files/lib/functions.sh
Normal file
@ -0,0 +1,436 @@
|
||||
# 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=" "
|
||||
|
||||
# xor multiple hex values of the same length
|
||||
xor() {
|
||||
local val
|
||||
local ret="0x$1"
|
||||
local retlen=${#1}
|
||||
|
||||
shift
|
||||
while [ -n "$1" ]; do
|
||||
val="0x$1"
|
||||
ret=$((ret ^ val))
|
||||
shift
|
||||
done
|
||||
|
||||
printf "%0${retlen}x" "$ret"
|
||||
}
|
||||
|
||||
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 "$2${3:-$1}" in
|
||||
*[!A-Za-z0-9_]*) : ;;
|
||||
*)
|
||||
case "$3" in
|
||||
"") eval echo "\"\${CONFIG_${1}_${2}:-\${4}}\"";;
|
||||
*) eval export ${NO_EXPORT:+-n} -- "${1}=\${CONFIG_${2}_${3}:-\${4}}";;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# get_bool <value> [<default>]
|
||||
get_bool() {
|
||||
local _tmp="$1"
|
||||
case "$_tmp" in
|
||||
1|on|true|yes|enabled) _tmp=1;;
|
||||
0|off|false|no|disabled) _tmp=0;;
|
||||
*) _tmp="$2";;
|
||||
esac
|
||||
echo -n "$_tmp"
|
||||
}
|
||||
|
||||
# config_get_bool <variable> <section> <option> [<default>]
|
||||
config_get_bool() {
|
||||
local _tmp
|
||||
config_get _tmp "$2" "$3" "$4"
|
||||
_tmp="$(get_bool "$_tmp" "$4")"
|
||||
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" ] && [ "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="$(command -v 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 addngroups addngroup addngname addngid
|
||||
|
||||
IFS=":"
|
||||
set -- $tuple; uname="$1"; gname="$2"; addngroups="$3"
|
||||
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
|
||||
|
||||
if [ -n "$uname" ] && [ -n "$addngroups" ]; then
|
||||
oIFS="$IFS"
|
||||
IFS=","
|
||||
for addngroup in $addngroups ; do
|
||||
IFS="="
|
||||
set -- $addngroup; addngname="$1"; addngid="$2"
|
||||
if [ -n "$addngid" ]; then
|
||||
group_exists "$addngname" || group_add "$addngname" "$addngid"
|
||||
else
|
||||
group_add_next "$addngname"
|
||||
fi
|
||||
|
||||
group_add_user "$addngname" "$uname"
|
||||
done
|
||||
IFS="$oIFS"
|
||||
fi
|
||||
|
||||
unset uid gid uname gname addngroups addngroup addngname addngid
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
default_postinst() {
|
||||
local root="${IPKG_INSTROOT}"
|
||||
local pkgname="$(basename ${1%.*})"
|
||||
local filelist="/usr/lib/opkg/info/${pkgname}.list"
|
||||
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" ]; then
|
||||
if grep -m1 -q -s "^/etc/modules.d/" "$filelist"; then
|
||||
kmodloader
|
||||
fi
|
||||
|
||||
if grep -m1 -q -s "^/etc/sysctl.d/" "$filelist"; then
|
||||
/etc/init.d/sysctl restart
|
||||
fi
|
||||
|
||||
if grep -m1 -q -s "^/etc/uci-defaults/" "$filelist"; then
|
||||
[ -d /tmp/.uci ] || mkdir -p /tmp/.uci
|
||||
for i in $(grep -s "^/etc/uci-defaults/" "$filelist"); do
|
||||
( [ -f "$i" ] && cd "$(dirname $i)" && . "$i" ) && rm -f "$i"
|
||||
done
|
||||
uci commit
|
||||
fi
|
||||
|
||||
rm -f /tmp/luci-indexcache
|
||||
fi
|
||||
|
||||
local shell="$(command -v bash)"
|
||||
for i in $(grep -s "^/etc/init.d/" "$root$filelist"); 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}"
|
||||
}
|
||||
|
||||
find_mmc_part() {
|
||||
local DEVNAME PARTNAME ROOTDEV
|
||||
|
||||
if grep -q "$1" /proc/mtd; then
|
||||
echo "" && return 0
|
||||
fi
|
||||
|
||||
if [ -n "$2" ]; then
|
||||
ROOTDEV="$2"
|
||||
else
|
||||
ROOTDEV="mmcblk*"
|
||||
fi
|
||||
|
||||
for DEVNAME in /sys/block/$ROOTDEV/mmcblk*p*; do
|
||||
PARTNAME="$(grep PARTNAME ${DEVNAME}/uevent | cut -f2 -d'=')"
|
||||
[ "$PARTNAME" = "$1" ] && echo "/dev/$(basename $DEVNAME)" && return 0
|
||||
done
|
||||
}
|
||||
|
||||
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=$(cut -d: -f3 ${IPKG_INSTROOT}/etc/group)
|
||||
gid=65536
|
||||
while echo "$gids" | grep -q "^$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)
|
||||
echo "$grp" | cut -d: -f4 | grep -q $2 && return
|
||||
echo "$grp" | grep -q ":$" && delim=""
|
||||
[ -n "$IPKG_INSTROOT" ] || lock /var/lock/passwd
|
||||
sed -i "s/$grp/$grp$delim$2/g" ${IPKG_INSTROOT}/etc/group
|
||||
if [ -z "$IPKG_INSTROOT" ] && [ -x /usr/sbin/selinuxenabled ] && selinuxenabled; then
|
||||
restorecon /etc/group
|
||||
fi
|
||||
[ -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=$(cut -d: -f3 ${IPKG_INSTROOT}/etc/passwd)
|
||||
uid=65536
|
||||
while echo "$uids" | grep -q "^$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"
|
||||
}
|
||||
|
||||
cmdline_get_var() {
|
||||
local var=$1
|
||||
local cmdlinevar tmp
|
||||
|
||||
for cmdlinevar in $(cat /proc/cmdline); do
|
||||
tmp=${cmdlinevar##${var}}
|
||||
[ "=" = "${tmp:0:1}" ] && echo ${tmp:1}
|
||||
done
|
||||
}
|
||||
|
||||
[ -z "$IPKG_INSTROOT" ] && [ -f /lib/config/uci.sh ] && . /lib/config/uci.sh
|
184
base-files/files/lib/functions/caldata.sh
Normal file
184
base-files/files/lib/functions/caldata.sh
Normal file
@ -0,0 +1,184 @@
|
||||
# Copyright (C) 2019 OpenWrt.org
|
||||
|
||||
. /lib/functions.sh
|
||||
. /lib/functions/system.sh
|
||||
|
||||
caldata_dd() {
|
||||
local source=$1
|
||||
local target=$2
|
||||
local count=$(($3))
|
||||
local offset=$(($4))
|
||||
|
||||
dd if=$source of=$target iflag=skip_bytes,fullblock bs=$count skip=$offset count=1 2>/dev/null
|
||||
return $?
|
||||
}
|
||||
|
||||
caldata_die() {
|
||||
echo "caldata: " "$*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
caldata_extract() {
|
||||
local part=$1
|
||||
local offset=$(($2))
|
||||
local count=$(($3))
|
||||
local mtd
|
||||
|
||||
mtd=$(find_mtd_chardev $part)
|
||||
[ -n "$mtd" ] || caldata_die "no mtd device found for partition $part"
|
||||
|
||||
caldata_dd $mtd /lib/firmware/$FIRMWARE $count $offset || \
|
||||
caldata_die "failed to extract calibration data from $mtd"
|
||||
}
|
||||
|
||||
caldata_extract_ubi() {
|
||||
local part=$1
|
||||
local offset=$(($2))
|
||||
local count=$(($3))
|
||||
local ubidev
|
||||
local ubi
|
||||
|
||||
. /lib/upgrade/nand.sh
|
||||
|
||||
ubidev=$(nand_find_ubi $CI_UBIPART)
|
||||
ubi=$(nand_find_volume $ubidev $part)
|
||||
[ -n "$ubi" ] || caldata_die "no UBI volume found for $part"
|
||||
|
||||
caldata_dd /dev/$ubi /lib/firmware/$FIRMWARE $count $offset || \
|
||||
caldata_die "failed to extract calibration data from $ubi"
|
||||
}
|
||||
|
||||
caldata_extract_mmc() {
|
||||
local part=$1
|
||||
local offset=$(($2))
|
||||
local count=$(($3))
|
||||
local mmc_part
|
||||
|
||||
mmc_part=$(find_mmc_part $part)
|
||||
[ -n "$mmc_part" ] || caldata_die "no mmc partition found for partition $part"
|
||||
|
||||
caldata_dd $mmc_part /lib/firmware/$FIRMWARE $count $offset || \
|
||||
caldata_die "failed to extract calibration data from $mmc_part"
|
||||
}
|
||||
|
||||
caldata_extract_reverse() {
|
||||
local part=$1
|
||||
local offset=$2
|
||||
local count=$(($3))
|
||||
local mtd
|
||||
local reversed
|
||||
local caldata
|
||||
|
||||
mtd=$(find_mtd_chardev "$part")
|
||||
reversed=$(hexdump -v -s $offset -n $count -e '/1 "%02x "' $mtd)
|
||||
|
||||
for byte in $reversed; do
|
||||
caldata="\x${byte}${caldata}"
|
||||
done
|
||||
|
||||
printf "%b" "$caldata" > /lib/firmware/$FIRMWARE
|
||||
}
|
||||
|
||||
caldata_from_file() {
|
||||
local source=$1
|
||||
local offset=$(($2))
|
||||
local count=$(($3))
|
||||
local target=$4
|
||||
|
||||
[ -n "$target" ] || target=/lib/firmware/$FIRMWARE
|
||||
|
||||
caldata_dd $source $target $count $offset || \
|
||||
caldata_die "failed to extract calibration data from $source"
|
||||
}
|
||||
|
||||
caldata_sysfsload_from_file() {
|
||||
local source=$1
|
||||
local offset=$(($2))
|
||||
local count=$(($3))
|
||||
local target_dir="/sys/$DEVPATH"
|
||||
local target="$target_dir/data"
|
||||
|
||||
[ -d "$target_dir" ] || \
|
||||
caldata_die "no sysfs dir to write: $target"
|
||||
|
||||
echo 1 > "$target_dir/loading"
|
||||
caldata_dd $source $target $count $offset
|
||||
if [ $? != 0 ]; then
|
||||
echo 1 > "$target_dir/loading"
|
||||
caldata_die "failed to extract calibration data from $source"
|
||||
else
|
||||
echo 0 > "$target_dir/loading"
|
||||
fi
|
||||
}
|
||||
|
||||
caldata_valid() {
|
||||
local expected="$1"
|
||||
local target=$2
|
||||
|
||||
[ -n "$target" ] || target=/lib/firmware/$FIRMWARE
|
||||
|
||||
magic=$(hexdump -v -n 2 -e '1/1 "%02x"' $target)
|
||||
[ "$magic" = "$expected" ]
|
||||
return $?
|
||||
}
|
||||
|
||||
caldata_patch_chksum() {
|
||||
local mac=$1
|
||||
local mac_offset=$(($2))
|
||||
local chksum_offset=$(($3))
|
||||
local target=$4
|
||||
local xor_mac
|
||||
local xor_fw_mac
|
||||
local xor_fw_chksum
|
||||
|
||||
xor_mac=${mac//:/}
|
||||
xor_mac="${xor_mac:0:4} ${xor_mac:4:4} ${xor_mac:8:4}"
|
||||
|
||||
xor_fw_mac=$(hexdump -v -n 6 -s $mac_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE)
|
||||
xor_fw_mac="${xor_fw_mac:0:4} ${xor_fw_mac:4:4} ${xor_fw_mac:8:4}"
|
||||
|
||||
xor_fw_chksum=$(hexdump -v -n 2 -s $chksum_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE)
|
||||
xor_fw_chksum=$(xor $xor_fw_chksum $xor_fw_mac $xor_mac)
|
||||
|
||||
printf "%b" "\x${xor_fw_chksum:0:2}\x${xor_fw_chksum:2:2}" | \
|
||||
dd of=$target conv=notrunc bs=1 seek=$chksum_offset count=2
|
||||
}
|
||||
|
||||
caldata_patch_mac() {
|
||||
local mac=$1
|
||||
local mac_offset=$(($2))
|
||||
local chksum_offset=$3
|
||||
local target=$4
|
||||
|
||||
[ -z "$mac" -o -z "$mac_offset" ] && return
|
||||
|
||||
[ -n "$target" ] || target=/lib/firmware/$FIRMWARE
|
||||
|
||||
[ -n "$chksum_offset" ] && caldata_patch_chksum "$mac" "$mac_offset" "$chksum_offset" "$target"
|
||||
|
||||
macaddr_2bin $mac | dd of=$target conv=notrunc oflag=seek_bytes bs=6 seek=$mac_offset count=1 || \
|
||||
caldata_die "failed to write MAC address to eeprom file"
|
||||
}
|
||||
|
||||
ath9k_patch_mac() {
|
||||
local mac=$1
|
||||
local target=$2
|
||||
|
||||
caldata_patch_mac "$mac" 0x2 "" "$target"
|
||||
}
|
||||
|
||||
ath9k_patch_mac_crc() {
|
||||
local mac=$1
|
||||
local mac_offset=$2
|
||||
local chksum_offset=$((mac_offset - 10))
|
||||
local target=$4
|
||||
|
||||
caldata_patch_mac "$mac" "$mac_offset" "$chksum_offset" "$target"
|
||||
}
|
||||
|
||||
ath10k_patch_mac() {
|
||||
local mac=$1
|
||||
local target=$2
|
||||
|
||||
caldata_patch_mac "$mac" 0x6 0x2 "$target"
|
||||
}
|
94
base-files/files/lib/functions/leds.sh
Normal file
94
base-files/files/lib/functions/leds.sh
Normal file
@ -0,0 +1,94 @@
|
||||
# Copyright (C) 2013 OpenWrt.org
|
||||
|
||||
get_dt_led_path() {
|
||||
local ledpath
|
||||
local basepath="/proc/device-tree"
|
||||
local nodepath="$basepath/aliases/led-$1"
|
||||
|
||||
[ -f "$nodepath" ] && ledpath=$(cat "$nodepath")
|
||||
[ -n "$ledpath" ] && ledpath="$basepath$ledpath"
|
||||
|
||||
echo "$ledpath"
|
||||
}
|
||||
|
||||
get_dt_led() {
|
||||
local label
|
||||
local ledpath=$(get_dt_led_path $1)
|
||||
|
||||
[ -n "$ledpath" ] && \
|
||||
label=$(cat "$ledpath/label" 2>/dev/null) || \
|
||||
label=$(cat "$ledpath/chan-name" 2>/dev/null) || \
|
||||
label=$(basename "$ledpath")
|
||||
|
||||
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_restore_trigger() {
|
||||
local trigger
|
||||
local ledpath=$(get_dt_led_path $1)
|
||||
|
||||
[ -n "$ledpath" ] && \
|
||||
trigger=$(cat "$ledpath/linux,default-trigger" 2>/dev/null)
|
||||
|
||||
[ -n "$trigger" ] && \
|
||||
led_set_attr "$(get_dt_led $1)" "trigger" "$trigger"
|
||||
}
|
||||
|
||||
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
|
||||
}
|
67
base-files/files/lib/functions/migrations.sh
Normal file
67
base-files/files/lib/functions/migrations.sh
Normal file
@ -0,0 +1,67 @@
|
||||
. /lib/functions.sh
|
||||
|
||||
migrate_led_sysfs() {
|
||||
local cfg="$1"; shift
|
||||
local tuples="$@"
|
||||
local sysfs
|
||||
local name
|
||||
|
||||
config_get sysfs ${cfg} sysfs
|
||||
config_get name ${cfg} name
|
||||
|
||||
[ -z "${sysfs}" ] && return
|
||||
|
||||
for tuple in ${tuples}; do
|
||||
local old=${tuple%=*}
|
||||
local new=${tuple#*=}
|
||||
local new_sysfs
|
||||
|
||||
new_sysfs=$(echo ${sysfs} | sed "s/${old}/${new}/")
|
||||
|
||||
[ "${new_sysfs}" = "${sysfs}" ] && continue
|
||||
|
||||
uci set system.${cfg}.sysfs="${new_sysfs}"
|
||||
|
||||
logger -t led-migration "sysfs option of LED \"${name}\" updated to ${new_sysfs}"
|
||||
done;
|
||||
}
|
||||
|
||||
remove_devicename_led_sysfs() {
|
||||
local cfg="$1"; shift
|
||||
local exceptions="$@"
|
||||
local sysfs
|
||||
local name
|
||||
local new_sysfs
|
||||
|
||||
config_get sysfs ${cfg} sysfs
|
||||
config_get name ${cfg} name
|
||||
|
||||
# only continue if two or more colons are present
|
||||
echo "${sysfs}" | grep -q ":.*:" || return
|
||||
|
||||
for exception in ${exceptions}; do
|
||||
# no change if exceptions provided as argument are found for devicename
|
||||
echo "${sysfs}" | grep -q "^${exception}:" && return
|
||||
done
|
||||
|
||||
new_sysfs=$(echo ${sysfs} | sed "s/^[^:]*://")
|
||||
|
||||
uci set system.${cfg}.sysfs="${new_sysfs}"
|
||||
|
||||
logger -t led-migration "sysfs option of LED \"${name}\" updated to ${new_sysfs}"
|
||||
}
|
||||
|
||||
migrate_leds() {
|
||||
config_load system
|
||||
config_foreach migrate_led_sysfs led "$@"
|
||||
}
|
||||
|
||||
remove_devicename_leds() {
|
||||
config_load system
|
||||
config_foreach remove_devicename_led_sysfs led "$@"
|
||||
}
|
||||
|
||||
migrations_apply() {
|
||||
local realm="$1"
|
||||
[ -n "$(uci changes ${realm})" ] && uci -q commit ${realm}
|
||||
}
|
325
base-files/files/lib/functions/network.sh
Normal file
325
base-files/files/lib/functions/network.sh
Normal file
@ -0,0 +1,325 @@
|
||||
# 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 first IPv6 prefix assignment of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_prefix_assignment6() {
|
||||
__network_ifstatus "$1" "$2" "['ipv6-prefix-assignment'][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 all IPv6 prefix assignments of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_prefix_assignments6() {
|
||||
__network_ifstatus "$1" "$2" "['ipv6-prefix-assignment'][*]['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 default 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 uptime of the given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_uptime() { __network_ifstatus "$1" "$2" ".uptime"; }
|
||||
|
||||
# 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; }
|
87
base-files/files/lib/functions/preinit.sh
Normal file
87
base-files/files/lib/functions/preinit.sh
Normal file
@ -0,0 +1,87 @@
|
||||
# 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
base-files/files/lib/functions/service.sh
Normal file
103
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 "$@"
|
||||
}
|
302
base-files/files/lib/functions/system.sh
Normal file
302
base-files/files/lib/functions/system.sh
Normal file
@ -0,0 +1,302 @@
|
||||
# Copyright (C) 2006-2013 OpenWrt.org
|
||||
|
||||
. /lib/functions.sh
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
get_mac_label_dt() {
|
||||
local basepath="/proc/device-tree"
|
||||
local macdevice="$(cat "$basepath/aliases/label-mac-device" 2>/dev/null)"
|
||||
local macaddr
|
||||
|
||||
[ -n "$macdevice" ] || return
|
||||
|
||||
macaddr=$(get_mac_binary "$basepath/$macdevice/mac-address" 0 2>/dev/null)
|
||||
[ -n "$macaddr" ] || macaddr=$(get_mac_binary "$basepath/$macdevice/local-mac-address" 0 2>/dev/null)
|
||||
|
||||
echo $macaddr
|
||||
}
|
||||
|
||||
get_mac_label_json() {
|
||||
local cfg="/etc/board.json"
|
||||
local macaddr
|
||||
|
||||
[ -s "$cfg" ] || return
|
||||
|
||||
json_init
|
||||
json_load "$(cat $cfg)"
|
||||
if json_is_a system object; then
|
||||
json_select system
|
||||
json_get_var macaddr label_macaddr
|
||||
json_select ..
|
||||
fi
|
||||
|
||||
echo $macaddr
|
||||
}
|
||||
|
||||
get_mac_label() {
|
||||
local macaddr=$(get_mac_label_dt)
|
||||
|
||||
[ -n "$macaddr" ] || macaddr=$(get_mac_label_json)
|
||||
|
||||
echo $macaddr
|
||||
}
|
||||
|
||||
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_encrypted_arcadyan() {
|
||||
local iv="00000000000000000000000000000000"
|
||||
local key="2A4B303D7644395C3B2B7053553C5200"
|
||||
local mac_dirty
|
||||
local mtdname="$1"
|
||||
local part
|
||||
local size
|
||||
|
||||
part=$(find_mtd_part "$mtdname")
|
||||
if [ -z "$part" ]; then
|
||||
echo "mtd_get_mac_encrypted_arcadyan: partition $mtdname not found!" >&2
|
||||
return
|
||||
fi
|
||||
|
||||
# Config decryption and getting mac. Trying uencrypt and openssl utils.
|
||||
size=$((0x$(dd if=$part skip=9 bs=1 count=4 2>/dev/null | hexdump -v -e '1/4 "%08x"')))
|
||||
if [[ -f "/usr/bin/uencrypt" ]]; then
|
||||
mac_dirty=$(dd if=$part bs=1 count=$size skip=$((0x100)) 2>/dev/null | \
|
||||
uencrypt -d -n -k $key -i $iv | grep mac | cut -c 5-)
|
||||
elif [[ -f "/usr/bin/openssl" ]]; then
|
||||
mac_dirty=$(dd if=$part bs=1 count=$size skip=$((0x100)) 2>/dev/null | \
|
||||
openssl aes-128-cbc -d -nopad -K $key -iv $iv | grep mac | cut -c 5-)
|
||||
else
|
||||
echo "mtd_get_mac_encrypted_arcadyan: Neither uencrypt nor openssl was found!" >&2
|
||||
return
|
||||
fi
|
||||
|
||||
# "canonicalize" mac
|
||||
[ -n "$mac_dirty" ] && macaddr_canonicalize "$mac_dirty"
|
||||
}
|
||||
|
||||
mtd_get_mac_encrypted_deco() {
|
||||
local mtdname="$1"
|
||||
|
||||
if ! [ -e "$mtdname" ]; then
|
||||
echo "mtd_get_mac_encrypted_deco: file $mtdname not found!" >&2
|
||||
return
|
||||
fi
|
||||
|
||||
tplink_key="3336303032384339"
|
||||
|
||||
key=$(dd if=$mtdname bs=1 skip=16 count=8 2>/dev/null | \
|
||||
uencrypt -n -d -k $tplink_key -c des-ecb | hexdump -v -n 8 -e '1/1 "%02x"')
|
||||
|
||||
macaddr=$(dd if=$mtdname bs=1 skip=32 count=8 2>/dev/null | \
|
||||
uencrypt -n -d -k $key -c des-ecb | hexdump -v -n 6 -e '5/1 "%02x:" 1/1 "%02x"')
|
||||
|
||||
echo $macaddr
|
||||
}
|
||||
|
||||
mtd_get_mac_uci_config_ubi() {
|
||||
local volumename="$1"
|
||||
|
||||
. /lib/upgrade/nand.sh
|
||||
|
||||
local ubidev=$(nand_attach_ubi $CI_UBIPART)
|
||||
local part=$(nand_find_volume $ubidev $volumename)
|
||||
|
||||
cat "/dev/$part" | sed -n 's/^\s*option macaddr\s*'"'"'\?\([0-9A-F:]\+\)'"'"'\?/\1/Ip'
|
||||
}
|
||||
|
||||
mtd_get_mac_text() {
|
||||
local mtdname="$1"
|
||||
local offset=$((${2:-0}))
|
||||
local length="${3:-17}"
|
||||
local part
|
||||
|
||||
part=$(find_mtd_part "$mtdname")
|
||||
if [ -z "$part" ]; then
|
||||
echo "mtd_get_mac_text: partition $mtdname not found!" >&2
|
||||
return
|
||||
fi
|
||||
|
||||
[ $((offset + length)) -le $(mtd_get_part_size "$mtdname") ] || return
|
||||
|
||||
macaddr_canonicalize $(dd bs=1 if="$part" skip="$offset" count="$length" 2>/dev/null)
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
get_mac_binary "/dev/$part" "$offset"
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
mmc_get_mac_binary() {
|
||||
local part_name="$1"
|
||||
local offset="$2"
|
||||
local part
|
||||
|
||||
part=$(find_mmc_part "$part_name")
|
||||
get_mac_binary "$part" "$offset"
|
||||
}
|
||||
|
||||
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_generate_from_mmc_cid() {
|
||||
local mmc_dev=$1
|
||||
|
||||
local sd_hash=$(sha256sum /sys/class/block/$mmc_dev/device/cid)
|
||||
local mac_base=$(macaddr_canonicalize "$(echo "${sd_hash}" | dd bs=1 count=12 2>/dev/null)")
|
||||
echo "$(macaddr_unsetbit_mc "$(macaddr_setbit_la "${mac_base}")")"
|
||||
}
|
||||
|
||||
macaddr_geteui() {
|
||||
local mac=$1
|
||||
local sep=$2
|
||||
|
||||
echo ${mac:9:2}$sep${mac:12:2}$sep${mac:15:2}
|
||||
}
|
||||
|
||||
macaddr_setbit() {
|
||||
local mac=$1
|
||||
local bit=${2:-0}
|
||||
|
||||
[ $bit -gt 0 -a $bit -le 48 ] || return
|
||||
|
||||
printf "%012x" $(( 0x${mac//:/} | 2**(48-bit) )) | sed -e 's/\(.\{2\}\)/\1:/g' -e 's/:$//'
|
||||
}
|
||||
|
||||
macaddr_unsetbit() {
|
||||
local mac=$1
|
||||
local bit=${2:-0}
|
||||
|
||||
[ $bit -gt 0 -a $bit -le 48 ] || return
|
||||
|
||||
printf "%012x" $(( 0x${mac//:/} & ~(2**(48-bit)) )) | sed -e 's/\(.\{2\}\)/\1:/g' -e 's/:$//'
|
||||
}
|
||||
|
||||
macaddr_setbit_la() {
|
||||
macaddr_setbit $1 7
|
||||
}
|
||||
|
||||
macaddr_unsetbit_mc() {
|
||||
local mac=$1
|
||||
|
||||
printf "%02x:%s" $((0x${mac%%:*} & ~0x01)) ${mac#*:}
|
||||
}
|
||||
|
||||
macaddr_random() {
|
||||
local randsrc=$(get_mac_binary /dev/urandom 0)
|
||||
|
||||
echo "$(macaddr_unsetbit_mc "$(macaddr_setbit_la "${randsrc}")")"
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
dt_is_enabled() {
|
||||
grep -q okay "/proc/device-tree/$1/status"
|
||||
}
|
681
base-files/files/lib/functions/uci-defaults.sh
Normal file
681
base-files/files/lib/functions/uci-defaults.sh
Normal file
@ -0,0 +1,681 @@
|
||||
. /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 network=$1; shift
|
||||
|
||||
[ -z "$network" ] && return
|
||||
|
||||
json_select_object network
|
||||
json_select_object "$network"
|
||||
|
||||
while [ -n "$1" ]; do
|
||||
local opt=$1; shift
|
||||
local val=$1; shift
|
||||
|
||||
[ -n "$opt" -a -n "$val" ] || break
|
||||
|
||||
[ "$opt" = "device" -a "$val" != "${val/ //}" ] && {
|
||||
json_select_array "ports"
|
||||
for e in $val; do json_add_string "" "$e"; done
|
||||
json_close_array
|
||||
} || {
|
||||
json_add_string "$opt" "$val"
|
||||
}
|
||||
done
|
||||
|
||||
if ! json_is_a protocol string; then
|
||||
case "$network" in
|
||||
lan) json_add_string protocol static ;;
|
||||
wan) json_add_string protocol dhcp ;;
|
||||
*) json_add_string protocol none ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
json_select ..
|
||||
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_compat_version() {
|
||||
json_select_object system
|
||||
json_add_string compat_version "${1:-1.0}"
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_interface_lan() {
|
||||
ucidef_set_interface "lan" device "$1" protocol "${2:-static}"
|
||||
}
|
||||
|
||||
ucidef_set_interface_wan() {
|
||||
ucidef_set_interface "wan" device "$1" protocol "${2:-dhcp}"
|
||||
}
|
||||
|
||||
ucidef_set_interfaces_lan_wan() {
|
||||
local lan_if="$1"
|
||||
local wan_if="$2"
|
||||
|
||||
ucidef_set_interface_lan "$lan_if"
|
||||
ucidef_set_interface_wan "$wan_if"
|
||||
}
|
||||
|
||||
ucidef_set_bridge_device() {
|
||||
json_select_object bridge
|
||||
json_add_string name "${1:-switch0}"
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_bridge_mac() {
|
||||
json_select_object bridge
|
||||
json_add_string macaddr "${1}"
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_network_device_mac() {
|
||||
json_select_object "network-device"
|
||||
json_select_object "${1}"
|
||||
json_add_string macaddr "${2}"
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_network_device_path() {
|
||||
json_select_object "network_device"
|
||||
json_select_object "$1"
|
||||
json_add_string path "$2"
|
||||
json_select ..
|
||||
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 device
|
||||
if ! list_contains devices "$device"; then
|
||||
devices="${devices:+$devices }$device"
|
||||
fi
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
ucidef_set_interface "$role" device "$devices"
|
||||
done
|
||||
}
|
||||
|
||||
ucidef_set_ar8xxx_switch_mib() {
|
||||
local name="$1"
|
||||
local type="$2"
|
||||
local interval="$3"
|
||||
|
||||
json_select_object switch
|
||||
json_select_object "$name"
|
||||
json_add_int ar8xxx_mib_type $type
|
||||
json_add_int ar8xxx_mib_poll_interval $interval
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
ucidef_set_interface "$network" macaddr "$macaddr"
|
||||
}
|
||||
|
||||
ucidef_set_label_macaddr() {
|
||||
local macaddr="$1"
|
||||
|
||||
json_select_object system
|
||||
json_add_string label_macaddr "$macaddr"
|
||||
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_heartbeat() {
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string trigger heartbeat
|
||||
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" disk-activity
|
||||
}
|
||||
|
||||
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"
|
||||
local mode="$7"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string trigger "$trigger_name"
|
||||
json_add_string type switch
|
||||
json_add_string mode "$mode"
|
||||
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_string 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 ..
|
||||
}
|
||||
|
||||
ucidef_add_wlan() {
|
||||
local path="$1"; shift
|
||||
|
||||
ucidef_wlan_idx=${ucidef_wlan_idx:-0}
|
||||
|
||||
json_select_object wlan
|
||||
json_select_object "wl$ucidef_wlan_idx"
|
||||
json_add_string path "$path"
|
||||
json_add_fields "$@"
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
ucidef_wlan_idx="$((ucidef_wlan_idx + 1))"
|
||||
}
|
||||
|
||||
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 -o ${CFG}
|
||||
}
|
5
base-files/files/lib/preinit/02_default_set_state
Normal file
5
base-files/files/lib/preinit/02_default_set_state
Normal file
@ -0,0 +1,5 @@
|
||||
define_default_set_state() {
|
||||
. /etc/diag.sh
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main define_default_set_state
|
10
base-files/files/lib/preinit/02_sysinfo
Normal file
10
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
|
17
base-files/files/lib/preinit/10_indicate_failsafe
Normal file
17
base-files/files/lib/preinit/10_indicate_failsafe
Normal file
@ -0,0 +1,17 @@
|
||||
# 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
|
207
base-files/files/lib/preinit/10_indicate_preinit
Normal file
207
base-files/files/lib/preinit/10_indicate_preinit
Normal file
@ -0,0 +1,207 @@
|
||||
# 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
|
||||
if [ -n "$vid" ]; then
|
||||
ip link set dev $1 up
|
||||
fi
|
||||
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 [ "$reset" -eq "1" ]; then
|
||||
swconfig dev $name set reset
|
||||
fi
|
||||
swconfig dev $name set enable_vlan $enable
|
||||
|
||||
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
|
||||
swconfig dev $name vlan $role set ports "$ports"
|
||||
fi
|
||||
done
|
||||
|
||||
json_select ..
|
||||
fi
|
||||
|
||||
swconfig dev $name set apply
|
||||
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
preinit_config_port() {
|
||||
local original
|
||||
|
||||
local netdev="$1"
|
||||
local path="$2"
|
||||
|
||||
[ -d "/sys/devices/$path/net" ] || return
|
||||
original="$(ls "/sys/devices/$path/net" | head -1)"
|
||||
|
||||
[ "$netdev" = "$original" ] && return
|
||||
|
||||
ip link set "$original" name "$netdev"
|
||||
}
|
||||
|
||||
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)"
|
||||
|
||||
# Find the current highest eth*
|
||||
max_eth=$(grep -o '^ *eth[0-9]*:' /proc/net/dev | tr -dc '[0-9]\n' | sort -n | tail -1)
|
||||
# Find and move netdevs using eth*s we are configuring
|
||||
json_get_keys keys "network_device"
|
||||
for netdev in $keys; do
|
||||
json_select "network_device"
|
||||
json_select "$netdev"
|
||||
json_get_vars path path
|
||||
if [ -n "$path" -a -h "/sys/class/net/$netdev" ]; then
|
||||
ip link set "$netdev" down
|
||||
ip link set "$netdev" name eth$((++max_eth))
|
||||
fi
|
||||
json_select ..
|
||||
json_select ..
|
||||
done
|
||||
|
||||
# Move interfaces by path to their netdev name
|
||||
json_get_keys keys "network_device"
|
||||
for netdev in $keys; do
|
||||
json_select "network_device"
|
||||
json_select "$netdev"
|
||||
json_get_vars path path
|
||||
[ -n "$path" ] && preinit_config_port "$netdev" "$path"
|
||||
json_select ..
|
||||
json_select ..
|
||||
done
|
||||
|
||||
json_select network
|
||||
json_select "lan"
|
||||
json_get_vars device
|
||||
json_get_values ports ports
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
[ -n "$device" -o -n "$ports" ] || return
|
||||
|
||||
# swconfig uses $device and DSA uses ports
|
||||
[ -z "$ports" ] && {
|
||||
ports="$device"
|
||||
}
|
||||
|
||||
# only use the first one
|
||||
ifname=${ports%% *}
|
||||
|
||||
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%\.*}
|
||||
# trim any vlan modifiers like :t
|
||||
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
|
102
base-files/files/lib/preinit/30_failsafe_wait
Normal file
102
base-files/files/lib/preinit/30_failsafe_wait
Normal file
@ -0,0 +1,102 @@
|
||||
# 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
|
||||
pi_failsafe_net_message=true \
|
||||
preinit_net_echo "Please press button now to enter failsafe"
|
||||
echo "$timer" >$keypress_sec
|
||||
timer=$(($timer - 1))
|
||||
sleep 1
|
||||
done
|
||||
lock -u $keypress_wait
|
||||
rm -f $keypress_wait
|
||||
} &
|
||||
|
||||
local consoles="$(sed -e 's/ /\n/g' /proc/cmdline | grep '^console=' | sed -e 's/^console=//' -e 's/,.*//')"
|
||||
[ -n "$consoles" ] || consoles=console
|
||||
for console in $consoles; do
|
||||
[ -c "/dev/$console" ] || continue
|
||||
[ "$pi_preinit_no_failsafe" != "y" ] && echo "Press the [$1] key and hit [enter] $2" > "/dev/$console"
|
||||
echo "Press the [1], [2], [3] or [4] key and hit [enter] to select the debug level" > "/dev/$console"
|
||||
{
|
||||
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 < "/dev/$console"
|
||||
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
|
||||
} &
|
||||
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
|
||||
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
|
16
base-files/files/lib/preinit/40_run_failsafe_hook
Normal file
16
base-files/files/lib/preinit/40_run_failsafe_hook
Normal file
@ -0,0 +1,16 @@
|
||||
# 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
|
9
base-files/files/lib/preinit/50_indicate_regular_preinit
Normal file
9
base-files/files/lib/preinit/50_indicate_regular_preinit
Normal file
@ -0,0 +1,9 @@
|
||||
# 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
|
12
base-files/files/lib/preinit/70_initramfs_test
Normal file
12
base-files/files/lib/preinit/70_initramfs_test
Normal file
@ -0,0 +1,12 @@
|
||||
# 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
|
35
base-files/files/lib/preinit/80_mount_root
Normal file
35
base-files/files/lib/preinit/80_mount_root
Normal file
@ -0,0 +1,35 @@
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
missing_lines() {
|
||||
local file1 file2 line
|
||||
file1="$1"
|
||||
file2="$2"
|
||||
oIFS="$IFS"
|
||||
IFS=":"
|
||||
while read line; do
|
||||
set -- $line
|
||||
grep -q "^$1:" "$file2" || echo "$*"
|
||||
done < "$file1"
|
||||
IFS="$oIFS"
|
||||
}
|
||||
|
||||
do_mount_root() {
|
||||
mount_root
|
||||
boot_run_hook preinit_mount_root
|
||||
[ -f /sysupgrade.tgz -o -f /tmp/sysupgrade.tar ] && {
|
||||
echo "- config restore -"
|
||||
cp /etc/passwd /etc/group /etc/shadow /tmp
|
||||
cd /
|
||||
[ -f /sysupgrade.tgz ] && tar xzf /sysupgrade.tgz
|
||||
[ -f /tmp/sysupgrade.tar ] && tar xf /tmp/sysupgrade.tar
|
||||
missing_lines /tmp/passwd /etc/passwd >> /etc/passwd
|
||||
missing_lines /tmp/group /etc/group >> /etc/group
|
||||
missing_lines /tmp/shadow /etc/shadow >> /etc/shadow
|
||||
rm /tmp/passwd /tmp/group /tmp/shadow
|
||||
# Prevent configuration corruption on a power loss
|
||||
sync
|
||||
}
|
||||
}
|
||||
|
||||
[ "$INITRAMFS" = "1" ] || boot_hook_add preinit_main do_mount_root
|
15
base-files/files/lib/preinit/99_10_failsafe_login
Normal file
15
base-files/files/lib/preinit/99_10_failsafe_login
Normal file
@ -0,0 +1,15 @@
|
||||
# Copyright (C) 2006-2015 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
failsafe_shell() {
|
||||
local consoles="$(sed -e 's/ /\n/g' /proc/cmdline | grep '^console=' | sed -e 's/^console=//' -e 's/,.*//')"
|
||||
[ -n "$consoles" ] || consoles=console
|
||||
for console in $consoles; do
|
||||
[ -c "/dev/$console" ] && while true; do
|
||||
ash --login <"/dev/$console" >"/dev/$console" 2>"/dev/$console"
|
||||
sleep 1
|
||||
done &
|
||||
done
|
||||
}
|
||||
|
||||
boot_hook_add failsafe failsafe_shell
|
8
base-files/files/lib/preinit/99_10_run_init
Normal file
8
base-files/files/lib/preinit/99_10_run_init
Normal file
@ -0,0 +1,8 @@
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
run_init() {
|
||||
preinit_ip_deconfig
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main run_init
|
317
base-files/files/lib/upgrade/common.sh
Normal file
317
base-files/files/lib/upgrade/common.sh
Normal file
@ -0,0 +1,317 @@
|
||||
RAM_ROOT=/tmp/root
|
||||
|
||||
export BACKUP_FILE=sysupgrade.tgz # file extracted by preinit
|
||||
|
||||
[ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }
|
||||
libs() { ldd $* 2>/dev/null | sed -E '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() {
|
||||
[ -n "$VERBOSE" ] && [ "$VERBOSE" -ge 1 ] && echo "$*" >&2
|
||||
}
|
||||
|
||||
v() {
|
||||
_v "$(date) upgrade: $@"
|
||||
logger -p info -t upgrade "$@"
|
||||
}
|
||||
|
||||
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="busybox zcat";;
|
||||
*) cmd="cat";;
|
||||
esac
|
||||
fi
|
||||
|
||||
$cmd <"$from"
|
||||
}
|
||||
|
||||
get_image_dd() {
|
||||
local from="$1"; shift
|
||||
|
||||
(
|
||||
exec 3>&2
|
||||
( exec 3>&2; get_image "$from" 2>&1 1>&3 | grep -v -F ' Broken pipe' ) 2>&1 1>&3 \
|
||||
| ( exec 3>&2; dd "$@" 2>&1 1>&3 | grep -v -E ' records (in|out)') 2>&1 1>&3
|
||||
exec 3>&-
|
||||
)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
get_magic_gpt() {
|
||||
(get_image "$@" | dd bs=8 count=1 skip=64) 2>/dev/null
|
||||
}
|
||||
|
||||
get_magic_vfat() {
|
||||
(get_image "$@" | dd bs=3 count=1 skip=18) 2>/dev/null
|
||||
}
|
||||
|
||||
get_magic_fat32() {
|
||||
(get_image "$@" | dd bs=1 count=5 skip=82) 2>/dev/null
|
||||
}
|
||||
|
||||
identify_magic_long() {
|
||||
local magic=$1
|
||||
case "$magic" in
|
||||
"55424923")
|
||||
echo "ubi"
|
||||
;;
|
||||
"31181006")
|
||||
echo "ubifs"
|
||||
;;
|
||||
"68737173")
|
||||
echo "squashfs"
|
||||
;;
|
||||
"d00dfeed")
|
||||
echo "fit"
|
||||
;;
|
||||
"4349"*)
|
||||
echo "combined"
|
||||
;;
|
||||
"1f8b"*)
|
||||
echo "gzip"
|
||||
;;
|
||||
*)
|
||||
echo "unknown $magic"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
part_magic_efi() {
|
||||
local magic=$(get_magic_gpt "$@")
|
||||
[ "$magic" = "EFI PART" ]
|
||||
}
|
||||
|
||||
part_magic_fat() {
|
||||
local magic=$(get_magic_vfat "$@")
|
||||
local magic_fat32=$(get_magic_fat32 "$@")
|
||||
[ "$magic" = "FAT" ] || [ "$magic_fat32" = "FAT32" ]
|
||||
}
|
||||
|
||||
export_bootdevice() {
|
||||
local cmdline uuid blockdev uevent line class
|
||||
local MAJOR MINOR DEVNAME DEVTYPE
|
||||
local rootpart="$(cmdline_get_var root)"
|
||||
|
||||
case "$rootpart" 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]-[a-f0-9][a-f0-9])
|
||||
uuid="${rootpart#PARTUUID=}"
|
||||
uuid="${uuid%-[a-f0-9][a-f0-9]}"
|
||||
for blockdev in $(find /dev -type b); do
|
||||
set -- $(dd if=$blockdev 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/${blockdev##*/}/uevent"
|
||||
break
|
||||
fi
|
||||
done
|
||||
;;
|
||||
PARTUUID=????????-????-????-????-??????????0?/PARTNROFF=1 | \
|
||||
PARTUUID=????????-????-????-????-??????????02)
|
||||
uuid="${rootpart#PARTUUID=}"
|
||||
uuid="${uuid%/PARTNROFF=1}"
|
||||
uuid="${uuid%0?}00"
|
||||
for disk in $(find /dev -type b); do
|
||||
set -- $(dd if=$disk bs=1 skip=568 count=16 2>/dev/null | hexdump -v -e '8/1 "%02x "" "2/1 "%02x""-"6/1 "%02x"')
|
||||
if [ "$4$3$2$1-$6$5-$8$7-$9" = "$uuid" ]; then
|
||||
uevent="/sys/class/block/${disk##*/}/uevent"
|
||||
break
|
||||
fi
|
||||
done
|
||||
;;
|
||||
/dev/*)
|
||||
uevent="/sys/class/block/${rootpart##*/}/../uevent"
|
||||
;;
|
||||
0x[a-f0-9][a-f0-9][a-f0-9] | 0x[a-f0-9][a-f0-9][a-f0-9][a-f0-9] | \
|
||||
[a-f0-9][a-f0-9][a-f0-9] | [a-f0-9][a-f0-9][a-f0-9][a-f0-9])
|
||||
rootpart=0x${rootpart#0x}
|
||||
for class in /sys/class/block/*; do
|
||||
while read line; do
|
||||
export -n "$line"
|
||||
done < "$class/uevent"
|
||||
if [ $((rootpart/256)) = $MAJOR -a $((rootpart%256)) = $MINOR ]; then
|
||||
uevent="$class/../uevent"
|
||||
fi
|
||||
done
|
||||
;;
|
||||
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
|
||||
|
||||
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
|
||||
part_magic_efi "$disk" && {
|
||||
#export_partdevice will fail when partition number is greater than 15, as
|
||||
#the partition major device number is not equal to the disk major device number
|
||||
for part in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
|
||||
set -- $(hexdump -v -n 48 -s "$((0x380 + $part * 0x80))" -e '4/4 "%08x"" "4/4 "%08x"" "4/4 "0x%08X "' "$disk")
|
||||
|
||||
local type="$1"
|
||||
local lba="$(( $(hex_le32_to_cpu $4) * 0x100000000 + $(hex_le32_to_cpu $3) ))"
|
||||
local end="$(( $(hex_le32_to_cpu $6) * 0x100000000 + $(hex_le32_to_cpu $5) ))"
|
||||
local num="$(( $end - $lba + 1 ))"
|
||||
|
||||
[ "$type" = "00000000000000000000000000000000" ] && continue
|
||||
|
||||
printf "%2d %5d %7d\n" $part $lba $num >> "/tmp/partmap.$filename"
|
||||
done
|
||||
} || {
|
||||
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
|
||||
}
|
||||
|
||||
indicate_upgrade() {
|
||||
. /etc/diag.sh
|
||||
set_state upgrade
|
||||
}
|
||||
|
||||
# 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
|
||||
echo 3 > /proc/sys/vm/drop_caches
|
||||
if [ -n "$UPGRADE_BACKUP" ]; then
|
||||
get_image "$1" "$2" | mtd $MTD_ARGS $MTD_CONFIG_ARGS -j "$UPGRADE_BACKUP" write - "${PART_NAME:-image}"
|
||||
else
|
||||
get_image "$1" "$2" | mtd $MTD_ARGS write - "${PART_NAME:-image}"
|
||||
fi
|
||||
[ $? -ne 0 ] && exit 1
|
||||
}
|
25
base-files/files/lib/upgrade/do_stage2
Executable file
25
base-files/files/lib/upgrade/do_stage2
Executable file
@ -0,0 +1,25 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
|
||||
include /lib/upgrade
|
||||
|
||||
v "Performing system upgrade..."
|
||||
if type 'platform_do_upgrade' >/dev/null 2>/dev/null; then
|
||||
platform_do_upgrade "$IMAGE"
|
||||
else
|
||||
default_do_upgrade "$IMAGE"
|
||||
fi
|
||||
|
||||
if [ -n "$UPGRADE_BACKUP" ] && 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
|
67
base-files/files/lib/upgrade/emmc.sh
Normal file
67
base-files/files/lib/upgrade/emmc.sh
Normal file
@ -0,0 +1,67 @@
|
||||
# Copyright (C) 2021 OpenWrt.org
|
||||
#
|
||||
|
||||
. /lib/functions.sh
|
||||
|
||||
emmc_upgrade_tar() {
|
||||
local tar_file="$1"
|
||||
[ "$CI_KERNPART" -a -z "$EMMC_KERN_DEV" ] && export EMMC_KERN_DEV="$(find_mmc_part $CI_KERNPART $CI_ROOTDEV)"
|
||||
[ "$CI_ROOTPART" -a -z "$EMMC_ROOT_DEV" ] && export EMMC_ROOT_DEV="$(find_mmc_part $CI_ROOTPART $CI_ROOTDEV)"
|
||||
[ "$CI_DATAPART" -a -z "$EMMC_DATA_DEV" ] && export EMMC_DATA_DEV="$(find_mmc_part $CI_DATAPART $CI_ROOTDEV)"
|
||||
local has_kernel
|
||||
local has_rootfs
|
||||
local board_dir=$(tar tf "$tar_file" | grep -m 1 '^sysupgrade-.*/$')
|
||||
board_dir=${board_dir%/}
|
||||
|
||||
tar tf "$tar_file" ${board_dir}/kernel 1>/dev/null 2>/dev/null && has_kernel=1
|
||||
tar tf "$tar_file" ${board_dir}/root 1>/dev/null 2>/dev/null && has_rootfs=1
|
||||
|
||||
[ "$has_kernel" = 1 -a "$EMMC_KERN_DEV" ] &&
|
||||
export EMMC_KERNEL_BLOCKS=$(($(tar xf "$tar_file" ${board_dir}/kernel -O | dd of="$EMMC_KERN_DEV" bs=512 2>&1 | grep "records out" | cut -d' ' -f1)))
|
||||
|
||||
[ "$has_rootfs" = 1 -a "$EMMC_ROOT_DEV" ] && {
|
||||
export EMMC_ROOTFS_BLOCKS=$(($(tar xf "$tar_file" ${board_dir}/root -O | dd of="$EMMC_ROOT_DEV" bs=512 2>&1 | grep "records out" | cut -d' ' -f1)))
|
||||
# Account for 64KiB ROOTDEV_OVERLAY_ALIGN in libfstools
|
||||
EMMC_ROOTFS_BLOCKS=$(((EMMC_ROOTFS_BLOCKS + 127) & ~127))
|
||||
}
|
||||
|
||||
if [ -z "$UPGRADE_BACKUP" ]; then
|
||||
if [ "$EMMC_DATA_DEV" ]; then
|
||||
dd if=/dev/zero of="$EMMC_DATA_DEV" bs=512 count=8
|
||||
elif [ "$EMMC_ROOTFS_BLOCKS" ]; then
|
||||
dd if=/dev/zero of="$EMMC_ROOT_DEV" bs=512 seek=$EMMC_ROOTFS_BLOCKS count=8
|
||||
elif [ "$EMMC_KERNEL_BLOCKS" ]; then
|
||||
dd if=/dev/zero of="$EMMC_KERN_DEV" bs=512 seek=$EMMC_KERNEL_BLOCKS count=8
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
emmc_upgrade_fit() {
|
||||
local fit_file="$1"
|
||||
[ "$CI_KERNPART" -a -z "$EMMC_KERN_DEV" ] && export EMMC_KERN_DEV="$(find_mmc_part $CI_KERNPART $CI_ROOTDEV)"
|
||||
|
||||
if [ "$EMMC_KERN_DEV" ]; then
|
||||
export EMMC_KERNEL_BLOCKS=$(($(get_image "$fit_file" | fwtool -i /dev/null -T - | dd of="$EMMC_KERN_DEV" bs=512 2>&1 | grep "records out" | cut -d' ' -f1)))
|
||||
|
||||
[ -z "$UPGRADE_BACKUP" ] && dd if=/dev/zero of="$EMMC_KERN_DEV" bs=512 seek=$EMMC_KERNEL_BLOCKS count=8
|
||||
fi
|
||||
}
|
||||
|
||||
emmc_copy_config() {
|
||||
if [ "$EMMC_DATA_DEV" ]; then
|
||||
dd if="$UPGRADE_BACKUP" of="$EMMC_DATA_DEV" bs=512
|
||||
elif [ "$EMMC_ROOTFS_BLOCKS" ]; then
|
||||
dd if="$UPGRADE_BACKUP" of="$EMMC_ROOT_DEV" bs=512 seek=$EMMC_ROOTFS_BLOCKS
|
||||
elif [ "$EMMC_KERNEL_BLOCKS" ]; then
|
||||
dd if="$UPGRADE_BACKUP" of="$EMMC_KERN_DEV" bs=512 seek=$EMMC_KERNEL_BLOCKS
|
||||
fi
|
||||
}
|
||||
|
||||
emmc_do_upgrade() {
|
||||
local file_type=$(identify_magic_long "$(get_magic_long "$1")")
|
||||
|
||||
case "$file_type" in
|
||||
"fit") emmc_upgrade_fit $1;;
|
||||
*) emmc_upgrade_tar $1;;
|
||||
esac
|
||||
}
|
93
base-files/files/lib/upgrade/fwtool.sh
Normal file
93
base-files/files/lib/upgrade/fwtool.sh
Normal file
@ -0,0 +1,93 @@
|
||||
fwtool_check_signature() {
|
||||
[ $# -gt 1 ] && return 1
|
||||
|
||||
[ ! -x /usr/bin/ucert ] && {
|
||||
if [ "$REQUIRE_IMAGE_SIGNATURE" = 1 ]; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
if ! fwtool -q -s /tmp/sysupgrade.ucert "$1"; then
|
||||
v "Image signature not present"
|
||||
[ "$REQUIRE_IMAGE_SIGNATURE" = 1 -a "$FORCE" != 1 ] && {
|
||||
v "Use sysupgrade -F to override this check when downgrading or flashing to vendor firmware"
|
||||
}
|
||||
[ "$REQUIRE_IMAGE_SIGNATURE" = 1 ] && return 1
|
||||
return 0
|
||||
fi
|
||||
|
||||
fwtool -q -T -s /dev/null "$1" | \
|
||||
ucert -V -m - -c "/tmp/sysupgrade.ucert" -P /etc/opkg/keys
|
||||
|
||||
return $?
|
||||
}
|
||||
|
||||
fwtool_check_image() {
|
||||
[ $# -gt 1 ] && return 1
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
if ! fwtool -q -i /tmp/sysupgrade.meta "$1"; then
|
||||
v "Image metadata not present"
|
||||
[ "$REQUIRE_IMAGE_METADATA" = 1 -a "$FORCE" != 1 ] && {
|
||||
v "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)" || {
|
||||
v "Invalid image metadata"
|
||||
return 1
|
||||
}
|
||||
|
||||
device="$(cat /tmp/sysinfo/board_name)"
|
||||
devicecompat="$(uci -q get system.@system[0].compat_version)"
|
||||
[ -n "$devicecompat" ] || devicecompat="1.0"
|
||||
|
||||
json_get_var imagecompat compat_version
|
||||
json_get_var compatmessage compat_message
|
||||
[ -n "$imagecompat" ] || imagecompat="1.0"
|
||||
|
||||
# select correct supported list based on compat_version
|
||||
# (using this ensures that compatibility check works for devices
|
||||
# not knowing about compat-version)
|
||||
local supported=supported_devices
|
||||
[ "$imagecompat" != "1.0" ] && supported=new_supported_devices
|
||||
json_select $supported || return 1
|
||||
|
||||
json_get_keys dev_keys
|
||||
for k in $dev_keys; do
|
||||
json_get_var dev "$k"
|
||||
if [ "$dev" = "$device" ]; then
|
||||
# major compat version -> no sysupgrade
|
||||
if [ "${devicecompat%.*}" != "${imagecompat%.*}" ]; then
|
||||
v "The device is supported, but this image is incompatible for sysupgrade based on the image version ($devicecompat->$imagecompat)."
|
||||
[ -n "$compatmessage" ] && v "$compatmessage"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# minor compat version -> sysupgrade with -n required
|
||||
if [ "${devicecompat#.*}" != "${imagecompat#.*}" ] && [ "$SAVE_CONFIG" = "1" ]; then
|
||||
[ "$IGNORE_MINOR_COMPAT" = 1 ] && return 0
|
||||
v "The device is supported, but the config is incompatible to the new image ($devicecompat->$imagecompat). Please upgrade without keeping config (sysupgrade -n)."
|
||||
[ -n "$compatmessage" ] && v "$compatmessage"
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
v "Device $device not supported by this image"
|
||||
local devices="Supported devices:"
|
||||
for k in $dev_keys; do
|
||||
json_get_var dev "$k"
|
||||
devices="$devices $dev"
|
||||
done
|
||||
v "$devices"
|
||||
|
||||
return 1
|
||||
}
|
11
base-files/files/lib/upgrade/keep.d/base-files-essential
Normal file
11
base-files/files/lib/upgrade/keep.d/base-files-essential
Normal file
@ -0,0 +1,11 @@
|
||||
# Essential files that will be always kept
|
||||
/etc/hosts
|
||||
/etc/inittab
|
||||
/etc/group
|
||||
/etc/passwd
|
||||
/etc/profile
|
||||
/etc/shadow
|
||||
/etc/shells
|
||||
/etc/shinit
|
||||
/etc/sysctl.conf
|
||||
/etc/rc.local
|
91
base-files/files/lib/upgrade/legacy-sdcard.sh
Normal file
91
base-files/files/lib/upgrade/legacy-sdcard.sh
Normal file
@ -0,0 +1,91 @@
|
||||
legacy_sdcard_check_image() {
|
||||
local file="$1"
|
||||
local diskdev partdev diff
|
||||
|
||||
export_bootdevice && export_partdevice diskdev 0 || {
|
||||
v "Unable to determine upgrade device"
|
||||
return 1
|
||||
}
|
||||
|
||||
get_partitions "/dev/$diskdev" bootdisk
|
||||
|
||||
v "Extract boot sector from the image"
|
||||
get_image_dd "$1" of=/tmp/image.bs count=1 bs=512b
|
||||
|
||||
get_partitions /tmp/image.bs image
|
||||
|
||||
#compare tables
|
||||
diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
|
||||
|
||||
rm -f /tmp/image.bs /tmp/partmap.bootdisk /tmp/partmap.image
|
||||
|
||||
if [ -n "$diff" ]; then
|
||||
v "Partition layout has changed. Full image will be written."
|
||||
ask_bool 0 "Abort" && exit 1
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
legacy_sdcard_do_upgrade() {
|
||||
local board=$(board_name)
|
||||
local diskdev partdev diff
|
||||
|
||||
export_bootdevice && export_partdevice diskdev 0 || {
|
||||
v "Unable to determine upgrade device"
|
||||
return 1
|
||||
}
|
||||
|
||||
sync
|
||||
|
||||
if [ "$UPGRADE_OPT_SAVE_PARTITIONS" = "1" ]; then
|
||||
get_partitions "/dev/$diskdev" bootdisk
|
||||
|
||||
v "Extract boot sector from the image"
|
||||
get_image_dd "$1" of=/tmp/image.bs count=1 bs=512b
|
||||
|
||||
get_partitions /tmp/image.bs image
|
||||
|
||||
#compare tables
|
||||
diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
|
||||
else
|
||||
diff=1
|
||||
fi
|
||||
|
||||
if [ -n "$diff" ]; then
|
||||
get_image_dd "$1" of="/dev/$diskdev" bs=4096 conv=fsync
|
||||
|
||||
# Separate removal and addtion is necessary; otherwise, partition 1
|
||||
# will be missing if it overlaps with the old partition 2
|
||||
partx -d - "/dev/$diskdev"
|
||||
partx -a - "/dev/$diskdev"
|
||||
else
|
||||
v "Writing bootloader to /dev/$diskdev"
|
||||
get_image_dd "$1" of="$diskdev" bs=512 skip=1 seek=1 count=2048 conv=fsync
|
||||
#iterate over each partition from the image and write it to the boot disk
|
||||
while read part start size; do
|
||||
if export_partdevice partdev $part; then
|
||||
v "Writing image to /dev/$partdev..."
|
||||
get_image_dd "$1" of="/dev/$partdev" ibs="512" obs=1M skip="$start" count="$size" conv=fsync
|
||||
else
|
||||
v "Unable to find partition $part device, skipped."
|
||||
fi
|
||||
done < /tmp/partmap.image
|
||||
|
||||
v "Writing new UUID to /dev/$diskdev..."
|
||||
get_image_dd "$1" of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
}
|
||||
|
||||
legacy_sdcard_copy_config() {
|
||||
local partdev
|
||||
|
||||
if export_partdevice partdev 1; then
|
||||
mkdir -p /boot
|
||||
[ -f /boot/kernel.img ] || mount -o rw,noatime /dev/$partdev /boot
|
||||
cp -af "$UPGRADE_BACKUP" "/boot/$BACKUP_FILE"
|
||||
sync
|
||||
umount /boot
|
||||
fi
|
||||
}
|
482
base-files/files/lib/upgrade/nand.sh
Normal file
482
base-files/files/lib/upgrade/nand.sh
Normal file
@ -0,0 +1,482 @@
|
||||
# Copyright (C) 2014 OpenWrt.org
|
||||
#
|
||||
|
||||
. /lib/functions.sh
|
||||
|
||||
# 'kernel' partition or UBI volume on NAND contains the kernel
|
||||
CI_KERNPART="${CI_KERNPART:-kernel}"
|
||||
|
||||
# 'ubi' partition on NAND contains UBI
|
||||
# There are also CI_KERN_UBIPART and CI_ROOT_UBIPART if kernel
|
||||
# and rootfs are on separated UBIs.
|
||||
CI_UBIPART="${CI_UBIPART:-ubi}"
|
||||
|
||||
# 'rootfs' UBI volume on NAND contains the rootfs
|
||||
CI_ROOTPART="${CI_ROOTPART:-rootfs}"
|
||||
|
||||
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/class/ubi/"
|
||||
[ ! -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 cmtdnum
|
||||
mtdnum="$( find_mtd_index $1 )"
|
||||
[ ! "$mtdnum" ] && return 1
|
||||
for ubidevdir in /sys/class/ubi/ubi*; do
|
||||
[ ! -e "$ubidevdir/mtd_num" ] && continue
|
||||
cmtdnum="$( cat $ubidevdir/mtd_num )"
|
||||
if [ "$mtdnum" = "$cmtdnum" ]; then
|
||||
ubidev=$( basename $ubidevdir )
|
||||
ubi_mknod "$ubidevdir"
|
||||
echo $ubidev
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
nand_get_magic_long() {
|
||||
(${3}cat "$1" | dd bs=4 "skip=${2:-0}" count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2> /dev/null
|
||||
}
|
||||
|
||||
get_magic_long_tar() {
|
||||
(tar xO${3}f "$1" "$2" | dd bs=4 count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2> /dev/null
|
||||
}
|
||||
|
||||
identify() {
|
||||
identify_magic_long $(nand_get_magic_long "$@")
|
||||
}
|
||||
|
||||
identify_tar() {
|
||||
identify_magic_long $(get_magic_long_tar "$@")
|
||||
}
|
||||
|
||||
identify_if_gzip() {
|
||||
if [ "$(identify "$1")" = gzip ]; then echo -n z; fi
|
||||
}
|
||||
|
||||
nand_restore_config() {
|
||||
local ubidev=$( nand_find_ubi "${CI_ROOT_UBIPART:-$CI_UBIPART}" )
|
||||
local ubivol="$( nand_find_volume $ubidev rootfs_data )"
|
||||
if [ ! "$ubivol" ]; then
|
||||
ubivol="$( nand_find_volume $ubidev "$CI_ROOTPART" )"
|
||||
if [ ! "$ubivol" ]; then
|
||||
echo "cannot find ubifs data volume"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
mkdir /tmp/new_root
|
||||
if ! mount -t ubifs /dev/$ubivol /tmp/new_root; then
|
||||
echo "cannot mount ubifs volume $ubivol"
|
||||
rmdir /tmp/new_root
|
||||
return 1
|
||||
fi
|
||||
if mv "$1" "/tmp/new_root/$BACKUP_FILE"; then
|
||||
if umount /tmp/new_root; then
|
||||
echo "configuration saved"
|
||||
rmdir /tmp/new_root
|
||||
return 0
|
||||
fi
|
||||
else
|
||||
umount /tmp/new_root
|
||||
fi
|
||||
echo "could not save configuration to ubifs volume $ubivol"
|
||||
rmdir /tmp/new_root
|
||||
return 1
|
||||
}
|
||||
|
||||
nand_remove_ubiblock() {
|
||||
local ubivol="$1"
|
||||
|
||||
local ubiblk="ubiblock${ubivol:3}"
|
||||
if [ -e "/dev/$ubiblk" ]; then
|
||||
umount "/dev/$ubiblk" && echo "unmounted /dev/$ubiblk" || :
|
||||
if ! ubiblock -r "/dev/$ubivol"; then
|
||||
echo "cannot remove $ubiblk"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
nand_attach_ubi() {
|
||||
local ubipart="$1"
|
||||
local has_env="${2:-0}"
|
||||
|
||||
local mtdnum="$( find_mtd_index "$ubipart" )"
|
||||
if [ ! "$mtdnum" ]; then
|
||||
>&2 echo "cannot find ubi mtd partition $ubipart"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local ubidev="$( nand_find_ubi "$ubipart" )"
|
||||
if [ ! "$ubidev" ]; then
|
||||
>&2 ubiattach -m "$mtdnum"
|
||||
ubidev="$( nand_find_ubi "$ubipart" )"
|
||||
|
||||
if [ ! "$ubidev" ]; then
|
||||
>&2 ubiformat /dev/mtd$mtdnum -y
|
||||
>&2 ubiattach -m "$mtdnum"
|
||||
ubidev="$( nand_find_ubi "$ubipart" )"
|
||||
|
||||
if [ ! "$ubidev" ]; then
|
||||
>&2 echo "cannot attach ubi mtd partition $ubipart"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "$has_env" -gt 0 ]; then
|
||||
>&2 ubimkvol /dev/$ubidev -n 0 -N ubootenv -s 1MiB
|
||||
>&2 ubimkvol /dev/$ubidev -n 1 -N ubootenv2 -s 1MiB
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "$ubidev"
|
||||
return 0
|
||||
}
|
||||
|
||||
nand_detach_ubi() {
|
||||
local ubipart="$1"
|
||||
|
||||
local mtdnum="$( find_mtd_index "$ubipart" )"
|
||||
if [ ! "$mtdnum" ]; then
|
||||
echo "cannot find ubi mtd partition $ubipart"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local ubidev="$( nand_find_ubi "$ubipart" )"
|
||||
if [ "$ubidev" ]; then
|
||||
for ubivol in $(find /dev -name "${ubidev}_*" -maxdepth 1 | sort); do
|
||||
ubivol="${ubivol:5}"
|
||||
nand_remove_ubiblock "$ubivol" || :
|
||||
umount "/dev/$ubivol" && echo "unmounted /dev/$ubivol" || :
|
||||
done
|
||||
if ! ubidetach -m "$mtdnum"; then
|
||||
echo "cannot detach ubi mtd partition $ubipart"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
nand_upgrade_prepare_ubi() {
|
||||
local rootfs_length="$1"
|
||||
local rootfs_type="$2"
|
||||
local rootfs_data_max="$(fw_printenv -n rootfs_data_max 2> /dev/null)"
|
||||
[ -n "$rootfs_data_max" ] && rootfs_data_max=$((rootfs_data_max))
|
||||
|
||||
local kernel_length="$3"
|
||||
local has_env="${4:-0}"
|
||||
local kern_ubidev
|
||||
local root_ubidev
|
||||
|
||||
[ -n "$rootfs_length" -o -n "$kernel_length" ] || return 1
|
||||
|
||||
if [ -n "$CI_KERN_UBIPART" -a -n "$CI_ROOT_UBIPART" ]; then
|
||||
kern_ubidev="$( nand_attach_ubi "$CI_KERN_UBIPART" "$has_env" )"
|
||||
[ -n "$kern_ubidev" ] || return 1
|
||||
root_ubidev="$( nand_attach_ubi "$CI_ROOT_UBIPART" )"
|
||||
[ -n "$root_ubidev" ] || return 1
|
||||
else
|
||||
kern_ubidev="$( nand_attach_ubi "$CI_UBIPART" "$has_env" )"
|
||||
[ -n "$kern_ubidev" ] || return 1
|
||||
root_ubidev="$kern_ubidev"
|
||||
fi
|
||||
|
||||
local kern_ubivol="$( nand_find_volume $kern_ubidev "$CI_KERNPART" )"
|
||||
local root_ubivol="$( nand_find_volume $root_ubidev "$CI_ROOTPART" )"
|
||||
local data_ubivol="$( nand_find_volume $root_ubidev rootfs_data )"
|
||||
[ "$root_ubivol" = "$kern_ubivol" ] && root_ubivol=
|
||||
|
||||
# remove ubiblocks
|
||||
[ "$kern_ubivol" ] && { nand_remove_ubiblock $kern_ubivol || return 1; }
|
||||
[ "$root_ubivol" ] && { nand_remove_ubiblock $root_ubivol || return 1; }
|
||||
[ "$data_ubivol" ] && { nand_remove_ubiblock $data_ubivol || return 1; }
|
||||
|
||||
# kill volumes
|
||||
[ "$kern_ubivol" ] && ubirmvol /dev/$kern_ubidev -N "$CI_KERNPART" || :
|
||||
[ "$root_ubivol" ] && ubirmvol /dev/$root_ubidev -N "$CI_ROOTPART" || :
|
||||
[ "$data_ubivol" ] && ubirmvol /dev/$root_ubidev -N rootfs_data || :
|
||||
|
||||
# create kernel vol
|
||||
if [ -n "$kernel_length" ]; then
|
||||
if ! ubimkvol /dev/$kern_ubidev -N "$CI_KERNPART" -s $kernel_length; then
|
||||
echo "cannot create kernel volume"
|
||||
return 1;
|
||||
fi
|
||||
fi
|
||||
|
||||
# create rootfs vol
|
||||
if [ -n "$rootfs_length" ]; then
|
||||
local rootfs_size_param
|
||||
if [ "$rootfs_type" = "ubifs" ]; then
|
||||
rootfs_size_param="-m"
|
||||
else
|
||||
rootfs_size_param="-s $rootfs_length"
|
||||
fi
|
||||
if ! ubimkvol /dev/$root_ubidev -N "$CI_ROOTPART" $rootfs_size_param; then
|
||||
echo "cannot create rootfs volume"
|
||||
return 1;
|
||||
fi
|
||||
fi
|
||||
|
||||
# create rootfs_data vol for non-ubifs rootfs
|
||||
if [ "$rootfs_type" != "ubifs" ]; then
|
||||
local rootfs_data_size_param="-m"
|
||||
if [ -n "$rootfs_data_max" ]; then
|
||||
rootfs_data_size_param="-s $rootfs_data_max"
|
||||
fi
|
||||
if ! ubimkvol /dev/$root_ubidev -N rootfs_data $rootfs_data_size_param; then
|
||||
if ! ubimkvol /dev/$root_ubidev -N rootfs_data -m; then
|
||||
echo "cannot initialize rootfs_data volume"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# Write the UBI image to MTD ubi partition
|
||||
nand_upgrade_ubinized() {
|
||||
local ubi_file="$1"
|
||||
local gz="$2"
|
||||
|
||||
local ubi_length=$( (${gz}cat "$ubi_file" | wc -c) 2> /dev/null)
|
||||
|
||||
nand_detach_ubi "$CI_UBIPART" || return 1
|
||||
|
||||
local mtdnum="$( find_mtd_index "$CI_UBIPART" )"
|
||||
${gz}cat "$ubi_file" | ubiformat "/dev/mtd$mtdnum" -S "$ubi_length" -y -f - && ubiattach -m "$mtdnum"
|
||||
}
|
||||
|
||||
# Write the UBIFS image to UBI rootfs volume
|
||||
nand_upgrade_ubifs() {
|
||||
local ubifs_file="$1"
|
||||
local gz="$2"
|
||||
|
||||
local ubifs_length=$( (${gz}cat "$ubifs_file" | wc -c) 2> /dev/null)
|
||||
|
||||
nand_upgrade_prepare_ubi "$ubifs_length" "ubifs" "" "" || return 1
|
||||
|
||||
local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
||||
local root_ubivol="$(nand_find_volume $ubidev "$CI_ROOTPART")"
|
||||
${gz}cat "$ubifs_file" | ubiupdatevol /dev/$root_ubivol -s "$ubifs_length" -
|
||||
}
|
||||
|
||||
# Write the FIT image to UBI kernel volume
|
||||
nand_upgrade_fit() {
|
||||
local fit_file="$1"
|
||||
local gz="$2"
|
||||
|
||||
local fit_length=$( (${gz}cat "$fit_file" | wc -c) 2> /dev/null)
|
||||
|
||||
nand_upgrade_prepare_ubi "" "" "$fit_length" "1" || return 1
|
||||
|
||||
local fit_ubidev="$(nand_find_ubi "$CI_UBIPART")"
|
||||
local fit_ubivol="$(nand_find_volume $fit_ubidev "$CI_KERNPART")"
|
||||
${gz}cat "$fit_file" | ubiupdatevol /dev/$fit_ubivol -s "$fit_length" -
|
||||
}
|
||||
|
||||
# Write images in the TAR file to MTD partitions and/or UBI volumes as required
|
||||
nand_upgrade_tar() {
|
||||
local tar_file="$1"
|
||||
local gz="$2"
|
||||
local jffs2_markers="${CI_JFFS2_CLEAN_MARKERS:-0}"
|
||||
|
||||
# WARNING: This fails if tar contains more than one 'sysupgrade-*' directory.
|
||||
local board_dir="$(tar t${gz}f "$tar_file" | grep -m 1 '^sysupgrade-.*/$')"
|
||||
board_dir="${board_dir%/}"
|
||||
|
||||
local kernel_mtd kernel_length
|
||||
if [ "$CI_KERNPART" != "none" ]; then
|
||||
kernel_mtd="$(find_mtd_index "$CI_KERNPART")"
|
||||
kernel_length=$( (tar xO${gz}f "$tar_file" "$board_dir/kernel" | wc -c) 2> /dev/null)
|
||||
[ "$kernel_length" = 0 ] && kernel_length=
|
||||
fi
|
||||
local rootfs_length=$( (tar xO${gz}f "$tar_file" "$board_dir/root" | wc -c) 2> /dev/null)
|
||||
[ "$rootfs_length" = 0 ] && rootfs_length=
|
||||
local rootfs_type
|
||||
[ "$rootfs_length" ] && rootfs_type="$(identify_tar "$tar_file" "$board_dir/root" "$gz")"
|
||||
|
||||
local ubi_kernel_length
|
||||
if [ "$kernel_length" ]; then
|
||||
if [ "$kernel_mtd" ]; then
|
||||
# On some devices, the raw kernel and ubi partitions overlap.
|
||||
# These devices brick if the kernel partition is erased.
|
||||
# Hence only invalidate kernel for now.
|
||||
dd if=/dev/zero bs=4096 count=1 2> /dev/null | \
|
||||
mtd write - "$CI_KERNPART"
|
||||
else
|
||||
ubi_kernel_length="$kernel_length"
|
||||
fi
|
||||
fi
|
||||
|
||||
local has_env=0
|
||||
nand_upgrade_prepare_ubi "$rootfs_length" "$rootfs_type" "$ubi_kernel_length" "$has_env" || return 1
|
||||
|
||||
if [ "$rootfs_length" ]; then
|
||||
local ubidev="$( nand_find_ubi "${CI_ROOT_UBIPART:-$CI_UBIPART}" )"
|
||||
local root_ubivol="$( nand_find_volume $ubidev "$CI_ROOTPART" )"
|
||||
tar xO${gz}f "$tar_file" "$board_dir/root" | \
|
||||
ubiupdatevol /dev/$root_ubivol -s "$rootfs_length" -
|
||||
fi
|
||||
if [ "$kernel_length" ]; then
|
||||
if [ "$kernel_mtd" ]; then
|
||||
if [ "$jffs2_markers" = 1 ]; then
|
||||
flash_erase -j "/dev/mtd${kernel_mtd}" 0 0
|
||||
tar xO${gz}f "$tar_file" "$board_dir/kernel" | \
|
||||
nandwrite "/dev/mtd${kernel_mtd}" -
|
||||
else
|
||||
tar xO${gz}f "$tar_file" "$board_dir/kernel" | \
|
||||
mtd write - "$CI_KERNPART"
|
||||
fi
|
||||
else
|
||||
local ubidev="$( nand_find_ubi "${CI_KERN_UBIPART:-$CI_UBIPART}" )"
|
||||
local kern_ubivol="$( nand_find_volume $ubidev "$CI_KERNPART" )"
|
||||
tar xO${gz}f "$tar_file" "$board_dir/kernel" | \
|
||||
ubiupdatevol /dev/$kern_ubivol -s "$kernel_length" -
|
||||
fi
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
nand_verify_if_gzip_file() {
|
||||
local file="$1"
|
||||
local gz="$2"
|
||||
|
||||
if [ "$gz" = z ]; then
|
||||
echo "verifying compressed sysupgrade file integrity"
|
||||
if ! gzip -t "$file"; then
|
||||
echo "corrupted compressed sysupgrade file"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
nand_verify_tar_file() {
|
||||
local file="$1"
|
||||
local gz="$2"
|
||||
|
||||
echo "verifying sysupgrade tar file integrity"
|
||||
if ! tar xO${gz}f "$file" > /dev/null; then
|
||||
echo "corrupted sysupgrade tar file"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
nand_do_flash_file() {
|
||||
local file="$1"
|
||||
|
||||
local gz="$(identify_if_gzip "$file")"
|
||||
local file_type="$(identify "$file" "" "$gz")"
|
||||
|
||||
[ ! "$(find_mtd_index "$CI_UBIPART")" ] && CI_UBIPART=rootfs
|
||||
|
||||
case "$file_type" in
|
||||
"fit")
|
||||
nand_verify_if_gzip_file "$file" "$gz" || return 1
|
||||
nand_upgrade_fit "$file" "$gz"
|
||||
;;
|
||||
"ubi")
|
||||
nand_verify_if_gzip_file "$file" "$gz" || return 1
|
||||
nand_upgrade_ubinized "$file" "$gz"
|
||||
;;
|
||||
"ubifs")
|
||||
nand_verify_if_gzip_file "$file" "$gz" || return 1
|
||||
nand_upgrade_ubifs "$file" "$gz"
|
||||
;;
|
||||
*)
|
||||
nand_verify_tar_file "$file" "$gz" || return 1
|
||||
nand_upgrade_tar "$file" "$gz"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
nand_do_restore_config() {
|
||||
local conf_tar="/tmp/sysupgrade.tgz"
|
||||
[ ! -f "$conf_tar" ] || nand_restore_config "$conf_tar"
|
||||
}
|
||||
|
||||
# Recognize type of passed file and start the upgrade process
|
||||
nand_do_upgrade() {
|
||||
local file="$1"
|
||||
|
||||
sync
|
||||
nand_do_flash_file "$file" && nand_do_upgrade_success
|
||||
nand_do_upgrade_failed
|
||||
}
|
||||
|
||||
nand_do_upgrade_success() {
|
||||
if nand_do_restore_config && sync; then
|
||||
echo "sysupgrade successful"
|
||||
umount -a
|
||||
reboot -f
|
||||
fi
|
||||
nand_do_upgrade_failed
|
||||
}
|
||||
|
||||
nand_do_upgrade_failed() {
|
||||
sync
|
||||
echo "sysupgrade failed"
|
||||
# Should we reboot or bring up some failsafe mode instead?
|
||||
umount -a
|
||||
reboot -f
|
||||
}
|
||||
|
||||
# Check if passed file is a valid one for NAND sysupgrade.
|
||||
# Currently it accepts 4 types of files:
|
||||
# 1) UBI: a ubinized image containing required UBI volumes.
|
||||
# 2) UBIFS: a UBIFS rootfs volume image.
|
||||
# 3) FIT: a FIT image containing kernel and rootfs.
|
||||
# 4) TAR: an archive that includes directory "sysupgrade-${BOARD_NAME}" containing
|
||||
# a non-empty "CONTROL" file and required partition and/or volume images.
|
||||
#
|
||||
# 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 file="$2"
|
||||
|
||||
local gz="$(identify_if_gzip "$file")"
|
||||
local file_type="$(identify "$file" "" "$gz")"
|
||||
local control_length=$( (tar xO${gz}f "$file" "sysupgrade-${board_name//,/_}/CONTROL" | wc -c) 2> /dev/null)
|
||||
|
||||
if [ "$control_length" = 0 ]; then
|
||||
control_length=$( (tar xO${gz}f "$file" "sysupgrade-${board_name//_/,}/CONTROL" | wc -c) 2> /dev/null)
|
||||
fi
|
||||
|
||||
if [ "$control_length" != 0 ]; then
|
||||
nand_verify_tar_file "$file" "$gz" || return 1
|
||||
else
|
||||
nand_verify_if_gzip_file "$file" "$gz" || return 1
|
||||
if [ "$file_type" != "fit" -a "$file_type" != "ubi" -a "$file_type" != "ubifs" ]; then
|
||||
echo "invalid sysupgrade file"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
175
base-files/files/lib/upgrade/stage2
Executable file
175
base-files/files/lib/upgrade/stage2
Executable file
@ -0,0 +1,175 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
. /lib/functions/system.sh
|
||||
|
||||
export IMAGE="$1"
|
||||
COMMAND="$2"
|
||||
|
||||
export INTERACTIVE=0
|
||||
export VERBOSE=1
|
||||
export CONFFILES=/tmp/sysupgrade.conffiles
|
||||
|
||||
RAMFS_COPY_BIN= # extra programs for temporary ramfs root
|
||||
RAMFS_COPY_DATA= # extra data files
|
||||
|
||||
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() {
|
||||
RAMFS_COPY_LOSETUP="$(command -v /usr/sbin/losetup)"
|
||||
RAMFS_COPY_LVM="$(command -v lvm)"
|
||||
|
||||
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 dd tar gzip \
|
||||
ls basename find cp mv rm mkdir rmdir mknod touch chmod \
|
||||
'[' printf wc grep awk sed cut sort tail \
|
||||
mtd partx losetup mkfs.ext4 nandwrite flash_erase \
|
||||
ubiupdatevol ubiattach ubiblock ubiformat \
|
||||
ubidetach ubirsvol ubirmvol ubimkvol \
|
||||
snapshot snapshot_tool date logger \
|
||||
/usr/sbin/fw_printenv /usr/bin/fwtool \
|
||||
$RAMFS_COPY_LOSETUP $RAMFS_COPY_LVM \
|
||||
$RAMFS_COPY_BIN
|
||||
do
|
||||
local file="$(command -v "$binary" 2>/dev/null)"
|
||||
[ -n "$file" ] && install_bin "$file"
|
||||
done
|
||||
install_file /etc/resolv.conf /lib/*.sh /lib/functions/*.sh \
|
||||
/lib/upgrade/*.sh /lib/upgrade/do_stage2 \
|
||||
/usr/share/libubox/jshn.sh /usr/sbin/fw_setenv \
|
||||
/etc/fw_env.config $RAMFS_COPY_DATA
|
||||
|
||||
mkdir -p $RAM_ROOT/var/lock
|
||||
|
||||
[ -L "/lib64" ] && ln -s /lib $RAM_ROOT/lib64
|
||||
|
||||
supivot $RAM_ROOT /mnt || {
|
||||
v "Failed to switch over to ramfs. Please reboot."
|
||||
exit 1
|
||||
}
|
||||
|
||||
/bin/mount -o remount,ro /mnt
|
||||
/bin/umount -l /mnt
|
||||
|
||||
grep -e "^/dev/dm-.*" -e "^/dev/loop.*" /proc/mounts | while read bdev mp _r; do
|
||||
umount $mp
|
||||
done
|
||||
|
||||
[ "$RAMFS_COPY_LOSETUP" ] && losetup -D
|
||||
[ "$RAMFS_COPY_LVM" ] && {
|
||||
mkdir -p /tmp/lvm/cache
|
||||
$RAMFS_COPY_LVM vgchange -aln --ignorelockingfailure
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
v "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 rest < $stat
|
||||
name="${rest#\(}" ; rest="${name##*\) }" ; name="${name%\)*}"
|
||||
set -- $rest ; state="$1" ; ppid="$2"
|
||||
|
||||
# Skip PID1, our parent, ourself and our children
|
||||
[ $pid -ne 1 -a $pid -ne $proc_ppid -a $pid -ne $$ -a $ppid -ne $$ ] || continue
|
||||
|
||||
[ -f "/proc/$pid/cmdline" ] || continue
|
||||
|
||||
local cmdline
|
||||
read cmdline < /proc/$pid/cmdline
|
||||
|
||||
# Skip kernel threads
|
||||
[ -n "$cmdline" ] || continue
|
||||
|
||||
v "Sending signal $sig to $name ($pid)"
|
||||
kill -$sig $pid 2>/dev/null
|
||||
|
||||
[ $loop -eq 1 ] && sleep 2 && run=true
|
||||
done
|
||||
|
||||
let loop_limit--
|
||||
[ $loop_limit -eq 0 ] && {
|
||||
v "Failed to kill all processes."
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
}
|
||||
|
||||
indicate_upgrade
|
||||
|
||||
while read -r a b c; do
|
||||
case "$a" in
|
||||
MemT*) mem="$b" ;; esac
|
||||
done < /proc/meminfo
|
||||
|
||||
[ "$mem" -gt 32768 ] && \
|
||||
skip_services="dnsmasq log network"
|
||||
for service in /etc/init.d/*; do
|
||||
service=${service##*/}
|
||||
|
||||
case " $skip_services " in
|
||||
*" $service "*) continue ;; esac
|
||||
|
||||
ubus call service delete '{ "name": "'"$service"'" }' 2>/dev/null
|
||||
done
|
||||
|
||||
killall -9 telnetd 2>/dev/null
|
||||
killall -9 dropbear 2>/dev/null
|
||||
killall -9 ash 2>/dev/null
|
||||
|
||||
kill_remaining TERM
|
||||
sleep 4
|
||||
kill_remaining KILL 1
|
||||
|
||||
sleep 6
|
||||
|
||||
echo 3 > /proc/sys/vm/drop_caches
|
||||
|
||||
if [ -n "$IMAGE" ] && type 'platform_pre_upgrade' >/dev/null 2>/dev/null; then
|
||||
platform_pre_upgrade "$IMAGE"
|
||||
fi
|
||||
|
||||
if [ -n "$(rootfs_type)" ]; then
|
||||
v "Switching to ramdisk..."
|
||||
switch_to_ramfs
|
||||
fi
|
||||
|
||||
# Exec new shell from ramfs
|
||||
exec /bin/busybox ash -c "$COMMAND"
|
3
base-files/files/rom/note
Normal file
3
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
base-files/files/sbin/firstboot
Executable file
3
base-files/files/sbin/firstboot
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
/sbin/jffs2reset $@
|
18
base-files/files/sbin/hotplug-call
Executable file
18
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##*/}"
|
||||
|
||||
if [ \! -z "$1" -a -d /etc/hotplug.d/$1 ]; then
|
||||
for script in $(ls /etc/hotplug.d/$1/* 2>&-); do (
|
||||
[ -f $script ] && . $script
|
||||
); done
|
||||
fi
|
25
base-files/files/sbin/led.sh
Executable file
25
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
|
||||
}
|
130
base-files/files/sbin/pkg_check
Executable file
130
base-files/files/sbin/pkg_check
Executable file
@ -0,0 +1,130 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Package checksums checking script
|
||||
# (C) 2018 CZ.NIC, z.s.p.o.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
ERRFATAL="no"
|
||||
QUIET="yes"
|
||||
MISSING=""
|
||||
SUMMARY=""
|
||||
NL="
|
||||
"
|
||||
|
||||
# Arguments parsing
|
||||
while expr "x$1" : "x-" > /dev/null; do
|
||||
if [ "x$1" = "x-s" ]; then
|
||||
ERRFATAL="yes"
|
||||
shift
|
||||
elif [ "x$1" = "x-v" ]; then
|
||||
QUIET=" no"
|
||||
shift
|
||||
else
|
||||
echo "Usage: $(basename $0) [-s] [-v] [pkg1 pkg2 ...]"
|
||||
echo
|
||||
echo " -s Stop on first change"
|
||||
echo " -v Verbose"
|
||||
if [ "x$1" = "x-h" ]; then
|
||||
exit 0
|
||||
else
|
||||
echo
|
||||
echo "ERROR: Unknown option '$1'"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# Check all packages by default
|
||||
if [ -z "$1" ]; then
|
||||
set $(cd /usr/lib/opkg/info/; for i in *.files-sha256sum; do basename $i .files-sha256sum; done)
|
||||
fi
|
||||
|
||||
# Iterate over packages
|
||||
while [ "$1" ]; do
|
||||
if [ \! -f "/usr/lib/opkg/info/$1.files-sha256sum" ]; then
|
||||
if [ "$ERRFATAL" = no ]; then
|
||||
echo " * No checksums for $1 - skipping"
|
||||
echo
|
||||
else
|
||||
echo " * No checksums for $1 - exiting"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$MISSING" ]; then
|
||||
MISSING="$1"
|
||||
else
|
||||
MISSING="$MISSING, $1"
|
||||
fi
|
||||
shift
|
||||
continue
|
||||
fi
|
||||
[ $QUIET = yes ] || echo " * Checking package $1:"
|
||||
ERR=""
|
||||
CHECK="$(sha256sum -c /usr/lib/opkg/info/$1.files-sha256sum 2> /dev/null)"
|
||||
|
||||
# Are the changed files config files?
|
||||
if [ $? -ne 0 ] && [ "$(cat "/usr/lib/opkg/info/$1.files-sha256sum")" ]; then
|
||||
NEWCHECK="$(echo "$CHECK" | grep '^.*: OK$')"
|
||||
for i in $(echo "$CHECK" | sed -n 's|^\(.*\): FAILED$|\1|p'); do
|
||||
if [ "$(grep "^$i\$" "/usr/lib/opkg/info/$1.conffiles" 2> /dev/null)" ] || \
|
||||
[ "$(echo "$i" | grep "^/etc/uci-defaults/")" ]; then
|
||||
NEWCHECK="${NEWCHECK}${NL}${i}: CONFIGURED"
|
||||
else
|
||||
NEWCHECK="${NEWCHECK}${NL}${i}: FAILED"
|
||||
ERR="y"
|
||||
fi
|
||||
done
|
||||
CHECK="$NEWCHECK"
|
||||
fi
|
||||
|
||||
# Do we have changed files or not?
|
||||
if [ -z "$ERR" ]; then
|
||||
[ $QUIET = yes ] || [ ! -s "/usr/lib/opkg/info/$1.files-sha256sum" ] || echo "$CHECK" | sed 's|^| - |'
|
||||
[ $QUIET = yes ] || echo " * Package $1 is ok"
|
||||
[ $QUIET = yes ] || echo
|
||||
else
|
||||
if [ $QUIET = yes ]; then
|
||||
echo " * Changes found in package $1:"
|
||||
echo "$CHECK" | sed -n 's|^\(.*:[[:blank:]]*FAILED\)$| - \1|p'
|
||||
else
|
||||
echo "$CHECK" | sed 's|^| - |'
|
||||
echo " * Changes found in package $1!"
|
||||
fi
|
||||
if [ "$ERRFATAL" = yes ]; then
|
||||
echo
|
||||
echo "Exiting on first change found!"
|
||||
exit 1
|
||||
fi
|
||||
for i in $(echo "$CHECK" | sed -n 's|^\(.*\): FAILED$|\1|p'); do
|
||||
SUMMARY="${SUMMARY}${NL} - $1: $i"
|
||||
done
|
||||
echo
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
# If there are changed files, report them
|
||||
if [ "$SUMMARY" ]; then
|
||||
echo "Some packages contain changed files!"
|
||||
echo "Maybe something worth looking into?"
|
||||
echo "Here is the list of packages and changed files:"
|
||||
echo "$SUMMARY"
|
||||
fi
|
||||
if [ "$MISSING" ]; then
|
||||
echo "Following packages are missing checksums: $MISSING"
|
||||
fi
|
||||
if [ "$MISSING" ] || [ "$SUMMARY" ]; then
|
||||
exit 1
|
||||
fi
|
384
base-files/files/sbin/sysupgrade
Executable file
384
base-files/files/sbin/sysupgrade
Executable file
@ -0,0 +1,384 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
. /lib/functions/system.sh
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
# initialize defaults
|
||||
export MTD_ARGS=""
|
||||
export MTD_CONFIG_ARGS=""
|
||||
export INTERACTIVE=0
|
||||
export VERBOSE=1
|
||||
export SAVE_CONFIG=1
|
||||
export SAVE_OVERLAY=0
|
||||
export SAVE_OVERLAY_PATH=
|
||||
export SAVE_PARTITIONS=1
|
||||
export SAVE_INSTALLED_PKGS=0
|
||||
export SKIP_UNCHANGED=0
|
||||
export CONF_IMAGE=
|
||||
export CONF_BACKUP_LIST=0
|
||||
export CONF_BACKUP=
|
||||
export CONF_RESTORE=
|
||||
export IGNORE_MINOR_COMPAT=0
|
||||
export NEED_IMAGE=
|
||||
export HELP=0
|
||||
export FORCE=0
|
||||
export TEST=0
|
||||
export UMOUNT_ETCBACKUP_DIR=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 SAVE_OVERLAY_PATH=/etc;;
|
||||
-o) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/;;
|
||||
-p) export SAVE_PARTITIONS=0;;
|
||||
-k) export SAVE_INSTALLED_PKGS=1;;
|
||||
-u) export SKIP_UNCHANGED=1;;
|
||||
-b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; shift;;
|
||||
-r|--restore-backup) export CONF_RESTORE="$2" NEED_IMAGE=1; shift;;
|
||||
-l|--list-backup) export CONF_BACKUP_LIST=1;;
|
||||
-f) export CONF_IMAGE="$2"; shift;;
|
||||
-F|--force) export FORCE=1;;
|
||||
-T|--test) export TEST=1;;
|
||||
-h|--help) export HELP=1; break;;
|
||||
--ignore-minor-compat-version) export IGNORE_MINOR_COMPAT=1;;
|
||||
-*)
|
||||
echo "Invalid option: $1" >&2
|
||||
exit 1
|
||||
;;
|
||||
*) break;;
|
||||
esac
|
||||
shift;
|
||||
done
|
||||
|
||||
export CONFFILES=/tmp/sysupgrade.conffiles
|
||||
export CONF_TAR=/tmp/sysupgrade.tgz
|
||||
export ETCBACKUP_DIR=/etc/backup
|
||||
export INSTALLED_PACKAGES=${ETCBACKUP_DIR}/installed_packages.txt
|
||||
|
||||
IMAGE="$1"
|
||||
|
||||
[ -z "$IMAGE" -a -z "$NEED_IMAGE" -a $CONF_BACKUP_LIST -eq 0 -o $HELP -gt 0 ] && {
|
||||
cat <<EOF
|
||||
Usage: $0 [<upgrade-option>...] <image file or URL>
|
||||
$0 [-q] [-i] [-c] [-u] [-o] [-k] <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/
|
||||
-o attempt to preserve all changed files in /, except those
|
||||
from packages but including changed confs.
|
||||
-u skip from backup files that are equal to those in /rom
|
||||
-n do not save configuration over reflash
|
||||
-p do not attempt to restore the partition table after flash.
|
||||
-k include in backup a list of current installed packages at
|
||||
$INSTALLED_PACKAGES
|
||||
-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!
|
||||
--ignore-minor-compat-version
|
||||
Flash image even if the minor compat version is incompatible.
|
||||
-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}" | busybox sha256sum -sc - || echo "$file"
|
||||
done
|
||||
}
|
||||
|
||||
list_static_conffiles() {
|
||||
local filter=$1
|
||||
|
||||
find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' \
|
||||
/etc/sysupgrade.conf /lib/upgrade/keep.d/* 2>/dev/null) \
|
||||
\( -type f -o -type l \) $filter 2>/dev/null
|
||||
}
|
||||
|
||||
add_conffiles() {
|
||||
local file="$1"
|
||||
|
||||
( list_static_conffiles "$find_filter"; list_changed_conffiles ) |
|
||||
sort -u > "$file"
|
||||
return 0
|
||||
}
|
||||
|
||||
add_overlayfiles() {
|
||||
local file="$1"
|
||||
|
||||
local packagesfiles=$1.packagesfiles
|
||||
touch "$packagesfiles"
|
||||
|
||||
if [ "$SAVE_OVERLAY_PATH" = / ]; then
|
||||
local conffiles=$1.conffiles
|
||||
local keepfiles=$1.keepfiles
|
||||
|
||||
list_conffiles | cut -f2 -d ' ' | sort -u > "$conffiles"
|
||||
|
||||
# backup files from /etc/sysupgrade.conf and /lib/upgrade/keep.d, but
|
||||
# ignore those aready controlled by opkg conffiles
|
||||
list_static_conffiles | sort -u |
|
||||
grep -h -v -x -F -f $conffiles > "$keepfiles"
|
||||
|
||||
# backup conffiles, but only those changed if '-u'
|
||||
[ $SKIP_UNCHANGED = 1 ] &&
|
||||
list_changed_conffiles | sort -u > "$conffiles"
|
||||
|
||||
# do not backup files from packages, except those listed
|
||||
# in conffiles and keep.d
|
||||
{
|
||||
find /usr/lib/opkg/info -type f -name "*.list" -exec cat {} \;
|
||||
find /usr/lib/opkg/info -type f -name "*.control" -exec sed \
|
||||
-ne '/^Alternatives/{s/^Alternatives: //;s/, /\n/g;p}' {} \; |
|
||||
cut -f2 -d:
|
||||
} | grep -v -x -F -f $conffiles |
|
||||
grep -v -x -F -f $keepfiles | sort -u > "$packagesfiles"
|
||||
rm -f "$keepfiles" "$conffiles"
|
||||
fi
|
||||
|
||||
# busybox grep bug when file is empty
|
||||
[ -s "$packagesfiles" ] || echo > $packagesfiles
|
||||
|
||||
( cd /overlay/upper/; find .$SAVE_OVERLAY_PATH \( -type f -o -type l \) $find_filter | sed \
|
||||
-e 's,^\.,,' \
|
||||
-e '\,^/etc/board.json$,d' \
|
||||
-e '\,/[^/]*-opkg$,d' \
|
||||
-e '\,^/etc/urandom.seed$,d' \
|
||||
-e "\,^$INSTALLED_PACKAGES$,d" \
|
||||
-e '\,^/usr/lib/opkg/.*,d' \
|
||||
) | grep -v -x -F -f $packagesfiles > "$file"
|
||||
|
||||
rm -f "$packagesfiles"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
if [ $SAVE_OVERLAY = 1 ]; then
|
||||
[ ! -d /overlay/upper/etc ] && {
|
||||
echo "Cannot find '/overlay/upper/etc', required for '-c'" >&2
|
||||
exit 1
|
||||
}
|
||||
sysupgrade_init_conffiles="add_overlayfiles"
|
||||
else
|
||||
sysupgrade_init_conffiles="add_conffiles"
|
||||
fi
|
||||
|
||||
find_filter=""
|
||||
if [ $SKIP_UNCHANGED = 1 ]; then
|
||||
[ ! -d /rom/ ] && {
|
||||
echo "'/rom/' is required by '-u'"
|
||||
exit 1
|
||||
}
|
||||
find_filter='( ( -exec test -e /rom/{} ; -exec cmp -s /{} /rom/{} ; ) -o -print )'
|
||||
fi
|
||||
|
||||
include /lib/upgrade
|
||||
|
||||
do_save_conffiles() {
|
||||
local conf_tar="$1"
|
||||
|
||||
[ "$(rootfs_type)" = "tmpfs" ] && {
|
||||
echo "Cannot save config while running from ramdisk." >&2
|
||||
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"
|
||||
|
||||
if [ "$SAVE_INSTALLED_PKGS" -eq 1 ]; then
|
||||
echo "${INSTALLED_PACKAGES}" >> "$CONFFILES"
|
||||
mkdir -p "$ETCBACKUP_DIR"
|
||||
# Avoid touching filesystem on each backup
|
||||
RAMFS="$(mktemp -d -t sysupgrade.XXXXXX)"
|
||||
mkdir -p "$RAMFS/upper" "$RAMFS/work"
|
||||
mount -t overlay overlay -o lowerdir=$ETCBACKUP_DIR,upperdir=$RAMFS/upper,workdir=$RAMFS/work $ETCBACKUP_DIR &&
|
||||
UMOUNT_ETCBACKUP_DIR=1 || {
|
||||
echo "Cannot mount '$ETCBACKUP_DIR' as tmpfs to avoid touching disk while saving the list of installed packages." >&2
|
||||
ask_bool 0 "Abort" && exit
|
||||
}
|
||||
|
||||
# Format: pkg-name<TAB>{rom,overlay,unkown}
|
||||
# rom is used for pkgs in /rom, even if updated later
|
||||
find /usr/lib/opkg/info -name "*.control" \( \
|
||||
\( -exec test -f /rom/{} \; -exec echo {} rom \; \) -o \
|
||||
\( -exec test -f /overlay/upper/{} \; -exec echo {} overlay \; \) -o \
|
||||
\( -exec echo {} unknown \; \) \
|
||||
\) | sed -e 's,.*/,,;s/\.control /\t/' > ${INSTALLED_PACKAGES}
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
[ "$UMOUNT_ETCBACKUP_DIR" -eq 1 ] && {
|
||||
umount "$ETCBACKUP_DIR"
|
||||
rm -rf "$RAMFS"
|
||||
}
|
||||
rm -f "$CONFFILES"
|
||||
}
|
||||
|
||||
if [ $CONF_BACKUP_LIST -eq 1 ]; then
|
||||
run_hooks "$CONFFILES" $sysupgrade_init_conffiles
|
||||
[ "$SAVE_INSTALLED_PKGS" -eq 1 ] && echo ${INSTALLED_PACKAGES} >> "$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." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
|
||||
v "Restoring config files..."
|
||||
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." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
case "$IMAGE" in
|
||||
http://*|\
|
||||
https://*)
|
||||
wget -O/tmp/sysupgrade.img "$IMAGE" || exit 1
|
||||
IMAGE=/tmp/sysupgrade.img
|
||||
;;
|
||||
esac
|
||||
|
||||
IMAGE="$(readlink -f "$IMAGE")"
|
||||
|
||||
case "$IMAGE" in
|
||||
'')
|
||||
echo "Image file not found." >&2
|
||||
exit 1
|
||||
;;
|
||||
/tmp/*) ;;
|
||||
*)
|
||||
v "Image not in /tmp, copying..."
|
||||
cp -f "$IMAGE" /tmp/sysupgrade.img
|
||||
IMAGE=/tmp/sysupgrade.img
|
||||
;;
|
||||
esac
|
||||
|
||||
json_load "$(/usr/libexec/validate_firmware_image "$IMAGE")" || {
|
||||
echo "Failed to check image"
|
||||
exit 1
|
||||
}
|
||||
json_get_var valid "valid"
|
||||
[ "$valid" -eq 0 ] && {
|
||||
if [ $FORCE -eq 1 ]; then
|
||||
echo "Image check failed but --force given - will update anyway!" >&2
|
||||
else
|
||||
echo "Image check failed." >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
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" >&2
|
||||
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 "$CONF_TAR"
|
||||
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
|
||||
|
||||
install_bin /sbin/upgraded
|
||||
v "Commencing upgrade. Closing all shell sessions."
|
||||
|
||||
COMMAND='/lib/upgrade/do_stage2'
|
||||
|
||||
if [ -n "$FAILSAFE" ]; then
|
||||
printf '%s\x00%s\x00%s' "$RAM_ROOT" "$IMAGE" "$COMMAND" >/tmp/sysupgrade
|
||||
lock -u /tmp/.failsafe
|
||||
else
|
||||
json_init
|
||||
json_add_string prefix "$RAM_ROOT"
|
||||
json_add_string path "$IMAGE"
|
||||
[ $FORCE -eq 1 ] && json_add_boolean force 1
|
||||
[ $SAVE_CONFIG -eq 1 ] && json_add_string backup "$CONF_TAR"
|
||||
json_add_string command "$COMMAND"
|
||||
json_add_object options
|
||||
json_add_int save_partitions "$SAVE_PARTITIONS"
|
||||
json_close_object
|
||||
|
||||
ubus call system sysupgrade "$(json_dump)"
|
||||
fi
|
271
base-files/files/sbin/wifi
Executable file
271
base-files/files/sbin/wifi
Executable file
@ -0,0 +1,271 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
|
||||
. /lib/functions.sh
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $0 [config|up|down|reconf|reload|status|isup]
|
||||
enables (default), disables or configures devices not yet configured.
|
||||
EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
ubus_wifi_cmd() {
|
||||
local cmd="$1"
|
||||
local dev="$2"
|
||||
|
||||
json_init
|
||||
[ -n "$dev" ] && json_add_string device "$dev"
|
||||
ubus call network.wireless "$cmd" "$(json_dump)"
|
||||
}
|
||||
|
||||
wifi_isup() {
|
||||
local dev="$1"
|
||||
|
||||
json_load "$(ubus_wifi_cmd "status" "$dev")"
|
||||
json_get_keys devices
|
||||
|
||||
for device in $devices; do
|
||||
json_select "$device"
|
||||
json_get_var up up
|
||||
[ $up -eq 0 ] && return 1
|
||||
json_select ..
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
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;;
|
||||
11ad) hwmode=ad;;
|
||||
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"
|
||||
ubus call network reload
|
||||
scan_wifi
|
||||
cmd=up
|
||||
}
|
||||
[ reconf = "$1" ] && {
|
||||
ubus call network reload
|
||||
scan_wifi
|
||||
cmd=reconf
|
||||
}
|
||||
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";;
|
||||
isup) wifi_isup "$2"; exit $?;;
|
||||
reload) wifi_reload "$2";;
|
||||
reload_legacy) wifi_reload_legacy "$2";;
|
||||
--help|help) usage;;
|
||||
reconf) wifi_updown "reconf" "$2";;
|
||||
''|up) wifi_updown "enable" "$2";;
|
||||
*) usage; exit 1;;
|
||||
esac
|
18
base-files/files/usr/lib/os-release
Normal file
18
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"
|
||||
OPENWRT_BOARD="%S"
|
||||
OPENWRT_ARCH="%A"
|
||||
OPENWRT_TAINTS="%t"
|
||||
OPENWRT_DEVICE_MANUFACTURER="%M"
|
||||
OPENWRT_DEVICE_MANUFACTURER_URL="%m"
|
||||
OPENWRT_DEVICE_PRODUCT="%P"
|
||||
OPENWRT_DEVICE_REVISION="%h"
|
||||
OPENWRT_RELEASE="%D %V %C"
|
5
base-files/files/usr/libexec/login.sh
Executable file
5
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
|
66
base-files/files/usr/libexec/validate_firmware_image
Executable file
66
base-files/files/usr/libexec/validate_firmware_image
Executable file
@ -0,0 +1,66 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
. /lib/functions/system.sh
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
include /lib/upgrade
|
||||
|
||||
VALID=1
|
||||
FORCEABLE=1
|
||||
ALLOW_BACKUP=1
|
||||
|
||||
# Mark image as invalid but still possible to install
|
||||
notify_firmware_invalid() {
|
||||
VALID=0
|
||||
}
|
||||
|
||||
# Mark image as broken (impossible to install)
|
||||
notify_firmware_broken() {
|
||||
VALID=0
|
||||
FORCEABLE=0
|
||||
}
|
||||
|
||||
# Mark image as incompatible with preserving a backup
|
||||
notify_firmware_no_backup() {
|
||||
ALLOW_BACKUP=0
|
||||
}
|
||||
|
||||
# Add result of validation test
|
||||
notify_firmware_test_result() {
|
||||
local old_ns
|
||||
|
||||
json_set_namespace validate_firmware_image old_ns
|
||||
json_add_boolean "$1" "$2"
|
||||
json_set_namespace $old_ns
|
||||
}
|
||||
|
||||
err_to_bool() {
|
||||
[ "$1" -ne 0 ] && echo 0 || echo 1
|
||||
}
|
||||
|
||||
fwtool_check_signature "$1" >&2
|
||||
FWTOOL_SIGNATURE=$?
|
||||
[ "$FWTOOL_SIGNATURE" -ne 0 ] && notify_firmware_invalid
|
||||
|
||||
fwtool_check_image "$1" >&2
|
||||
FWTOOL_DEVICE_MATCH=$?
|
||||
[ "$FWTOOL_DEVICE_MATCH" -ne 0 ] && notify_firmware_invalid
|
||||
|
||||
json_set_namespace validate_firmware_image old_ns
|
||||
json_init
|
||||
json_add_object "tests"
|
||||
json_add_boolean fwtool_signature "$(err_to_bool $FWTOOL_SIGNATURE)"
|
||||
json_add_boolean fwtool_device_match "$(err_to_bool $FWTOOL_DEVICE_MATCH)"
|
||||
|
||||
# Call platform_check_image() here so it can add its test
|
||||
# results and still mark image properly.
|
||||
json_set_namespace $old_ns
|
||||
platform_check_image "$1" >&2 || notify_firmware_invalid
|
||||
json_set_namespace validate_firmware_image old_ns
|
||||
json_close_object
|
||||
json_add_boolean valid "$VALID"
|
||||
json_add_boolean forceable "$FORCEABLE"
|
||||
json_add_boolean allow_backup "$ALLOW_BACKUP"
|
||||
json_dump -i
|
||||
json_set_namespace $old_ns
|
284
base-files/image-config.in
Normal file
284
base-files/image-config.in
Normal file
@ -0,0 +1,284 @@
|
||||
# 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.
|
||||
#
|
||||
|
||||
config TARGET_DEFAULT_LAN_IP_FROM_PREINIT
|
||||
bool "Use preinit IP configuration as default LAN IP" if IMAGEOPT
|
||||
default n
|
||||
help
|
||||
Enabling this will set the default LAN IP address and netmask
|
||||
to the preinit values set in the image config.
|
||||
|
||||
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 separated 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 "https://downloads.openwrt.org/releases/23.05-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"
|
204
dnsmasq/Makefile
Normal file
204
dnsmasq/Makefile
Normal file
@ -0,0 +1,204 @@
|
||||
#
|
||||
# Copyright (C) 2006-2016 OpenWrt.org
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=dnsmasq
|
||||
PKG_UPSTREAM_VERSION:=2.89
|
||||
PKG_VERSION:=$(subst test,~~test,$(subst rc,~rc,$(PKG_UPSTREAM_VERSION)))
|
||||
PKG_RELEASE:=4
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_UPSTREAM_VERSION).tar.xz
|
||||
PKG_SOURCE_URL:=https://thekelleys.org.uk/dnsmasq/
|
||||
PKG_HASH:=02bd230346cf0b9d5909f5e151df168b2707103785eb616b56685855adebb609
|
||||
|
||||
PKG_LICENSE:=GPL-2.0
|
||||
PKG_LICENSE_FILES:=COPYING
|
||||
PKG_CPE_ID:=cpe:/a:thekelleys:dnsmasq
|
||||
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(BUILD_VARIANT)/$(PKG_NAME)-$(PKG_UPSTREAM_VERSION)
|
||||
|
||||
PKG_INSTALL:=1
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
PKG_BUILD_FLAGS:=lto
|
||||
PKG_ASLR_PIE_REGULAR:=1
|
||||
PKG_CONFIG_DEPENDS:= CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_dhcp \
|
||||
CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_dhcpv6 \
|
||||
CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_dnssec \
|
||||
CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_auth \
|
||||
CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_ipset \
|
||||
CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_nftset \
|
||||
CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_conntrack \
|
||||
CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_noid \
|
||||
CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_broken_rtc \
|
||||
CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_tftp
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/dnsmasq/Default
|
||||
SECTION:=net
|
||||
CATEGORY:=Base system
|
||||
TITLE:=DNS and DHCP server
|
||||
URL:=http://www.thekelleys.org.uk/dnsmasq/
|
||||
DEPENDS:=+libubus
|
||||
USERID:=dnsmasq=453:dnsmasq=453
|
||||
endef
|
||||
|
||||
define Package/dnsmasq
|
||||
$(call Package/dnsmasq/Default)
|
||||
VARIANT:=nodhcpv6
|
||||
endef
|
||||
|
||||
define Package/dnsmasq-dhcpv6
|
||||
$(call Package/dnsmasq/Default)
|
||||
TITLE += (with DHCPv6 support)
|
||||
DEPENDS+=@IPV6
|
||||
VARIANT:=dhcpv6
|
||||
PROVIDES:=dnsmasq
|
||||
endef
|
||||
|
||||
define Package/dnsmasq-full
|
||||
$(call Package/dnsmasq/Default)
|
||||
TITLE += (with DNSSEC, DHCPv6, Auth DNS, IPset, Nftset, Conntrack, NO_ID enabled by default)
|
||||
DEPENDS+=+PACKAGE_dnsmasq_full_dnssec:libnettle \
|
||||
+PACKAGE_dnsmasq_full_ipset:kmod-ipt-ipset \
|
||||
+PACKAGE_dnsmasq_full_conntrack:libnetfilter-conntrack \
|
||||
+PACKAGE_dnsmasq_full_nftset:nftables-json
|
||||
VARIANT:=full
|
||||
PROVIDES:=dnsmasq
|
||||
endef
|
||||
|
||||
define Package/dnsmasq/description
|
||||
It is intended to provide coupled DNS and DHCP service to a LAN.
|
||||
endef
|
||||
|
||||
define Package/dnsmasq-dhcpv6/description
|
||||
$(call Package/dnsmasq/description)
|
||||
|
||||
This is a variant with DHCPv6 support
|
||||
endef
|
||||
|
||||
define Package/dnsmasq-full/description
|
||||
$(call Package/dnsmasq/description)
|
||||
|
||||
This is a fully configurable variant with DHCPv4, DHCPv6, DNSSEC, Authoritative DNS
|
||||
and nftset, Conntrack support & NO_ID enabled by default.
|
||||
endef
|
||||
|
||||
define Package/dnsmasq/conffiles
|
||||
/etc/config/dhcp
|
||||
/etc/dnsmasq.conf
|
||||
/etc/dnsmasq.d/
|
||||
endef
|
||||
|
||||
define Package/dnsmasq-full/config
|
||||
if PACKAGE_dnsmasq-full
|
||||
config PACKAGE_dnsmasq_full_dhcp
|
||||
bool "Build with DHCP support."
|
||||
default y
|
||||
config PACKAGE_dnsmasq_full_dhcpv6
|
||||
bool "Build with DHCPv6 support."
|
||||
depends on IPV6 && PACKAGE_dnsmasq_full_dhcp
|
||||
default y
|
||||
config PACKAGE_dnsmasq_full_dnssec
|
||||
bool "Build with DNSSEC support."
|
||||
default y
|
||||
config PACKAGE_dnsmasq_full_auth
|
||||
bool "Build with the facility to act as an authoritative DNS server."
|
||||
default y
|
||||
config PACKAGE_dnsmasq_full_ipset
|
||||
bool "Build with IPset support."
|
||||
default n
|
||||
config PACKAGE_dnsmasq_full_nftset
|
||||
bool "Build with Nftset support."
|
||||
default y
|
||||
config PACKAGE_dnsmasq_full_conntrack
|
||||
bool "Build with Conntrack support."
|
||||
default y
|
||||
config PACKAGE_dnsmasq_full_noid
|
||||
bool "Build with NO_ID. (hide *.bind pseudo domain)"
|
||||
default y
|
||||
config PACKAGE_dnsmasq_full_broken_rtc
|
||||
bool "Build with HAVE_BROKEN_RTC."
|
||||
default n
|
||||
config PACKAGE_dnsmasq_full_tftp
|
||||
bool "Build with TFTP server support."
|
||||
default y
|
||||
endif
|
||||
endef
|
||||
|
||||
Package/dnsmasq-dhcpv6/conffiles = $(Package/dnsmasq/conffiles)
|
||||
Package/dnsmasq-full/conffiles = $(Package/dnsmasq/conffiles)
|
||||
|
||||
COPTS = -DHAVE_UBUS -DHAVE_POLL_H \
|
||||
$(if $(CONFIG_IPV6),,-DNO_IPV6)
|
||||
|
||||
ifeq ($(BUILD_VARIANT),nodhcpv6)
|
||||
COPTS += -DNO_DHCP6
|
||||
endif
|
||||
|
||||
ifeq ($(BUILD_VARIANT),full)
|
||||
COPTS += $(if $(CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_dhcp),,-DNO_DHCP) \
|
||||
$(if $(CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_dhcpv6),,-DNO_DHCP6) \
|
||||
$(if $(CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_dnssec),-DHAVE_DNSSEC) \
|
||||
$(if $(CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_auth),,-DNO_AUTH) \
|
||||
$(if $(CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_ipset),,-DNO_IPSET) \
|
||||
$(if $(CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_nftset),-DHAVE_NFTSET,) \
|
||||
$(if $(CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_conntrack),-DHAVE_CONNTRACK,) \
|
||||
$(if $(CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_noid),-DNO_ID,) \
|
||||
$(if $(CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_broken_rtc),-DHAVE_BROKEN_RTC) \
|
||||
$(if $(CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_tftp),,-DNO_TFTP)
|
||||
COPTS += $(if $(CONFIG_LIBNETTLE_MINI),-DNO_GMP,)
|
||||
else
|
||||
COPTS += -DNO_AUTH -DNO_IPSET -DNO_ID
|
||||
endif
|
||||
|
||||
MAKE_FLAGS := \
|
||||
$(TARGET_CONFIGURE_OPTS) \
|
||||
CFLAGS="$(TARGET_CFLAGS) $(TARGET_CPPFLAGS)" \
|
||||
LDFLAGS="$(TARGET_LDFLAGS)" \
|
||||
COPTS="$(COPTS)" \
|
||||
PREFIX="/usr"
|
||||
|
||||
define Package/dnsmasq/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/sbin/dnsmasq $(1)/usr/sbin/
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_CONF) ./files/dhcp.conf $(1)/etc/config/dhcp
|
||||
$(INSTALL_CONF) ./files/dnsmasq.conf $(1)/etc/dnsmasq.conf
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) ./files/dnsmasq.init $(1)/etc/init.d/dnsmasq
|
||||
$(INSTALL_DIR) $(1)/etc/hotplug.d/dhcp
|
||||
$(INSTALL_DIR) $(1)/etc/hotplug.d/neigh
|
||||
$(INSTALL_DIR) $(1)/etc/hotplug.d/ntp
|
||||
$(INSTALL_DIR) $(1)/etc/hotplug.d/tftp
|
||||
$(INSTALL_DATA) ./files/dnsmasqsec.hotplug $(1)/etc/hotplug.d/ntp/25-dnsmasqsec
|
||||
$(INSTALL_DIR) $(1)/usr/share/dnsmasq
|
||||
$(INSTALL_CONF) ./files/dhcpbogushostname.conf $(1)/usr/share/dnsmasq/
|
||||
$(INSTALL_CONF) ./files/rfc6761.conf $(1)/usr/share/dnsmasq/
|
||||
$(INSTALL_DIR) $(1)/usr/lib/dnsmasq
|
||||
$(INSTALL_BIN) ./files/dhcp-script.sh $(1)/usr/lib/dnsmasq/dhcp-script.sh
|
||||
$(INSTALL_DIR) $(1)/usr/share/acl.d
|
||||
$(INSTALL_DATA) ./files/dnsmasq_acl.json $(1)/usr/share/acl.d/
|
||||
$(INSTALL_DIR) $(1)/etc/uci-defaults
|
||||
$(INSTALL_BIN) ./files/50-dnsmasq-migrate-resolv-conf-auto.sh $(1)/etc/uci-defaults
|
||||
$(INSTALL_BIN) ./files/50-dnsmasq-migrate-ipset.sh $(1)/etc/uci-defaults
|
||||
endef
|
||||
|
||||
Package/dnsmasq-dhcpv6/install = $(Package/dnsmasq/install)
|
||||
|
||||
define Package/dnsmasq-full/install
|
||||
$(call Package/dnsmasq/install,$(1))
|
||||
ifneq ($(CONFIG_PACKAGE_dnsmasq_full_dnssec),)
|
||||
$(INSTALL_DIR) $(1)/usr/share/dnsmasq
|
||||
$(INSTALL_CONF) $(PKG_BUILD_DIR)/trust-anchors.conf $(1)/usr/share/dnsmasq
|
||||
endif
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,dnsmasq))
|
||||
$(eval $(call BuildPackage,dnsmasq-dhcpv6))
|
||||
$(eval $(call BuildPackage,dnsmasq-full))
|
32
dnsmasq/files/50-dnsmasq-migrate-ipset.sh
Executable file
32
dnsmasq/files/50-dnsmasq-migrate-ipset.sh
Executable file
@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
ipsets=$(uci -q get dhcp.@dnsmasq[0].ipset)
|
||||
[ -z "$ipsets" ] && exit 0
|
||||
|
||||
for ipset in $ipsets; do
|
||||
names=${ipset##*/}
|
||||
domains=${ipset%/*}
|
||||
|
||||
[ -z "$names" ] || [ -z "$domains" ] && continue
|
||||
|
||||
uci add dhcp ipset
|
||||
|
||||
OLDIFS="$IFS"
|
||||
|
||||
IFS=","
|
||||
for name in $names; do
|
||||
uci add_list dhcp.@ipset[-1].name="$name"
|
||||
done
|
||||
|
||||
IFS="/"
|
||||
for domain in ${domains:1}; do
|
||||
uci add_list dhcp.@ipset[-1].domain="$domain"
|
||||
done
|
||||
|
||||
IFS="$OLDIFS"
|
||||
|
||||
uci del_list dhcp.@dnsmasq[0].ipset="$ipset"
|
||||
done
|
||||
|
||||
uci commit dhcp
|
||||
exit 0
|
8
dnsmasq/files/50-dnsmasq-migrate-resolv-conf-auto.sh
Executable file
8
dnsmasq/files/50-dnsmasq-migrate-resolv-conf-auto.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ "$(uci get dhcp.@dnsmasq[0].resolvfile)" = "/tmp/resolv.conf.auto" ] && {
|
||||
uci set dhcp.@dnsmasq[0].resolvfile="/tmp/resolv.conf.d/resolv.conf.auto"
|
||||
uci commit dhcp
|
||||
}
|
||||
|
||||
exit 0
|
53
dnsmasq/files/dhcp-script.sh
Executable file
53
dnsmasq/files/dhcp-script.sh
Executable file
@ -0,0 +1,53 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ -f "$USER_DHCPSCRIPT" ] && . "$USER_DHCPSCRIPT" "$@"
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
json_init
|
||||
json_add_array env
|
||||
hotplugobj=""
|
||||
|
||||
case "$1" in
|
||||
add | del | old | arp-add | arp-del)
|
||||
json_add_string "" "MACADDR=$2"
|
||||
json_add_string "" "IPADDR=$3"
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$1" in
|
||||
add)
|
||||
json_add_string "" "ACTION=add"
|
||||
json_add_string "" "HOSTNAME=$4"
|
||||
hotplugobj="dhcp"
|
||||
;;
|
||||
del)
|
||||
json_add_string "" "ACTION=remove"
|
||||
json_add_string "" "HOSTNAME=$4"
|
||||
hotplugobj="dhcp"
|
||||
;;
|
||||
old)
|
||||
json_add_string "" "ACTION=update"
|
||||
json_add_string "" "HOSTNAME=$4"
|
||||
hotplugobj="dhcp"
|
||||
;;
|
||||
arp-add)
|
||||
json_add_string "" "ACTION=add"
|
||||
hotplugobj="neigh"
|
||||
;;
|
||||
arp-del)
|
||||
json_add_string "" "ACTION=remove"
|
||||
hotplugobj="neigh"
|
||||
;;
|
||||
tftp)
|
||||
json_add_string "" "ACTION=add"
|
||||
json_add_string "" "TFTP_SIZE=$2"
|
||||
json_add_string "" "TFTP_ADDR=$3"
|
||||
json_add_string "" "TFTP_PATH=$4"
|
||||
hotplugobj="tftp"
|
||||
;;
|
||||
esac
|
||||
|
||||
json_close_array env
|
||||
|
||||
[ -n "$hotplugobj" ] && ubus call hotplug.${hotplugobj} call "$(json_dump)"
|
37
dnsmasq/files/dhcp.conf
Normal file
37
dnsmasq/files/dhcp.conf
Normal file
@ -0,0 +1,37 @@
|
||||
config dnsmasq
|
||||
option domainneeded 1
|
||||
option boguspriv 1
|
||||
option filterwin2k 0 # enable for dial on demand
|
||||
option localise_queries 1
|
||||
option rebind_protection 1 # disable if upstream must serve RFC1918 addresses
|
||||
option rebind_localhost 1 # enable for RBL checking and similar services
|
||||
#list rebind_domain example.lan # whitelist RFC1918 responses for domains
|
||||
option local '/lan/'
|
||||
option domain 'lan'
|
||||
option expandhosts 1
|
||||
option nonegcache 0
|
||||
option cachesize 1000
|
||||
option authoritative 1
|
||||
option readethers 1
|
||||
option leasefile '/tmp/dhcp.leases'
|
||||
option resolvfile '/tmp/resolv.conf.d/resolv.conf.auto'
|
||||
#list server '/mycompany.local/1.2.3.4'
|
||||
option nonwildcard 1 # bind to & keep track of interfaces
|
||||
#list interface br-lan
|
||||
#list notinterface lo
|
||||
#list bogusnxdomain '64.94.110.11'
|
||||
option localservice 1 # disable to allow DNS requests from non-local subnets
|
||||
option ednspacket_max 1232
|
||||
option filter_aaaa 0
|
||||
option filter_a 0
|
||||
#list addnmount /some/path # read-only mount path to expose it to dnsmasq
|
||||
|
||||
config dhcp lan
|
||||
option interface lan
|
||||
option start 100
|
||||
option limit 150
|
||||
option leasetime 12h
|
||||
|
||||
config dhcp wan
|
||||
option interface wan
|
||||
option ignore 1
|
8
dnsmasq/files/dhcpbogushostname.conf
Normal file
8
dnsmasq/files/dhcpbogushostname.conf
Normal file
@ -0,0 +1,8 @@
|
||||
# dhcpbogushostname.conf included configuration file for dnsmasq
|
||||
#
|
||||
# includes a list of hostnames that should not be associated with dhcp leases
|
||||
# in response to CERT VU#598349
|
||||
# file included by default, option dhcpbogushostname 0 to disable
|
||||
|
||||
dhcp-name-match=set:dhcp_bogus_hostname,localhost
|
||||
dhcp-name-match=set:dhcp_bogus_hostname,wpad
|
37
dnsmasq/files/dnsmasq.conf
Normal file
37
dnsmasq/files/dnsmasq.conf
Normal file
@ -0,0 +1,37 @@
|
||||
# Change the following lines if you want dnsmasq to serve SRV
|
||||
# records.
|
||||
# You may add multiple srv-host lines.
|
||||
# The fields are <name>,<target>,<port>,<priority>,<weight>
|
||||
|
||||
# A SRV record sending LDAP for the example.com domain to
|
||||
# ldapserver.example.com port 289
|
||||
#srv-host=_ldap._tcp.example.com,ldapserver.example.com,389
|
||||
|
||||
# Two SRV records for LDAP, each with different priorities
|
||||
#srv-host=_ldap._tcp.example.com,ldapserver.example.com,389,1
|
||||
#srv-host=_ldap._tcp.example.com,ldapserver.example.com,389,2
|
||||
|
||||
# A SRV record indicating that there is no LDAP server for the domain
|
||||
# example.com
|
||||
#srv-host=_ldap._tcp.example.com
|
||||
|
||||
# The following line shows how to make dnsmasq serve an arbitrary PTR
|
||||
# record. This is useful for DNS-SD.
|
||||
# The fields are <name>,<target>
|
||||
#ptr-record=_http._tcp.dns-sd-services,"New Employee Page._http._tcp.dns-sd-services"
|
||||
|
||||
# Change the following lines to enable dnsmasq to serve TXT records.
|
||||
# These are used for things like SPF and zeroconf.
|
||||
# The fields are <name>,<text>,<text>...
|
||||
|
||||
#Example SPF.
|
||||
#txt-record=example.com,"v=spf1 a -all"
|
||||
|
||||
#Example zeroconf
|
||||
#txt-record=_http._tcp.example.com,name=value,paper=A4
|
||||
|
||||
# Provide an alias for a "local" DNS name. Note that this _only_ works
|
||||
# for targets which are names from DHCP or /etc/hosts. Give host
|
||||
# "bert" another name, bertrand
|
||||
# The fields are <cname>,<target>
|
||||
#cname=bertand,bert
|
1333
dnsmasq/files/dnsmasq.init
Executable file
1333
dnsmasq/files/dnsmasq.init
Executable file
File diff suppressed because it is too large
Load Diff
15
dnsmasq/files/dnsmasq_acl.json
Normal file
15
dnsmasq/files/dnsmasq_acl.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"user": "dnsmasq",
|
||||
"publish": [ "dnsmasq" ],
|
||||
"access": {
|
||||
"hotplug.dhcp": {
|
||||
"methods": [ "call" ]
|
||||
},
|
||||
"hotplug.neigh": {
|
||||
"methods": [ "call" ]
|
||||
},
|
||||
"hotplug.tftp": {
|
||||
"methods": [ "call" ]
|
||||
}
|
||||
}
|
||||
}
|
12
dnsmasq/files/dnsmasqsec.hotplug
Normal file
12
dnsmasq/files/dnsmasqsec.hotplug
Normal file
@ -0,0 +1,12 @@
|
||||
TIMEVALIDFILE="/var/state/dnsmasqsec"
|
||||
|
||||
[ "$ACTION" = "stratum" ] || exit 0
|
||||
|
||||
[ -f "$TIMEVALIDFILE" ] || {
|
||||
echo "ntpd says time is valid" >$TIMEVALIDFILE
|
||||
/etc/init.d/dnsmasq enabled && {
|
||||
initscript=dnsmasq
|
||||
. /lib/functions/procd.sh
|
||||
procd_send_signal dnsmasq '*' INT
|
||||
}
|
||||
}
|
11
dnsmasq/files/rfc6761.conf
Normal file
11
dnsmasq/files/rfc6761.conf
Normal file
@ -0,0 +1,11 @@
|
||||
# RFC6761 included configuration file for dnsmasq
|
||||
#
|
||||
# includes a list of domains that should not be forwarded to Internet name servers
|
||||
# to reduce burden on them, asking questions that they won't know the answer to.
|
||||
|
||||
server=/bind/
|
||||
server=/invalid/
|
||||
server=/local/
|
||||
server=/localhost/
|
||||
server=/onion/
|
||||
server=/test/
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user