shell scripts clean up and formatting (#874)

pull/876/head
Paul Philippov 2023-06-11 15:44:27 -04:00 committed by GitHub
parent 52f4b1ec5c
commit 500d11cbc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 803 additions and 731 deletions

View File

@ -1,17 +1,17 @@
config BR2_OPENIPC_SOC_VENDOR config BR2_OPENIPC_SOC_VENDOR
string "openipc soc vendor" string "SoC vendor"
default "hisilicon" default "hisilicon"
config BR2_OPENIPC_SOC_MODEL config BR2_OPENIPC_SOC_MODEL
string "openipc soc model" string "SoC model"
default "hi3516ev300" default "hi3516ev300"
config BR2_OPENIPC_SOC_FAMILY config BR2_OPENIPC_SOC_FAMILY
string "openipc soc family" string "SoC family"
default "hi3516ev200" default "hi3516ev200"
config BR2_OPENIPC_FLAVOR config BR2_OPENIPC_FLAVOR
string "openipc flavor" string "OpenIPC flavor"
default "lite" default "lite"
source "$BR2_EXTERNAL_GENERAL_PATH/package/Config.in" source "$BR2_EXTERNAL_GENERAL_PATH/package/Config.in"

View File

@ -36,19 +36,19 @@ stop() {
return "$status" return "$status"
} }
restart() { case "$1" in
start|stop)
"$1"
;;
restart|reload)
stop stop
sleep 1 sleep 1
start start
} ;;
case "$1" in
start|stop|restart)
"$1" ;;
reload)
# Restart, since there is no true "reload" feature.
restart ;;
*) *)
echo "Usage: $0 {start|stop|restart|reload}" echo "Usage: $0 {start|stop|restart|reload}"
exit 1 exit 1
;;
esac esac

View File

@ -10,7 +10,8 @@ case "$1" in
[ -r /etc/modules ] || exit 0 [ -r /etc/modules ] || exit 0
while read module args; do while read module args; do
case "$module" in case "$module" in
""|"#"*) continue ;; ""|"#"*) continue
;;
esac esac
# attempt to load modules # attempt to load modules

View File

@ -32,10 +32,16 @@ stop()
case "$1" in case "$1" in
start|stop) start|stop)
"$1" ;; "$1"
;;
restart|reload) restart|reload)
stop; start ;; stop
start
;;
*) *)
echo "Usage: $0 {start|stop|restart|reload}" >&2 echo "Usage: $0 {start|stop|restart|reload}" >&2
exit 1 exit 1
;;
esac esac

View File

@ -9,13 +9,17 @@ case "$1" in
echo /sbin/mdev >/proc/sys/kernel/hotplug echo /sbin/mdev >/proc/sys/kernel/hotplug
/sbin/mdev -s /sbin/mdev -s
;; ;;
stop) stop)
;; ;;
restart|reload) restart|reload)
;; ;;
*) *)
echo "Usage: $0 {start|stop|restart}" echo "Usage: $0 {start|stop|restart|reload}"
exit 1 exit 1
;;
esac esac
exit $? exit $?

View File

@ -36,18 +36,19 @@ stop() {
return "$status" return "$status"
} }
restart() { case "$1" in
start|stop)
"$1"
;;
reload)
stop stop
sleep 1 sleep 1
start start
} ;;
case "$1" in
start|stop|restart)
"$1" ;;
reload)
restart ;;
*) *)
echo "Usage: $0 {start|stop|restart|reload}" echo "Usage: $0 {start|stop|restart|reload}"
exit 1 exit 1
;;
esac esac

View File

@ -30,24 +30,27 @@ start() {
start-stop-daemon -S -q -p /var/run/dropbear.pid --exec /usr/sbin/dropbear -- $DROPBEAR_ARGS start-stop-daemon -S -q -p /var/run/dropbear.pid --exec /usr/sbin/dropbear -- $DROPBEAR_ARGS
[ $? = 0 ] && echo "OK" || echo "FAIL" [ $? = 0 ] && echo "OK" || echo "FAIL"
} }
stop() { stop() {
printf "Stopping dropbear sshd: " printf "Stopping dropbear sshd: "
start-stop-daemon -K -q -p /var/run/dropbear.pid start-stop-daemon -K -q -p /var/run/dropbear.pid
[ $? = 0 ] && echo "OK" || echo "FAIL" [ $? = 0 ] && echo "OK" || echo "FAIL"
} }
restart() {
stop
start
}
case "$1" in case "$1" in
start|stop|restart) start|stop)
"$1" ;; "$1"
reload) ;;
restart ;;
restart|reload)
stop
start
;;
*) *)
echo "Usage: $0 {start|stop|restart}" echo "Usage: $0 {start|stop|restart|reload}"
exit 1 exit 1
;;
esac esac
exit $? exit $?

