diff --git a/board/common/mkimage.sh b/board/common/mkimage.sh index 2e9ccedfd2..6ec4fb8c8c 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 71065f714d..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/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 685f63a5fb..4190059f95 100755 --- a/board/common/overlay/etc/init.d/S02modules +++ b/board/common/overlay/etc/init.d/S02modules @@ -1,20 +1,26 @@ #!/bin/bash -sys_modules_file="/etc/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 + +test -n "$OS_VERSION" || source /etc/init.d/base 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 $modules_file ]]; then - cat $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 fi msg_done diff --git a/board/common/overlay/etc/init.d/S03hostname b/board/common/overlay/etc/init.d/S03hostname index 8b886e838d..5660423ad9 100755 --- a/board/common/overlay/etc/init.d/S03hostname +++ b/board/common/overlay/etc/init.d/S03hostname @@ -1,27 +1,22 @@ #!/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 + +test -n "$OS_VERSION" || source /etc/init.d/base 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) + 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 b7a1eb3ac4..7eba761d12 100755 --- a/board/common/overlay/etc/init.d/S04syslog +++ b/board/common/overlay/etc/init.d/S04syslog @@ -1,16 +1,17 @@ #!/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" -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..73d187e397 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 -n "$os_version" || source /etc/init.d/base -source /etc/udev/udev.conf +test -f $CONF || exit 0 + +test -n "$OS_VERSION" || source /etc/init.d/base + +source $CONF start() { msg_begin "Starting eudev" 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 65c0adf96b..4820f340af 100755 --- a/board/common/overlay/etc/init.d/S14postupgrade +++ b/board/common/overlay/etc/init.d/S14postupgrade @@ -1,19 +1,18 @@ #!/bin/bash -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_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) +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) 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 @@ -24,37 +23,24 @@ 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 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 + 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..c6391f624d 100755 --- a/board/common/overlay/etc/init.d/S30dbus +++ b/board/common/overlay/etc/init.d/S30dbus @@ -1,15 +1,16 @@ #!/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 -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 b8d6759589..7704e31ecc 100755 --- a/board/common/overlay/etc/init.d/S33hostapd +++ b/board/common/overlay/etc/init.d/S33hostapd @@ -1,30 +1,25 @@ #!/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 -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 +test -n "$OS_VERSION" || source /etc/init.d/base -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 -n "$os_version" || source /etc/init.d/base running() { killall -0 hostapd &> /dev/null @@ -55,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 7ab6635531..8dd54f2725 100755 --- a/board/common/overlay/etc/init.d/S35wifi +++ b/board/common/overlay/etc/init.d/S35wifi @@ -1,49 +1,35 @@ #!/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" -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 -source $watch_conf +test -n "$OS_VERSION" || source /etc/init.d/base -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 $WATCH_CONF $SYS_WATCH_CONF $BOOT_WATCH_CONF +source $WATCH_CONF -test -f $conf || exit 0 +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) +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 +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() { @@ -65,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 @@ -80,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 c67f7253e6..76a0484993 100755 --- a/board/common/overlay/etc/init.d/S36ppp +++ b/board/common/overlay/etc/init.d/S36ppp @@ -1,33 +1,29 @@ #!/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" -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 +test -n "$OS_VERSION" || source /etc/init.d/base -test -e $conf/modem || exit 0 -test -e $conf/apn || exit 0 +prepare_conf $CONF $SYS_CONF $BOOT_CONF -test -n "$os_version" || source /etc/init.d/base +test -e $CONF/modem || exit 0 +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() { @@ -55,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 @@ -83,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 76e570ab00..7b1a1b56d9 100755 --- a/board/common/overlay/etc/init.d/S37bluetooth +++ b/board/common/overlay/etc/init.d/S37bluetooth @@ -1,18 +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" -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 hci=hci0 bluetoothd=/usr/libexec/bluetooth/bluetoothd @@ -22,12 +18,11 @@ 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 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 93b03c81af..060662bd86 100755 --- a/board/common/overlay/etc/init.d/S40network +++ b/board/common/overlay/etc/init.d/S40network @@ -1,33 +1,29 @@ #!/bin/bash +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 + + +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 + 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" -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 - -test -r $static_conf && source $static_conf - -test -n "$os_version" || source /etc/init.d/base 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 @@ -66,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 } @@ -100,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 @@ -110,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 @@ -125,36 +121,36 @@ 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 + while [[ "$(cat /sys/class/net/$OS_ETH/carrier 2>&1)" != "1" ]]; do sleep 1 count=$(($count + 1)) - if [[ $count -ge $link_nego_timeout ]]; then + if [[ $count -ge $LINK_NEGO_TIMEOUT ]]; then msg_done "no link" return 1 fi done if [[ -n "$mtu" ]]; then - 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 } @@ -164,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 a7bd496f32..ef2d743d97 100755 --- a/board/common/overlay/etc/init.d/S41netwatch +++ b/board/common/overlay/etc/init.d/S41netwatch @@ -1,29 +1,31 @@ #!/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 -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() { 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 3e049c18d8..cdd700d9ad 100755 --- a/board/common/overlay/etc/init.d/S43firewall +++ b/board/common/overlay/etc/init.d/S43firewall @@ -1,25 +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" -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 -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" - 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 e6c7c3ffed..419964cd49 100755 --- a/board/common/overlay/etc/init.d/S45dnsmasq +++ b/board/common/overlay/etc/init.d/S45dnsmasq @@ -1,33 +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" -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 -test -n "$os_version" || source /etc/init.d/base 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 0390037222..941e741f4d 100755 --- a/board/common/overlay/etc/init.d/S50date +++ b/board/common/overlay/etc/init.d/S50date @@ -1,60 +1,49 @@ #!/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" -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 -n "$OS_VERSION" || source /etc/init.d/base -test -f $conf || exit 0 +prepare_conf $CONF $SYS_CONF $BOOT_CONF +prepare_conf $NTP_CONF $SYS_NTP_CONF $BOOT_NTP_CONF -test -n "$os_version" || source /etc/init.d/base +test -f $CONF || exit 0 -test "$os_networkless" == "true" && exit 0 +test "$OS_NETWORKLESS" == "true" && exit 0 date_timeout=10 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 @@ -67,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 } @@ -106,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..b825a52453 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 +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..04db9febcd 100755 --- a/board/common/overlay/etc/init.d/S60sshd +++ b/board/common/overlay/etc/init.d/S60sshd @@ -1,12 +1,12 @@ #!/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 +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" @@ -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..1b3f861e50 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 -n "$os_version" || source /etc/init.d/base +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/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 old mode 100755 new mode 100644 index 7b08c9384d..1d262a6e7c --- a/board/common/overlay/etc/init.d/base +++ b/board/common/overlay/etc/init.d/base @@ -1,13 +1,13 @@ -#!/bin/bash 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/conf +test -n "$OS_DEBUG" || source /etc/init.d/os_conf source /etc/init.d/panic + msg_begin() { echo -n " * $1: " } @@ -24,3 +24,37 @@ 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" && -e "$user_conf" ]]; then + cp -rf "$user_conf" "$actual_conf" + grep -E "/boot .*ro[\s,]" /proc/mounts &>/dev/null + RO=$? + test $RO == 0 && mount -o remount,rw /boot + rm -rf $user_conf + test $RO == 0 && mount -o remount,ro /boot + fi + + 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 +} + 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/conf b/board/common/overlay/etc/init.d/conf deleted file mode 100644 index 46ab1a6378..0000000000 --- a/board/common/overlay/etc/init.d/conf +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -_sys_conf="/etc/os.conf" -_boot_conf="/boot/os.conf" -_conf="/data/etc/os.conf" - -if ! [[ -d /data/etc ]]; then - # use boot/system variants if we don't have the data partition mounted - if [[ -f $_boot_conf ]]; then - source $_boot_conf - elif [[ -f $_sys_conf ]]; then - source $_sys_conf - fi - - return -fi - -if ! [[ -f $_conf ]]; then - if [[ -f $_boot_conf ]]; then - cp $_boot_conf $_conf - elif [[ -f $_sys_conf ]]; then - cp $_sys_conf $_conf - fi -fi - -if [[ -f $_conf ]]; then - source $_conf -fi - diff --git a/board/common/overlay/etc/init.d/os_conf b/board/common/overlay/etc/init.d/os_conf new file mode 100644 index 0000000000..8d5f011674 --- /dev/null +++ b/board/common/overlay/etc/init.d/os_conf @@ -0,0 +1,21 @@ + +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 +fi + +if [[ -f $data_conf ]]; then + source $data_conf +fi + +if [[ -f $boot_conf ]]; then + source $boot_conf +fi + +unset sys_conf boot_conf data_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..4c6c992c20 --- a/board/common/overlay/etc/init.d/panic +++ b/board/common/overlay/etc/init.d/panic @@ -1,20 +1,19 @@ -#!/bin/bash -_PANIC_COUNTER_FILE="/var/lib/panic_counter" -_PANIC_REBOOT_DELAY_FACTOR=10 -_PANIC_REBOOT_DELAY_MAX=3600 # reboot at least once an hour in case of panic +PANIC_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 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 56f584fbd9..6c759e1e75 100644 --- a/board/common/overlay/etc/os.conf +++ b/board/common/overlay/etc/os.conf @@ -1,12 +1,12 @@ -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/motioneyeos" -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/motioneyeos" +OS_FIRMWARE_USERNAME="" +OS_FIRMWARE_PASSWORD="" diff --git a/board/common/overlay/etc/version b/board/common/overlay/etc/version index bb599ad14e..140cdc1f3f 100644 --- a/board/common/overlay/etc/version +++ b/board/common/overlay/etc/version @@ -1,4 +1,4 @@ -os_name="motionEyeOS" -os_short_name="motioneyeos" -os_prefix="meye" -os_version="unknown" +OS_NAME="motionEyeOS" +OS_SHORT_NAME="motioneyeos" +OS_PREFIX="meye" +OS_VERSION="unknown" diff --git a/board/common/overlay/sbin/fwupdate b/board/common/overlay/sbin/fwupdate index adb7c4be0d..a383615700 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" @@ -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,21 +77,22 @@ fi #### versions #### function show_versions() { - source $OS_CONF + 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 } @@ -123,11 +123,29 @@ 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 - source $OS_CONF + # 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 /etc/init.d/os_conf # we need this for the OS_ vars + board=$(cat $SYS_BOARD_FILE) url=$1 version=$1 @@ -155,13 +173,11 @@ 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" - 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 82ae420f49..0644c34e22 100755 --- a/board/raspberrypi/overlay/etc/init.d/S05cpufreq +++ b/board/raspberrypi/overlay/etc/init.d/S05cpufreq @@ -1,18 +1,19 @@ #!/bin/bash -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" -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 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..b8ea3272f3 100755 --- a/board/raspberrypi/overlay/etc/init.d/S11throttlewatch +++ b/board/raspberrypi/overlay/etc/init.d/S11throttlewatch @@ -1,8 +1,9 @@ #!/bin/bash -check_interval=30 +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) @@ -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..c874c8b9ef 100755 --- a/board/raspberrypi/overlay/etc/init.d/S13btuart +++ b/board/raspberrypi/overlay/etc/init.d/S13btuart @@ -1,14 +1,15 @@ #!/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 +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 82ae420f49..0644c34e22 100755 --- a/board/raspberrypi2/overlay/etc/init.d/S05cpufreq +++ b/board/raspberrypi2/overlay/etc/init.d/S05cpufreq @@ -1,18 +1,19 @@ #!/bin/bash -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" -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 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..b8ea3272f3 100755 --- a/board/raspberrypi2/overlay/etc/init.d/S11throttlewatch +++ b/board/raspberrypi2/overlay/etc/init.d/S11throttlewatch @@ -1,8 +1,9 @@ #!/bin/bash -check_interval=30 +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) @@ -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..0644c34e22 100755 --- a/board/raspberrypi3/overlay/etc/init.d/S05cpufreq +++ b/board/raspberrypi3/overlay/etc/init.d/S05cpufreq @@ -1,18 +1,19 @@ #!/bin/bash -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" -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 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..b8ea3272f3 100755 --- a/board/raspberrypi3/overlay/etc/init.d/S11throttlewatch +++ b/board/raspberrypi3/overlay/etc/init.d/S11throttlewatch @@ -1,8 +1,9 @@ #!/bin/bash -check_interval=30 +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) @@ -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..c874c8b9ef 100755 --- a/board/raspberrypi3/overlay/etc/init.d/S13btuart +++ b/board/raspberrypi3/overlay/etc/init.d/S13btuart @@ -1,12 +1,15 @@ #!/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 -n "$os_version" || source /etc/init.d/base +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 function start() { if [[ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ]] ; then