From f12a7498d9cdc48bf4fff7f57e226c9f98b0805a Mon Sep 17 00:00:00 2001 From: Joo Aun Saw Date: Fri, 4 Jan 2019 15:49:08 +1100 Subject: [PATCH 01/23] fwupdate: upgrade from local file first if exists --- board/common/overlay/sbin/fwupdate | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/board/common/overlay/sbin/fwupdate b/board/common/overlay/sbin/fwupdate index 0a07aac2ce..7e44a7f642 100755 --- a/board/common/overlay/sbin/fwupdate +++ b/board/common/overlay/sbin/fwupdate @@ -112,6 +112,26 @@ function do_download() { rm -f $FW_DIR/$FW_FILE_GZ $FW_DIR/$FW_FILE_XZ rm -f $FW_DIR/$FW_FILE_EXTR rm -f $FW_DIR/$BOOT_READY_FILE + rm -rf $FW_DIR/* + mkdir -p $FW_DIR + + # Look for local file first + if [ -f "$1" ]; then + version="custom" + FNAME=`basename $1` + FILEEXT=${FNAME##*.} + DST_FNAME="" + if [ "$FILEEXT" == "xz" ]; then + DST_FNAME="$FW_DIR/$FW_FILE_XZ" + elif [ "$FILEEXT" == "gz" ]; then + DST_FNAME="$FW_DIR/$FW_FILE_GZ" + fi + if [ -n "$DST_FNAME" ]; then + cp -f $1 $DST_FNAME + echo $version > $FW_DIR/$VER_FILE + return + fi + fi source $OS_CONF board=$(cat $SYS_BOARD_FILE) @@ -141,8 +161,6 @@ function do_download() { outfile=$FW_DIR/$FW_FILE_XZ fi - rm -rf $FW_DIR/* - mkdir -p $FW_DIR echo $version > $FW_DIR/$VER_FILE curl_opts="-S -f -L" From 353bfd21a54ba7872179360024fce92a735b888b Mon Sep 17 00:00:00 2001 From: Joo Aun Saw Date: Fri, 4 Jan 2019 16:42:29 +1100 Subject: [PATCH 02/23] fwupdate: fixed indentation --- board/common/overlay/sbin/fwupdate | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/board/common/overlay/sbin/fwupdate b/board/common/overlay/sbin/fwupdate index 7e44a7f642..c3a2f0dcde 100755 --- a/board/common/overlay/sbin/fwupdate +++ b/board/common/overlay/sbin/fwupdate @@ -115,22 +115,22 @@ function do_download() { rm -rf $FW_DIR/* mkdir -p $FW_DIR - # Look for local file first + # Look for local file first if [ -f "$1" ]; then version="custom" FNAME=`basename $1` FILEEXT=${FNAME##*.} - DST_FNAME="" + DST_FNAME="" if [ "$FILEEXT" == "xz" ]; then DST_FNAME="$FW_DIR/$FW_FILE_XZ" elif [ "$FILEEXT" == "gz" ]; then DST_FNAME="$FW_DIR/$FW_FILE_GZ" fi - if [ -n "$DST_FNAME" ]; then + if [ -n "$DST_FNAME" ]; then cp -f $1 $DST_FNAME - echo $version > $FW_DIR/$VER_FILE - return - fi + echo $version > $FW_DIR/$VER_FILE + return + fi fi source $OS_CONF From acca93a9e48a833321f7fc662aed68593af76c66 Mon Sep 17 00:00:00 2001 From: Joo Aun Saw Date: Fri, 4 Jan 2019 17:16:10 +1100 Subject: [PATCH 03/23] always copy /boot/wpa_supplicant.conf during startup --- board/common/overlay/etc/init.d/S35wifi | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/board/common/overlay/etc/init.d/S35wifi b/board/common/overlay/etc/init.d/S35wifi index 7ab6635531..60ec787932 100755 --- a/board/common/overlay/etc/init.d/S35wifi +++ b/board/common/overlay/etc/init.d/S35wifi @@ -22,10 +22,17 @@ fi source $watch_conf +if [[ -f $boot_conf ]]; then + cp -f $boot_conf $conf + grep -E "/boot .*ro[\s,]" /proc/mounts + RO=$? + test $RO == 0 && mount -o remount,rw /boot + rm -f $boot_conf + test $RO == 0 && mount -o remount,ro /boot +fi + if ! [[ -f $conf ]]; then - if [[ -f $boot_conf ]]; then - cp $boot_conf $conf - elif [[ -f $sys_conf ]]; then + if [[ -f $sys_conf ]]; then cp $sys_conf $conf fi fi From 6945f998a57bb62ed9e28c441ebb2252d9b02822 Mon Sep 17 00:00:00 2001 From: Joo Aun Saw Date: Tue, 8 Jan 2019 00:10:19 +1100 Subject: [PATCH 04/23] fwupdate: remove redundant rm commands --- board/common/overlay/sbin/fwupdate | 3 --- 1 file changed, 3 deletions(-) diff --git a/board/common/overlay/sbin/fwupdate b/board/common/overlay/sbin/fwupdate index c3a2f0dcde..51c8c531aa 100755 --- a/board/common/overlay/sbin/fwupdate +++ b/board/common/overlay/sbin/fwupdate @@ -109,9 +109,6 @@ function show_current() { function do_download() { echo "downloading..." - rm -f $FW_DIR/$FW_FILE_GZ $FW_DIR/$FW_FILE_XZ - rm -f $FW_DIR/$FW_FILE_EXTR - rm -f $FW_DIR/$BOOT_READY_FILE rm -rf $FW_DIR/* mkdir -p $FW_DIR From 40e95378c6ac2b1ac56a566a2d01ef402d8c7285 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 11 Jan 2019 11:06:48 +0200 Subject: [PATCH 05/23] fwupdate: show download file argument in usage --- board/common/overlay/sbin/fwupdate | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/board/common/overlay/sbin/fwupdate b/board/common/overlay/sbin/fwupdate index 4c37db228c..ea3bfeb0f6 100755 --- a/board/common/overlay/sbin/fwupdate +++ b/board/common/overlay/sbin/fwupdate @@ -4,14 +4,14 @@ #### usage #### function exit_usage() { - echo "Usage: fwupdate versions [-j] (lists available versions, optionally outputting json)" - echo " fwupdate current (shows the current version" - echo " fwupdate download (downloads a firmware version)" - echo " fwupdate extract (extracts the downloaded firmware archive)" - echo " fwupdate flashboot (flashes the boot partition from extracted image)" - echo " fwupdate flashreboot (prepares for reboot + root partititon flash)" - echo " fwupdate status (shows the current firmware updating status; see below)" - echo " fwupdate upgrade (performs all the operations necessary for upgrading)" + echo "Usage: fwupdate versions [-j] (lists available versions, optionally outputting json)" + echo " fwupdate current (shows the current version" + echo " fwupdate download (downloads a firmware version)" + echo " fwupdate extract (extracts the downloaded firmware archive)" + echo " fwupdate flashboot (flashes the boot partition from extracted image)" + echo " fwupdate flashreboot (prepares for reboot + root partititon flash)" + echo " fwupdate status (shows the current firmware updating status; see below)" + echo " fwupdate upgrade (performs all the operations necessary for upgrading)" echo "" echo "Statuses:" echo " idle" From e78a2de15b3dda4815cc982290b7b7bcb3c7c0a6 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 11 Jan 2019 11:41:02 +0200 Subject: [PATCH 06/23] Add /boot/modules support --- board/common/overlay/etc/init.d/S02modules | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/board/common/overlay/etc/init.d/S02modules b/board/common/overlay/etc/init.d/S02modules index 685f63a5fb..2a65d476c5 100755 --- a/board/common/overlay/etc/init.d/S02modules +++ b/board/common/overlay/etc/init.d/S02modules @@ -1,6 +1,7 @@ #!/bin/bash sys_modules_file="/etc/modules" +boot_modules_file="/boot/modules" modules_file="/data/etc/modules" test -n "$os_version" || source /etc/init.d/base @@ -13,6 +14,10 @@ case "$1" in cat $sys_modules_file | while read line; do test -n "$line" && /sbin/modprobe $line &>/dev/null; done fi + if [[ -r $boot_modules_file ]]; then + cat $boot_modules_file | while read line; do test -n "$line" && /sbin/modprobe $line &>/dev/null; done + fi + if [[ -r $modules_file ]]; then cat $modules_file | while read line; do test -n "$line" && /sbin/modprobe $line &>/dev/null; done fi From ace9bdcf2be27bae89075207ff2ca60f200b81cf Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 11 Jan 2019 11:43:22 +0200 Subject: [PATCH 07/23] Init scripts: generalize config file setup --- board/common/overlay/etc/init.d/base | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/board/common/overlay/etc/init.d/base b/board/common/overlay/etc/init.d/base index 7b08c9384d..7a102d51ff 100755 --- a/board/common/overlay/etc/init.d/base +++ b/board/common/overlay/etc/init.d/base @@ -8,6 +8,7 @@ test -n "$os_debug" || source /etc/init.d/conf source /etc/init.d/panic + msg_begin() { echo -n " * $1: " } @@ -24,3 +25,35 @@ msg_background() { test -n "$1" && echo $1 || echo "pending" } +prepare_conf() { + # $1 - actual config file + # $2 - system-provided config file + # $3 - user-provided config file + + # long story short: + # * user conf file takes precedence, if present + # * system conf file is used by default, if actual file absent + + actual_conf="$1" + system_conf="$2" + user_conf="$3" + + if [[ -n "$user_conf" && -f "$user_conf" ]]; then + cp -f "$user_conf" "$actual_conf" + grep -E "/boot .*ro[\s,]" /proc/mounts + RO=$? + test $RO == 0 && mount -o remount,rw /boot + rm -f $user_conf + test $RO == 0 && mount -o remount,ro /boot + fi + + if [[ ! -f "$actual_conf" && -f "$system_conf" ]]; then + cp "$system_conf" "$actual_conf" + fi + + # we want only Unix newlines in conf files + if [[ -f "$actual_conf" ]]; then + sed -i 's/\r//g' "$actual_conf" + fi +} + From df44e16f881e0f9bce43b5817c71cda8b090d3ef Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 11 Jan 2019 11:43:53 +0200 Subject: [PATCH 08/23] S03hostname: use prepare_conf --- board/common/overlay/etc/init.d/S03hostname | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/board/common/overlay/etc/init.d/S03hostname b/board/common/overlay/etc/init.d/S03hostname index 8b886e838d..a730cc65c0 100755 --- a/board/common/overlay/etc/init.d/S03hostname +++ b/board/common/overlay/etc/init.d/S03hostname @@ -10,13 +10,7 @@ case "$1" in start) msg_begin "Setting hostname" - if ! [[ -f $hostname_file ]]; then - if [[ -f $boot_hostname_file ]]; then - cp $boot_hostname_file $hostname_file - elif [[ -f $sys_hostname_file ]]; then - cp $sys_hostname_file $hostname_file - fi - fi + prepare_conf $hostname_file $sys_hostname_file $boot_hostname_file if [[ -f $hostname_file ]]; then hostname=$(cat $hostname_file) From 3a06cf48de689d50ccc62420cdfaac0443bced6e Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 11 Jan 2019 13:29:12 +0200 Subject: [PATCH 09/23] Source in all available os.conf files --- .../common/overlay/etc/init.d/S14postupgrade | 15 ---------- board/common/overlay/etc/init.d/S35wifi | 28 ++----------------- board/common/overlay/etc/init.d/conf | 28 +++++++------------ board/common/overlay/sbin/fwupdate | 7 +++-- 4 files changed, 16 insertions(+), 62 deletions(-) diff --git a/board/common/overlay/etc/init.d/S14postupgrade b/board/common/overlay/etc/init.d/S14postupgrade index 65c0adf96b..bb41a4e105 100755 --- a/board/common/overlay/etc/init.d/S14postupgrade +++ b/board/common/overlay/etc/init.d/S14postupgrade @@ -5,8 +5,6 @@ test -n "$os_version" || source /etc/init.d/base sys_version_file="/etc/version" version_file="/data/etc/version" post_upgrade_dir="/usr/share/post-upgrade" -sys_os_conf="/etc/os.conf" -os_conf="/data/etc/os.conf" hash=$(md5sum $version_file 2>/dev/null | cut -d ' ' -f 1) sys_hash=$(md5sum $sys_version_file 2>/dev/null | cut -d ' ' -f 1) @@ -38,23 +36,10 @@ function run_post_upgrade() { done } -function update_os_conf() { - source $sys_os_conf - sys_vars=$(cat $sys_os_conf | cut -d '=' -f 1) - for var in $sys_vars; do - if ! grep "$var=" $os_conf &>/dev/null; then - msg_begin "Adding $var to os.conf" - echo "$var=\"${!var}\"" >> $os_conf - msg_done - fi - done -} - case "$1" in start) run_post_upgrade cp $sys_version_file $version_file - update_os_conf ;; stop) diff --git a/board/common/overlay/etc/init.d/S35wifi b/board/common/overlay/etc/init.d/S35wifi index 60ec787932..018ee5852e 100755 --- a/board/common/overlay/etc/init.d/S35wifi +++ b/board/common/overlay/etc/init.d/S35wifi @@ -12,36 +12,12 @@ 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 - cp $boot_watch_conf $watch_conf - elif [[ -f $sys_watch_conf ]]; then - cp $sys_watch_conf $watch_conf - fi -fi - +prepare_conf $watch_conf $sys_watch_conf $boot_watch_conf source $watch_conf -if [[ -f $boot_conf ]]; then - cp -f $boot_conf $conf - grep -E "/boot .*ro[\s,]" /proc/mounts - RO=$? - test $RO == 0 && mount -o remount,rw /boot - rm -f $boot_conf - test $RO == 0 && mount -o remount,ro /boot -fi - -if ! [[ -f $conf ]]; then - if [[ -f $sys_conf ]]; then - cp $sys_conf $conf - fi -fi - +prepare_conf $conf $sys_conf $boot_conf test -f $conf || exit 0 -# we want only Unix newlines here -sed -i 's/\r//g' $conf - ssid=$(cat $conf | grep ssid | grep -v scan_ssid | cut -d '"' -f 2) test -n "$ssid" || exit 0 diff --git a/board/common/overlay/etc/init.d/conf b/board/common/overlay/etc/init.d/conf index 46ab1a6378..c8fd635052 100644 --- a/board/common/overlay/etc/init.d/conf +++ b/board/common/overlay/etc/init.d/conf @@ -2,28 +2,20 @@ _sys_conf="/etc/os.conf" _boot_conf="/boot/os.conf" -_conf="/data/etc/os.conf" +_data_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 +# source in all conf files in order of precedence +if [[ -f $_sys_conf ]]; then + source $_sys_conf fi -if ! [[ -f $_conf ]]; then - if [[ -f $_boot_conf ]]; then - cp $_boot_conf $_conf - elif [[ -f $_sys_conf ]]; then - cp $_sys_conf $_conf - fi +if [[ -f $_data_conf ]]; then + source $_data_conf fi -if [[ -f $_conf ]]; then - source $_conf +if [[ -f $_boot_conf ]]; then + source $_boot_conf fi +unset _sys_conf _boot_conf _data_conf + diff --git a/board/common/overlay/sbin/fwupdate b/board/common/overlay/sbin/fwupdate index ea3bfeb0f6..fd7bee5db1 100755 --- a/board/common/overlay/sbin/fwupdate +++ b/board/common/overlay/sbin/fwupdate @@ -35,7 +35,6 @@ fi SYS_VERSION_FILE=/etc/version SYS_BOARD_FILE=/etc/board -OS_CONF=/data/etc/os.conf MIN_FREE_DISK=$((500*1024)) # 500 MB VER_FILE=version @@ -78,7 +77,8 @@ fi #### versions #### function show_versions() { - source $OS_CONF + source /etc/init.d/conf # we need this for the os_ vars + board=$(cat $SYS_BOARD_FILE) show_json=$1 @@ -144,7 +144,8 @@ function do_download() { fi fi - source $OS_CONF + source /etc/init.d/conf # we need this for the os_ vars + board=$(cat $SYS_BOARD_FILE) url=$1 version=$1 From bf567ddf77e2c41eae169733034affd7fb83ef8e Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 11 Jan 2019 13:45:19 +0200 Subject: [PATCH 10/23] Rename /etc/init.d/conf to /etc/init.d/os_conf --- board/common/overlay/etc/init.d/S01mountall | 2 +- board/common/overlay/etc/init.d/base | 2 +- board/common/overlay/etc/init.d/{conf => os_conf} | 0 board/common/overlay/sbin/fwupdate | 4 ++-- 4 files changed, 4 insertions(+), 4 deletions(-) rename board/common/overlay/etc/init.d/{conf => os_conf} (100%) diff --git a/board/common/overlay/etc/init.d/S01mountall b/board/common/overlay/etc/init.d/S01mountall index 71065f714d..ac987534aa 100755 --- a/board/common/overlay/etc/init.d/S01mountall +++ b/board/common/overlay/etc/init.d/S01mountall @@ -31,7 +31,7 @@ case "$1" in mount_fs # we need to source conf again, now that /data is available - test -n "$os_debug" || source /etc/init.d/conf + test -n "$os_debug" || source /etc/init.d/os_conf test "$os_debug" == "true" && remount_rw mk_tty_login ;; diff --git a/board/common/overlay/etc/init.d/base b/board/common/overlay/etc/init.d/base index 7a102d51ff..b6917581f3 100755 --- a/board/common/overlay/etc/init.d/base +++ b/board/common/overlay/etc/init.d/base @@ -4,7 +4,7 @@ source /etc/version board_sn=$(/etc/init.d/boardsn) board_name=$(cat /etc/board) -test -n "$os_debug" || source /etc/init.d/conf +test -n "$os_debug" || source /etc/init.d/os_conf source /etc/init.d/panic diff --git a/board/common/overlay/etc/init.d/conf b/board/common/overlay/etc/init.d/os_conf similarity index 100% rename from board/common/overlay/etc/init.d/conf rename to board/common/overlay/etc/init.d/os_conf diff --git a/board/common/overlay/sbin/fwupdate b/board/common/overlay/sbin/fwupdate index fd7bee5db1..3dafd3b1db 100755 --- a/board/common/overlay/sbin/fwupdate +++ b/board/common/overlay/sbin/fwupdate @@ -77,7 +77,7 @@ fi #### versions #### function show_versions() { - source /etc/init.d/conf # we need this for the os_ vars + source /etc/init.d/os_conf # we need this for the os_ vars board=$(cat $SYS_BOARD_FILE) show_json=$1 @@ -144,7 +144,7 @@ function do_download() { fi fi - source /etc/init.d/conf # we need this for the os_ vars + source /etc/init.d/os_conf # we need this for the os_ vars board=$(cat $SYS_BOARD_FILE) url=$1 From 89bf6b9720e44a834a8cf075888b99026549af43 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 11 Jan 2019 13:47:09 +0200 Subject: [PATCH 11/23] S33hostapd: use prepare_conf --- board/common/overlay/etc/init.d/S33hostapd | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/board/common/overlay/etc/init.d/S33hostapd b/board/common/overlay/etc/init.d/S33hostapd index b8d6759589..7bee37fb4c 100755 --- a/board/common/overlay/etc/init.d/S33hostapd +++ b/board/common/overlay/etc/init.d/S33hostapd @@ -14,14 +14,7 @@ link_watch_timeout=20 test -f $watch_conf && source $watch_conf -if ! [[ -f $conf ]]; then - if [[ -f $boot_conf ]]; then - cp $boot_conf $conf - elif [[ -f $sys_conf ]]; then - cp $sys_conf $conf - fi -fi - +prepare_conf $conf $sys_conf $boot_conf test -f $conf || exit 0 test -n "$os_version" || source /etc/init.d/base From e17e87f569621d7f642f75ef83fbbd589ffd8064 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 11 Jan 2019 13:59:53 +0200 Subject: [PATCH 12/23] Adapt prepare_conf for directories --- board/common/overlay/etc/init.d/base | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/board/common/overlay/etc/init.d/base b/board/common/overlay/etc/init.d/base index b6917581f3..e21a61130c 100755 --- a/board/common/overlay/etc/init.d/base +++ b/board/common/overlay/etc/init.d/base @@ -38,22 +38,24 @@ prepare_conf() { system_conf="$2" user_conf="$3" - if [[ -n "$user_conf" && -f "$user_conf" ]]; then - cp -f "$user_conf" "$actual_conf" + if [[ -n "$user_conf" && -e "$user_conf" ]]; then + cp -rf "$user_conf" "$actual_conf" grep -E "/boot .*ro[\s,]" /proc/mounts RO=$? test $RO == 0 && mount -o remount,rw /boot - rm -f $user_conf + rm -rf $user_conf test $RO == 0 && mount -o remount,ro /boot fi - if [[ ! -f "$actual_conf" && -f "$system_conf" ]]; then + if [[ ! -e "$actual_conf" && -e "$system_conf" ]]; then cp "$system_conf" "$actual_conf" fi # we want only Unix newlines in conf files if [[ -f "$actual_conf" ]]; then sed -i 's/\r//g' "$actual_conf" + elif [[ -d "$actual_conf" ]]; then + find "$actual_conf" -type f | xargs -L1 sed -i 's/\r//g' fi } From 6dff0a0ad1ab265e21275f8c5ab92dd27bca7ea1 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 11 Jan 2019 14:00:11 +0200 Subject: [PATCH 13/23] S36ppp: use prepare_conf --- board/common/overlay/etc/init.d/S36ppp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/board/common/overlay/etc/init.d/S36ppp b/board/common/overlay/etc/init.d/S36ppp index c67f7253e6..4a88d4b68a 100755 --- a/board/common/overlay/etc/init.d/S36ppp +++ b/board/common/overlay/etc/init.d/S36ppp @@ -11,13 +11,7 @@ watch_conf="/data/etc/watch.conf" source $watch_conf -if ! [[ -d $conf ]]; then - if [[ -d $boot_conf ]]; then - cp -r $boot_conf $conf - elif [[ -d $sys_conf ]]; then - cp -r $sys_conf $conf - fi -fi +prepare_conf $conf $sys_conf $boot_conf test -e $conf/modem || exit 0 test -e $conf/apn || exit 0 From 2d7d5c68d06f879d92eaec6e33757ee64e360fd0 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 11 Jan 2019 14:00:44 +0200 Subject: [PATCH 14/23] S37bluetooth: use prepare_conf --- board/common/overlay/etc/init.d/S37bluetooth | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/board/common/overlay/etc/init.d/S37bluetooth b/board/common/overlay/etc/init.d/S37bluetooth index 76e570ab00..1714ce0704 100755 --- a/board/common/overlay/etc/init.d/S37bluetooth +++ b/board/common/overlay/etc/init.d/S37bluetooth @@ -4,14 +4,7 @@ sys_conf="/etc/bluetooth.conf" boot_conf="/boot/bluetooth.conf" conf="/data/etc/bluetooth.conf" -if ! [[ -f $conf ]]; then - if [[ -f $boot_conf ]]; then - cp $boot_conf $conf - elif [[ -f $sys_conf ]]; then - cp $sys_conf $conf - fi -fi - +prepare_conf $conf $sys_conf $boot_conf test -f $conf || exit 0 hci=hci0 From 6f65d633b9d272929f62ae7e447c3e0a6515e63b Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 11 Jan 2019 14:02:58 +0200 Subject: [PATCH 15/23] S40network: use prepare_conf --- board/common/overlay/etc/init.d/S40network | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/board/common/overlay/etc/init.d/S40network b/board/common/overlay/etc/init.d/S40network index 93b03c81af..e33275a903 100755 --- a/board/common/overlay/etc/init.d/S40network +++ b/board/common/overlay/etc/init.d/S40network @@ -11,14 +11,7 @@ link_nego_timeout=10 source $watch_conf -if ! [[ -f $static_conf ]]; then - if [[ -f $boot_static_conf ]]; then - cp $boot_static_conf $static_conf - elif [[ -f $sys_static_conf ]]; then - cp $sys_static_conf $static_conf - fi -fi - +prepare_conf $static_conf $sys_static_conf $boot_static_conf test -r $static_conf && source $static_conf test -n "$os_version" || source /etc/init.d/base From ef11ee161a64b108a77eceb039e67d619c422b7e Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 11 Jan 2019 14:04:20 +0200 Subject: [PATCH 16/23] S43firewall: use prepare_conf --- board/common/overlay/etc/init.d/S43firewall | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/board/common/overlay/etc/init.d/S43firewall b/board/common/overlay/etc/init.d/S43firewall index 3e049c18d8..6ff91fc33a 100755 --- a/board/common/overlay/etc/init.d/S43firewall +++ b/board/common/overlay/etc/init.d/S43firewall @@ -4,18 +4,11 @@ sys_conf="/etc/firewall.sh" boot_conf="/boot/firewall.sh" conf="/data/etc/firewall.sh" -if ! [[ -f $conf ]]; then - if [[ -f $boot_conf ]]; then - cp $boot_conf $conf - elif [[ -f $sys_conf ]]; then - cp $sys_conf $conf - fi -fi - -test -f $conf || exit 0 - test -n "$os_version" || source /etc/init.d/base +prepare_conf $conf $sys_conf $boot_conf +test -f $conf || exit 0 + start() { msg_begin "Starting firewall" From 6ac44f70cfab7b3a3a9588c9a8b21a94af385c74 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 11 Jan 2019 14:09:33 +0200 Subject: [PATCH 17/23] Init scripts: fix sourcing order --- board/common/overlay/etc/init.d/S02modules | 1 + board/common/overlay/etc/init.d/S03hostname | 1 + board/common/overlay/etc/init.d/S33hostapd | 6 ++++-- board/common/overlay/etc/init.d/S35wifi | 5 ++++- board/common/overlay/etc/init.d/S36ppp | 6 ++++-- board/common/overlay/etc/init.d/S37bluetooth | 3 ++- board/common/overlay/etc/init.d/S45dnsmasq | 13 ++++-------- board/common/overlay/etc/init.d/S50date | 22 +++++--------------- 8 files changed, 25 insertions(+), 32 deletions(-) diff --git a/board/common/overlay/etc/init.d/S02modules b/board/common/overlay/etc/init.d/S02modules index 2a65d476c5..26b91921df 100755 --- a/board/common/overlay/etc/init.d/S02modules +++ b/board/common/overlay/etc/init.d/S02modules @@ -4,6 +4,7 @@ sys_modules_file="/etc/modules" boot_modules_file="/boot/modules" modules_file="/data/etc/modules" + test -n "$os_version" || source /etc/init.d/base case "$1" in diff --git a/board/common/overlay/etc/init.d/S03hostname b/board/common/overlay/etc/init.d/S03hostname index a730cc65c0..9feb017d92 100755 --- a/board/common/overlay/etc/init.d/S03hostname +++ b/board/common/overlay/etc/init.d/S03hostname @@ -4,6 +4,7 @@ sys_hostname_file="/etc/hostname" boot_hostname_file="/boot/hostname" hostname_file="/data/etc/hostname" + test -n "$os_version" || source /etc/init.d/base case "$1" in diff --git a/board/common/overlay/etc/init.d/S33hostapd b/board/common/overlay/etc/init.d/S33hostapd index 7bee37fb4c..6d1ace6df5 100755 --- a/board/common/overlay/etc/init.d/S33hostapd +++ b/board/common/overlay/etc/init.d/S33hostapd @@ -12,12 +12,14 @@ watch_conf="/data/etc/watch.conf" link_watch=yes link_watch_timeout=20 -test -f $watch_conf && source $watch_conf + +test -n "$os_version" || source /etc/init.d/base prepare_conf $conf $sys_conf $boot_conf test -f $conf || exit 0 -test -n "$os_version" || source /etc/init.d/base +test -f $watch_conf && source $watch_conf + running() { killall -0 hostapd &> /dev/null diff --git a/board/common/overlay/etc/init.d/S35wifi b/board/common/overlay/etc/init.d/S35wifi index 018ee5852e..9b17d30ba7 100755 --- a/board/common/overlay/etc/init.d/S35wifi +++ b/board/common/overlay/etc/init.d/S35wifi @@ -12,6 +12,9 @@ sys_watch_conf="/etc/watch.conf" boot_watch_conf="/boot/watch.conf" watch_conf="/data/etc/watch.conf" + +test -n "$os_version" || source /etc/init.d/base + prepare_conf $watch_conf $sys_watch_conf $boot_watch_conf source $watch_conf @@ -21,10 +24,10 @@ test -f $conf || exit 0 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 "$os_networkless" == "true" && exit 0 + connected() { ip link show dev $os_wlan 2>&1 | grep LOWER_UP &> /dev/null && return 0 || return 1 } diff --git a/board/common/overlay/etc/init.d/S36ppp b/board/common/overlay/etc/init.d/S36ppp index 4a88d4b68a..53972281c6 100755 --- a/board/common/overlay/etc/init.d/S36ppp +++ b/board/common/overlay/etc/init.d/S36ppp @@ -9,17 +9,19 @@ provider="mobile" watch_conf="/data/etc/watch.conf" -source $watch_conf + +test -n "$os_version" || source /etc/init.d/base prepare_conf $conf $sys_conf $boot_conf test -e $conf/modem || exit 0 test -e $conf/apn || exit 0 -test -n "$os_version" || source /etc/init.d/base +source $watch_conf test "$os_networkless" == "true" && exit 0 + connected() { ifconfig | grep $os_ppp &>/dev/null && return 0 || return 1 } diff --git a/board/common/overlay/etc/init.d/S37bluetooth b/board/common/overlay/etc/init.d/S37bluetooth index 1714ce0704..3acdd69d1f 100755 --- a/board/common/overlay/etc/init.d/S37bluetooth +++ b/board/common/overlay/etc/init.d/S37bluetooth @@ -4,6 +4,8 @@ sys_conf="/etc/bluetooth.conf" boot_conf="/boot/bluetooth.conf" conf="/data/etc/bluetooth.conf" +test -n "$os_version" || source /etc/init.d/base + prepare_conf $conf $sys_conf $boot_conf test -f $conf || exit 0 @@ -15,7 +17,6 @@ run_conf=/var/lib/bluetooth.conf test -x $bluetoothd || exit 0 -test -n "$os_version" || source /etc/init.d/base configure() { mkdir -p $run_data_dir diff --git a/board/common/overlay/etc/init.d/S45dnsmasq b/board/common/overlay/etc/init.d/S45dnsmasq index e6c7c3ffed..3eea12d66f 100755 --- a/board/common/overlay/etc/init.d/S45dnsmasq +++ b/board/common/overlay/etc/init.d/S45dnsmasq @@ -7,18 +7,13 @@ conf="/data/etc/dnsmasq.conf" log="/var/log/dnsmasq.log" prog="/usr/sbin/dnsmasq" -if ! [[ -f $conf ]]; then - if [[ -f $boot_conf ]]; then - cp $boot_conf $conf - elif [[ -f $sys_conf ]]; then - cp $sys_conf $conf - fi -fi - -test -f $conf || exit 0 test -n "$os_version" || source /etc/init.d/base +prepare_conf $conf $sys_conf $boot_conf +test -f $conf || exit 0 + + start() { msg_begin "Starting dnsmasq" diff --git a/board/common/overlay/etc/init.d/S50date b/board/common/overlay/etc/init.d/S50date index 0390037222..ad6324e4f6 100755 --- a/board/common/overlay/etc/init.d/S50date +++ b/board/common/overlay/etc/init.d/S50date @@ -11,26 +11,14 @@ 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 - cp $boot_conf $conf - elif [[ -f $sys_conf ]]; then - cp $sys_conf $conf - fi -fi - -if ! [[ -f $ntp_conf ]]; then - if [[ -f $boot_ntp_conf ]]; then - cp $boot_ntp_conf $ntp_conf - elif [[ -f $sys_ntp_conf ]]; then - cp $sys_ntp_conf $ntp_conf - fi -fi - -test -f $conf || exit 0 test -n "$os_version" || source /etc/init.d/base +prepare_conf $conf $sys_conf $boot_conf +prepare_conf $ntp_conf $sys_ntp_conf $boot_ntp_conf + +test -f $conf || exit 0 + test "$os_networkless" == "true" && exit 0 date_timeout=10 From 1edf7f0c62156c4cb40c92a84cac9e4c910af51d Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 11 Jan 2019 23:32:34 +0200 Subject: [PATCH 18/23] S40network: fix sourcing order --- board/common/overlay/etc/init.d/S40network | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/board/common/overlay/etc/init.d/S40network b/board/common/overlay/etc/init.d/S40network index e33275a903..7bd0ea7d0a 100755 --- a/board/common/overlay/etc/init.d/S40network +++ b/board/common/overlay/etc/init.d/S40network @@ -9,12 +9,14 @@ watch_conf="/data/etc/watch.conf" link_nego_timeout=10 + +test -n "$os_version" || source /etc/init.d/base + source $watch_conf prepare_conf $static_conf $sys_static_conf $boot_static_conf test -r $static_conf && source $static_conf -test -n "$os_version" || source /etc/init.d/base watch_eth() { count=0 From 000eff13a312a3b4ca0afd79d8e72aacb7c981f4 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 11 Jan 2019 23:36:23 +0200 Subject: [PATCH 19/23] Remove unnecessary execute flag from some init.d files --- board/common/overlay/etc/init.d/base | 3 +-- board/common/overlay/etc/init.d/os_conf | 1 - board/common/overlay/etc/init.d/panic | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) mode change 100755 => 100644 board/common/overlay/etc/init.d/base mode change 100755 => 100644 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 old mode 100755 new mode 100644 index e21a61130c..852ca513a4 --- a/board/common/overlay/etc/init.d/base +++ b/board/common/overlay/etc/init.d/base @@ -1,4 +1,3 @@ -#!/bin/bash source /etc/version board_sn=$(/etc/init.d/boardsn) @@ -40,7 +39,7 @@ prepare_conf() { if [[ -n "$user_conf" && -e "$user_conf" ]]; then cp -rf "$user_conf" "$actual_conf" - grep -E "/boot .*ro[\s,]" /proc/mounts + grep -E "/boot .*ro[\s,]" /proc/mounts &>/dev/null RO=$? test $RO == 0 && mount -o remount,rw /boot rm -rf $user_conf diff --git a/board/common/overlay/etc/init.d/os_conf b/board/common/overlay/etc/init.d/os_conf index c8fd635052..21713596b1 100644 --- a/board/common/overlay/etc/init.d/os_conf +++ b/board/common/overlay/etc/init.d/os_conf @@ -1,4 +1,3 @@ -#!/bin/bash _sys_conf="/etc/os.conf" _boot_conf="/boot/os.conf" diff --git a/board/common/overlay/etc/init.d/panic b/board/common/overlay/etc/init.d/panic old mode 100755 new mode 100644 index fcf6724e54..7a1785188c --- a/board/common/overlay/etc/init.d/panic +++ b/board/common/overlay/etc/init.d/panic @@ -1,4 +1,3 @@ -#!/bin/bash _PANIC_COUNTER_FILE="/var/lib/panic_counter" _PANIC_REBOOT_DELAY_FACTOR=10 From 58a6be0e49b1f60b4bbd18683c525354b881f8b9 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 11 Jan 2019 23:40:05 +0200 Subject: [PATCH 20/23] Init: make some panic vars public --- board/common/overlay/etc/init.d/bootdone | 2 +- board/common/overlay/etc/init.d/panic | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/board/common/overlay/etc/init.d/bootdone b/board/common/overlay/etc/init.d/bootdone index 14ca681cfc..38e16f566b 100755 --- a/board/common/overlay/etc/init.d/bootdone +++ b/board/common/overlay/etc/init.d/bootdone @@ -3,5 +3,5 @@ source /etc/init.d/panic # reset panic counter after a successful boot -echo 0 > ${_PANIC_COUNTER_FILE} +echo 0 > ${PANIC_COUNTER_FILE} diff --git a/board/common/overlay/etc/init.d/panic b/board/common/overlay/etc/init.d/panic index 7a1785188c..4c6c992c20 100644 --- a/board/common/overlay/etc/init.d/panic +++ b/board/common/overlay/etc/init.d/panic @@ -1,19 +1,19 @@ -_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_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) + panic_counter=$(cat ${PANIC_COUNTER_FILE} 2>/dev/null || echo 0) # write increased counter back to file - echo $((panic_counter + 1)) > ${_PANIC_COUNTER_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} + 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 From 39e10d0eff71c7543d95022c7079f36eabac7695 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sat, 12 Jan 2019 00:02:05 +0200 Subject: [PATCH 21/23] Init scripts: use uppercase for constants --- board/common/overlay/etc/init.d/S02modules | 18 ++++---- board/common/overlay/etc/init.d/S03hostname | 12 ++--- board/common/overlay/etc/init.d/S04syslog | 7 +-- board/common/overlay/etc/init.d/S12udev | 7 ++- .../common/overlay/etc/init.d/S14postupgrade | 25 ++++++----- board/common/overlay/etc/init.d/S30dbus | 9 ++-- board/common/overlay/etc/init.d/S33hostapd | 22 ++++----- board/common/overlay/etc/init.d/S35wifi | 30 ++++++------- board/common/overlay/etc/init.d/S36ppp | 30 ++++++------- board/common/overlay/etc/init.d/S37bluetooth | 13 +++--- board/common/overlay/etc/init.d/S40network | 29 ++++++------ board/common/overlay/etc/init.d/S41netwatch | 22 ++++----- board/common/overlay/etc/init.d/S43firewall | 13 +++--- board/common/overlay/etc/init.d/S45dnsmasq | 20 ++++----- board/common/overlay/etc/init.d/S50date | 45 ++++++++++--------- board/common/overlay/etc/init.d/S51crond | 12 ++--- board/common/overlay/etc/init.d/S60sshd | 6 +-- board/common/overlay/etc/init.d/S98userinit | 7 +-- board/common/overlay/etc/init.d/os_conf | 21 ++++----- 19 files changed, 181 insertions(+), 167 deletions(-) diff --git a/board/common/overlay/etc/init.d/S02modules b/board/common/overlay/etc/init.d/S02modules index 26b91921df..b667086346 100755 --- a/board/common/overlay/etc/init.d/S02modules +++ b/board/common/overlay/etc/init.d/S02modules @@ -1,8 +1,8 @@ #!/bin/bash -sys_modules_file="/etc/modules" -boot_modules_file="/boot/modules" -modules_file="/data/etc/modules" +SYS_MODULES_FILE="/etc/modules" +BOOT_MODULES_FILE="/boot/modules" +MODULES_FILE="/data/etc/modules" test -n "$os_version" || source /etc/init.d/base @@ -11,16 +11,16 @@ case "$1" in start) msg_begin "Loading kernel modules" - if [[ -r $sys_modules_file ]]; then - cat $sys_modules_file | while read line; do test -n "$line" && /sbin/modprobe $line &>/dev/null; done + 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 $boot_modules_file ]]; then - cat $boot_modules_file | while read line; do test -n "$line" && /sbin/modprobe $line &>/dev/null; done + if [[ -r $BOOT_MODULES_FILE ]]; then + cat $BOOT_MODULES_FILE | while read line; do test -n "$line" && /sbin/modprobe $line &>/dev/null; done fi - if [[ -r $modules_file ]]; then - cat $modules_file | while read line; do test -n "$line" && /sbin/modprobe $line &>/dev/null; done + if [[ -r $MODULES_FILE ]]; then + cat $MODULES_FILE | while read line; do test -n "$line" && /sbin/modprobe $line &>/dev/null; done fi msg_done diff --git a/board/common/overlay/etc/init.d/S03hostname b/board/common/overlay/etc/init.d/S03hostname index 9feb017d92..f081363b86 100755 --- a/board/common/overlay/etc/init.d/S03hostname +++ b/board/common/overlay/etc/init.d/S03hostname @@ -1,8 +1,8 @@ #!/bin/bash -sys_hostname_file="/etc/hostname" -boot_hostname_file="/boot/hostname" -hostname_file="/data/etc/hostname" +SYS_HOSTNAME_FILE="/etc/hostname" +BOOT_HOSTNAME_FILE="/boot/hostname" +HOSTNAME_FILE="/data/etc/hostname" test -n "$os_version" || source /etc/init.d/base @@ -11,10 +11,10 @@ case "$1" in start) msg_begin "Setting hostname" - prepare_conf $hostname_file $sys_hostname_file $boot_hostname_file + prepare_conf $HOSTNAME_FILE $SYS_HOSTNAME_FILE $BOOT_HOSTNAME_FILE - if [[ -f $hostname_file ]]; then - hostname=$(cat $hostname_file) + if [[ -f $HOSTNAME_FILE ]]; then + hostname=$(cat $HOSTNAME_FILE) else hostname="$os_prefix-$board_sn" fi diff --git a/board/common/overlay/etc/init.d/S04syslog b/board/common/overlay/etc/init.d/S04syslog index b7a1eb3ac4..da74427391 100755 --- a/board/common/overlay/etc/init.d/S04syslog +++ b/board/common/overlay/etc/init.d/S04syslog @@ -2,15 +2,16 @@ test -n "$os_version" || source /etc/init.d/base -dmesg_log="/var/log/dmesg.log" +DMESG_LOG="/var/log/dmesg.log" + case "$1" in start) msg_begin "Starting syslogd" syslogd test $? == 0 && msg_done || msg_fail - echo "---- booting $os_name $os_version ----" >> $dmesg_log - dmesg -T -w >> $dmesg_log & + echo "---- booting $os_name $os_version ----" >> $DMESG_LOG + dmesg -T -w >> $DMESG_LOG & ;; stop) diff --git a/board/common/overlay/etc/init.d/S12udev b/board/common/overlay/etc/init.d/S12udev index ce1c2af7f8..2c2f20c4b1 100755 --- a/board/common/overlay/etc/init.d/S12udev +++ b/board/common/overlay/etc/init.d/S12udev @@ -1,10 +1,13 @@ #!/bin/bash -test -f /etc/udev/udev.conf || exit 0 +CONF=/etc/udev/udev.conf + + +test -f $CONF || exit 0 test -n "$os_version" || source /etc/init.d/base -source /etc/udev/udev.conf +source $CONF start() { msg_begin "Starting eudev" diff --git a/board/common/overlay/etc/init.d/S14postupgrade b/board/common/overlay/etc/init.d/S14postupgrade index bb41a4e105..225c0f6c6e 100755 --- a/board/common/overlay/etc/init.d/S14postupgrade +++ b/board/common/overlay/etc/init.d/S14postupgrade @@ -1,17 +1,18 @@ #!/bin/bash +SYS_VERSION_FILE="/etc/version" +VERSION_FILE="/data/etc/version" +POST_UPGRADE_DIR="/usr/share/post-upgrade" + + test -n "$os_version" || source /etc/init.d/base -sys_version_file="/etc/version" -version_file="/data/etc/version" -post_upgrade_dir="/usr/share/post-upgrade" - -hash=$(md5sum $version_file 2>/dev/null | cut -d ' ' -f 1) -sys_hash=$(md5sum $sys_version_file 2>/dev/null | cut -d ' ' -f 1) +hash=$(md5sum $VERSION_FILE 2>/dev/null | cut -d ' ' -f 1) +sys_hash=$(md5sum $SYS_VERSION_FILE 2>/dev/null | cut -d ' ' -f 1) test "$hash" == "$sys_hash" && exit 0 -test -d $post_upgrade_dir || 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 @@ -22,14 +23,14 @@ function version_gt() { } function run_post_upgrade() { - version="$(source $version_file 2>/dev/null && echo $os_version)" - sys_version="$(source $sys_version_file 2>/dev/null && echo $os_version)" + version="$(source $VERSION_FILE 2>/dev/null && echo $os_version)" + sys_version="$(source $SYS_VERSION_FILE 2>/dev/null && echo $os_version)" - versions=$(ls -1 $post_upgrade_dir | cut -d '.' -f 1) + versions=$(ls -1 $POST_UPGRADE_DIR | cut -d '.' -f 1) for v in $versions; do if [[ -z "$version" ]] || version_gt $v $version; then msg_begin "Post-upgrading to version $v" - out=$($post_upgrade_dir/$v.sh 2>&1) + out=$($POST_UPGRADE_DIR/$v.sh 2>&1) test $? == 0 && msg_done || msg_fail echo "$out" | logger -t post-upgrade fi @@ -39,7 +40,7 @@ function run_post_upgrade() { case "$1" in start) run_post_upgrade - cp $sys_version_file $version_file + cp $SYS_VERSION_FILE $VERSION_FILE ;; stop) diff --git a/board/common/overlay/etc/init.d/S30dbus b/board/common/overlay/etc/init.d/S30dbus index 946aa5271d..92fad2e731 100755 --- a/board/common/overlay/etc/init.d/S30dbus +++ b/board/common/overlay/etc/init.d/S30dbus @@ -1,11 +1,12 @@ #!/bin/bash -sys_btconf="/etc/bluetooth.conf" -boot_btconf="/boot/bluetooth.conf" -btconf="/data/etc/bluetooth.conf" +SYS_BTCONF="/etc/bluetooth.conf" +BOOT_BTCONF="/boot/bluetooth.conf" +BTCONF="/data/etc/bluetooth.conf" + # dbus is currently only used by bluez -test -f $btconf || test -f $boot_btconf || test -f $sys_btconf || exit 0 +test -f $BTCONF || test -f $BOOT_BTCONF || test -f $SYS_BTCONF || exit 0 test -x /usr/bin/dbus-daemon || exit 0 diff --git a/board/common/overlay/etc/init.d/S33hostapd b/board/common/overlay/etc/init.d/S33hostapd index 6d1ace6df5..d55dc040ae 100755 --- a/board/common/overlay/etc/init.d/S33hostapd +++ b/board/common/overlay/etc/init.d/S33hostapd @@ -1,13 +1,13 @@ #!/bin/bash -sys_conf="/etc/hostapd.conf" -boot_conf="/boot/hostapd.conf" -conf="/data/etc/hostapd.conf" +SYS_CONF="/etc/hostapd.conf" +BOOT_CONF="/boot/hostapd.conf" +CONF="/data/etc/hostapd.conf" -log="/var/log/hostapd.log" -prog="/usr/sbin/hostapd" +LOG="/var/log/hostapd.log" +PROG="/usr/sbin/hostapd" -watch_conf="/data/etc/watch.conf" +WATCH_CONF="/data/etc/watch.conf" link_watch=yes link_watch_timeout=20 @@ -15,10 +15,10 @@ link_watch_timeout=20 test -n "$os_version" || source /etc/init.d/base -prepare_conf $conf $sys_conf $boot_conf -test -f $conf || exit 0 +prepare_conf $CONF $SYS_CONF $BOOT_CONF +test -f $CONF || exit 0 -test -f $watch_conf && source $watch_conf +test -f $WATCH_CONF && source $WATCH_CONF running() { @@ -50,11 +50,11 @@ start() { fi done - iface=$(cat $conf | grep interface | cut -d '=' -f 2) + iface=$(cat $CONF | grep interface | cut -d '=' -f 2) module=$(basename $(readlink /sys/class/net/$iface/device/driver/module 2>/dev/null) 2>/dev/null) iwconfig $iface power off &> /dev/null - $prog $conf &> $log & + $PROG $CONF &> $LOG & if [[ "$link_watch" == "yes" ]]; then watch & diff --git a/board/common/overlay/etc/init.d/S35wifi b/board/common/overlay/etc/init.d/S35wifi index 9b17d30ba7..c89466b6ac 100755 --- a/board/common/overlay/etc/init.d/S35wifi +++ b/board/common/overlay/etc/init.d/S35wifi @@ -1,27 +1,27 @@ #!/bin/bash -sys_conf="/etc/wpa_supplicant.conf" -boot_conf="/boot/wpa_supplicant.conf" -conf="/data/etc/wpa_supplicant.conf" +SYS_CONF="/etc/wpa_supplicant.conf" +BOOT_CONF="/boot/wpa_supplicant.conf" +CONF="/data/etc/wpa_supplicant.conf" -log="/var/log/wpa_supplicant.log" -prog="/usr/sbin/wpa_supplicant" -driver=nl80211,wext +LOG="/var/log/wpa_supplicant.log" +PROG="/usr/sbin/wpa_supplicant" +DRIVER=nl80211,wext -sys_watch_conf="/etc/watch.conf" -boot_watch_conf="/boot/watch.conf" -watch_conf="/data/etc/watch.conf" +SYS_WATCH_CONF="/etc/watch.conf" +BOOT_WATCH_CONF="/boot/watch.conf" +WATCH_CONF="/data/etc/watch.conf" test -n "$os_version" || source /etc/init.d/base -prepare_conf $watch_conf $sys_watch_conf $boot_watch_conf -source $watch_conf +prepare_conf $WATCH_CONF $SYS_WATCH_CONF $BOOT_WATCH_CONF +source $WATCH_CONF -prepare_conf $conf $sys_conf $boot_conf -test -f $conf || exit 0 +prepare_conf $CONF $SYS_CONF $BOOT_CONF +test -f $CONF || exit 0 -ssid=$(cat $conf | grep ssid | grep -v scan_ssid | cut -d '"' -f 2) +ssid=$(cat $CONF | grep ssid | grep -v scan_ssid | cut -d '"' -f 2) test -n "$ssid" || exit 0 @@ -70,7 +70,7 @@ start() { iwconfig $os_wlan power off &> /dev/null iw $os_wlan set power_save off &> /dev/null - $prog -i$os_wlan -c$conf -D$driver -B &> $log + $PROG -i$os_wlan -c$CONF -D$DRIVER -B &> $LOG count=0 while true; do sleep 1 diff --git a/board/common/overlay/etc/init.d/S36ppp b/board/common/overlay/etc/init.d/S36ppp index 53972281c6..03e21ee5ba 100755 --- a/board/common/overlay/etc/init.d/S36ppp +++ b/board/common/overlay/etc/init.d/S36ppp @@ -1,23 +1,23 @@ #!/bin/bash -sys_conf="/etc/ppp/default" -boot_conf="/boot/ppp" -conf="/data/etc/ppp" +SYS_CONF="/etc/ppp/default" +BOOT_CONF="/boot/ppp" +CONF="/data/etc/ppp" -prog="/usr/sbin/pppd" -provider="mobile" +PROG="/usr/sbin/pppd" +PROVIDER="mobile" -watch_conf="/data/etc/watch.conf" +WATCH_CONF="/data/etc/watch.conf" test -n "$os_version" || source /etc/init.d/base -prepare_conf $conf $sys_conf $boot_conf +prepare_conf $CONF $SYS_CONF $BOOT_CONF -test -e $conf/modem || exit 0 -test -e $conf/apn || exit 0 +test -e $CONF/modem || exit 0 +test -e $CONF/apn || exit 0 -source $watch_conf +source $WATCH_CONF test "$os_networkless" == "true" && exit 0 @@ -51,15 +51,15 @@ udev_trigger_add() { } start() { - test -e $conf/auth || touch $conf/auth - test -e $conf/extra || touch $conf/extra - test -e $conf/pin || touch $conf/pin + test -e $CONF/auth || touch $CONF/auth + test -e $CONF/extra || touch $CONF/extra + test -e $CONF/pin || touch $CONF/pin mknod /dev/ppp c 108 0 &>/dev/null msg_begin "Starting pppd" # wait for modem - modem=$(head -n 1 $conf/modem) + modem=$(head -n 1 $CONF/modem) if ! [[ -e /dev/$modem ]]; then udev_trigger_add 4 & fi @@ -79,7 +79,7 @@ start() { return fi - $prog call $provider + $PROG call $PROVIDER count=0 while true; do sleep 1 diff --git a/board/common/overlay/etc/init.d/S37bluetooth b/board/common/overlay/etc/init.d/S37bluetooth index 3acdd69d1f..13b61893be 100755 --- a/board/common/overlay/etc/init.d/S37bluetooth +++ b/board/common/overlay/etc/init.d/S37bluetooth @@ -1,13 +1,14 @@ #!/bin/bash -sys_conf="/etc/bluetooth.conf" -boot_conf="/boot/bluetooth.conf" -conf="/data/etc/bluetooth.conf" +SYS_CONF="/etc/bluetooth.conf" +BOOT_CONF="/boot/bluetooth.conf" +CONF="/data/etc/bluetooth.conf" + test -n "$os_version" || source /etc/init.d/base -prepare_conf $conf $sys_conf $boot_conf -test -f $conf || exit 0 +prepare_conf $CONF $SYS_CONF $BOOT_CONF +test -f $CONF || exit 0 hci=hci0 bluetoothd=/usr/libexec/bluetooth/bluetoothd @@ -21,7 +22,7 @@ test -x $bluetoothd || exit 0 configure() { mkdir -p $run_data_dir ln -sf $run_data_dir $data_dir - cp $conf $run_conf + cp $CONF $run_conf # if no specific name configured, use hostname if ! grep -E 'Name\s*=' $run_conf &>/dev/null; then diff --git a/board/common/overlay/etc/init.d/S40network b/board/common/overlay/etc/init.d/S40network index 7bd0ea7d0a..df8d2b932d 100755 --- a/board/common/overlay/etc/init.d/S40network +++ b/board/common/overlay/etc/init.d/S40network @@ -1,21 +1,22 @@ #!/bin/bash -mkdir -p /var/lib/dhcp -dh_conf="/var/cache/dhclient.conf" -sys_static_conf="/etc/static_ip.conf" -boot_static_conf="/boot/static_ip.conf" -static_conf="/data/etc/static_ip.conf" -watch_conf="/data/etc/watch.conf" +DH_CONF="/var/cache/dhclient.conf" +SYS_STATIC_CONF="/etc/static_ip.conf" +BOOT_STATIC_CONF="/boot/static_ip.conf" +STATIC_CONF="/data/etc/static_ip.conf" +WATCH_CONF="/data/etc/watch.conf" -link_nego_timeout=10 +LINK_NEGO_TIMEOUT=10 test -n "$os_version" || source /etc/init.d/base -source $watch_conf +source $WATCH_CONF -prepare_conf $static_conf $sys_static_conf $boot_static_conf -test -r $static_conf && source $static_conf +prepare_conf $STATIC_CONF $SYS_STATIC_CONF $BOOT_STATIC_CONF +test -r $STATIC_CONF && source $STATIC_CONF + +mkdir -p /var/lib/dhcp watch_eth() { @@ -81,7 +82,7 @@ start_wlan() { static_ip="" # won't be used again else msg_done dhcp - dhclient -cf "$dh_conf" $os_wlan + dhclient -cf "$DH_CONF" $os_wlan fi if [[ "$ip_watch" == "true" ]] && ip addr show dev $os_wlan | grep inet &>/dev/null; then @@ -120,12 +121,12 @@ start_eth() { done # wait for link - test "$link_watch" == "true" || link_nego_timeout=5 + test "$link_watch" == "true" || LINK_NEGO_TIMEOUT=5 count=0 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 @@ -141,7 +142,7 @@ start_eth() { static_ip="" # won't be used again else msg_done dhcp - dhclient -cf "$dh_conf" $os_eth + dhclient -cf "$DH_CONF" $os_eth fi if [[ "$link_watch" == "true" ]]; then diff --git a/board/common/overlay/etc/init.d/S41netwatch b/board/common/overlay/etc/init.d/S41netwatch index a7bd496f32..f7cbbeb4b0 100755 --- a/board/common/overlay/etc/init.d/S41netwatch +++ b/board/common/overlay/etc/init.d/S41netwatch @@ -1,13 +1,14 @@ #!/bin/bash -watch_conf="/data/etc/watch.conf" -netwatch_retries=3 -netwatch_timeout=5 -netwatch_interval=20 +WATCH_CONF="/data/etc/watch.conf" +NETWATCH_RETRIES=3 +NETWATCH_TIMEOUT=5 +NETWATCH_INTERVAL=20 -test -f $watch_conf && source $watch_conf || exit 0 -if [[ -z "$netwatch_host" ]] || [[ -z "$netwatch_port" ]]; then +test -f $WATCH_CONF && source $WATCH_CONF || exit 0 + +if [[ -z "$netwatch_host" || -z "$netwatch_port" ]]; then exit 0 fi @@ -15,15 +16,16 @@ test -n "$os_version" || source /etc/init.d/base test "$os_networkless" == "true" && exit 0 + watch() { count=0 - netwatch_retries=$(($netwatch_retries - 1)) + NETWATCH_RETRIES=$(($NETWATCH_RETRIES - 1)) while true; do - sleep $netwatch_interval - if nc -z -w $netwatch_timeout $netwatch_host $netwatch_port /dev/null 2>&1; then + sleep $NETWATCH_INTERVAL + 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 6ff91fc33a..0557ce5813 100755 --- a/board/common/overlay/etc/init.d/S43firewall +++ b/board/common/overlay/etc/init.d/S43firewall @@ -1,18 +1,19 @@ #!/bin/bash -sys_conf="/etc/firewall.sh" -boot_conf="/boot/firewall.sh" -conf="/data/etc/firewall.sh" +SYS_CONF="/etc/firewall.sh" +BOOT_CONF="/boot/firewall.sh" +CONF="/data/etc/firewall.sh" + test -n "$os_version" || source /etc/init.d/base -prepare_conf $conf $sys_conf $boot_conf -test -f $conf || exit 0 +prepare_conf $CONF $SYS_CONF $BOOT_CONF +test -f $CONF || exit 0 start() { msg_begin "Starting firewall" - bash $conf + bash $CONF test $? == 0 && msg_done || msg_fail } diff --git a/board/common/overlay/etc/init.d/S45dnsmasq b/board/common/overlay/etc/init.d/S45dnsmasq index 3eea12d66f..9d1f0326d5 100755 --- a/board/common/overlay/etc/init.d/S45dnsmasq +++ b/board/common/overlay/etc/init.d/S45dnsmasq @@ -1,28 +1,28 @@ #!/bin/bash -sys_conf="/etc/dnsmasq.conf" -boot_conf="/boot/dnsmasq.conf" -conf="/data/etc/dnsmasq.conf" +SYS_CONF="/etc/dnsmasq.conf" +BOOT_CONF="/boot/dnsmasq.conf" +CONF="/data/etc/dnsmasq.conf" -log="/var/log/dnsmasq.log" -prog="/usr/sbin/dnsmasq" +LOG="/var/log/dnsmasq.log" +PROG="/usr/sbin/dnsmasq" test -n "$os_version" || source /etc/init.d/base -prepare_conf $conf $sys_conf $boot_conf -test -f $conf || exit 0 +prepare_conf $CONF $SYS_CONF $BOOT_CONF +test -f $CONF || exit 0 start() { msg_begin "Starting dnsmasq" - iface=$(cat $conf | grep interface | cut -d '=' -f 2) - ip=$(cat $conf | grep range | cut -d '=' -f 2 | cut -d '.' -f 1,2,3).1 + iface=$(cat $CONF | grep interface | cut -d '=' -f 2) + ip=$(cat $CONF | grep range | cut -d '=' -f 2 | cut -d '.' -f 1,2,3).1 ifconfig $iface $ip - $prog -C $conf --log-facility=$log + $PROG -C $CONF --log-facility=$LOG test $? == 0 && msg_done || msg_fail } diff --git a/board/common/overlay/etc/init.d/S50date b/board/common/overlay/etc/init.d/S50date index ad6324e4f6..5393314d1b 100755 --- a/board/common/overlay/etc/init.d/S50date +++ b/board/common/overlay/etc/init.d/S50date @@ -1,23 +1,23 @@ #!/bin/bash # Date executable points to /bin/busybox\ date explicitly in the cases that date binary gets overwritten -date_exec=/bin/busybox\ date +DATE_PROG=/bin/busybox\ date -sys_conf="/etc/date.conf" -boot_conf="/boot/date.conf" -conf="/data/etc/date.conf" +SYS_CONF="/etc/date.conf" +BOOT_CONF="/boot/date.conf" +CONF="/data/etc/date.conf" -sys_ntp_conf="/etc/ntp.conf" -boot_ntp_conf="/boot/ntp.conf" -ntp_conf="/data/etc/ntp.conf" +SYS_NTP_CONF="/etc/ntp.conf" +BOOT_NTP_CONF="/boot/ntp.conf" +NTP_CONF="/data/etc/ntp.conf" test -n "$os_version" || source /etc/init.d/base -prepare_conf $conf $sys_conf $boot_conf -prepare_conf $ntp_conf $sys_ntp_conf $boot_ntp_conf +prepare_conf $CONF $SYS_CONF $BOOT_CONF +prepare_conf $NTP_CONF $SYS_NTP_CONF $BOOT_NTP_CONF -test -f $conf || exit 0 +test -f $CONF || exit 0 test "$os_networkless" == "true" && exit 0 @@ -26,23 +26,24 @@ date_method=http date_host="google.com" date_interval="900" -source $conf +source $CONF + set_current_date_http() { date_str=$(curl -v -s -m $date_timeout -X GET http://$date_host 2>&1 | grep Date | sed -e 's/< Date: //') test -z "$date_str" && return 1 - $date_exec -u -D "%a, %d %b %Y %H:%M:%S" -s "$date_str" > /dev/null + $DATE_PROG -u -D "%a, %d %b %Y %H:%M:%S" -s "$date_str" > /dev/null return $? } set_current_date_ntp() { - cat $ntp_conf | grep server | head -n 1 | cut -d ' ' -f 2 | xargs ntpdate -t $date_timeout -s + cat $NTP_CONF | grep server | head -n 1 | cut -d ' ' -f 2 | xargs ntpdate -t $date_timeout -s } start_http() { msg_begin "Setting current date using http" set_current_date_http || set_current_date_http - test $? == 0 && msg_done "$($date_exec)" || msg_fail + test $? == 0 && msg_done "$($DATE_PROG)" || msg_fail msg_begin "Starting http date updater" while true; do @@ -55,23 +56,23 @@ start_http() { start_ntp() { mkdir -p /var/lib/ntp - cat $ntp_conf | grep -v iburst > ${ntp_conf}.tmp + cat $NTP_CONF | grep -v iburst > ${NTP_CONF}.tmp if [[ -n "$date_ntp_server" ]]; then - echo "server $date_ntp_server iburst" > $ntp_conf + echo "server $date_ntp_server iburst" > $NTP_CONF else - cat $sys_ntp_conf | grep iburst > $ntp_conf + cat $SYS_NTP_CONF | grep iburst > $NTP_CONF fi - cat ${ntp_conf}.tmp >> $ntp_conf - rm ${ntp_conf}.tmp + cat ${NTP_CONF}.tmp >> $NTP_CONF + rm ${NTP_CONF}.tmp msg_begin "Setting current date using ntp" set_current_date_ntp || set_current_date_ntp - test $? == 0 && msg_done "$($date_exec)" || msg_fail + test $? == 0 && msg_done "$($DATE_PROG)" || msg_fail msg_begin "Starting ntpd" - ntpd -g -c $ntp_conf + ntpd -g -c $NTP_CONF test $? == 0 && msg_done || msg_fail } @@ -94,7 +95,7 @@ start() { start_ntp fi - echo "system date is $($date_exec '+%Y-%m-%d %H:%M:%S')" > /dev/kmsg + echo "system date is $($DATE_PROG '+%Y-%m-%d %H:%M:%S')" > /dev/kmsg } stop() { diff --git a/board/common/overlay/etc/init.d/S51crond b/board/common/overlay/etc/init.d/S51crond index 618b482e12..5e464afc3f 100755 --- a/board/common/overlay/etc/init.d/S51crond +++ b/board/common/overlay/etc/init.d/S51crond @@ -1,19 +1,19 @@ #!/bin/bash -sys_conf="/etc/crontabs" -conf="/data/etc/crontabs" +SYS_CONF="/etc/crontabs" +CONF="/data/etc/crontabs" test -n "$os_version" || source /etc/init.d/base start() { msg_begin "Starting crond" - if [[ -d $sys_conf ]]; then - /usr/sbin/crond -c $sys_conf + if [[ -d $SYS_CONF ]]; then + /usr/sbin/crond -c $SYS_CONF fi - mkdir -p $conf - /usr/sbin/crond -c $conf + mkdir -p $CONF + /usr/sbin/crond -c $CONF test $? == 0 && msg_done || msg_fail } diff --git a/board/common/overlay/etc/init.d/S60sshd b/board/common/overlay/etc/init.d/S60sshd index 2dcd04ac7b..7acc266486 100755 --- a/board/common/overlay/etc/init.d/S60sshd +++ b/board/common/overlay/etc/init.d/S60sshd @@ -1,8 +1,8 @@ #!/bin/bash -conf="/etc/sshd_config" +CONF="/etc/sshd_config" -test -f $conf || exit 0 +test -f $CONF || exit 0 test -n "$os_version" || source /etc/init.d/base @@ -22,7 +22,7 @@ start() { echo "Welcome to $hostname!" > /var/cache/sshd_banner sync - /usr/sbin/sshd -f $conf + /usr/sbin/sshd -f $CONF test $? == 0 && msg_done || msg_fail } diff --git a/board/common/overlay/etc/init.d/S98userinit b/board/common/overlay/etc/init.d/S98userinit index ffaf1dfb10..6dfcf08902 100755 --- a/board/common/overlay/etc/init.d/S98userinit +++ b/board/common/overlay/etc/init.d/S98userinit @@ -1,15 +1,16 @@ #!/bin/bash -userinit_sh="/data/etc/userinit.sh" +USERINIT="/data/etc/userinit.sh" -test -f $userinit_sh || exit 0 + +test -f $USERINIT || exit 0 test -n "$os_version" || source /etc/init.d/base case "$1" in start) msg_begin "Executing user init script" - /bin/bash $userinit_sh + /bin/bash $USERINIT test $? == 0 && msg_done || msg_fail ;; diff --git a/board/common/overlay/etc/init.d/os_conf b/board/common/overlay/etc/init.d/os_conf index 21713596b1..8d5f011674 100644 --- a/board/common/overlay/etc/init.d/os_conf +++ b/board/common/overlay/etc/init.d/os_conf @@ -1,20 +1,21 @@ -_sys_conf="/etc/os.conf" -_boot_conf="/boot/os.conf" -_data_conf="/data/etc/os.conf" +sys_conf="/etc/os.conf" +boot_conf="/boot/os.conf" +data_conf="/data/etc/os.conf" + # source in all conf files in order of precedence -if [[ -f $_sys_conf ]]; then - source $_sys_conf +if [[ -f $sys_conf ]]; then + source $sys_conf fi -if [[ -f $_data_conf ]]; then - source $_data_conf +if [[ -f $data_conf ]]; then + source $data_conf fi -if [[ -f $_boot_conf ]]; then - source $_boot_conf +if [[ -f $boot_conf ]]; then + source $boot_conf fi -unset _sys_conf _boot_conf _data_conf +unset sys_conf boot_conf data_conf From 0a8edd5a0d2457719a3774e769686e01b7e17a55 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sat, 12 Jan 2019 13:14:45 +0200 Subject: [PATCH 22/23] Raspberry Pi (1,2,3): init scripts: use uppercase for constants --- .../raspberrypi/overlay/etc/init.d/S05cpufreq | 21 ++++++++++--------- .../overlay/etc/init.d/S11throttlewatch | 7 ++++--- .../raspberrypi/overlay/etc/init.d/S13btuart | 9 ++++---- .../overlay/etc/init.d/S05cpufreq | 21 ++++++++++--------- .../overlay/etc/init.d/S11throttlewatch | 7 ++++--- .../overlay/etc/init.d/S05cpufreq | 21 ++++++++++--------- .../overlay/etc/init.d/S11throttlewatch | 7 ++++--- .../raspberrypi3/overlay/etc/init.d/S13btuart | 11 ++++++---- 8 files changed, 57 insertions(+), 47 deletions(-) diff --git a/board/raspberrypi/overlay/etc/init.d/S05cpufreq b/board/raspberrypi/overlay/etc/init.d/S05cpufreq index 82ae420f49..6a9ff9ce85 100755 --- a/board/raspberrypi/overlay/etc/init.d/S05cpufreq +++ b/board/raspberrypi/overlay/etc/init.d/S05cpufreq @@ -1,18 +1,19 @@ #!/bin/bash +GOV="ondemand" +CPUFREQDIR="/sys/devices/system/cpu/cpu0/cpufreq" +GOVDIR="/sys/devices/system/cpu/cpufreq/$GOV" + + test -n "$os_version" || source /etc/init.d/base -gov="ondemand" -cpufreqdir="/sys/devices/system/cpu/cpu0/cpufreq" -govdir="/sys/devices/system/cpu/cpufreq/$gov" - configure() { - echo $gov > $cpufreqdir/scaling_governor - if [[ $gov == "ondemand" ]]; then - echo 50 > $govdir/up_threshold - echo 100000 > $govdir/sampling_rate - echo 50 > $govdir/sampling_down_factor - echo 1 > $govdir/io_is_busy + echo $GOV > $CPUFREQDIR/scaling_governor + if [[ $GOV == "ondemand" ]]; then + echo 50 > $GOVDIR/up_threshold + echo 100000 > $GOVDIR/sampling_rate + echo 50 > $GOVDIR/sampling_down_factor + echo 1 > $GOVDIR/io_is_busy fi } diff --git a/board/raspberrypi/overlay/etc/init.d/S11throttlewatch b/board/raspberrypi/overlay/etc/init.d/S11throttlewatch index a06374158c..116c3f30fc 100755 --- a/board/raspberrypi/overlay/etc/init.d/S11throttlewatch +++ b/board/raspberrypi/overlay/etc/init.d/S11throttlewatch @@ -1,6 +1,7 @@ #!/bin/bash -check_interval=30 +CHECK_INTERVAL=30 + test -n "$os_version" || source /etc/init.d/base @@ -25,7 +26,7 @@ watch_now() { logger -t throttlewatch -s "currently: $t" fi - sleep $check_interval + sleep $CHECK_INTERVAL done } @@ -37,7 +38,7 @@ watch_since_boot() { break fi - sleep $check_interval + sleep $CHECK_INTERVAL done } diff --git a/board/raspberrypi/overlay/etc/init.d/S13btuart b/board/raspberrypi/overlay/etc/init.d/S13btuart index f5d51a4148..27a92d3e3f 100755 --- a/board/raspberrypi/overlay/etc/init.d/S13btuart +++ b/board/raspberrypi/overlay/etc/init.d/S13btuart @@ -1,10 +1,11 @@ #!/bin/bash -sys_conf="/etc/bluetooth.conf" -boot_conf="/boot/bluetooth.conf" -conf="/data/etc/bluetooth.conf" +SYS_CONF="/etc/bluetooth.conf" +BOOT_CONF="/boot/bluetooth.conf" +CONF="/data/etc/bluetooth.conf" -test -f $conf || test -f $boot_conf || test -f $sys_conf || exit 0 + +test -f $CONF || test -f $BOOT_CONF || test -f $SYS_CONF || exit 0 test -d "/proc/device-tree/soc/gpio@7e200000/uart0_pins" || exit 0 # no rpi bluetooth detected diff --git a/board/raspberrypi2/overlay/etc/init.d/S05cpufreq b/board/raspberrypi2/overlay/etc/init.d/S05cpufreq index 82ae420f49..6a9ff9ce85 100755 --- a/board/raspberrypi2/overlay/etc/init.d/S05cpufreq +++ b/board/raspberrypi2/overlay/etc/init.d/S05cpufreq @@ -1,18 +1,19 @@ #!/bin/bash +GOV="ondemand" +CPUFREQDIR="/sys/devices/system/cpu/cpu0/cpufreq" +GOVDIR="/sys/devices/system/cpu/cpufreq/$GOV" + + test -n "$os_version" || source /etc/init.d/base -gov="ondemand" -cpufreqdir="/sys/devices/system/cpu/cpu0/cpufreq" -govdir="/sys/devices/system/cpu/cpufreq/$gov" - configure() { - echo $gov > $cpufreqdir/scaling_governor - if [[ $gov == "ondemand" ]]; then - echo 50 > $govdir/up_threshold - echo 100000 > $govdir/sampling_rate - echo 50 > $govdir/sampling_down_factor - echo 1 > $govdir/io_is_busy + echo $GOV > $CPUFREQDIR/scaling_governor + if [[ $GOV == "ondemand" ]]; then + echo 50 > $GOVDIR/up_threshold + echo 100000 > $GOVDIR/sampling_rate + echo 50 > $GOVDIR/sampling_down_factor + echo 1 > $GOVDIR/io_is_busy fi } diff --git a/board/raspberrypi2/overlay/etc/init.d/S11throttlewatch b/board/raspberrypi2/overlay/etc/init.d/S11throttlewatch index a06374158c..116c3f30fc 100755 --- a/board/raspberrypi2/overlay/etc/init.d/S11throttlewatch +++ b/board/raspberrypi2/overlay/etc/init.d/S11throttlewatch @@ -1,6 +1,7 @@ #!/bin/bash -check_interval=30 +CHECK_INTERVAL=30 + test -n "$os_version" || source /etc/init.d/base @@ -25,7 +26,7 @@ watch_now() { logger -t throttlewatch -s "currently: $t" fi - sleep $check_interval + sleep $CHECK_INTERVAL done } @@ -37,7 +38,7 @@ watch_since_boot() { break fi - sleep $check_interval + sleep $CHECK_INTERVAL done } diff --git a/board/raspberrypi3/overlay/etc/init.d/S05cpufreq b/board/raspberrypi3/overlay/etc/init.d/S05cpufreq index 82ae420f49..6a9ff9ce85 100755 --- a/board/raspberrypi3/overlay/etc/init.d/S05cpufreq +++ b/board/raspberrypi3/overlay/etc/init.d/S05cpufreq @@ -1,18 +1,19 @@ #!/bin/bash +GOV="ondemand" +CPUFREQDIR="/sys/devices/system/cpu/cpu0/cpufreq" +GOVDIR="/sys/devices/system/cpu/cpufreq/$GOV" + + test -n "$os_version" || source /etc/init.d/base -gov="ondemand" -cpufreqdir="/sys/devices/system/cpu/cpu0/cpufreq" -govdir="/sys/devices/system/cpu/cpufreq/$gov" - configure() { - echo $gov > $cpufreqdir/scaling_governor - if [[ $gov == "ondemand" ]]; then - echo 50 > $govdir/up_threshold - echo 100000 > $govdir/sampling_rate - echo 50 > $govdir/sampling_down_factor - echo 1 > $govdir/io_is_busy + echo $GOV > $CPUFREQDIR/scaling_governor + if [[ $GOV == "ondemand" ]]; then + echo 50 > $GOVDIR/up_threshold + echo 100000 > $GOVDIR/sampling_rate + echo 50 > $GOVDIR/sampling_down_factor + echo 1 > $GOVDIR/io_is_busy fi } diff --git a/board/raspberrypi3/overlay/etc/init.d/S11throttlewatch b/board/raspberrypi3/overlay/etc/init.d/S11throttlewatch index a06374158c..116c3f30fc 100755 --- a/board/raspberrypi3/overlay/etc/init.d/S11throttlewatch +++ b/board/raspberrypi3/overlay/etc/init.d/S11throttlewatch @@ -1,6 +1,7 @@ #!/bin/bash -check_interval=30 +CHECK_INTERVAL=30 + test -n "$os_version" || source /etc/init.d/base @@ -25,7 +26,7 @@ watch_now() { logger -t throttlewatch -s "currently: $t" fi - sleep $check_interval + sleep $CHECK_INTERVAL done } @@ -37,7 +38,7 @@ watch_since_boot() { break fi - sleep $check_interval + sleep $CHECK_INTERVAL done } diff --git a/board/raspberrypi3/overlay/etc/init.d/S13btuart b/board/raspberrypi3/overlay/etc/init.d/S13btuart index 513842ba6a..27a92d3e3f 100755 --- a/board/raspberrypi3/overlay/etc/init.d/S13btuart +++ b/board/raspberrypi3/overlay/etc/init.d/S13btuart @@ -1,10 +1,13 @@ #!/bin/bash -sys_conf="/etc/bluetooth.conf" -boot_conf="/boot/bluetooth.conf" -conf="/data/etc/bluetooth.conf" +SYS_CONF="/etc/bluetooth.conf" +BOOT_CONF="/boot/bluetooth.conf" +CONF="/data/etc/bluetooth.conf" -test -f $conf || test -f $boot_conf || test -f $sys_conf || exit 0 + +test -f $CONF || test -f $BOOT_CONF || test -f $SYS_CONF || exit 0 + +test -d "/proc/device-tree/soc/gpio@7e200000/uart0_pins" || exit 0 # no rpi bluetooth detected test -n "$os_version" || source /etc/init.d/base From d907029ee4f3cc57c933a7864ede4ee00d0e201a Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sat, 12 Jan 2019 13:45:30 +0200 Subject: [PATCH 23/23] Convert all os_ variables to uppercase --- board/common/mkimage.sh | 10 ++--- board/common/overlay/etc/init.d/S00datapart | 2 +- board/common/overlay/etc/init.d/S01mountall | 10 ++--- board/common/overlay/etc/init.d/S02modules | 2 +- board/common/overlay/etc/init.d/S03hostname | 4 +- board/common/overlay/etc/init.d/S04syslog | 4 +- board/common/overlay/etc/init.d/S12udev | 2 +- board/common/overlay/etc/init.d/S13watchdog | 2 +- .../common/overlay/etc/init.d/S14postupgrade | 6 +-- board/common/overlay/etc/init.d/S30dbus | 2 +- board/common/overlay/etc/init.d/S33hostapd | 2 +- board/common/overlay/etc/init.d/S35wifi | 18 ++++----- board/common/overlay/etc/init.d/S36ppp | 6 +-- board/common/overlay/etc/init.d/S37bluetooth | 2 +- board/common/overlay/etc/init.d/S40network | 40 +++++++++---------- board/common/overlay/etc/init.d/S41netwatch | 4 +- board/common/overlay/etc/init.d/S43firewall | 2 +- board/common/overlay/etc/init.d/S45dnsmasq | 2 +- board/common/overlay/etc/init.d/S50date | 4 +- board/common/overlay/etc/init.d/S51crond | 2 +- board/common/overlay/etc/init.d/S60sshd | 4 +- board/common/overlay/etc/init.d/S98userinit | 2 +- board/common/overlay/etc/init.d/S99showinfo | 8 ++-- board/common/overlay/etc/init.d/base | 6 +-- board/common/overlay/etc/init.d/rcK | 2 +- board/common/overlay/etc/init.d/rcS | 2 +- board/common/overlay/etc/os.conf | 25 ++++++------ board/common/overlay/etc/version | 8 ++-- board/common/overlay/sbin/fwupdate | 16 ++++---- board/nanopineo/os.conf | 2 +- board/nanopineo2/os.conf | 2 +- board/odroidc1/os.conf | 2 +- board/odroidc2/os.conf | 2 +- board/odroidxu4/overlay/etc/init.d/S02waiteth | 2 +- .../raspberrypi/overlay/etc/init.d/S05cpufreq | 2 +- .../overlay/etc/init.d/S11throttlewatch | 2 +- .../raspberrypi/overlay/etc/init.d/S13btuart | 2 +- .../overlay/etc/init.d/S05cpufreq | 2 +- .../overlay/etc/init.d/S11throttlewatch | 2 +- .../overlay/etc/init.d/S05cpufreq | 2 +- .../overlay/etc/init.d/S11throttlewatch | 2 +- .../raspberrypi3/overlay/etc/init.d/S13btuart | 2 +- 42 files changed, 113 insertions(+), 112 deletions(-) diff --git a/board/common/mkimage.sh b/board/common/mkimage.sh index a681280f63..96143054ba 100755 --- a/board/common/mkimage.sh +++ b/board/common/mkimage.sh @@ -28,7 +28,7 @@ GUARD_SIZE="10" # MB DISK_SIZE=$((ROOT_START + ROOT_SIZE + GUARD_SIZE)) COMMON_DIR=$(cd $IMG_DIR/../../../board/common; pwd) -OS_NAME=$(source $COMMON_DIR/overlay/etc/version && echo $os_short_name) +OS_NAME=$(source $COMMON_DIR/overlay/etc/version && echo $OS_SHORT_NAME) # boot filesystem msg "creating boot loop device" @@ -73,19 +73,19 @@ tar -xpsf $ROOT_SRC -C $ROOT if [ -f $ROOT/etc/version ]; then if [ -n "$THINGOS_NAME" ]; then msg "setting OS name to $THINGOS_NAME" - sed -ri "s/os_name=\".*\"/os_name=\"$THINGOS_NAME\"/" $ROOT/etc/version + sed -ri "s/OS_NAME=\".*\"/OS_NAME=\"$THINGOS_NAME\"/" $ROOT/etc/version fi if [ -n "$THINGOS_SHORT_NAME" ]; then msg "setting OS short name to $THINGOS_SHORT_NAME" - sed -ri "s/os_short_name=\".*\"/os_short_name=\"$THINGOS_SHORT_NAME\"/" $ROOT/etc/version + sed -ri "s/OS_SHORT_NAME=\".*\"/OS_SHORT_NAME=\"$THINGOS_SHORT_NAME\"/" $ROOT/etc/version fi if [ -n "$THINGOS_PREFIX" ]; then msg "setting OS prefix to $THINGOS_PREFIX" - sed -ri "s/os_prefix=\".*\"/os_prefix=\"$THINGOS_PREFIX\"/" $ROOT/etc/version + sed -ri "s/OS_PREFIX=\".*\"/OS_PREFIX=\"$THINGOS_PREFIX\"/" $ROOT/etc/version fi if [ -n "$THINGOS_VERSION" ]; then msg "setting OS version to $THINGOS_VERSION" - sed -ri "s/os_version=\".*\"/os_version=\"$THINGOS_VERSION\"/" $ROOT/etc/version + sed -ri "s/OS_VERSION=\".*\"/OS_VERSION=\"$THINGOS_VERSION\"/" $ROOT/etc/version fi fi diff --git a/board/common/overlay/etc/init.d/S00datapart b/board/common/overlay/etc/init.d/S00datapart index f8b2747c07..7bf25bdc27 100755 --- a/board/common/overlay/etc/init.d/S00datapart +++ b/board/common/overlay/etc/init.d/S00datapart @@ -1,6 +1,6 @@ #!/bin/bash -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base case "$1" in start) diff --git a/board/common/overlay/etc/init.d/S01mountall b/board/common/overlay/etc/init.d/S01mountall index ac987534aa..8354d3054c 100755 --- a/board/common/overlay/etc/init.d/S01mountall +++ b/board/common/overlay/etc/init.d/S01mountall @@ -1,6 +1,6 @@ #!/bin/bash -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base mount_fs() { msg_begin "Mounting filesystems" @@ -22,8 +22,8 @@ remount_rw() { } mk_tty_login() { - test -z "$os_tty_login" && os_tty_login=tty1 - ln -sf /dev/$os_tty_login /dev/ttylogin + test -z "$OS_TTY_LOGIN" && OS_TTY_LOGIN=tty1 + ln -sf /dev/$OS_TTY_LOGIN /dev/ttylogin } case "$1" in @@ -31,8 +31,8 @@ case "$1" in mount_fs # we need to source conf again, now that /data is available - test -n "$os_debug" || source /etc/init.d/os_conf - test "$os_debug" == "true" && remount_rw + test -n "$OS_DEBUG" || source /etc/init.d/os_conf + test "$OS_DEBUG" == "true" && remount_rw mk_tty_login ;; diff --git a/board/common/overlay/etc/init.d/S02modules b/board/common/overlay/etc/init.d/S02modules index b667086346..4190059f95 100755 --- a/board/common/overlay/etc/init.d/S02modules +++ b/board/common/overlay/etc/init.d/S02modules @@ -5,7 +5,7 @@ BOOT_MODULES_FILE="/boot/modules" MODULES_FILE="/data/etc/modules" -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base case "$1" in start) diff --git a/board/common/overlay/etc/init.d/S03hostname b/board/common/overlay/etc/init.d/S03hostname index f081363b86..5660423ad9 100755 --- a/board/common/overlay/etc/init.d/S03hostname +++ b/board/common/overlay/etc/init.d/S03hostname @@ -5,7 +5,7 @@ BOOT_HOSTNAME_FILE="/boot/hostname" HOSTNAME_FILE="/data/etc/hostname" -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base case "$1" in start) @@ -16,7 +16,7 @@ case "$1" in if [[ -f $HOSTNAME_FILE ]]; then hostname=$(cat $HOSTNAME_FILE) else - hostname="$os_prefix-$board_sn" + hostname="$OS_PREFIX-$BOARD_SN" fi /bin/hostname $hostname diff --git a/board/common/overlay/etc/init.d/S04syslog b/board/common/overlay/etc/init.d/S04syslog index da74427391..7eba761d12 100755 --- a/board/common/overlay/etc/init.d/S04syslog +++ b/board/common/overlay/etc/init.d/S04syslog @@ -1,6 +1,6 @@ #!/bin/bash -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base DMESG_LOG="/var/log/dmesg.log" @@ -10,7 +10,7 @@ case "$1" in msg_begin "Starting syslogd" syslogd test $? == 0 && msg_done || msg_fail - echo "---- booting $os_name $os_version ----" >> $DMESG_LOG + echo "---- booting $OS_NAME $OS_VERSION ----" >> $DMESG_LOG dmesg -T -w >> $DMESG_LOG & ;; diff --git a/board/common/overlay/etc/init.d/S12udev b/board/common/overlay/etc/init.d/S12udev index 2c2f20c4b1..73d187e397 100755 --- a/board/common/overlay/etc/init.d/S12udev +++ b/board/common/overlay/etc/init.d/S12udev @@ -5,7 +5,7 @@ CONF=/etc/udev/udev.conf test -f $CONF || exit 0 -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base source $CONF diff --git a/board/common/overlay/etc/init.d/S13watchdog b/board/common/overlay/etc/init.d/S13watchdog index 2ef0f11278..3ffe16881a 100755 --- a/board/common/overlay/etc/init.d/S13watchdog +++ b/board/common/overlay/etc/init.d/S13watchdog @@ -2,7 +2,7 @@ test -c /dev/watchdog || exit 0 -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base case "$1" in start) diff --git a/board/common/overlay/etc/init.d/S14postupgrade b/board/common/overlay/etc/init.d/S14postupgrade index 225c0f6c6e..4820f340af 100755 --- a/board/common/overlay/etc/init.d/S14postupgrade +++ b/board/common/overlay/etc/init.d/S14postupgrade @@ -5,7 +5,7 @@ VERSION_FILE="/data/etc/version" POST_UPGRADE_DIR="/usr/share/post-upgrade" -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base hash=$(md5sum $VERSION_FILE 2>/dev/null | cut -d ' ' -f 1) sys_hash=$(md5sum $SYS_VERSION_FILE 2>/dev/null | cut -d ' ' -f 1) @@ -23,8 +23,8 @@ function version_gt() { } function run_post_upgrade() { - version="$(source $VERSION_FILE 2>/dev/null && echo $os_version)" - sys_version="$(source $SYS_VERSION_FILE 2>/dev/null && echo $os_version)" + version="$(source $VERSION_FILE 2>/dev/null && echo $OS_VERSION)" + sys_version="$(source $SYS_VERSION_FILE 2>/dev/null && echo $OS_VERSION)" versions=$(ls -1 $POST_UPGRADE_DIR | cut -d '.' -f 1) for v in $versions; do diff --git a/board/common/overlay/etc/init.d/S30dbus b/board/common/overlay/etc/init.d/S30dbus index 92fad2e731..c6391f624d 100755 --- a/board/common/overlay/etc/init.d/S30dbus +++ b/board/common/overlay/etc/init.d/S30dbus @@ -10,7 +10,7 @@ test -f $BTCONF || test -f $BOOT_BTCONF || test -f $SYS_BTCONF || exit 0 test -x /usr/bin/dbus-daemon || exit 0 -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base start() { mkdir -p /tmp/dbus diff --git a/board/common/overlay/etc/init.d/S33hostapd b/board/common/overlay/etc/init.d/S33hostapd index d55dc040ae..7704e31ecc 100755 --- a/board/common/overlay/etc/init.d/S33hostapd +++ b/board/common/overlay/etc/init.d/S33hostapd @@ -13,7 +13,7 @@ link_watch=yes link_watch_timeout=20 -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base prepare_conf $CONF $SYS_CONF $BOOT_CONF test -f $CONF || exit 0 diff --git a/board/common/overlay/etc/init.d/S35wifi b/board/common/overlay/etc/init.d/S35wifi index c89466b6ac..8dd54f2725 100755 --- a/board/common/overlay/etc/init.d/S35wifi +++ b/board/common/overlay/etc/init.d/S35wifi @@ -13,7 +13,7 @@ BOOT_WATCH_CONF="/boot/watch.conf" WATCH_CONF="/data/etc/watch.conf" -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base prepare_conf $WATCH_CONF $SYS_WATCH_CONF $BOOT_WATCH_CONF source $WATCH_CONF @@ -25,11 +25,11 @@ ssid=$(cat $CONF | grep ssid | grep -v scan_ssid | cut -d '"' -f 2) test -n "$ssid" || exit 0 -test "$os_networkless" == "true" && exit 0 +test "$OS_NETWORKLESS" == "true" && exit 0 connected() { - ip link show dev $os_wlan 2>&1 | grep LOWER_UP &> /dev/null && return 0 || return 1 + ip link show dev $OS_WLAN 2>&1 | grep LOWER_UP &> /dev/null && return 0 || return 1 } watch() { @@ -51,13 +51,13 @@ watch() { } start() { - test -n "$os_country" && iw reg set $os_country + test -n "$OS_COUNTRY" && iw reg set $OS_COUNTRY msg_begin "Starting wpa_supplicant" # wait up to 5 seconds for interface count=0 - while ! ifconfig $os_wlan >/dev/null 2>&1; do + while ! ifconfig $OS_WLAN >/dev/null 2>&1; do sleep 1 count=$(($count + 1)) if [[ $count -ge 5 ]]; then @@ -66,11 +66,11 @@ start() { fi done - module=$(basename $(readlink /sys/class/net/$os_wlan/device/driver/module 2>/dev/null) 2>/dev/null) + module=$(basename $(readlink /sys/class/net/$OS_WLAN/device/driver/module 2>/dev/null) 2>/dev/null) - iwconfig $os_wlan power off &> /dev/null - iw $os_wlan set power_save off &> /dev/null - $PROG -i$os_wlan -c$CONF -D$DRIVER -B &> $LOG + iwconfig $OS_WLAN power off &> /dev/null + iw $OS_WLAN set power_save off &> /dev/null + $PROG -i$OS_WLAN -c$CONF -D$DRIVER -B &> $LOG count=0 while true; do sleep 1 diff --git a/board/common/overlay/etc/init.d/S36ppp b/board/common/overlay/etc/init.d/S36ppp index 03e21ee5ba..76a0484993 100755 --- a/board/common/overlay/etc/init.d/S36ppp +++ b/board/common/overlay/etc/init.d/S36ppp @@ -10,7 +10,7 @@ PROVIDER="mobile" WATCH_CONF="/data/etc/watch.conf" -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base prepare_conf $CONF $SYS_CONF $BOOT_CONF @@ -19,11 +19,11 @@ test -e $CONF/apn || exit 0 source $WATCH_CONF -test "$os_networkless" == "true" && exit 0 +test "$OS_NETWORKLESS" == "true" && exit 0 connected() { - ifconfig | grep $os_ppp &>/dev/null && return 0 || return 1 + ifconfig | grep $OS_PPP &>/dev/null && return 0 || return 1 } watch() { diff --git a/board/common/overlay/etc/init.d/S37bluetooth b/board/common/overlay/etc/init.d/S37bluetooth index 13b61893be..7b1a1b56d9 100755 --- a/board/common/overlay/etc/init.d/S37bluetooth +++ b/board/common/overlay/etc/init.d/S37bluetooth @@ -5,7 +5,7 @@ BOOT_CONF="/boot/bluetooth.conf" CONF="/data/etc/bluetooth.conf" -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base prepare_conf $CONF $SYS_CONF $BOOT_CONF test -f $CONF || exit 0 diff --git a/board/common/overlay/etc/init.d/S40network b/board/common/overlay/etc/init.d/S40network index df8d2b932d..060662bd86 100755 --- a/board/common/overlay/etc/init.d/S40network +++ b/board/common/overlay/etc/init.d/S40network @@ -9,7 +9,7 @@ WATCH_CONF="/data/etc/watch.conf" LINK_NEGO_TIMEOUT=10 -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base source $WATCH_CONF @@ -23,7 +23,7 @@ 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 @@ -62,31 +62,31 @@ start_lo() { start_wlan() { msg_begin "Configuring wireless network" - if ! ifconfig $os_wlan &>/dev/null; then + if ! ifconfig $OS_WLAN &>/dev/null; then msg_fail "no device" 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 - ip link set mtu $mtu dev $os_wlan + ip link set mtu $mtu dev $OS_WLAN fi if [[ -n "$static_ip" ]]; then msg_done $static_ip - ifconfig $os_wlan $static_ip up + ifconfig $OS_WLAN $static_ip up static_ip="" # won't be used again else msg_done dhcp - dhclient -cf "$DH_CONF" $os_wlan + dhclient -cf "$DH_CONF" $OS_WLAN fi - if [[ "$ip_watch" == "true" ]] && ip addr show dev $os_wlan | grep inet &>/dev/null; then - watch_ip $os_wlan & + if [[ "$ip_watch" == "true" ]] && ip addr show dev $OS_WLAN | grep inet &>/dev/null; then + watch_ip $OS_WLAN & fi } @@ -96,7 +96,7 @@ start_eth() { # wait for driver w=3 count=0 - while ! ifconfig $os_eth >/dev/null 2>&1; do + while ! ifconfig $OS_ETH >/dev/null 2>&1; do sleep 1 count=$(($count + 1)) if [[ $count -ge $w ]]; then @@ -106,12 +106,12 @@ start_eth() { done # bring it up - ifconfig $os_eth up + ifconfig $OS_ETH up # 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 @@ -123,7 +123,7 @@ 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 @@ -133,24 +133,24 @@ start_eth() { done if [[ -n "$mtu" ]]; then - ip link set mtu $mtu dev $os_eth + ip link set mtu $mtu dev $OS_ETH fi if [[ -n "$static_ip" ]]; then msg_done $static_ip - ifconfig $os_eth $static_ip up + ifconfig $OS_ETH $static_ip up static_ip="" # won't be used again else msg_done dhcp - dhclient -cf "$DH_CONF" $os_eth + dhclient -cf "$DH_CONF" $OS_ETH fi if [[ "$link_watch" == "true" ]]; then watch_eth & fi - if [[ "$ip_watch" == "true" ]] && ip addr show dev $os_eth | grep inet &>/dev/null; then - watch_ip $os_eth & + if [[ "$ip_watch" == "true" ]] && ip addr show dev $OS_ETH | grep inet &>/dev/null; then + watch_ip $OS_ETH & fi } @@ -160,12 +160,12 @@ start() { start_lo - test "$os_networkless" == "true" && return 0 + test "$OS_NETWORKLESS" == "true" && return 0 ssid=$(cat /data/etc/wpa_supplicant.conf 2>&1 | grep ssid | grep -v scan_ssid | cut -d '"' -f 2) test -n "$ssid" && start_wlan && wlan_ok="ok" - test -r /data/etc/ppp/modem && ifconfig | grep $os_ppp &>/dev/null && ppp_ok="ok" + 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 diff --git a/board/common/overlay/etc/init.d/S41netwatch b/board/common/overlay/etc/init.d/S41netwatch index f7cbbeb4b0..ef2d743d97 100755 --- a/board/common/overlay/etc/init.d/S41netwatch +++ b/board/common/overlay/etc/init.d/S41netwatch @@ -12,9 +12,9 @@ if [[ -z "$netwatch_host" || -z "$netwatch_port" ]]; then exit 0 fi -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base -test "$os_networkless" == "true" && exit 0 +test "$OS_NETWORKLESS" == "true" && exit 0 watch() { diff --git a/board/common/overlay/etc/init.d/S43firewall b/board/common/overlay/etc/init.d/S43firewall index 0557ce5813..cdd700d9ad 100755 --- a/board/common/overlay/etc/init.d/S43firewall +++ b/board/common/overlay/etc/init.d/S43firewall @@ -5,7 +5,7 @@ BOOT_CONF="/boot/firewall.sh" CONF="/data/etc/firewall.sh" -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base prepare_conf $CONF $SYS_CONF $BOOT_CONF test -f $CONF || exit 0 diff --git a/board/common/overlay/etc/init.d/S45dnsmasq b/board/common/overlay/etc/init.d/S45dnsmasq index 9d1f0326d5..419964cd49 100755 --- a/board/common/overlay/etc/init.d/S45dnsmasq +++ b/board/common/overlay/etc/init.d/S45dnsmasq @@ -8,7 +8,7 @@ LOG="/var/log/dnsmasq.log" PROG="/usr/sbin/dnsmasq" -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base prepare_conf $CONF $SYS_CONF $BOOT_CONF test -f $CONF || exit 0 diff --git a/board/common/overlay/etc/init.d/S50date b/board/common/overlay/etc/init.d/S50date index 5393314d1b..941e741f4d 100755 --- a/board/common/overlay/etc/init.d/S50date +++ b/board/common/overlay/etc/init.d/S50date @@ -12,14 +12,14 @@ BOOT_NTP_CONF="/boot/ntp.conf" NTP_CONF="/data/etc/ntp.conf" -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base prepare_conf $CONF $SYS_CONF $BOOT_CONF prepare_conf $NTP_CONF $SYS_NTP_CONF $BOOT_NTP_CONF test -f $CONF || exit 0 -test "$os_networkless" == "true" && exit 0 +test "$OS_NETWORKLESS" == "true" && exit 0 date_timeout=10 date_method=http diff --git a/board/common/overlay/etc/init.d/S51crond b/board/common/overlay/etc/init.d/S51crond index 5e464afc3f..b825a52453 100755 --- a/board/common/overlay/etc/init.d/S51crond +++ b/board/common/overlay/etc/init.d/S51crond @@ -3,7 +3,7 @@ SYS_CONF="/etc/crontabs" CONF="/data/etc/crontabs" -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base start() { msg_begin "Starting crond" diff --git a/board/common/overlay/etc/init.d/S60sshd b/board/common/overlay/etc/init.d/S60sshd index 7acc266486..04db9febcd 100755 --- a/board/common/overlay/etc/init.d/S60sshd +++ b/board/common/overlay/etc/init.d/S60sshd @@ -4,9 +4,9 @@ CONF="/etc/sshd_config" test -f $CONF || exit 0 -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base -test "$os_networkless" == "true" && exit 0 +test "$OS_NETWORKLESS" == "true" && exit 0 start() { msg_begin "Starting sshd" diff --git a/board/common/overlay/etc/init.d/S98userinit b/board/common/overlay/etc/init.d/S98userinit index 6dfcf08902..1b3f861e50 100755 --- a/board/common/overlay/etc/init.d/S98userinit +++ b/board/common/overlay/etc/init.d/S98userinit @@ -5,7 +5,7 @@ USERINIT="/data/etc/userinit.sh" test -f $USERINIT || exit 0 -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base case "$1" in start) diff --git a/board/common/overlay/etc/init.d/S99showinfo b/board/common/overlay/etc/init.d/S99showinfo index fac00a387d..65862148da 100755 --- a/board/common/overlay/etc/init.d/S99showinfo +++ b/board/common/overlay/etc/init.d/S99showinfo @@ -1,6 +1,6 @@ #!/bin/bash -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base msg_info() { echo " # $1" @@ -24,9 +24,9 @@ show_dns() { case "$1" in start) - show_iface_ip_addr $os_eth - show_iface_ip_addr $os_wlan - show_iface_ip_addr $os_ppp + show_iface_ip_addr $OS_ETH + show_iface_ip_addr $OS_WLAN + show_iface_ip_addr $OS_PPP show_gateway show_dns ;; diff --git a/board/common/overlay/etc/init.d/base b/board/common/overlay/etc/init.d/base index 852ca513a4..1d262a6e7c 100644 --- a/board/common/overlay/etc/init.d/base +++ b/board/common/overlay/etc/init.d/base @@ -1,9 +1,9 @@ source /etc/version -board_sn=$(/etc/init.d/boardsn) -board_name=$(cat /etc/board) +BOARD_SN=$(/etc/init.d/boardsn) +BOARD_NAME=$(cat /etc/board) -test -n "$os_debug" || source /etc/init.d/os_conf +test -n "$OS_DEBUG" || source /etc/init.d/os_conf source /etc/init.d/panic diff --git a/board/common/overlay/etc/init.d/rcK b/board/common/overlay/etc/init.d/rcK index 7d08910c5b..e56f000d5d 100755 --- a/board/common/overlay/etc/init.d/rcK +++ b/board/common/overlay/etc/init.d/rcK @@ -5,7 +5,7 @@ pid_file=/tmp/rc.pid source /etc/init.d/base -echo "---- shutting down $os_name $os_version ----" >> $boot_log +echo "---- shutting down $OS_NAME $OS_VERSION ----" >> $boot_log # stop all init scripts in /etc/init.d, # executing them in reverse numerical order. diff --git a/board/common/overlay/etc/init.d/rcS b/board/common/overlay/etc/init.d/rcS index d15157610f..f4b0dab1b6 100755 --- a/board/common/overlay/etc/init.d/rcS +++ b/board/common/overlay/etc/init.d/rcS @@ -6,7 +6,7 @@ pid_file=/tmp/rc.pid source /etc/init.d/base -echo "---- booting $os_name $os_version ----" >> $tmp_boot_log +echo "---- booting $OS_NAME $OS_VERSION ----" >> $tmp_boot_log # start all init scripts in /etc/init.d, # executing them in numerical order. diff --git a/board/common/overlay/etc/os.conf b/board/common/overlay/etc/os.conf index 96fff5eb4a..d9b0361c35 100644 --- a/board/common/overlay/etc/os.conf +++ b/board/common/overlay/etc/os.conf @@ -1,12 +1,13 @@ -os_debug="false" -os_prereleases="false" -os_tty_login="tty1" -os_eth="eth0" -os_wlan="wlan0" -os_ppp="ppp0" -os_networkless="false" -os_country="GB" -os_firmware_method="github" -os_firmware_repo="ccrisan/thingos" -os_firmware_username="" -os_firmware_password="" +OS_DEBUG="false" +OS_PRERELEASES="false" +OS_TTY_LOGIN="tty1" +OS_ETH="eth0" +OS_WLAN="wlan0" +OS_PPP="ppp0" +OS_NETWORKLESS="false" +OS_COUNTRY="GB" +OS_FIRMWARE_METHOD="github" +OS_FIRMWARE_REPO="ccrisan/thingos" +OS_FIRMWARE_USERNAME="" +OS_FIRMWARE_PASSWORD="" + diff --git a/board/common/overlay/etc/version b/board/common/overlay/etc/version index b42047004c..6921062dac 100644 --- a/board/common/overlay/etc/version +++ b/board/common/overlay/etc/version @@ -1,4 +1,4 @@ -os_name="thingOS" -os_short_name="thingos" -os_prefix="thing" -os_version="unknown" +OS_NAME="thingOS" +OS_SHORT_NAME="thingos" +OS_PREFIX="thing" +OS_VERSION="unknown" diff --git a/board/common/overlay/sbin/fwupdate b/board/common/overlay/sbin/fwupdate index 3dafd3b1db..a383615700 100755 --- a/board/common/overlay/sbin/fwupdate +++ b/board/common/overlay/sbin/fwupdate @@ -77,22 +77,22 @@ fi #### versions #### function show_versions() { - source /etc/init.d/os_conf # we need this for the os_ vars + source /etc/init.d/os_conf # we need this for the OS_ vars board=$(cat $SYS_BOARD_FILE) show_json=$1 # the /usr/libexec/list-versions-* helpers return a table with the following format: # |||| - versions=$(FW_USERNAME=$os_firmware_username FW_PASSWORD=$os_firmware_password \ - /usr/libexec/list-versions-$os_firmware_method $os_firmware_repo) + versions=$(FW_USERNAME=$OS_FIRMWARE_USERNAME FW_PASSWORD=$OS_FIRMWARE_PASSWORD \ + /usr/libexec/list-versions-$OS_FIRMWARE_METHOD $OS_FIRMWARE_REPO) for version in ${versions[@]}; do OIFS=$IFS IFS="|" varr=($version) IFS=$OIFS - if [ "$os_prereleases" == "false" ] && [ "${varr[1]}" == "true" ]; then + if [ "$OS_PRERELEASES" == "false" ] && [ "${varr[1]}" == "true" ]; then continue # skip prereleases fi if [ "$board" != "${varr[2]}" ]; then @@ -114,7 +114,7 @@ function show_versions() { function show_current() { source $SYS_VERSION_FILE - echo $os_version + echo $OS_VERSION } @@ -144,7 +144,7 @@ function do_download() { fi fi - source /etc/init.d/os_conf # we need this for the os_ vars + source /etc/init.d/os_conf # we need this for the OS_ vars board=$(cat $SYS_BOARD_FILE) url=$1 @@ -176,8 +176,8 @@ function do_download() { echo $version > $FW_DIR/$VER_FILE curl_opts="-S -f -L" - if [ -n "$os_firmware_username" ]; then - curl_opts+=" --user $os_firmware_username:$os_firmware_password" + if [ -n "$OS_FIRMWARE_USERNAME" ]; then + curl_opts+=" --user $OS_FIRMWARE_USERNAME:$OS_FIRMWARE_PASSWORD" fi curl $curl_opts -o $outfile "$url" &> $FW_DIR/$CURL_LOG_FILE & diff --git a/board/nanopineo/os.conf b/board/nanopineo/os.conf index dc77b07e6d..bbfeece44c 100644 --- a/board/nanopineo/os.conf +++ b/board/nanopineo/os.conf @@ -1,2 +1,2 @@ -os_tty_login="ttyS0" +OS_TTY_LOGIN="ttyS0" diff --git a/board/nanopineo2/os.conf b/board/nanopineo2/os.conf index dc77b07e6d..bbfeece44c 100644 --- a/board/nanopineo2/os.conf +++ b/board/nanopineo2/os.conf @@ -1,2 +1,2 @@ -os_tty_login="ttyS0" +OS_TTY_LOGIN="ttyS0" diff --git a/board/odroidc1/os.conf b/board/odroidc1/os.conf index dc77b07e6d..bbfeece44c 100644 --- a/board/odroidc1/os.conf +++ b/board/odroidc1/os.conf @@ -1,2 +1,2 @@ -os_tty_login="ttyS0" +OS_TTY_LOGIN="ttyS0" diff --git a/board/odroidc2/os.conf b/board/odroidc2/os.conf index dc77b07e6d..bbfeece44c 100644 --- a/board/odroidc2/os.conf +++ b/board/odroidc2/os.conf @@ -1,2 +1,2 @@ -os_tty_login="ttyS0" +OS_TTY_LOGIN="ttyS0" diff --git a/board/odroidxu4/overlay/etc/init.d/S02waiteth b/board/odroidxu4/overlay/etc/init.d/S02waiteth index 6873243889..4b891c7d71 100755 --- a/board/odroidxu4/overlay/etc/init.d/S02waiteth +++ b/board/odroidxu4/overlay/etc/init.d/S02waiteth @@ -1,6 +1,6 @@ #!/bin/bash -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base case "$1" in start) diff --git a/board/raspberrypi/overlay/etc/init.d/S05cpufreq b/board/raspberrypi/overlay/etc/init.d/S05cpufreq index 6a9ff9ce85..0644c34e22 100755 --- a/board/raspberrypi/overlay/etc/init.d/S05cpufreq +++ b/board/raspberrypi/overlay/etc/init.d/S05cpufreq @@ -5,7 +5,7 @@ CPUFREQDIR="/sys/devices/system/cpu/cpu0/cpufreq" GOVDIR="/sys/devices/system/cpu/cpufreq/$GOV" -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base configure() { echo $GOV > $CPUFREQDIR/scaling_governor diff --git a/board/raspberrypi/overlay/etc/init.d/S11throttlewatch b/board/raspberrypi/overlay/etc/init.d/S11throttlewatch index 116c3f30fc..b8ea3272f3 100755 --- a/board/raspberrypi/overlay/etc/init.d/S11throttlewatch +++ b/board/raspberrypi/overlay/etc/init.d/S11throttlewatch @@ -3,7 +3,7 @@ CHECK_INTERVAL=30 -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base get_throttled_now() { t=$(vcgencmd get_throttled | cut -d '=' -f 2) diff --git a/board/raspberrypi/overlay/etc/init.d/S13btuart b/board/raspberrypi/overlay/etc/init.d/S13btuart index 27a92d3e3f..c874c8b9ef 100755 --- a/board/raspberrypi/overlay/etc/init.d/S13btuart +++ b/board/raspberrypi/overlay/etc/init.d/S13btuart @@ -9,7 +9,7 @@ test -f $CONF || test -f $BOOT_CONF || test -f $SYS_CONF || exit 0 test -d "/proc/device-tree/soc/gpio@7e200000/uart0_pins" || exit 0 # no rpi bluetooth detected -test -n "$os_version" || source /etc/init.d/base +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 diff --git a/board/raspberrypi2/overlay/etc/init.d/S05cpufreq b/board/raspberrypi2/overlay/etc/init.d/S05cpufreq index 6a9ff9ce85..0644c34e22 100755 --- a/board/raspberrypi2/overlay/etc/init.d/S05cpufreq +++ b/board/raspberrypi2/overlay/etc/init.d/S05cpufreq @@ -5,7 +5,7 @@ CPUFREQDIR="/sys/devices/system/cpu/cpu0/cpufreq" GOVDIR="/sys/devices/system/cpu/cpufreq/$GOV" -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base configure() { echo $GOV > $CPUFREQDIR/scaling_governor diff --git a/board/raspberrypi2/overlay/etc/init.d/S11throttlewatch b/board/raspberrypi2/overlay/etc/init.d/S11throttlewatch index 116c3f30fc..b8ea3272f3 100755 --- a/board/raspberrypi2/overlay/etc/init.d/S11throttlewatch +++ b/board/raspberrypi2/overlay/etc/init.d/S11throttlewatch @@ -3,7 +3,7 @@ CHECK_INTERVAL=30 -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base get_throttled_now() { t=$(vcgencmd get_throttled | cut -d '=' -f 2) diff --git a/board/raspberrypi3/overlay/etc/init.d/S05cpufreq b/board/raspberrypi3/overlay/etc/init.d/S05cpufreq index 6a9ff9ce85..0644c34e22 100755 --- a/board/raspberrypi3/overlay/etc/init.d/S05cpufreq +++ b/board/raspberrypi3/overlay/etc/init.d/S05cpufreq @@ -5,7 +5,7 @@ CPUFREQDIR="/sys/devices/system/cpu/cpu0/cpufreq" GOVDIR="/sys/devices/system/cpu/cpufreq/$GOV" -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base configure() { echo $GOV > $CPUFREQDIR/scaling_governor diff --git a/board/raspberrypi3/overlay/etc/init.d/S11throttlewatch b/board/raspberrypi3/overlay/etc/init.d/S11throttlewatch index 116c3f30fc..b8ea3272f3 100755 --- a/board/raspberrypi3/overlay/etc/init.d/S11throttlewatch +++ b/board/raspberrypi3/overlay/etc/init.d/S11throttlewatch @@ -3,7 +3,7 @@ CHECK_INTERVAL=30 -test -n "$os_version" || source /etc/init.d/base +test -n "$OS_VERSION" || source /etc/init.d/base get_throttled_now() { t=$(vcgencmd get_throttled | cut -d '=' -f 2) diff --git a/board/raspberrypi3/overlay/etc/init.d/S13btuart b/board/raspberrypi3/overlay/etc/init.d/S13btuart index 27a92d3e3f..c874c8b9ef 100755 --- a/board/raspberrypi3/overlay/etc/init.d/S13btuart +++ b/board/raspberrypi3/overlay/etc/init.d/S13btuart @@ -9,7 +9,7 @@ test -f $CONF || test -f $BOOT_CONF || test -f $SYS_CONF || exit 0 test -d "/proc/device-tree/soc/gpio@7e200000/uart0_pins" || exit 0 # no rpi bluetooth detected -test -n "$os_version" || source /etc/init.d/base +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