View File

@ -38,18 +38,19 @@ stop() {
return "$status" return "$status"
} }
restart() { case "$1" in
start|stop)
"$1"
;;
restart|reload)
stop stop
sleep 1 sleep 1
start start
} ;;
case "$1" in
start|stop|restart)
"$1" ;;
reload)
restart ;;
*) *)
echo "Usage: $0 {start|stop|restart|reload}" echo "Usage: $0 {start|stop|restart|reload}"
exit 1 exit 1
;;
esac esac

View File

@ -22,12 +22,18 @@ stop() {
case "$1" in case "$1" in
start|stop) start|stop)
"$1" ;; "$1"
;;
restart|reload) restart|reload)
stop; start ;; stop
start
;;
*) *)
echo "Usage: $0 {start|stop|restart}" echo "Usage: $0 {start|stop|restart|reload}"
exit 1 exit 1
;;
esac esac
exit $? exit $?

View File

@ -38,18 +38,19 @@ stop() {
return "$status" return "$status"
} }
restart() { case "$1" in
start|stop)
"$1"
;;
restart|reload)
stop stop
sleep 1 sleep 1
start start
} ;;
case "$1" in
start|stop|restart)
"$1" ;;
reload)
restart ;;
*) *)
echo "Usage: $0 {start|stop|restart|reload}" echo "Usage: $0 {start|stop|restart|reload}"
exit 1 exit 1
;;
esac esac

View File

@ -1,7 +1,6 @@
#!/bin/sh #!/bin/sh
# load vendor specific drivers # load vendor specific drivers
#
vendor=$(ipcinfo -v) vendor=$(ipcinfo -v)
status=$(check_mac) status=$(check_mac)

View File

@ -1,21 +1,14 @@
#!/bin/sh #!/bin/sh
# Setting the TimeZone for all processes # Setting the TimeZone for all processes
#
export TZ=$(cat /etc/TZ) export TZ=$(cat /etc/TZ)
# Set the firmware creation time as the base system time # Set the firmware creation time as the base system time
#
/bin/date -s @$(stat -t /etc/os-release | cut -d" " -f12) /bin/date -s @$(stat -t /etc/os-release | cut -d" " -f12)
# Start all init scripts in /etc/init.d # Start all init scripts in /etc/init.d
# executing them in numerical order. # executing them in numerical order.
#
for i in /etc/init.d/S??* ; do for i in /etc/init.d/S??* ; do
# Ignore dangling symlinks (if any). # Ignore dangling symlinks (if any).
[ ! -f "$i" ] && continue [ ! -f "$i" ] && continue
@ -25,13 +18,13 @@ for i in /etc/init.d/S??* ;do
( (
trap - INT QUIT TSTP trap - INT QUIT TSTP
set start set start
. $i $i
) )
;; ;;
*) *)
# No sh extension, so fork subprocess. # No sh extension, so fork subprocess.
$i start $i start
;; ;;
esac esac
done done

View File

@ -7,13 +7,20 @@
case "$IF_BRIDGE_PORTS" in case "$IF_BRIDGE_PORTS" in
"") "")
exit 0 ;; exit 0
;;
none) none)
INTERFACES="" ;; INTERFACES=""
;;
all) all)
INTERFACES=$(grep eth /proc/net/dev|sed 's/\(\ *\)\(eth[^:]*\)\(.*\)/\2/') ;; INTERFACES=$(grep eth /proc/net/dev|sed 's/\(\ *\)\(eth[^:]*\)\(.*\)/\2/')
;;
*) *)
INTERFACES="$IF_BRIDGE_PORTS" ;; INTERFACES="$IF_BRIDGE_PORTS"
;;
esac esac
brctl delbr $IFACE brctl delbr $IFACE

View File

@ -7,13 +7,20 @@
case "$IF_BRIDGE_PORTS" in case "$IF_BRIDGE_PORTS" in
"") "")
exit 0 ;; exit 0
;;
none) none)
INTERFACES="" ;; INTERFACES=""
;;
all) all)
INTERFACES=$(grep eth /proc/net/dev|sed 's/\(\ *\)\(eth[^:]*\)\(.*\)/\2/') ;; INTERFACES=$(grep eth /proc/net/dev|sed 's/\(\ *\)\(eth[^:]*\)\(.*\)/\2/')
;;
*) *)
INTERFACES="$IF_BRIDGE_PORTS" ;; INTERFACES="$IF_BRIDGE_PORTS"
;;
esac esac
brctl addbr $IFACE && brctl addbr $IFACE &&

