From 2d9cc9000bf1e22818f268055ab5ea943711c719 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sun, 16 Sep 2018 23:03:42 +0300 Subject: [PATCH 1/8] /etc/init.d/conf: remove unused has_net_conf() function --- board/common/overlay/etc/init.d/conf | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/board/common/overlay/etc/init.d/conf b/board/common/overlay/etc/init.d/conf index fd1afc129c..39abf427ae 100644 --- a/board/common/overlay/etc/init.d/conf +++ b/board/common/overlay/etc/init.d/conf @@ -14,16 +14,3 @@ fi source $_conf -has_net_conn() { - test "$os_networkless" == "true" && return 1 - - addr_eth=$(ip addr show dev $os_eth 2>/dev/null | grep inet | tr -s ' ' | sed -r 's/^\s+//' | cut -d ' ' -f 2) - addr_wlan=$(ip addr show dev $os_wlan 2>/dev/null | grep inet | tr -s ' ' | sed -r 's/^\s+//' | cut -d ' ' -f 2) - - if [ -n "$addr_eth" ] || [ -n "$addr_wlan" ]; then - return 0 - else - return 1 - fi -} - From 1484de1aba1f12bf7a312b516d78b6c5479c3292 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sun, 16 Sep 2018 23:13:08 +0300 Subject: [PATCH 2/8] init: include /etc/init.d/conf from base --- board/common/overlay/etc/init.d/S01mountall | 2 ++ board/common/overlay/etc/init.d/S35wifi | 1 - board/common/overlay/etc/init.d/S36ppp | 1 - board/common/overlay/etc/init.d/S40network | 1 - board/common/overlay/etc/init.d/S41netwatch | 1 - board/common/overlay/etc/init.d/S50date | 1 - board/common/overlay/etc/init.d/S60sshd | 1 - board/common/overlay/etc/init.d/S99showinfo | 1 - board/common/overlay/etc/init.d/base | 7 +++++++ 9 files changed, 9 insertions(+), 7 deletions(-) diff --git a/board/common/overlay/etc/init.d/S01mountall b/board/common/overlay/etc/init.d/S01mountall index bfde44d17b..829b974c64 100755 --- a/board/common/overlay/etc/init.d/S01mountall +++ b/board/common/overlay/etc/init.d/S01mountall @@ -29,6 +29,8 @@ mk_tty_login() { case "$1" in start) mount_fs + + # we need to source conf again, now that /data is available test -n "$os_debug" || source /etc/init.d/conf test "$os_debug" == "true" && remount_rw mk_tty_login diff --git a/board/common/overlay/etc/init.d/S35wifi b/board/common/overlay/etc/init.d/S35wifi index 357ee80b56..828fc71d49 100755 --- a/board/common/overlay/etc/init.d/S35wifi +++ b/board/common/overlay/etc/init.d/S35wifi @@ -39,7 +39,6 @@ ssid=$(cat $conf | grep ssid | grep -v scan_ssid | cut -d '"' -f 2) test -n "$ssid" || exit 0 test -n "$os_version" || source /etc/init.d/base -test -n "$os_debug" || source /etc/init.d/conf test "$os_networkless" == "true" && exit 0 diff --git a/board/common/overlay/etc/init.d/S36ppp b/board/common/overlay/etc/init.d/S36ppp index 01919e2281..7de9ee41ad 100755 --- a/board/common/overlay/etc/init.d/S36ppp +++ b/board/common/overlay/etc/init.d/S36ppp @@ -23,7 +23,6 @@ test -e $conf/modem || exit 0 test -e $conf/apn || exit 0 test -n "$os_version" || source /etc/init.d/base -test -n "$os_debug" || source /etc/init.d/conf test "$os_networkless" == "true" && exit 0 diff --git a/board/common/overlay/etc/init.d/S40network b/board/common/overlay/etc/init.d/S40network index a744bd1f9a..04328cfb5d 100755 --- a/board/common/overlay/etc/init.d/S40network +++ b/board/common/overlay/etc/init.d/S40network @@ -22,7 +22,6 @@ fi test -r $static_conf && source $static_conf test -n "$os_version" || source /etc/init.d/base -test -n "$os_debug" || source /etc/init.d/conf watch_eth() { count=0 diff --git a/board/common/overlay/etc/init.d/S41netwatch b/board/common/overlay/etc/init.d/S41netwatch index c7421d72f8..2ec59f483a 100755 --- a/board/common/overlay/etc/init.d/S41netwatch +++ b/board/common/overlay/etc/init.d/S41netwatch @@ -12,7 +12,6 @@ if [ -z "$netwatch_host" ] || [ -z "$netwatch_port" ]; then fi test -n "$os_version" || source /etc/init.d/base -test -n "$os_debug" || source /etc/init.d/conf test "$os_networkless" == "true" && exit 0 diff --git a/board/common/overlay/etc/init.d/S50date b/board/common/overlay/etc/init.d/S50date index 695d694bb8..87464d368c 100755 --- a/board/common/overlay/etc/init.d/S50date +++ b/board/common/overlay/etc/init.d/S50date @@ -30,7 +30,6 @@ fi test -f $conf || exit 0 test -n "$os_version" || source /etc/init.d/base -test -n "$os_debug" || source /etc/init.d/conf test "$os_networkless" == "true" && exit 0 diff --git a/board/common/overlay/etc/init.d/S60sshd b/board/common/overlay/etc/init.d/S60sshd index 37546b1161..2dcd04ac7b 100755 --- a/board/common/overlay/etc/init.d/S60sshd +++ b/board/common/overlay/etc/init.d/S60sshd @@ -5,7 +5,6 @@ conf="/etc/sshd_config" test -f $conf || exit 0 test -n "$os_version" || source /etc/init.d/base -test -n "$os_debug" || source /etc/init.d/conf test "$os_networkless" == "true" && exit 0 diff --git a/board/common/overlay/etc/init.d/S99showinfo b/board/common/overlay/etc/init.d/S99showinfo index 1e0b7390d1..fac00a387d 100755 --- a/board/common/overlay/etc/init.d/S99showinfo +++ b/board/common/overlay/etc/init.d/S99showinfo @@ -1,7 +1,6 @@ #!/bin/bash test -n "$os_version" || source /etc/init.d/base -test -n "$os_debug" || source /etc/init.d/conf msg_info() { echo " # $1" diff --git a/board/common/overlay/etc/init.d/base b/board/common/overlay/etc/init.d/base index 11a5ef95eb..ef900a8955 100755 --- a/board/common/overlay/etc/init.d/base +++ b/board/common/overlay/etc/init.d/base @@ -4,6 +4,8 @@ source /etc/version board_sn=$(/etc/init.d/boardsn) board_name=$(cat /etc/board) +test -n "$os_debug" || source /etc/init.d/conf + msg_begin() { echo -n " * $1: " } @@ -20,3 +22,8 @@ msg_background() { test -n "$1" && echo $1 || echo "pending" } +panic_action() { + logger -t panic -s "rebooting" + /sbin/reboot +} + From 4f47cacd837f50f20943384f18ee616e38df11d5 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sun, 16 Sep 2018 23:19:20 +0300 Subject: [PATCH 3/8] init: replace reboots with calls to panic_action --- board/common/overlay/etc/init.d/S33hostapd | 4 ++-- board/common/overlay/etc/init.d/S35wifi | 4 ++-- board/common/overlay/etc/init.d/S36ppp | 4 ++-- board/common/overlay/etc/init.d/S37bluetooth | 4 ++-- board/common/overlay/etc/init.d/S40network | 12 ++++++------ board/common/overlay/etc/init.d/S41netwatch | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/board/common/overlay/etc/init.d/S33hostapd b/board/common/overlay/etc/init.d/S33hostapd index 82e74bd0b1..bbdb797ff0 100755 --- a/board/common/overlay/etc/init.d/S33hostapd +++ b/board/common/overlay/etc/init.d/S33hostapd @@ -34,8 +34,8 @@ watch() { while true; do sleep 5 if ! running; then - logger -t hostapd -s "dead, rebooting" - reboot + logger -t hostapd -s "dead, calling panic action" + panic_action hostapd break fi done diff --git a/board/common/overlay/etc/init.d/S35wifi b/board/common/overlay/etc/init.d/S35wifi index 828fc71d49..67d07047b6 100755 --- a/board/common/overlay/etc/init.d/S35wifi +++ b/board/common/overlay/etc/init.d/S35wifi @@ -57,8 +57,8 @@ watch() { count=$(($count + 5)) logger -t wifi -s "disconnected" else - logger -t wifi -s "disconnected for $link_watch_timeout seconds, rebooting" - reboot + logger -t wifi -s "disconnected for $link_watch_timeout seconds, calling panic action" + panic_action wifi fi fi done diff --git a/board/common/overlay/etc/init.d/S36ppp b/board/common/overlay/etc/init.d/S36ppp index 7de9ee41ad..b3dc0be5c6 100755 --- a/board/common/overlay/etc/init.d/S36ppp +++ b/board/common/overlay/etc/init.d/S36ppp @@ -41,8 +41,8 @@ watch() { count=$(($count + 5)) logger -t ppp -s "disconnected" else - logger -t ppp -s "disconnected for $link_watch_timeout seconds, rebooting" - reboot + logger -t ppp -s "disconnected for $link_watch_timeout seconds, calling panic action" + panic_action ppp fi fi done diff --git a/board/common/overlay/etc/init.d/S37bluetooth b/board/common/overlay/etc/init.d/S37bluetooth index 0e9a03c807..1e61009058 100755 --- a/board/common/overlay/etc/init.d/S37bluetooth +++ b/board/common/overlay/etc/init.d/S37bluetooth @@ -48,8 +48,8 @@ start() { count=$(($count + 1)) if [ $count -ge 10 ]; then msg_fail "no device" - logger -t bluetooth -s "bluetooth device not available, rebooting" - reboot + logger -t bluetooth -s "bluetooth device not available, calling panic action" + panic_action bluetooth return 1 fi done diff --git a/board/common/overlay/etc/init.d/S40network b/board/common/overlay/etc/init.d/S40network index 04328cfb5d..010329219a 100755 --- a/board/common/overlay/etc/init.d/S40network +++ b/board/common/overlay/etc/init.d/S40network @@ -34,8 +34,8 @@ watch_eth() { count=$(($count + 5)) logger -t ethernet -s "disconnected" else - logger -t ethernet -s "disconnected for $link_watch_timeout seconds, rebooting" - reboot + logger -t ethernet -s "disconnected for $link_watch_timeout seconds, calling panic action" + panic_action network fi fi done @@ -53,8 +53,8 @@ watch_ip() { count=$(($count + 5)) logger -t network -s "$iface has no IP address" else - logger -t network -s "$iface had no IP address for $ip_watch_timeout seconds, rebooting" - reboot + logger -t network -s "$iface had no IP address for $ip_watch_timeout seconds, calling panic action" + panic_action network fi fi done @@ -180,8 +180,8 @@ start() { if [ "$eth_ok" != "ok" ] && [ "$wlan_ok" != "ok" ] && [ "$ppp_ok" != "ok" ]; then if [ "$link_watch" == "true" ]; then - logger -t network -s "no network connection available, rebooting" - reboot + logger -t network -s "no network connection available, calling panic action" + panic_action network return 1 else logger -t network -s "no network connection available" diff --git a/board/common/overlay/etc/init.d/S41netwatch b/board/common/overlay/etc/init.d/S41netwatch index 2ec59f483a..2abd6433c6 100755 --- a/board/common/overlay/etc/init.d/S41netwatch +++ b/board/common/overlay/etc/init.d/S41netwatch @@ -28,8 +28,8 @@ watch() { count=$(($count + 1)) continue else - logger -t netwatch -s "cannot connect to $netwatch_host:$netwatch_port, rebooting" - reboot + logger -t netwatch -s "cannot connect to $netwatch_host:$netwatch_port, calling panic action" + panic_action netwatch fi fi done From fda8329f209414bb5a5df52bfb6b7885d2bea99c Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Mon, 15 Oct 2018 23:45:11 +0300 Subject: [PATCH 4/8] add bootdone init script --- board/common/overlay/etc/init.d/bootdone | 7 +++++++ board/common/overlay/etc/init.d/rcS | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100755 board/common/overlay/etc/init.d/bootdone diff --git a/board/common/overlay/etc/init.d/bootdone b/board/common/overlay/etc/init.d/bootdone new file mode 100755 index 0000000000..14ca681cfc --- /dev/null +++ b/board/common/overlay/etc/init.d/bootdone @@ -0,0 +1,7 @@ +#!/bin/bash + +source /etc/init.d/panic + +# reset panic counter after a successful boot +echo 0 > ${_PANIC_COUNTER_FILE} + diff --git a/board/common/overlay/etc/init.d/rcS b/board/common/overlay/etc/init.d/rcS index 5f0d70cc09..22fa4ac98f 100755 --- a/board/common/overlay/etc/init.d/rcS +++ b/board/common/overlay/etc/init.d/rcS @@ -10,7 +10,7 @@ echo "---- booting $os_name $os_version ----" >> $tmp_boot_log # start all init scripts in /etc/init.d, # executing them in numerical order. -(for i in /etc/init.d/S??*; do +(for i in /etc/init.d/S??* /etc/init.d/bootdone; do [ ! -x "$i" ] && continue [ -f /data/etc/no_$(basename $i) ] && continue $i start || break From 0c5ce8c19ffc253cda90bfd96c62e604ae7c36f6 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Mon, 15 Oct 2018 23:45:38 +0300 Subject: [PATCH 5/8] add panic init script --- board/common/overlay/etc/init.d/base | 7 ++----- board/common/overlay/etc/init.d/panic | 28 +++++++++++++++++++++++++++ board/common/overlay/sbin/reboot | 10 +++++++++- 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100755 board/common/overlay/etc/init.d/panic diff --git a/board/common/overlay/etc/init.d/base b/board/common/overlay/etc/init.d/base index ef900a8955..7b08c9384d 100755 --- a/board/common/overlay/etc/init.d/base +++ b/board/common/overlay/etc/init.d/base @@ -6,6 +6,8 @@ board_name=$(cat /etc/board) test -n "$os_debug" || source /etc/init.d/conf +source /etc/init.d/panic + msg_begin() { echo -n " * $1: " } @@ -22,8 +24,3 @@ msg_background() { test -n "$1" && echo $1 || echo "pending" } -panic_action() { - logger -t panic -s "rebooting" - /sbin/reboot -} - diff --git a/board/common/overlay/etc/init.d/panic b/board/common/overlay/etc/init.d/panic new file mode 100755 index 0000000000..e0d288d0d6 --- /dev/null +++ b/board/common/overlay/etc/init.d/panic @@ -0,0 +1,28 @@ +#!/bin/bash + +_PANIC_COUNTER_FILE="/var/lib/panic_counter" +_PANIC_REBOOT_DELAY_FACTOR=10 +_PANIC_REBOOT_DELAY_MAX=3600 # reboot at least once an hour in case of panic + + +panic_action() { + # read counter from file + panic_counter=$(cat ${_PANIC_COUNTER_FILE} 2>/dev/null || echo 0) + + # write increased counter back to file + echo $((panic_counter + 1)) > ${_PANIC_COUNTER_FILE} + + delay=$((_PANIC_REBOOT_DELAY_FACTOR * panic_counter)) + if [ "${delay}" -gt "${_PANIC_REBOOT_DELAY_MAX}" ]; then + delay=${_PANIC_REBOOT_DELAY_MAX} + fi + + if [ "${delay}" -gt 0 ]; then + logger -t panic -s "rebooting in ${delay} seconds (caused by $1)" + sleep ${delay} + fi + + logger -t panic -s "rebooting (caused by $1)" + /sbin/reboot +} + diff --git a/board/common/overlay/sbin/reboot b/board/common/overlay/sbin/reboot index 5278c19d34..3b214bdd85 100755 --- a/board/common/overlay/sbin/reboot +++ b/board/common/overlay/sbin/reboot @@ -1,7 +1,15 @@ #!/bin/bash +# carry on with the script in case of error set +e + +# write buffers to disk /bin/sync -(sleep 10 && /usr/bin/killall -STOP watchdog) & + +# allow the shutdown script 20 seconds to shut down, +# after which we stop feeding the watchdog +(sleep 20 && /usr/bin/killall -STOP watchdog) & + +# actual reboot command /bin/busybox reboot From 5281a3dfe6a49294779f44bacc78a16e41d45247 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Mon, 15 Oct 2018 23:46:08 +0300 Subject: [PATCH 6/8] datapart init script: do not do anything at stop --- board/common/overlay/etc/init.d/S00datapart | 38 ++++++++++----------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/board/common/overlay/etc/init.d/S00datapart b/board/common/overlay/etc/init.d/S00datapart index 63582b5fe7..b971503039 100755 --- a/board/common/overlay/etc/init.d/S00datapart +++ b/board/common/overlay/etc/init.d/S00datapart @@ -2,26 +2,26 @@ test -n "$os_version" || source /etc/init.d/base -msg_begin "Detecting disk device" -root_dev=$(cat /proc/cmdline | grep -oE 'root=[/a-z0-9]+' | cut -d '=' -f 2) -if [[ "$root_dev" =~ ^([/a-z0-9]+)(p[0-9])$ ]]; then # e.g. /dev/mmcblk0p2 - disk_dev=${BASH_REMATCH[1]} - boot_dev=${disk_dev}p1 - data_dev=${disk_dev}p3 -elif [[ "$root_dev" =~ ^([/a-z0-9]+)([0-9])$ ]]; then # e.g. /dev/sdc2 - disk_dev=${BASH_REMATCH[1]} - boot_dev=${disk_dev}1 - data_dev=${disk_dev}3 -else - msg_fail "unknown ($root_dev)" - exit 1 -fi -msg_done "$disk_dev" - -test -b $data_dev && exit 0 - case "$1" in start) + msg_begin "Detecting disk device" + root_dev=$(cat /proc/cmdline | grep -oE 'root=[/a-z0-9]+' | cut -d '=' -f 2) + if [[ "$root_dev" =~ ^([/a-z0-9]+)(p[0-9])$ ]]; then # e.g. /dev/mmcblk0p2 + disk_dev=${BASH_REMATCH[1]} + boot_dev=${disk_dev}p1 + data_dev=${disk_dev}p3 + elif [[ "$root_dev" =~ ^([/a-z0-9]+)([0-9])$ ]]; then # e.g. /dev/sdc2 + disk_dev=${BASH_REMATCH[1]} + boot_dev=${disk_dev}1 + data_dev=${disk_dev}3 + else + msg_fail "unknown ($root_dev)" + exit 1 + fi + msg_done "$disk_dev" + + test -b $data_dev && exit 0 + msg_begin "Creating data partition" root_end=$(partx -s -g -o END $root_dev) data_start=$(($root_end + 1)) @@ -68,5 +68,3 @@ case "$1" in exit 1 esac -# always exit with a successful status -exit 0 From cf57e4b483e70c050c1390416a3b4c22afcb6a72 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Tue, 16 Oct 2018 22:45:23 +0300 Subject: [PATCH 7/8] init: fix conf script sourcing when no data partition available --- board/common/overlay/etc/init.d/conf | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/board/common/overlay/etc/init.d/conf b/board/common/overlay/etc/init.d/conf index 39abf427ae..dc71091fb9 100644 --- a/board/common/overlay/etc/init.d/conf +++ b/board/common/overlay/etc/init.d/conf @@ -4,6 +4,17 @@ _sys_conf="/etc/os.conf" _boot_conf="/boot/os.conf" _conf="/data/etc/os.conf" +if ! [ -d /data/etc ]; then + # use boot/system variants if we don't have the data partition mounted + if [ -f $_boot_conf ]; then + source $_boot_conf + elif [ -f $_sys_conf ]; then + source $_sys_conf + fi + + return +fi + if ! [ -f $_conf ]; then if [ -f $_boot_conf ]; then cp $_boot_conf $_conf @@ -12,5 +23,7 @@ if ! [ -f $_conf ]; then fi fi -source $_conf +if [ -f $_conf ]; then + source $_conf +fi From c9ef303908fdf2bfb9a40869ec5e664b61094476 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Tue, 16 Oct 2018 23:08:14 +0300 Subject: [PATCH 8/8] init: use [[ cond ]] bash ifs --- board/common/overlay/etc/init.d/S01mountall | 2 +- board/common/overlay/etc/init.d/S02modules | 4 +- board/common/overlay/etc/init.d/S03hostname | 8 ++-- .../common/overlay/etc/init.d/S14postupgrade | 4 +- board/common/overlay/etc/init.d/S33hostapd | 10 ++-- board/common/overlay/etc/init.d/S35wifi | 20 ++++---- board/common/overlay/etc/init.d/S36ppp | 18 +++---- board/common/overlay/etc/init.d/S37bluetooth | 8 ++-- board/common/overlay/etc/init.d/S40network | 48 +++++++++---------- board/common/overlay/etc/init.d/S41netwatch | 4 +- board/common/overlay/etc/init.d/S43firewall | 6 +-- board/common/overlay/etc/init.d/S45dnsmasq | 6 +-- board/common/overlay/etc/init.d/S50date | 18 +++---- board/common/overlay/etc/init.d/S51crond | 2 +- board/common/overlay/etc/init.d/conf | 14 +++--- board/common/overlay/etc/init.d/panic | 4 +- board/common/overlay/etc/init.d/rcK | 4 +- board/common/overlay/etc/init.d/rcS | 4 +- .../raspberrypi/overlay/etc/init.d/S05cpufreq | 2 +- .../overlay/etc/init.d/S11throttlewatch | 4 +- .../raspberrypi/overlay/etc/init.d/S13btuart | 4 +- .../overlay/etc/init.d/S05cpufreq | 2 +- .../overlay/etc/init.d/S11throttlewatch | 4 +- .../overlay/etc/init.d/S05cpufreq | 2 +- .../overlay/etc/init.d/S11throttlewatch | 4 +- .../raspberrypi3/overlay/etc/init.d/S13btuart | 4 +- 26 files changed, 105 insertions(+), 105 deletions(-) diff --git a/board/common/overlay/etc/init.d/S01mountall b/board/common/overlay/etc/init.d/S01mountall index 829b974c64..71065f714d 100755 --- a/board/common/overlay/etc/init.d/S01mountall +++ b/board/common/overlay/etc/init.d/S01mountall @@ -6,7 +6,7 @@ mount_fs() { msg_begin "Mounting filesystems" /bin/mount -T /etc/fstab.disk -a && /bin/mount -T /etc/fstab.extra -a && - if [ -r /data/etc/fstab.user ]; then /bin/mount -T /data/etc/fstab.user -a; fi + if [[ -r /data/etc/fstab.user ]]; then /bin/mount -T /data/etc/fstab.user -a; fi test $? == 0 && msg_done || msg_fail } diff --git a/board/common/overlay/etc/init.d/S02modules b/board/common/overlay/etc/init.d/S02modules index 8e1b5a9fd8..685f63a5fb 100755 --- a/board/common/overlay/etc/init.d/S02modules +++ b/board/common/overlay/etc/init.d/S02modules @@ -9,11 +9,11 @@ case "$1" in start) msg_begin "Loading kernel modules" - if [ -r $sys_modules_file ]; then + if [[ -r $sys_modules_file ]]; then cat $sys_modules_file | while read line; do test -n "$line" && /sbin/modprobe $line &>/dev/null; done fi - if [ -r $modules_file ]; then + if [[ -r $modules_file ]]; then cat $modules_file | while read line; do test -n "$line" && /sbin/modprobe $line &>/dev/null; done fi diff --git a/board/common/overlay/etc/init.d/S03hostname b/board/common/overlay/etc/init.d/S03hostname index dc1a56e345..8b886e838d 100755 --- a/board/common/overlay/etc/init.d/S03hostname +++ b/board/common/overlay/etc/init.d/S03hostname @@ -10,15 +10,15 @@ case "$1" in start) msg_begin "Setting hostname" - if ! [ -f $hostname_file ]; then - if [ -f $boot_hostname_file ]; then + if ! [[ -f $hostname_file ]]; then + if [[ -f $boot_hostname_file ]]; then cp $boot_hostname_file $hostname_file - elif [ -f $sys_hostname_file ]; then + elif [[ -f $sys_hostname_file ]]; then cp $sys_hostname_file $hostname_file fi fi - if [ -f $hostname_file ]; then + if [[ -f $hostname_file ]]; then hostname=$(cat $hostname_file) else hostname="$os_prefix-$board_sn" diff --git a/board/common/overlay/etc/init.d/S14postupgrade b/board/common/overlay/etc/init.d/S14postupgrade index 0765d72b76..65c0adf96b 100755 --- a/board/common/overlay/etc/init.d/S14postupgrade +++ b/board/common/overlay/etc/init.d/S14postupgrade @@ -16,7 +16,7 @@ test "$hash" == "$sys_hash" && exit 0 test -d $post_upgrade_dir || exit 0 function version_gt() { - if [ "$1" != "$2" ] && [ $(echo -e "$2\n$1" | sort -t . | head -n 1) == "$2" ]; then + if [[ "$1" != "$2" ]] && [[ $(echo -e "$2\n$1" | sort -t . | head -n 1) == "$2" ]]; then return 0 else return 1 @@ -29,7 +29,7 @@ function run_post_upgrade() { versions=$(ls -1 $post_upgrade_dir | cut -d '.' -f 1) for v in $versions; do - if [ -z "$version" ] || version_gt $v $version; then + if [[ -z "$version" ]] || version_gt $v $version; then msg_begin "Post-upgrading to version $v" out=$($post_upgrade_dir/$v.sh 2>&1) test $? == 0 && msg_done || msg_fail diff --git a/board/common/overlay/etc/init.d/S33hostapd b/board/common/overlay/etc/init.d/S33hostapd index bbdb797ff0..b8d6759589 100755 --- a/board/common/overlay/etc/init.d/S33hostapd +++ b/board/common/overlay/etc/init.d/S33hostapd @@ -14,10 +14,10 @@ link_watch_timeout=20 test -f $watch_conf && source $watch_conf -if ! [ -f $conf ]; then - if [ -f $boot_conf ]; then +if ! [[ -f $conf ]]; then + if [[ -f $boot_conf ]]; then cp $boot_conf $conf - elif [ -f $sys_conf ]; then + elif [[ -f $sys_conf ]]; then cp $sys_conf $conf fi fi @@ -49,7 +49,7 @@ start() { while ! ifconfig $iface >/dev/null 2>&1; do sleep 1 count=$(($count + 1)) - if [ $count -ge 5 ]; then + if [[ $count -ge 5 ]]; then msg_fail "no device" return 1 fi @@ -61,7 +61,7 @@ start() { iwconfig $iface power off &> /dev/null $prog $conf &> $log & - if [ "$link_watch" == "yes" ]; then + if [[ "$link_watch" == "yes" ]]; then watch & fi diff --git a/board/common/overlay/etc/init.d/S35wifi b/board/common/overlay/etc/init.d/S35wifi index 67d07047b6..7ab6635531 100755 --- a/board/common/overlay/etc/init.d/S35wifi +++ b/board/common/overlay/etc/init.d/S35wifi @@ -12,20 +12,20 @@ sys_watch_conf="/etc/watch.conf" boot_watch_conf="/boot/watch.conf" watch_conf="/data/etc/watch.conf" -if ! [ -f $watch_conf ]; then - if [ -f $boot_watch_conf ]; then +if ! [[ -f $watch_conf ]]; then + if [[ -f $boot_watch_conf ]]; then cp $boot_watch_conf $watch_conf - elif [ -f $sys_watch_conf ]; then + elif [[ -f $sys_watch_conf ]]; then cp $sys_watch_conf $watch_conf fi fi source $watch_conf -if ! [ -f $conf ]; then - if [ -f $boot_conf ]; then +if ! [[ -f $conf ]]; then + if [[ -f $boot_conf ]]; then cp $boot_conf $conf - elif [ -f $sys_conf ]; then + elif [[ -f $sys_conf ]]; then cp $sys_conf $conf fi fi @@ -53,7 +53,7 @@ watch() { if connected; then count=0 else - if [ $count -lt $link_watch_timeout ]; then + if [[ $count -lt $link_watch_timeout ]]; then count=$(($count + 5)) logger -t wifi -s "disconnected" else @@ -74,7 +74,7 @@ start() { while ! ifconfig $os_wlan >/dev/null 2>&1; do sleep 1 count=$(($count + 1)) - if [ $count -ge 5 ]; then + if [[ $count -ge 5 ]]; then msg_fail "no device" return 1 fi @@ -93,7 +93,7 @@ start() { break fi - if [ $count -gt $link_watch_timeout ] || ! pidof wpa_supplicant > /dev/null; then + if [[ $count -gt $link_watch_timeout ]] || ! pidof wpa_supplicant > /dev/null; then test -n "$module" && msg_fail "failed ($module)"|| msg_fail return 1 fi @@ -101,7 +101,7 @@ start() { count=$(($count + 1)) done - if [ "$link_watch" == "true" ]; then + if [[ "$link_watch" == "true" ]]; then watch & fi diff --git a/board/common/overlay/etc/init.d/S36ppp b/board/common/overlay/etc/init.d/S36ppp index b3dc0be5c6..c67f7253e6 100755 --- a/board/common/overlay/etc/init.d/S36ppp +++ b/board/common/overlay/etc/init.d/S36ppp @@ -11,10 +11,10 @@ watch_conf="/data/etc/watch.conf" source $watch_conf -if ! [ -d $conf ]; then - if [ -d $boot_conf ]; then +if ! [[ -d $conf ]]; then + if [[ -d $boot_conf ]]; then cp -r $boot_conf $conf - elif [ -d $sys_conf ]; then + elif [[ -d $sys_conf ]]; then cp -r $sys_conf $conf fi fi @@ -37,7 +37,7 @@ watch() { if connected; then count=0 else - if [ $count -lt $link_watch_timeout ]; then + if [[ $count -lt $link_watch_timeout ]]; then count=$(($count + 5)) logger -t ppp -s "disconnected" else @@ -64,13 +64,13 @@ start() { # wait for modem modem=$(head -n 1 $conf/modem) - if ! [ -e /dev/$modem ]; then + if ! [[ -e /dev/$modem ]]; then udev_trigger_add 4 & fi count=0 while true; do - if [ -e /dev/$modem ] || [ $count -gt $link_watch_timeout ]; then + if [[ -e /dev/$modem ]] || [[ $count -gt $link_watch_timeout ]]; then break fi @@ -78,7 +78,7 @@ start() { sleep 1 done - if ! [ -e /dev/$modem ]; then + if ! [[ -e /dev/$modem ]]; then msg_fail "modem /dev/$modem not present" return fi @@ -92,7 +92,7 @@ start() { break fi - if [ $count -gt $link_watch_timeout ] || ! pidof pppd > /dev/null; then + if [[ $count -gt $link_watch_timeout ]] || ! pidof pppd > /dev/null; then msg_fail return fi @@ -100,7 +100,7 @@ start() { count=$(($count + 1)) done - if [ "$link_watch" == "true" ]; then + if [[ "$link_watch" == "true" ]]; then watch & fi diff --git a/board/common/overlay/etc/init.d/S37bluetooth b/board/common/overlay/etc/init.d/S37bluetooth index 1e61009058..76e570ab00 100755 --- a/board/common/overlay/etc/init.d/S37bluetooth +++ b/board/common/overlay/etc/init.d/S37bluetooth @@ -4,10 +4,10 @@ sys_conf="/etc/bluetooth.conf" boot_conf="/boot/bluetooth.conf" conf="/data/etc/bluetooth.conf" -if ! [ -f $conf ]; then - if [ -f $boot_conf ]; then +if ! [[ -f $conf ]]; then + if [[ -f $boot_conf ]]; then cp $boot_conf $conf - elif [ -f $sys_conf ]; then + elif [[ -f $sys_conf ]]; then cp $sys_conf $conf fi fi @@ -46,7 +46,7 @@ start() { while ! hciconfig $hci &>/dev/null; do sleep 1 count=$(($count + 1)) - if [ $count -ge 10 ]; then + if [[ $count -ge 10 ]]; then msg_fail "no device" logger -t bluetooth -s "bluetooth device not available, calling panic action" panic_action bluetooth diff --git a/board/common/overlay/etc/init.d/S40network b/board/common/overlay/etc/init.d/S40network index 010329219a..93b03c81af 100755 --- a/board/common/overlay/etc/init.d/S40network +++ b/board/common/overlay/etc/init.d/S40network @@ -11,10 +11,10 @@ link_nego_timeout=10 source $watch_conf -if ! [ -f $static_conf ]; then - if [ -f $boot_static_conf ]; then +if ! [[ -f $static_conf ]]; then + if [[ -f $boot_static_conf ]]; then cp $boot_static_conf $static_conf - elif [ -f $sys_static_conf ]; then + elif [[ -f $sys_static_conf ]]; then cp $sys_static_conf $static_conf fi fi @@ -27,10 +27,10 @@ watch_eth() { count=0 while true; do sleep 5 - if [ "$(cat /sys/class/net/$os_eth/operstate 2>/dev/null)" == "up" ]; then + if [[ "$(cat /sys/class/net/$os_eth/operstate 2>/dev/null)" == "up" ]]; then count=0 else - if [ $count -lt $link_watch_timeout ]; then + if [[ $count -lt $link_watch_timeout ]]; then count=$(($count + 5)) logger -t ethernet -s "disconnected" else @@ -49,7 +49,7 @@ watch_ip() { if ip addr show dev $iface | grep inet &>/dev/null; then count=0 else - if [ $count -lt $ip_watch_timeout ]; then + if [[ $count -lt $ip_watch_timeout ]]; then count=$(($count + 5)) logger -t network -s "$iface has no IP address" else @@ -71,16 +71,16 @@ start_wlan() { return 1 fi - if [ "$(cat /sys/class/net/$os_wlan/carrier 2>/dev/null)" != "1" ]; then + if [[ "$(cat /sys/class/net/$os_wlan/carrier 2>/dev/null)" != "1" ]]; then msg_fail "no link" return 1 fi - if [ -n "$mtu" ]; then + if [[ -n "$mtu" ]]; then ip link set mtu $mtu dev $os_wlan fi - if [ -n "$static_ip" ]; then + if [[ -n "$static_ip" ]]; then msg_done $static_ip ifconfig $os_wlan $static_ip up static_ip="" # won't be used again @@ -89,7 +89,7 @@ start_wlan() { dhclient -cf "$dh_conf" $os_wlan fi - if [ "$ip_watch" == "true" ] && ip addr show dev $os_wlan | grep inet &>/dev/null; then + if [[ "$ip_watch" == "true" ]] && ip addr show dev $os_wlan | grep inet &>/dev/null; then watch_ip $os_wlan & fi } @@ -103,7 +103,7 @@ start_eth() { while ! ifconfig $os_eth >/dev/null 2>&1; do sleep 1 count=$(($count + 1)) - if [ $count -ge $w ]; then + if [[ $count -ge $w ]]; then msg_done "no device" return 1 fi @@ -115,10 +115,10 @@ start_eth() { # wait for operstate w=3 count=0 - while [ "$(cat /sys/class/net/$os_eth/operstate 2>&1)" == "unknown" ]; do + while [[ "$(cat /sys/class/net/$os_eth/operstate 2>&1)" == "unknown" ]]; do sleep 1 count=$(($count + 1)) - if [ $count -ge $w ]; then + if [[ $count -ge $w ]]; then msg_done "no link" return 1 fi @@ -127,20 +127,20 @@ start_eth() { # wait for link test "$link_watch" == "true" || link_nego_timeout=5 count=0 - while [ "$(cat /sys/class/net/$os_eth/carrier 2>&1)" != "1" ]; do + while [[ "$(cat /sys/class/net/$os_eth/carrier 2>&1)" != "1" ]]; do sleep 1 count=$(($count + 1)) - if [ $count -ge $link_nego_timeout ]; then + if [[ $count -ge $link_nego_timeout ]]; then msg_done "no link" return 1 fi done - if [ -n "$mtu" ]; then + if [[ -n "$mtu" ]]; then ip link set mtu $mtu dev $os_eth fi - if [ -n "$static_ip" ]; then + if [[ -n "$static_ip" ]]; then msg_done $static_ip ifconfig $os_eth $static_ip up static_ip="" # won't be used again @@ -149,11 +149,11 @@ start_eth() { dhclient -cf "$dh_conf" $os_eth fi - if [ "$link_watch" == "true" ]; then + if [[ "$link_watch" == "true" ]]; then watch_eth & fi - if [ "$ip_watch" == "true" ] && ip addr show dev $os_eth | grep inet &>/dev/null; then + if [[ "$ip_watch" == "true" ]] && ip addr show dev $os_eth | grep inet &>/dev/null; then watch_ip $os_eth & fi } @@ -172,14 +172,14 @@ start() { test -r /data/etc/ppp/modem && ifconfig | grep $os_ppp &>/dev/null && ppp_ok="ok" # if wifi or ppp link ok, start eth in background - if [ "$wlan_ok" == "ok" ] || [ "$ppp_ok" == "ok" ]; then + if [[ "$wlan_ok" == "ok" ]] || [[ "$ppp_ok" == "ok" ]]; then start_eth &>/dev/null & else start_eth && eth_ok="ok" fi - if [ "$eth_ok" != "ok" ] && [ "$wlan_ok" != "ok" ] && [ "$ppp_ok" != "ok" ]; then - if [ "$link_watch" == "true" ]; then + if [[ "$eth_ok" != "ok" ]] && [[ "$wlan_ok" != "ok" ]] && [[ "$ppp_ok" != "ok" ]]; then + if [[ "$link_watch" == "true" ]]; then logger -t network -s "no network connection available, calling panic action" panic_action network return 1 @@ -189,13 +189,13 @@ start() { fi fi - if [ -n "$static_gw" ]; then + if [[ -n "$static_gw" ]]; then msg_begin "Setting static gateway to $static_gw" ip route add default via $static_gw test $? == 0 && msg_done || msg_fail fi - if [ -n "$static_dns" ]; then + if [[ -n "$static_dns" ]]; then msg_begin "Setting static DNS server to $static_dns" echo "nameserver $static_dns" > /etc/resolv.conf test $? == 0 && msg_done || msg_fail diff --git a/board/common/overlay/etc/init.d/S41netwatch b/board/common/overlay/etc/init.d/S41netwatch index 2abd6433c6..a7bd496f32 100755 --- a/board/common/overlay/etc/init.d/S41netwatch +++ b/board/common/overlay/etc/init.d/S41netwatch @@ -7,7 +7,7 @@ netwatch_interval=20 test -f $watch_conf && source $watch_conf || exit 0 -if [ -z "$netwatch_host" ] || [ -z "$netwatch_port" ]; then +if [[ -z "$netwatch_host" ]] || [[ -z "$netwatch_port" ]]; then exit 0 fi @@ -23,7 +23,7 @@ watch() { if nc -z -w $netwatch_timeout $netwatch_host $netwatch_port /dev/null 2>&1; then count=0 else - if [ $count -lt $netwatch_retries ]; then + if [[ $count -lt $netwatch_retries ]]; then logger -t netwatch -s "cannot connect to $netwatch_host:$netwatch_port" count=$(($count + 1)) continue diff --git a/board/common/overlay/etc/init.d/S43firewall b/board/common/overlay/etc/init.d/S43firewall index a6313d2559..3e049c18d8 100755 --- a/board/common/overlay/etc/init.d/S43firewall +++ b/board/common/overlay/etc/init.d/S43firewall @@ -4,10 +4,10 @@ sys_conf="/etc/firewall.sh" boot_conf="/boot/firewall.sh" conf="/data/etc/firewall.sh" -if ! [ -f $conf ]; then - if [ -f $boot_conf ]; then +if ! [[ -f $conf ]]; then + if [[ -f $boot_conf ]]; then cp $boot_conf $conf - elif [ -f $sys_conf ]; then + elif [[ -f $sys_conf ]]; then cp $sys_conf $conf fi fi diff --git a/board/common/overlay/etc/init.d/S45dnsmasq b/board/common/overlay/etc/init.d/S45dnsmasq index c571488db4..e6c7c3ffed 100755 --- a/board/common/overlay/etc/init.d/S45dnsmasq +++ b/board/common/overlay/etc/init.d/S45dnsmasq @@ -7,10 +7,10 @@ conf="/data/etc/dnsmasq.conf" log="/var/log/dnsmasq.log" prog="/usr/sbin/dnsmasq" -if ! [ -f $conf ]; then - if [ -f $boot_conf ]; then +if ! [[ -f $conf ]]; then + if [[ -f $boot_conf ]]; then cp $boot_conf $conf - elif [ -f $sys_conf ]; then + elif [[ -f $sys_conf ]]; then cp $sys_conf $conf fi fi diff --git a/board/common/overlay/etc/init.d/S50date b/board/common/overlay/etc/init.d/S50date index 87464d368c..0390037222 100755 --- a/board/common/overlay/etc/init.d/S50date +++ b/board/common/overlay/etc/init.d/S50date @@ -11,18 +11,18 @@ sys_ntp_conf="/etc/ntp.conf" boot_ntp_conf="/boot/ntp.conf" ntp_conf="/data/etc/ntp.conf" -if ! [ -f $conf ]; then - if [ -f $boot_conf ]; then +if ! [[ -f $conf ]]; then + if [[ -f $boot_conf ]]; then cp $boot_conf $conf - elif [ -f $sys_conf ]; then + elif [[ -f $sys_conf ]]; then cp $sys_conf $conf fi fi -if ! [ -f $ntp_conf ]; then - if [ -f $boot_ntp_conf ]; then +if ! [[ -f $ntp_conf ]]; then + if [[ -f $boot_ntp_conf ]]; then cp $boot_ntp_conf $ntp_conf - elif [ -f $sys_ntp_conf ]; then + elif [[ -f $sys_ntp_conf ]]; then cp $sys_ntp_conf $ntp_conf fi fi @@ -69,7 +69,7 @@ start_ntp() { cat $ntp_conf | grep -v iburst > ${ntp_conf}.tmp - if [ -n "$date_ntp_server" ]; then + if [[ -n "$date_ntp_server" ]]; then echo "server $date_ntp_server iburst" > $ntp_conf else cat $sys_ntp_conf | grep iburst > $ntp_conf @@ -100,7 +100,7 @@ stop_ntp() { } start() { - if [ "$date_method" == "http" ]; then + if [[ "$date_method" == "http" ]]; then start_http else start_ntp @@ -110,7 +110,7 @@ start() { } stop() { - if [ "$date_method" == "http" ]; then + if [[ "$date_method" == "http" ]]; then stop_http else stop_ntp diff --git a/board/common/overlay/etc/init.d/S51crond b/board/common/overlay/etc/init.d/S51crond index 1a839f71df..618b482e12 100755 --- a/board/common/overlay/etc/init.d/S51crond +++ b/board/common/overlay/etc/init.d/S51crond @@ -8,7 +8,7 @@ test -n "$os_version" || source /etc/init.d/base start() { msg_begin "Starting crond" - if [ -d $sys_conf ]; then + if [[ -d $sys_conf ]]; then /usr/sbin/crond -c $sys_conf fi diff --git a/board/common/overlay/etc/init.d/conf b/board/common/overlay/etc/init.d/conf index dc71091fb9..46ab1a6378 100644 --- a/board/common/overlay/etc/init.d/conf +++ b/board/common/overlay/etc/init.d/conf @@ -4,26 +4,26 @@ _sys_conf="/etc/os.conf" _boot_conf="/boot/os.conf" _conf="/data/etc/os.conf" -if ! [ -d /data/etc ]; then +if ! [[ -d /data/etc ]]; then # use boot/system variants if we don't have the data partition mounted - if [ -f $_boot_conf ]; then + if [[ -f $_boot_conf ]]; then source $_boot_conf - elif [ -f $_sys_conf ]; then + elif [[ -f $_sys_conf ]]; then source $_sys_conf fi return fi -if ! [ -f $_conf ]; then - if [ -f $_boot_conf ]; then +if ! [[ -f $_conf ]]; then + if [[ -f $_boot_conf ]]; then cp $_boot_conf $_conf - elif [ -f $_sys_conf ]; then + elif [[ -f $_sys_conf ]]; then cp $_sys_conf $_conf fi fi -if [ -f $_conf ]; then +if [[ -f $_conf ]]; then source $_conf fi diff --git a/board/common/overlay/etc/init.d/panic b/board/common/overlay/etc/init.d/panic index e0d288d0d6..fcf6724e54 100755 --- a/board/common/overlay/etc/init.d/panic +++ b/board/common/overlay/etc/init.d/panic @@ -13,11 +13,11 @@ panic_action() { echo $((panic_counter + 1)) > ${_PANIC_COUNTER_FILE} delay=$((_PANIC_REBOOT_DELAY_FACTOR * panic_counter)) - if [ "${delay}" -gt "${_PANIC_REBOOT_DELAY_MAX}" ]; then + if [[ "${delay}" -gt "${_PANIC_REBOOT_DELAY_MAX}" ]]; then delay=${_PANIC_REBOOT_DELAY_MAX} fi - if [ "${delay}" -gt 0 ]; then + if [[ "${delay}" -gt 0 ]]; then logger -t panic -s "rebooting in ${delay} seconds (caused by $1)" sleep ${delay} fi diff --git a/board/common/overlay/etc/init.d/rcK b/board/common/overlay/etc/init.d/rcK index 90d77ec140..7d08910c5b 100755 --- a/board/common/overlay/etc/init.d/rcK +++ b/board/common/overlay/etc/init.d/rcK @@ -10,8 +10,8 @@ echo "---- shutting down $os_name $os_version ----" >> $boot_log # stop all init scripts in /etc/init.d, # executing them in reverse numerical order. (for i in $(ls -r /etc/init.d/S??*); do - [ ! -x "$i" ] && continue - [ -f /data/etc/no_$(basename $i) ] && continue + if ! [[ -x "$i" ]]; then continue; fi + if [[ -f /data/etc/no_$(basename $i) ]]; then continue; fi $i stop done& echo $! > $pid_file) | tee -a $boot_log & diff --git a/board/common/overlay/etc/init.d/rcS b/board/common/overlay/etc/init.d/rcS index 22fa4ac98f..d15157610f 100755 --- a/board/common/overlay/etc/init.d/rcS +++ b/board/common/overlay/etc/init.d/rcS @@ -11,8 +11,8 @@ echo "---- booting $os_name $os_version ----" >> $tmp_boot_log # start all init scripts in /etc/init.d, # executing them in numerical order. (for i in /etc/init.d/S??* /etc/init.d/bootdone; do - [ ! -x "$i" ] && continue - [ -f /data/etc/no_$(basename $i) ] && continue + if ! [[ -x "$i" ]]; then continue; fi + if [[ -f /data/etc/no_$(basename $i) ]]; then continue; fi $i start || break done& echo $! > $pid_file) | tee -a $tmp_boot_log & diff --git a/board/raspberrypi/overlay/etc/init.d/S05cpufreq b/board/raspberrypi/overlay/etc/init.d/S05cpufreq index 5c97047d42..82ae420f49 100755 --- a/board/raspberrypi/overlay/etc/init.d/S05cpufreq +++ b/board/raspberrypi/overlay/etc/init.d/S05cpufreq @@ -8,7 +8,7 @@ govdir="/sys/devices/system/cpu/cpufreq/$gov" configure() { echo $gov > $cpufreqdir/scaling_governor - if [ $gov == "ondemand" ]; then + if [[ $gov == "ondemand" ]]; then echo 50 > $govdir/up_threshold echo 100000 > $govdir/sampling_rate echo 50 > $govdir/sampling_down_factor diff --git a/board/raspberrypi/overlay/etc/init.d/S11throttlewatch b/board/raspberrypi/overlay/etc/init.d/S11throttlewatch index 05e1ada454..a06374158c 100755 --- a/board/raspberrypi/overlay/etc/init.d/S11throttlewatch +++ b/board/raspberrypi/overlay/etc/init.d/S11throttlewatch @@ -21,7 +21,7 @@ get_throttled_since_boot() { watch_now() { while true; do t=$(get_throttled_now) - if [ -n "$t" ]; then + if [[ -n "$t" ]]; then logger -t throttlewatch -s "currently: $t" fi @@ -32,7 +32,7 @@ watch_now() { watch_since_boot() { while true; do t=$(get_throttled_since_boot) - if [ -n "$t" ]; then + if [[ -n "$t" ]]; then logger -t throttlewatch -s "since boot: $t" break fi diff --git a/board/raspberrypi/overlay/etc/init.d/S13btuart b/board/raspberrypi/overlay/etc/init.d/S13btuart index 48464b8263..f5d51a4148 100755 --- a/board/raspberrypi/overlay/etc/init.d/S13btuart +++ b/board/raspberrypi/overlay/etc/init.d/S13btuart @@ -11,8 +11,8 @@ test -d "/proc/device-tree/soc/gpio@7e200000/uart0_pins" || exit 0 # no rpi blu test -n "$os_version" || source /etc/init.d/base function start() { - if [ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ] ; then - if [ "$(wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' ')" = " 16" ] ; then + if [[ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ]] ; then + if [[ "$(wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' ')" = " 16" ]] ; then /usr/bin/hciattach -t5 /dev/serial1 bcm43xx 3000000 flow - &>/dev/null else /usr/bin/hciattach -t5 /dev/serial1 bcm43xx 921600 noflow - &>/dev/null diff --git a/board/raspberrypi2/overlay/etc/init.d/S05cpufreq b/board/raspberrypi2/overlay/etc/init.d/S05cpufreq index 5c97047d42..82ae420f49 100755 --- a/board/raspberrypi2/overlay/etc/init.d/S05cpufreq +++ b/board/raspberrypi2/overlay/etc/init.d/S05cpufreq @@ -8,7 +8,7 @@ govdir="/sys/devices/system/cpu/cpufreq/$gov" configure() { echo $gov > $cpufreqdir/scaling_governor - if [ $gov == "ondemand" ]; then + if [[ $gov == "ondemand" ]]; then echo 50 > $govdir/up_threshold echo 100000 > $govdir/sampling_rate echo 50 > $govdir/sampling_down_factor diff --git a/board/raspberrypi2/overlay/etc/init.d/S11throttlewatch b/board/raspberrypi2/overlay/etc/init.d/S11throttlewatch index 05e1ada454..a06374158c 100755 --- a/board/raspberrypi2/overlay/etc/init.d/S11throttlewatch +++ b/board/raspberrypi2/overlay/etc/init.d/S11throttlewatch @@ -21,7 +21,7 @@ get_throttled_since_boot() { watch_now() { while true; do t=$(get_throttled_now) - if [ -n "$t" ]; then + if [[ -n "$t" ]]; then logger -t throttlewatch -s "currently: $t" fi @@ -32,7 +32,7 @@ watch_now() { watch_since_boot() { while true; do t=$(get_throttled_since_boot) - if [ -n "$t" ]; then + if [[ -n "$t" ]]; then logger -t throttlewatch -s "since boot: $t" break fi diff --git a/board/raspberrypi3/overlay/etc/init.d/S05cpufreq b/board/raspberrypi3/overlay/etc/init.d/S05cpufreq index 5c97047d42..82ae420f49 100755 --- a/board/raspberrypi3/overlay/etc/init.d/S05cpufreq +++ b/board/raspberrypi3/overlay/etc/init.d/S05cpufreq @@ -8,7 +8,7 @@ govdir="/sys/devices/system/cpu/cpufreq/$gov" configure() { echo $gov > $cpufreqdir/scaling_governor - if [ $gov == "ondemand" ]; then + if [[ $gov == "ondemand" ]]; then echo 50 > $govdir/up_threshold echo 100000 > $govdir/sampling_rate echo 50 > $govdir/sampling_down_factor diff --git a/board/raspberrypi3/overlay/etc/init.d/S11throttlewatch b/board/raspberrypi3/overlay/etc/init.d/S11throttlewatch index 05e1ada454..a06374158c 100755 --- a/board/raspberrypi3/overlay/etc/init.d/S11throttlewatch +++ b/board/raspberrypi3/overlay/etc/init.d/S11throttlewatch @@ -21,7 +21,7 @@ get_throttled_since_boot() { watch_now() { while true; do t=$(get_throttled_now) - if [ -n "$t" ]; then + if [[ -n "$t" ]]; then logger -t throttlewatch -s "currently: $t" fi @@ -32,7 +32,7 @@ watch_now() { watch_since_boot() { while true; do t=$(get_throttled_since_boot) - if [ -n "$t" ]; then + if [[ -n "$t" ]]; then logger -t throttlewatch -s "since boot: $t" break fi diff --git a/board/raspberrypi3/overlay/etc/init.d/S13btuart b/board/raspberrypi3/overlay/etc/init.d/S13btuart index 6899065c82..513842ba6a 100755 --- a/board/raspberrypi3/overlay/etc/init.d/S13btuart +++ b/board/raspberrypi3/overlay/etc/init.d/S13btuart @@ -9,8 +9,8 @@ test -f $conf || test -f $boot_conf || test -f $sys_conf || exit 0 test -n "$os_version" || source /etc/init.d/base function start() { - if [ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ] ; then - if [ "$(wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' ')" = " 16" ] ; then + if [[ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ]] ; then + if [[ "$(wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' ')" = " 16" ]] ; then /usr/bin/hciattach -t5 /dev/serial1 bcm43xx 3000000 flow - &>/dev/null else /usr/bin/hciattach -t5 /dev/serial1 bcm43xx 921600 noflow - &>/dev/null