View File

@ -7,30 +7,37 @@ case "$IFACE" in
vconfig set_name_type VLAN_PLUS_VID vconfig set_name_type VLAN_PLUS_VID
VLANID=$(echo $IFACE|sed "s/vlan0*//") VLANID=$(echo $IFACE|sed "s/vlan0*//")
;; ;;
vlan*) vlan*)
vconfig set_name_type VLAN_PLUS_VID_NO_PAD vconfig set_name_type VLAN_PLUS_VID_NO_PAD
VLANID=$(echo $IFACE|sed "s/vlan*//") VLANID=$(echo $IFACE|sed "s/vlan*//")
;; ;;
*.0*) *.0*)
vconfig set_name_type DEV_PLUS_VID vconfig set_name_type DEV_PLUS_VID
VLANID=$(echo $IFACE|sed "s/.*\.0*\([0-9]\+\)$/\1/g") VLANID=$(echo $IFACE|sed "s/.*\.0*\([0-9]\+\)$/\1/g")
IF_VLAN_RAW_DEVICE=$(echo $IFACE|sed "s/^\(.*\)\.[^.]*/\1/") IF_VLAN_RAW_DEVICE=$(echo $IFACE|sed "s/^\(.*\)\.[^.]*/\1/")
;; ;;
*.*) *.*)
vconfig set_name_type DEV_PLUS_VID_NO_PAD vconfig set_name_type DEV_PLUS_VID_NO_PAD
VLANID=$(echo $IFACE|sed "s/.*\.0*\([0-9]\+\)$/\1/g") VLANID=$(echo $IFACE|sed "s/.*\.0*\([0-9]\+\)$/\1/g")
IF_VLAN_RAW_DEVICE=$(echo $IFACE|sed "s/^\(.*\)\.[^.]*/\1/") IF_VLAN_RAW_DEVICE=$(echo $IFACE|sed "s/^\(.*\)\.[^.]*/\1/")
;; ;;
*) *)
exit 0 exit 0
;;
esac esac
if [ -n "$IF_VLAN_RAW_DEVICE" ]; then if [ -n "$IF_VLAN_RAW_DEVICE" ]; then
[ ! -x /sbin/vconfig ] && exit 0 [ ! -x /sbin/vconfig ] && exit 0
if ! ip link show dev "$IF_VLAN_RAW_DEVICE" > /dev/null; then if ! ip link show dev "$IF_VLAN_RAW_DEVICE" > /dev/null; then
echo "$IF_VLAN_RAW_DEVICE does not exist, unable to create $IFACE" echo "$IF_VLAN_RAW_DEVICE does not exist, unable to create $IFACE"
exit 1 exit 1
fi fi
ip link set up dev $IF_VLAN_RAW_DEVICE ip link set up dev $IF_VLAN_RAW_DEVICE
vconfig add $IF_VLAN_RAW_DEVICE $VLANID vconfig add $IF_VLAN_RAW_DEVICE $VLANID
fi fi

View File

@ -23,17 +23,29 @@ export EDITOR='/bin/vi'
[ -x /usr/bin/arp ] || arp() { cat /proc/net/arp; } [ -x /usr/bin/arp ] || arp() { cat /proc/net/arp; }
differ() { diff -rN "/rom$1" "$1"; } differ() {
diff -rN "/rom$1" "$1"
}
majestic_changes() { diff -L "Majestic changes" -U 3 /rom/etc/majestic.yaml /etc/majestic.yaml; } majestic_changes() {
diff -L "Majestic changes" -U 3 /rom/etc/majestic.yaml /etc/majestic.yaml
}
show_modules() { echo; cat /proc/modules | cut -f 1 -d " " | while read module; do echo "Module: $module"; \ show_modules() {
echo; cat /proc/modules | cut -f 1 -d " " | while read module; do echo "Module: $module"; \
if [ -d "/sys/module/$module/parameters" ]; then ls /sys/module/$module/parameters/ | while read parameter; \ if [ -d "/sys/module/$module/parameters" ]; then ls /sys/module/$module/parameters/ | while read parameter; \
do echo -n "Parameter: $parameter --> "; cat /sys/module/$module/parameters/$parameter; done; fi; echo; done; } do echo -n "Parameter: $parameter --> "; cat /sys/module/$module/parameters/$parameter; done; fi; echo; done
}
show_fullname() { echo "openipc-$(ipcinfo --chip-name)-$(ipcinfo --short-sensor)"; } show_fullname() {
echo "openipc-$(ipcinfo --chip-name)-$(ipcinfo --short-sensor)"
}
set_fullname() { show_fullname >/etc/hostname; } set_fullname() {
show_fullname >/etc/hostname
}
# Source configuration files from /etc/profile.d # Source configuration files from /etc/profile.d
for i in /etc/profile.d/*.sh; do [ -r "$i" ] && . $i; done; unset i for i in /etc/profile.d/*.sh; do
[ -r "$i" ] && . $i
done; unset i

View File

@ -13,9 +13,11 @@ case "${CMD}" in
cli) cli)
yaml-cli -i /etc/majestic.yaml "$@" yaml-cli -i /etc/majestic.yaml "$@"
;; ;;
sensor_cli) sensor_cli)
yaml-cli -i /etc/sensor/$(fw_printenv -n sensor).yaml $@ yaml-cli -i /etc/sensor/$(fw_printenv -n sensor).yaml $@
;; ;;
ipctool) ipctool)
IPCTOOL=/tmp/ipctool IPCTOOL=/tmp/ipctool
if [ ! -x $IPCTOOL ]; then if [ ! -x $IPCTOOL ]; then
@ -25,11 +27,13 @@ case "${CMD}" in
fi fi
$IPCTOOL $@ $IPCTOOL $@
;; ;;
check_mac) check_mac)
if [ "$(fw_printenv -n ethaddr)" = "00:00:23:34:45:66" ]; then if [ "$(fw_printenv -n ethaddr)" = "00:00:23:34:45:66" ]; then
XMMAC="$(ipcinfo --xm-mac)" && [ -n "${XMMAC}" ] && [ ! "Nothing found." = "${XMMAC}" ] && fw_setenv ethaddr ${XMMAC} && reboot -f || echo "Warning. Wired network interface has default MAC address, please change it." XMMAC="$(ipcinfo --xm-mac)" && [ -n "${XMMAC}" ] && [ ! "Nothing found." = "${XMMAC}" ] && fw_setenv ethaddr ${XMMAC} && reboot -f || echo "Warning. Wired network interface has default MAC address, please change it."
fi fi
;; ;;
*) *)
;; ;;
esac esac

View File

@ -36,7 +36,6 @@ setBlue() {
if [ -n $1 ]; then if [ -n $1 ]; then
case $1 in case $1 in
off) off)
setRed 0 setRed 0
setGreen 0 setGreen 0

View File

@ -12,6 +12,7 @@ case ${manufacturer} in
;; ;;
esac esac
;; ;;
Camhi|Hichip|Xin) Camhi|Hichip|Xin)
case ${soc} in case ${soc} in
hi3516ev200|gk7205v200) hi3516ev200|gk7205v200)
@ -28,6 +29,7 @@ case ${manufacturer} in
;; ;;
esac esac
;; ;;
Herospeed|Longsee|Cantonk) Herospeed|Longsee|Cantonk)
case ${soc} in case ${soc} in
hi3516ev200|gk7205v200) hi3516ev200|gk7205v200)
@ -41,6 +43,7 @@ case ${manufacturer} in
;; ;;
esac esac
;; ;;
Jabsco) Jabsco)
case ${soc} in case ${soc} in
hi3516ev200|gk7205v200) hi3516ev200|gk7205v200)
@ -48,6 +51,7 @@ case ${manufacturer} in
;; ;;
esac esac
;; ;;
Jvt) Jvt)
case ${soc} in case ${soc} in
hi3516cv200) hi3516cv200)
@ -58,6 +62,7 @@ case ${manufacturer} in
;; ;;
esac esac
;; ;;
Juan|Sannce) Juan|Sannce)
case ${soc} in case ${soc} in
hi3518ev200) hi3518ev200)
@ -65,6 +70,7 @@ case ${manufacturer} in
;; ;;
esac esac
;; ;;
Tiandy) Tiandy)
case ${soc} in case ${soc} in
hi3518ev200) hi3518ev200)
@ -72,6 +78,7 @@ case ${manufacturer} in
;; ;;
esac esac
;; ;;
Uniview) Uniview)
case ${soc} in case ${soc} in
hi3516ev300|gk7205v300) hi3516ev300|gk7205v300)
@ -79,6 +86,7 @@ case ${manufacturer} in
;; ;;
esac esac
;; ;;
Xiongmai) Xiongmai)
case ${soc} in case ${soc} in
hi3516ev200|gk7205v200) hi3516ev200|gk7205v200)
@ -98,6 +106,7 @@ case ${manufacturer} in
;; ;;
esac esac
;; ;;
Zenotech|Videopark) Zenotech|Videopark)
case ${soc} in case ${soc} in
hi3516ev300|gk7205v300) hi3516ev300|gk7205v300)

View File

@ -15,8 +15,7 @@ if [ ! -d /sys/class/gpio/gpio${GPIO} ]; then
fi fi
# continuously monitor current value of reset switch # continuously monitor current value of reset switch
while [ true ] while [ true ]; do
do
if [ "$(cat /sys/class/gpio/gpio"${GPIO}"/value)" -eq 1 ]; then if [ "$(cat /sys/class/gpio/gpio"${GPIO}"/value)" -eq 1 ]; then
count=0 count=0
else else

View File

@ -263,69 +263,84 @@ for i in "$@"; do
skip_ver=1 skip_ver=1
shift shift
;; ;;
--force_md5) --force_md5)
skip_md5=1 skip_md5=1
shift shift
;; ;;
--force_soc) --force_soc)
skip_soc=1 skip_soc=1
shift shift
;; ;;
--force_ver) --force_ver)
skip_ver=1 skip_ver=1
shift shift
;; ;;
-d) -d)
branch_dev=1 branch_dev=1
shift shift
;; ;;
-h | --help) -h | --help)
print_sysinfo print_sysinfo
print_usage print_usage
exit 0 exit 0
;; ;;
-k) -k)
update_kernel=1 update_kernel=1
remote_update=1 remote_update=1
shift shift
;; ;;
--kernel=*) --kernel=*)
update_kernel=1 update_kernel=1
kernel_file="${i#*=}" kernel_file="${i#*=}"
[ "$kernel_file" != ${kernel_file#/mnt/mmc} ] && skip_unmount=1 [ "$kernel_file" != ${kernel_file#/mnt/mmc} ] && skip_unmount=1
shift shift
;; ;;
-n | --wipe_overlay) -n | --wipe_overlay)
clear_overlay=1 clear_overlay=1
shift shift
;; ;;
-r) -r)
update_rootfs=1 update_rootfs=1
remote_update=1 remote_update=1
shift shift
;; ;;
--rootfs=*) --rootfs=*)
update_rootfs=1 update_rootfs=1
rootfs_file="${i#*=}" rootfs_file="${i#*=}"
[ "$rootfs_file" != ${rootfs_file#/mnt/mmc} ] && skip_unmount=1 [ "$rootfs_file" != ${rootfs_file#/mnt/mmc} ] && skip_unmount=1
shift shift
;; ;;
--url=*) --url=*)
url="${i#*=}" url="${i#*=}"
shift shift
;; ;;
-x | --no_reboot)
skip_reboot=1
shift
;;
-w) -w)
update_webui=1 update_webui=1
shift shift
;; ;;
-x | --no_reboot)
skip_reboot=1
shift
;;
-z | --no_update) -z | --no_update)
skip_selfupdate=1 skip_selfupdate=1
shift shift
;; ;;
*) *)
print_sysinfo print_sysinfo
echo_c 37 "\nUnknown option: $1" echo_c 37 "\nUnknown option: $1"

View File

@ -17,9 +17,7 @@ RESOLV_CONF="/tmp/resolv.conf"
# Handle stateful DHCPv6 like DHCPv4 # Handle stateful DHCPv6 like DHCPv4
[ -n "$ipv6" ] && ip="$ipv6/128" [ -n "$ipv6" ] && ip="$ipv6/128"
if [ -z "${IF_WAIT_DELAY}" ]; then [ -z "${IF_WAIT_DELAY}" ] && IF_WAIT_DELAY=10
IF_WAIT_DELAY=10
fi
wait_for_ipv6_default_route() { wait_for_ipv6_default_route() {
printf "Waiting for IPv6 default route to appear" printf "Waiting for IPv6 default route to appear"

View File

@ -265,8 +265,8 @@ sys_config() {
devmem 0x20030058 32 0x2 # TDE unreset devmem 0x20030058 32 0x2 # TDE unreset
devmem 0x20030068 32 0x2 # MDU unreset devmem 0x20030068 32 0x2 # MDU unreset
#devmem 0x2003006c 32 0x2; # IVE unreset #devmem 0x2003006c 32 0x2 # IVE unreset
#devmem 0x2003008c 32 0x2; # SIO unreset and clock enable,m/f/bclk config in code. #devmem 0x2003008c 32 0x2 # SIO unreset and clock enable,m/f/bclk config in code.
#devmem 0x20050068 32 0x58000000 # Audio Codec channel config for power down. #devmem 0x20050068 32 0x58000000 # Audio Codec channel config for power down.
} }
sysctl() { sysctl() {