diff --git a/board/common/busybox-1.22.x.config b/board/common/busybox-1.22.x.config index 09e062bdfd..13ce081b61 100644 --- a/board/common/busybox-1.22.x.config +++ b/board/common/busybox-1.22.x.config @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit -# Busybox version: 1.23.1 -# Tue May 5 19:36:40 2015 +# Busybox version: 1.23.2 +# Sat Nov 14 19:10:47 2015 # CONFIG_HAVE_DOT_CONFIG=y @@ -279,8 +279,8 @@ CONFIG_SORT=y CONFIG_FEATURE_SORT_BIG=y # CONFIG_SPLIT is not set # CONFIG_FEATURE_SPLIT_FANCY is not set -# CONFIG_STAT is not set -# CONFIG_FEATURE_STAT_FORMAT is not set +CONFIG_STAT=y +CONFIG_FEATURE_STAT_FORMAT=y CONFIG_STTY=y # CONFIG_SUM is not set CONFIG_SYNC=y diff --git a/board/common/overlay/etc/init.d/S00osinit b/board/common/overlay/etc/init.d/S00osinit deleted file mode 100755 index 58487cdcc6..0000000000 --- a/board/common/overlay/etc/init.d/S00osinit +++ /dev/null @@ -1,94 +0,0 @@ -#!/bin/bash - -sys_conf="/etc/os.conf" -conf="/data/etc/os.conf" - -if [ -f $sys_conf ] && ! [ -f $conf ]; then - cp $sys_conf $conf -fi - -if [ -f $conf ]; then - source $conf -fi - -mount_all() { - echo -n "Mounting filesystems: " - - /bin/mkdir -p /dev/pts - /bin/mkdir -p /dev/shm - /bin/mount --make-shared / - /bin/mount -a - - echo "done" - - if [ "$os_debug" == "true" ]; then - echo -n "Remounting boot partition read-write: " - mount -o remount,rw /boot - [ $? == 0 ] && echo "done" || echo "failed" - - echo -n "Remounting root partition read-write: " - mount -o remount,rw / - [ $? == 0 ] && echo "done" || echo "failed" - fi -} - -unmount_all() { - /bin/umount -a -r - /sbin/swapoff -a -} - -set_hostname() { - echo -n "Setting hostname: " - - if [ -f /data/etc/hostname ]; then - hostname=$(cat /data/etc/hostname) - else - hostname="$os_prefix-$board_sn" - fi - - /bin/hostname $hostname - echo "127.0.0.1 localhost $hostname" > /etc/hosts - - echo "done" -} - -load_modules() { - echo -n "Loading kernel modules: " - - if [ -r /etc/modules ]; then - cat /etc/modules | while read line; do test -n "$line" && /sbin/modprobe $line; done - fi - - if [ -r /data/etc/modules ]; then - cat /data/etc/modules | while read line; do test -n "$line" && /sbin/modprobe $line; done - fi - - echo "done" -} - -start() { - mount_all - set_hostname - load_modules -} - -stop() { - unmount_all -} - -case "$1" in - start) - start - ;; - - stop) - stop - ;; - - *) - echo "Usage: $0 {start|stop}" - exit 1 -esac - -exit $? - diff --git a/board/common/overlay/etc/init.d/S01hostname b/board/common/overlay/etc/init.d/S01hostname new file mode 100755 index 0000000000..de378e7e7c --- /dev/null +++ b/board/common/overlay/etc/init.d/S01hostname @@ -0,0 +1,34 @@ +#!/bin/bash + +sys_hostname_file="/etc/hostname" +hostname_file="/data/etc/hostname" + +case "$1" in + start) + msg_begin "Setting hostname" + + if [ -f $hostname_file ]; then + hostname=$(cat $hostname_file) + elif [ -f $sys_hostname_file ]; then + hostname=$(cat $sys_hostname_file) + else + hostname="$os_prefix-$board_sn" + fi + + /bin/hostname $hostname + echo "127.0.0.1 localhost $hostname" > /etc/hosts + + msg_done + ;; + + stop) + true + ;; + + *) + echo "Usage: $0 {start}" + exit 1 +esac + +exit $? + diff --git a/board/common/overlay/etc/init.d/S02modules b/board/common/overlay/etc/init.d/S02modules new file mode 100755 index 0000000000..4ddeeba0f9 --- /dev/null +++ b/board/common/overlay/etc/init.d/S02modules @@ -0,0 +1,31 @@ +#!/bin/bash + +sys_modules_file="/etc_modules" +modules_file="/data/etc_modules" + +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; done + fi + + if [ -r $modules_file ]; then + cat $modules_file | while read line; do test -n "$line" && /sbin/modprobe $line; done + fi + + msg_done + ;; + + stop) + true + ;; + + *) + echo "Usage: $0 {start}" + exit 1 +esac + +exit $? + diff --git a/board/common/overlay/etc/init.d/S02watchdog b/board/common/overlay/etc/init.d/S02watchdog deleted file mode 100755 index 1750fbf520..0000000000 --- a/board/common/overlay/etc/init.d/S02watchdog +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -test -c /dev/watchdog || exit 0 - -case "$1" in - start) - echo -n "Starting watchdog: " - watchdog -t 5 /dev/watchdog - [ $? == 0 ] && echo "done" || echo "failed" - ;; - - stop) - echo -n "Stopping watchdog: " - kill `pidof watchdog` 2>/dev/null - [ $? == 0 ] && echo "done" || echo "failed" - ;; - - restart|reload) - ;; - - *) - echo $"Usage: $0 {start|stop|restart}" - exit 1 -esac - -exit $? - diff --git a/board/common/overlay/etc/init.d/S01logging b/board/common/overlay/etc/init.d/S03logging similarity index 52% rename from board/common/overlay/etc/init.d/S01logging rename to board/common/overlay/etc/init.d/S03logging index a37052d8e0..c618089b2f 100755 --- a/board/common/overlay/etc/init.d/S01logging +++ b/board/common/overlay/etc/init.d/S03logging @@ -1,26 +1,20 @@ -#!/bin/sh -# -# Start logging -# +#!/bin/bash case "$1" in start) - echo -n "Starting logging: " + msg_begin "Starting logging" start-stop-daemon -b -S -q -m -p /var/run/syslogd.pid --exec /sbin/syslogd -- -n - echo "done" + msg_done ;; stop) - echo -n "Stopping logging: " + msg_begin "Stopping logging" start-stop-daemon -K -q -p /var/run/syslogd.pid - echo "done" - ;; - - restart|reload) + msg_done ;; *) - echo "Usage: $0 {start|stop|restart}" + echo "Usage: $0 {start|stop}" exit 1 esac diff --git a/board/common/overlay/etc/init.d/S10watchdog b/board/common/overlay/etc/init.d/S10watchdog new file mode 100755 index 0000000000..9ece91787f --- /dev/null +++ b/board/common/overlay/etc/init.d/S10watchdog @@ -0,0 +1,33 @@ +#!/bin/bash + +# these aren't used in this file but +# throughout various init scripts +sys_watch_conf="/etc/watch.conf" +watch_conf="/data/etc/watch.conf" + +if [ -f $sys_watch_conf ] && ! [ -f $watch_conf ]; then + cp $sys_watch_conf $watch_conf +fi + +test -c /dev/watchdog || exit 0 + +case "$1" in + start) + msg_begin "Starting watchdog" + watchdog -t 5 /dev/watchdog + test $? == 0 && msg_done || msg_fail + ;; + + stop) + msg_begin "Stopping watchdog" + killall watchdog &>/dev/null + test $? == 0 && msg_done || msg_fail + ;; + + *) + echo $"Usage: $0 {start|stop}" + exit 1 +esac + +exit $? + diff --git a/board/common/overlay/etc/init.d/S11datapart b/board/common/overlay/etc/init.d/S11datapart index 4424b3837f..e4094388c1 100755 --- a/board/common/overlay/etc/init.d/S11datapart +++ b/board/common/overlay/etc/init.d/S11datapart @@ -1,86 +1,42 @@ #!/bin/bash -DISK_DEV="/dev/mmcblk0" -DATA_DEV="${DISK_DEV}p3" +disk_dev="/dev/mmcblk0" +data_dev="${disk_dev}p3" -start() { - echo "Setting up data partition" - - # if the data partition is not present, create and format it - if ! [ -b $DATA_DEV ]; then - echo "Creating data partition" - echo -e "n - p - 3 - \n - \n - w - " | /sbin/fdisk $DISK_DEV - sync - partx -a $DISK_DEV &>/dev/null - - echo "Formatting data partition" - mkfs.ext4 $DATA_DEV - - echo "Mounting data partition" - mount /data - fi - - if df /dev/mmcblk0p3 >/dev/null 2>&1; then - # make sure required directories exist - mkdir -p /data/etc - mkdir -p /data/log - mkdir -p /data/output - mkdir -p /data/media - chmod 775 /data/output - chmod 775 /data/media - - # mount any partitions depending on data folders - mount -a - - # make sure a localtime symlink exists - if ! [ -e /data/etc/localtime ]; then - ln -s /usr/share/zoneinfo/UTC /data/etc/localtime - fi - - # make sure root and admin users exist - touch /data/etc/shadow - chmod go-rwx /data/etc/shadow - if ! grep root /data/etc/shadow &>/dev/null; then - echo 'root::::::::' >> /data/etc/shadow - fi - if ! grep admin /data/etc/shadow &>/dev/null; then - echo 'admin::::::::' >> /data/etc/shadow - fi - - # set root and admin passwords - if [ -f /data/etc/motion.conf ]; then - password=$(cat /data/etc/motion.conf | grep admin_password | cut -d ' ' -f 3-) - fi - if [ -z "$password" ]; then - echo "Setting empty admin password" - else - echo "Setting custom root/admin password" - fi - - rm -f /data/etc/shadow+ - - echo -en "$password\n$password\n" | passwd &>/dev/null # root - echo -en "$password\n$password\n" | passwd admin &>/dev/null # admin - - sed -r -i 's/root:([^:]+):[[:digit:]]+:/root:\1::/' /data/etc/shadow # removes pwd expiration - sed -r -i 's/admin:([^:]+):[[:digit:]]+:/admin:\1::/' /data/etc/shadow # removes pwd expiration - - # copy common sys config files - if [ -f /etc/watch.conf ] && ! [ -f /data/etc/watch.conf ]; then - cp /etc/watch.conf /data/etc/watch.conf - fi - fi -} +test -b $data_dev && exit 0 case "$1" in start) - start + msg_begin "Creating data partition" + echo -e "n + p + 3 + \n + \n + w" | /sbin/fdisk $disk_dev >/dev/null + test $? == 0 && msg_done || msg_fail + sync + partx -a $disk_dev &>/dev/null + + msg_begin "Formatting data partition" + mkfs.ext4 $data_dev + test $? == 0 && msg_done || msg_fail + + msg_begin "Mounting data partition" + mount /data + test $? == 0 && msg_done || msg_fail + + msg_begin "Creating required data files" + mkdir /data/etc + mkdir /data/log + mkdir -m 775 /data/output + mkdir -m 775 /data/media + + ln -s /usr/share/zoneinfo/UTC /data/etc/localtime + msg_done + + # mount other partitions depending on data + mount -a ;; stop) @@ -88,7 +44,7 @@ case "$1" in ;; *) - echo "Usage: $0 {start|stop}" + echo "Usage: $0 {start}" exit 1 esac diff --git a/board/common/overlay/etc/init.d/S10udev b/board/common/overlay/etc/init.d/S12udev similarity index 70% rename from board/common/overlay/etc/init.d/S10udev rename to board/common/overlay/etc/init.d/S12udev index dd8d975b82..1e243eab3f 100755 --- a/board/common/overlay/etc/init.d/S10udev +++ b/board/common/overlay/etc/init.d/S12udev @@ -1,24 +1,25 @@ -#!/bin/sh +#!/bin/bash -[ -f /etc/udev/udev.conf ] || exit 0 +test -f /etc/udev/udev.conf || exit 0 source /etc/udev/udev.conf start() { - echo -n "Starting eudev: " + msg_begin "Starting eudev" echo '\000\000\000\000' > /proc/sys/kernel/hotplug /sbin/udevd --daemon - [ $? == 0 ] && echo "done" || echo "failed" + test $? == 0 && msg_done || msg_fail + /sbin/udevadm trigger --type=subsystems --action=add /sbin/udevadm trigger --type=devices --action=add /sbin/udevadm settle --timeout=30 } stop() { - echo -n "Stopping eudev: " + msg_begin "Stopping eudev" udevadm control --stop-exec-queue - killall udevd - [ $? == 0 ] && echo "done" || echo "failed" + killall udevd &>/dev/null + test $? == 0 && msg_done || msg_fail } case "$1" in @@ -41,5 +42,5 @@ case "$1" in ;; esac -exit 0 +exit $? diff --git a/board/common/overlay/etc/init.d/S13mountall b/board/common/overlay/etc/init.d/S13mountall new file mode 100755 index 0000000000..4ee2629f96 --- /dev/null +++ b/board/common/overlay/etc/init.d/S13mountall @@ -0,0 +1,41 @@ +#!/bin/bash + +sys_conf="/etc/os.conf" +conf="/data/etc/os.conf" + +if [ -f $sys_conf ] && ! [ -f $conf ]; then + cp $sys_conf $conf +fi + +if [ -f $conf ]; then + source $conf +fi + +case "$1" in + start) + msg_begin "Mounting filesystems" + /bin/mount -a + test $? == 0 && msg_done || msg_fail + + if [ "$os_debug" == "true" ]; then + msg_begin "Remounting boot partition read-write" + mount -o remount,rw /boot + test $? == 0 && msg_done || msg_fail + + echo -n "Remounting root partition read-write: " + mount -o remount,rw / + test $? == 0 && msg_done || msg_fail + fi + ;; + + stop) + true + ;; + + *) + echo "Usage: $0 {start}" + exit 1 +esac + +exit $? + diff --git a/board/common/overlay/etc/init.d/S21passwd b/board/common/overlay/etc/init.d/S21passwd new file mode 100755 index 0000000000..d3398e577c --- /dev/null +++ b/board/common/overlay/etc/init.d/S21passwd @@ -0,0 +1,43 @@ +#!/bin/bash + +case "$1" in + start) + # make sure root and admin users exist in shadow file + touch /data/etc/shadow + chmod go-rwx /data/etc/shadow + if ! grep root /data/etc/shadow &>/dev/null; then + echo 'root::::::::' >> /data/etc/shadow + fi + if ! grep admin /data/etc/shadow &>/dev/null; then + echo 'admin::::::::' >> /data/etc/shadow + fi + + # set root and admin passwords + password=$(/etc/init.d/adminpw) + if [ -z "$password" ]; then + echo "Setting empty root/admin password" + else + echo "Setting custom root/admin password" + fi + + rm -f /data/etc/shadow+ + rm -f /data/etc/shadow- + + echo -en "$password\n$password\n" | passwd &>/dev/null # root + echo -en "$password\n$password\n" | passwd admin &>/dev/null # admin + + sed -r -i 's/root:([^:]+):[[:digit:]]+:/root:\1::/' /data/etc/shadow # removes pwd expiration + sed -r -i 's/admin:([^:]+):[[:digit:]]+:/admin:\1::/' /data/etc/shadow # removes pwd expiration + ;; + + stop) + true + ;; + + *) + echo "Usage: $0 {start}" + exit 1 +esac + +exit $? + diff --git a/board/common/overlay/etc/init.d/S35wifi b/board/common/overlay/etc/init.d/S35wifi index 90765e845a..277a386f43 100755 --- a/board/common/overlay/etc/init.d/S35wifi +++ b/board/common/overlay/etc/init.d/S35wifi @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash sys_conf="/etc/wpa_supplicant.conf" conf="/data/etc/wpa_supplicant.conf" @@ -11,31 +11,19 @@ watch_conf="/data/etc/watch.conf" link_watch=yes link_watch_timeout=20 -if [ -f $watch_conf ]; then - source $watch_conf -fi +test -f $watch_conf && source $watch_conf if [ -f $sys_conf ] && ! [ -f $conf ]; then - mkdir -p $(dirname $conf) cp $sys_conf $conf fi -if ! [ -f $conf ] || ! [ -s $conf ]; then - exit 0 -fi +test -f $watch_conf || exit 0 -SSID=$(cat ${conf} | grep ssid | grep -v scan_ssid | cut -d '"' -f 2) - -if [ -z "$SSID" ]; then - exit 0 -fi +ssid=$(cat $conf | grep ssid | grep -v scan_ssid | cut -d '"' -f 2) +test -n "$ssid" || exit 0 connected() { - if ip link show dev $iface 2>&1 | grep LOWER_UP > /dev/null 2>&1; then - return 0 - else - return 1 - fi + ip link show dev $iface 2>&1 | grep LOWER_UP &> /dev/null && return 0 || return 1 } watch() { @@ -57,7 +45,7 @@ watch() { } start() { - echo -n "Starting wpa_supplicant: " + msg_begin "Starting wpa_supplicant" # wait up to 5 seconds for interface count=0 @@ -65,13 +53,13 @@ start() { sleep 1 count=$(($count + 1)) if [ $count -ge 5 ]; then - echo "no device" - return + msg_fail "no device" + return 1 fi done - iwconfig $iface power off > /dev/null 2>&1 - $prog -i$iface -c$conf -D$driver -B > $log 2>&1 + iwconfig $iface power off &> /dev/null + $prog -i$iface -c$conf -D$driver -B &> $log count=0 while true; do sleep 1 @@ -81,9 +69,9 @@ start() { fi if [ $count -gt $link_watch_timeout ] || ! pidof wpa_supplicant > /dev/null; then - echo "failed" + msg_fail reboot - return + return 1 fi count=$(($count + 1)) @@ -93,19 +81,14 @@ start() { watch & fi - echo "done" + msg_done } stop() { - echo -n "Shutting down wpa_supplicant: " - kill `pidof wpa_supplicant` 2>/dev/null + msg_begin "Stopping wpa_supplicant" + killall wpa_supplicant &>/dev/null ps | grep wifi | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill - echo "done" -} - -restart() { - stop - start + msg_done } case "$1" in @@ -118,7 +101,8 @@ case "$1" in ;; restart) - restart + stop + start ;; *) diff --git a/board/common/overlay/etc/init.d/S36ppp b/board/common/overlay/etc/init.d/S36ppp index b9da0d2c9c..fd79a2717d 100755 --- a/board/common/overlay/etc/init.d/S36ppp +++ b/board/common/overlay/etc/init.d/S36ppp @@ -1,32 +1,24 @@ -#!/bin/sh +#!/bin/bash sys_conf="/etc/ppp/default" conf="/data/etc/ppp" + prog="/usr/sbin/pppd" -net_dev="ppp0" +dev="ppp0" provider="mobile" watch_conf="/data/etc/watch.conf" -if [ -f $watch_conf ]; then - source $watch_conf -fi +test -f $watch_conf && source $watch_conf if [ -d $sys_conf ] && ! [ -d $conf ]; then - mkdir -p $(dirname $conf) cp -r $sys_conf $conf fi -if ! [ -f $conf/modem ]; then - exit 0 -fi +test -f $conf/modem || exit 0 connected() { - if ifconfig | grep ppp0 >/dev/null 2>&1; then - return 0 - else - return 1 - fi + ifconfig | grep $dev &>/dev/null 2>&1 && return 0 || return 1 } watch() { @@ -54,7 +46,7 @@ start() { product=${venprod[1]} # wait for usb device if [ -n "$vendor" ] && [ -n "$product" ]; then - echo -n "Starting usb_modeswitch: " + msg_begin "Starting usb_modeswitch" count=0 while true; do if lsusb | grep $vendor:$product >/dev/null 2>&1 || [ $count -gt $link_watch_timeout ]; then @@ -65,11 +57,11 @@ start() { sleep 1 done /usr/sbin/usb_modeswitch -c /etc/usb_modeswitch.conf -v $vendor -p $product > /var/log/usb_modeswitch.log 2>&1 - echo "done" + msg_done fi fi - echo -n "Starting pppd: " + msg_begin "Starting pppd" # wait for modem modem=$(head -n 1 $conf/modem) @@ -84,8 +76,8 @@ start() { done if ! [ -e /dev/$modem ]; then - echo "modem /dev/$modem not present" - return + msg_fail "modem /dev/$modem not present" + return 1 fi $prog call $provider @@ -98,9 +90,9 @@ start() { fi if [ $count -gt $link_watch_timeout ] || ! pidof pppd > /dev/null; then - echo "failed" + msg_fail reboot - return + return 1 fi count=$(($count + 1)) @@ -110,19 +102,14 @@ start() { watch & fi - echo "done" + msg_done } stop() { - echo -n "Shutting down pppd: " - kill `pidof pppd` 2>/dev/null + msg_begin "Stopping pppd" + killall pppd &>/dev/null ps | grep ppp | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill - echo "done" -} - -restart() { - stop - start + msg_done } case "$1" in @@ -135,7 +122,8 @@ case "$1" in ;; restart) - restart + stop + start ;; *) diff --git a/board/common/overlay/etc/init.d/S40network b/board/common/overlay/etc/init.d/S40network index b12a1dc3a2..ec8566b5f2 100755 --- a/board/common/overlay/etc/init.d/S40network +++ b/board/common/overlay/etc/init.d/S40network @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash mkdir -p /var/lib/dhcp dh_conf="/var/cache/dhclient.conf" @@ -66,22 +66,23 @@ start_lo() { } start_wlan() { - if ! ifconfig $wlan >/dev/null 2>&1; then - echo "$wlan: no device" - return + msg_begin "Configuring wireless network" + if ! ifconfig $wlan &>/dev/null; then + msg_fail "no device" + return 1 fi if [ "$(cat /sys/class/net/$wlan/carrier 2>/dev/null)" != "1" ]; then - echo "$wlan: no link" - return + msg_fail "no link" + return 1 fi if [ -n "$static_ip" ]; then - echo "$wlan: setting static IP to $static_ip" + msg_done $static_ip ifconfig $wlan $static_ip up static_ip="" # won't be used again else - echo "$wlan: starting dhclient" + msg_done dhcp dhclient -cf "$dh_conf" $wlan fi @@ -91,13 +92,15 @@ start_wlan() { } start_eth() { + msg_begin "Configuring wired network" + # wait up to 3 seconds for driver count=0 while ! ifconfig $eth >/dev/null 2>&1; do sleep 1 count=$(($count + 1)) if [ $count -ge 3 ]; then - echo "$eth: no device" + msg_done "no device" return fi done @@ -110,8 +113,8 @@ start_eth() { while [ "$(cat /sys/class/net/$eth/operstate 2>&1)" == "unknown" ]; do sleep 1 count=$(($count + 1)) - if [ $count -ge 3 ]; then - echo "$eth: no link" + if [ $count -ge 3 ]; then + msg_done "no link" return fi done @@ -122,17 +125,17 @@ start_eth() { sleep 1 count=$(($count + 1)) if [ $count -ge $link_nego_timeout ]; then - echo "$eth: no link" + msg_done "no link" return fi done if [ -n "$static_ip" ]; then - echo "$eth: setting static IP to $static_ip" + msg_done $static_ip ifconfig $eth $static_ip up static_ip="" # won't be used again else - echo "$eth: starting dhclient" + msg_done dhcp dhclient -cf "$dh_conf" $eth fi @@ -149,11 +152,13 @@ start() { hostname=$(hostname) echo "send host-name = \"$hostname\";" > /var/cache/dhclient.conf + ssid=$(cat /data/etc/wpa_supplicant.conf 2>&1 | grep ssid | grep -v scan_ssid | cut -d '"' -f 2) + start_lo - start_wlan + + test -n "$ssid" && start_wlan # if wifi or ppp connection configured, start eth in background - ssid=$(cat /data/etc/wpa_supplicant.conf 2>&1 | grep ssid | grep -v scan_ssid | cut -d '"' -f 2) if [ -n "$ssid" ] || [ -r /data/etc/ppp/modem ]; then start_eth &>/dev/null & else @@ -161,36 +166,37 @@ start() { fi if [ -n "$static_gw" ]; then - echo "setting static gateway to $static_gw" + msg_begin "setting static gateway to $static_gw" ip route add default via $static_gw + test $? == 0 && msg_done || msg_fail fi if [ -n "$static_dns" ]; then - echo "setting static DNS server to $static_dns" + msg_begin "setting static DNS server to $static_dns" echo "nameserver $static_dns" > /etc/resolv.conf + test $? == 0 && msg_done || msg_fail fi +} - # print the current network configuration - ifconfig -a +stop() { + msg_begin "Stopping network" + killall dhclient &>/dev/null + ps | grep S40network | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill + msg_done } case "$1" in start) - echo -n "Starting network: " start - echo "done" ;; stop) - echo -n "Stopping network: " - killall dhclient - ps | grep S40network | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill - echo "done" + stop ;; - restart|reload) - "$0" stop - "$0" start + restart) + stop + start ;; *) diff --git a/board/common/overlay/etc/init.d/S41netwatch b/board/common/overlay/etc/init.d/S41netwatch index befa1d0a01..8031f02599 100755 --- a/board/common/overlay/etc/init.d/S41netwatch +++ b/board/common/overlay/etc/init.d/S41netwatch @@ -1,19 +1,13 @@ -#!/bin/sh +#!/bin/bash watch_conf="/data/etc/watch.conf" netwatch_retries=3 netwatch_timeout=5 netwatch_interval=20 -if [ -f $watch_conf ]; then - source $watch_conf -else - exit -fi +test -f $watch_conf && source $watch_conf || exit 0 -if [ -z "$netwatch_host" ] || [ -z "$netwatch_port" ]; then - exit -fi +test -z "$netwatch_host" || -z "$netwatch_port" && exit 0 watch() { count=0 @@ -36,20 +30,20 @@ watch() { case "$1" in start) - echo -n "Starting netwatch: " + msg_begin "Starting netwatch" watch & - echo "done" + msg_done ;; stop) - echo -n "Stopping netwatch: " + msg_begin "Stopping netwatch" ps | grep netwatch | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill - echo "done" + msg_done ;; - restart|reload) - "$0" stop - "$0" start + restart) + stop + start ;; *) diff --git a/board/common/overlay/etc/init.d/S50date b/board/common/overlay/etc/init.d/S50date index 6523d353ad..e0adb2bd61 100755 --- a/board/common/overlay/etc/init.d/S50date +++ b/board/common/overlay/etc/init.d/S50date @@ -1,16 +1,13 @@ -#!/bin/sh +#!/bin/bash sys_conf="/etc/date.conf" conf="/data/etc/date.conf" if [ -f $sys_conf ] && ! [ -f $conf ]; then - mkdir -p $(dirname $conf) cp $sys_conf $conf fi -if ! [ -f $conf ]; then - exit -fi +test -f $conf || exit 0 date_timeout=10 date_method=http @@ -42,40 +39,40 @@ set_current_date_ntp() { } start_http() { - echo -n "Setting current date using http: " + msg_begin "Setting current date using http" set_current_date_http - [ $? == 0 ] && date || echo "failed" + test $? == 0 && msg_done $(date) || msg_fail - echo -n "Starting http date updater: " + msg_begin "Starting http date updater" while true; do sleep $date_interval set_current_date_http done & - [ $? == 0 ] && echo "done" || echo "failed" + msg_done } start_ntp() { mkdir -p /var/lib/ntp - echo -n "Setting current date using ntp: " + msg_begin "Setting current date using ntp" set_current_date_ntp - [ $? == 0 ] && date || echo "failed" + test $? == 0 && msg_done $(date) || msg_fail - echo -n "Starting ntpd: " + msg_begin "Starting ntpd" ntpd -g -c /etc/ntp.conf - [ $? == 0 ] && echo "done" || echo "failed" + test $? == 0 && msg_done || msg_fail } stop_http() { - echo -n "Shutting down date updater: " + msg_begin "Stopping date updater" ps | grep S60date | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill - [ $? == 0 ] && echo "done" || echo "failed" + test $? == 0 && msg_done || msg_fail } stop_ntp() { - echo -n "Shutting down ntpd: " - kill `pidof ntpd`&>/dev/null - [ $? == 0 ] && echo "done" || echo "failed" + msg_begin "Stopping ntpd" + killall ntpd &>/dev/null + test $? == 0 && msg_done || msg_fail } start() { @@ -94,11 +91,6 @@ stop() { fi } -restart() { - stop - start -} - case "$1" in start) start @@ -109,7 +101,8 @@ case "$1" in ;; restart) - restart + stop + start ;; *) diff --git a/board/common/overlay/etc/init.d/S51crond b/board/common/overlay/etc/init.d/S51crond index c24490d273..4c109d659c 100755 --- a/board/common/overlay/etc/init.d/S51crond +++ b/board/common/overlay/etc/init.d/S51crond @@ -1,17 +1,18 @@ -#!/bin/sh - -mkdir -p /data/etc/crontabs/ +#!/bin/bash start() { - echo -n "Starting crond: " + msg_begin "Starting crond" + + mkdir -p /data/etc/crontabs/ + /usr/sbin/crond - [ $? == 0 ] && echo "done" || echo "failed" + test $? == 0 && msg_done || msg_fail } stop() { - echo -n "Stopping crond: " - kill `pidof crond` 2>/dev/null - [ $? == 0 ] && echo "done" || echo "failed" + msg_begin "Stopping crond" + killall crond &>/dev/null + test $? == 0 && msg_done || msg_fail } case "$1" in diff --git a/board/common/overlay/etc/init.d/S60sshd b/board/common/overlay/etc/init.d/S60sshd index 2efc5cd2cd..025faadb07 100755 --- a/board/common/overlay/etc/init.d/S60sshd +++ b/board/common/overlay/etc/init.d/S60sshd @@ -1,34 +1,26 @@ -#!/bin/sh +#!/bin/bash conf="/etc/sshd_config" -# Make sure the ssh-keygen program exists -[ -f /usr/bin/ssh-keygen ] || exit 0 - -# Create any missing keys -/usr/bin/ssh-keygen -A - -umask 077 +test -f $conf || exit 0 start() { - echo -n "Starting sshd: " + msg_begin "Starting sshd" + + # create any missing keys + /usr/bin/ssh-keygen -A + umask 077 hostname=$(hostname) echo "Welcome to $hostname!" > /var/cache/sshd_banner + /usr/sbin/sshd -f $conf - touch /var/lock/sshd - echo "done" + test $? == 0 && msg_done || msg_fail } stop() { - echo -n "Stopping sshd: " - killall sshd - rm -f /var/lock/sshd - echo "done" -} - -restart() { - stop - start + msg_begin "Stopping sshd" + killall sshd &>/dev/null + test $? == 0 && msg_done || msg_fail } case "$1" in @@ -38,6 +30,7 @@ case "$1" in stop) stop + start ;; restart|reload) diff --git a/board/common/overlay/etc/init.d/S61proftpd b/board/common/overlay/etc/init.d/S61proftpd index 177c472fc9..5effec7b3c 100755 --- a/board/common/overlay/etc/init.d/S61proftpd +++ b/board/common/overlay/etc/init.d/S61proftpd @@ -1,20 +1,19 @@ -#!/bin/sh +#!/bin/bash -[ -f /etc/proftpd.conf ] || exit 0 - -mkdir -p /var/run/proftpd -touch /var/log/wtmp +test -f /etc/proftpd.conf || exit 0 start() { - echo -n "Starting proftpd: " + msg_begin "Starting proftpd" + mkdir -p /var/run/proftpd + touch /var/log/wtmp /usr/sbin/proftpd &>/dev/null - [ $? == 0 ] && echo "done" || echo "failed" + test $? == 0 && msg_done || msg_fail } stop() { - echo -n "Stopping proftpd: " - kill -9 `pidof proftpd` 2>/dev/null - [ $? == 0 ] && echo "done" || echo "failed" + msg_begin "Stopping proftpd" + killall proftpd &>/dev/null + test $? == 0 && msg_done || msg_fail } case "$1" in diff --git a/board/common/overlay/etc/init.d/S62smb b/board/common/overlay/etc/init.d/S62smb index 981a9b35c6..d7ff9d659e 100755 --- a/board/common/overlay/etc/init.d/S62smb +++ b/board/common/overlay/etc/init.d/S62smb @@ -1,46 +1,34 @@ -#!/bin/sh +#!/bin/bash -[ -f /etc/samba/smb.conf ] || exit 0 - -mkdir -p /var/log/samba -mkdir -p /var/lib/samba/private +test -f /etc/samba/smb.conf || exit 0 start() { - echo -n "Setting smb admin password: " - if [ -f /data/etc/motion.conf ]; then - password=$(cat /data/etc/motion.conf | grep admin_password | cut -d ' ' -f 3) - fi + msg_begin "Setting smb admin password" + + mkdir -p /var/log/samba + mkdir -p /var/lib/samba/private + + password=$(/etc/init.d/adminpw) echo -e "$password\n$password\n" | /usr/bin/smbpasswd -a admin -s > /dev/null - [ $? == 0 ] && echo "done" || echo "failed" + test $? == 0 && msg_done || msg_fail - echo -n "Starting smbd: " + msg_begin "Starting smbd" smbd -D - [ $? == 0 ] && echo "done" || echo "failed" + test $? == 0 && msg_done || msg_fail - echo -n "Starting nmbd: " + msg_begin "Starting nmbd" nmbd -D - [ $? == 0 ] && echo "done" || echo "failed" + test $? == 0 && msg_done || msg_fail } stop() { - echo -n "Shutting down smbd: " - kill -9 `pidof smbd` 2>/dev/null - [ $? == 0 ] && echo "done" || echo "failed" + msg_begin "Stopping smbd" + killall smbd &>/dev/null + test $? == 0 && msg_done || msg_fail - echo -n "Shutting down nmbd: " - kill -9 `pidof nmbd` 2>/dev/null - [ $? == 0 ] && echo "done" || echo "failed" -} - -restart() { - stop - start -} - -reload() { - echo -n "Reloading smb.conf file: " - kill -HUP `pidof smbd` 2>/dev/null - [ $? == 0 ] && echo "done" || echo "failed" + msg_begin "Stopping nmbd" + killall nmbd &>/dev/null + test $? == 0 && msg_done || msg_fail } case "$1" in @@ -53,16 +41,14 @@ case "$1" in ;; restart) - restart - ;; - - reload) - reload + stop + start ;; *) - echo "Usage: $0 {start|stop|restart|reload}" + echo "Usage: $0 {start|stop|restart}" exit 1 esac exit $? + diff --git a/board/common/overlay/etc/init.d/S85motioneye b/board/common/overlay/etc/init.d/S85motioneye index 9e841e20e1..862ee9f559 100755 --- a/board/common/overlay/etc/init.d/S85motioneye +++ b/board/common/overlay/etc/init.d/S85motioneye @@ -1,29 +1,22 @@ -#!/bin/sh +#!/bin/bash sys_conf="/etc/motioneye.conf" conf="/data/etc/motioneye.conf" +motion_conf="/data/etc/motion.conf" watch_timeout=120 dev_v4l_by_id="/dev/v4l/by-id/" if [ -f $sys_conf ] && ! [ -f $conf ]; then - mkdir -p $(dirname $conf) cp $sys_conf $conf fi -if [ -f "$conf" ]; then - opts=$(cat "$conf" | while read line; do echo "--$line"; done) - port=$(echo "$opts" | grep -oE 'port [[:digit:]]+' | cut -d ' ' -f 2) -else - echo "configuration file not present" - exit 0 -fi +test -f "$conf" || exit 0 + +opts=$(cat "$conf" | while read line; do echo "--$line"; done) +port=$(echo "$opts" | grep -oE 'port [[:digit:]]+' | cut -d ' ' -f 2) responsive() { - if wget -q -t 1 -T 2 -O - http://127.0.0.1:$port/static/img/motioneye-logo.svg >/dev/null 2>&1; then - return 0 - else - return 1 - fi + wget -q -t 1 -T 2 -O - http://127.0.0.1:$port/static/img/motioneye-logo.svg &>/dev/null && return 0 || return 1 } watch() { @@ -62,7 +55,7 @@ find_persistent_device() { } start() { - echo -n "Starting motioneye: " + msg_begin "Starting motioneye" meyectl startserver -b -c $conf -l count=0 @@ -74,16 +67,16 @@ start() { fi if [ $count -gt $watch_timeout ]; then - echo "failed" - reboot - return + msg_fail + reboot + return 1 fi count=$(($count + 1)) done # add connected camera(s) with default settings - if responsive && ! [ -f /data/etc/motion.conf ]; then + if responsive && ! [ -f $motion_conf ]; then count=$(ls /dev/video* 2>/dev/null | wc -l) index=1 for device in $(ls /dev/video* 2>/dev/null); do @@ -104,20 +97,16 @@ start() { watch & - echo "done" + msg_done } stop() { - echo -n "Shutting down motioneye: " - meyectl stopserver -c $conf &>/dev/null && echo "done" || echo "failed" + msg_begin "Stopping motioneye" + meyectl stopserver -c $conf &>/dev/null + test $? == 0 && msg_done || msg_fail ps | grep motioneye | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill } -restart() { - stop - start -} - case "$1" in start) start @@ -128,7 +117,8 @@ case "$1" in ;; restart) - restart + stop + start ;; *) diff --git a/board/common/overlay/etc/init.d/S99userinit b/board/common/overlay/etc/init.d/S99userinit index 9ada77a624..d79a7728b6 100755 --- a/board/common/overlay/etc/init.d/S99userinit +++ b/board/common/overlay/etc/init.d/S99userinit @@ -1,12 +1,14 @@ #!/bin/bash +userinit_sh="/data/etc/userinit.sh" + +test -f $userinit_sh || exit 0 + case "$1" in start) - if [ -r /data/etc/userinit.sh ]; then - echo -n "Executing user init script: " - /bin/bash /data/etc/userinit.sh - echo "done" - fi + msg_begin "Executing user init script" + /bin/bash $userinit_sh + test $? == 0 && msg_done || msg_fail ;; stop) @@ -14,7 +16,7 @@ case "$1" in ;; *) - echo "Usage: $0 {start|stop}" + echo "Usage: $0 {start}" exit 1 esac diff --git a/board/common/overlay/etc/init.d/adminpw b/board/common/overlay/etc/init.d/adminpw new file mode 100755 index 0000000000..d51501c74b --- /dev/null +++ b/board/common/overlay/etc/init.d/adminpw @@ -0,0 +1,6 @@ +#!/bin/bash + +if [ -f /data/etc/motion.conf ]; then + cat /data/etc/motion.conf | grep admin_password | cut -d ' ' -f 3- +fi + diff --git a/board/common/overlay/etc/init.d/functions b/board/common/overlay/etc/init.d/functions index 7a693aac0b..d3dc896465 100755 --- a/board/common/overlay/etc/init.d/functions +++ b/board/common/overlay/etc/init.d/functions @@ -1,3 +1,14 @@ #!/bin/bash +msg_begin() { + echo -n "$1: " +} + +msg_done() { + test -n "$1" && echo $1 || echo "done" +} + +msg_fail() { + test -n "$1" && echo $1 || echo "failed" +} diff --git a/board/common/overlay/etc/init.d/mountsys b/board/common/overlay/etc/init.d/mountsys new file mode 100755 index 0000000000..744b29a360 --- /dev/null +++ b/board/common/overlay/etc/init.d/mountsys @@ -0,0 +1,10 @@ +#!/bin/bash + +/bin/mkdir -p /dev/pts +/bin/mkdir -p /dev/shm +/bin/mount --make-shared / +/bin/mount -a -t proc +/bin/mount -a -t devpts +/bin/mount -a -t tmpfs +/bin/mount -a -t sysfs + diff --git a/board/common/overlay/etc/init.d/rcK b/board/common/overlay/etc/init.d/rcK index 74fcda1b50..44e5cb49b0 100755 --- a/board/common/overlay/etc/init.d/rcK +++ b/board/common/overlay/etc/init.d/rcK @@ -11,7 +11,7 @@ echo "---- shutting down $os_name $os_version ----" >> $boot_log # stop all init scripts in /etc/init.d, # executing them in numerical order. (for i in /etc/init.d/S??*; do - [ ! -f "$i" ] && continue + [ ! -x "$i" ] && continue [ -f /data/etc/no_$(basename $i) ] && continue ( diff --git a/board/common/overlay/etc/init.d/rcS b/board/common/overlay/etc/init.d/rcS index 925bca7861..bb0dc01c76 100755 --- a/board/common/overlay/etc/init.d/rcS +++ b/board/common/overlay/etc/init.d/rcS @@ -18,7 +18,7 @@ echo "---- booting $os_name $os_version----" >> $boot_log # start all init scripts in /etc/init.d, # executing them in numerical order. (for i in /etc/init.d/S??*; do - [ ! -f "$i" ] && continue + [ ! -x "$i" ] && continue [ -f /data/etc/no_$(basename $i) ] && continue ( diff --git a/board/common/overlay/etc/init.d/vars b/board/common/overlay/etc/init.d/vars index 1b1fed0e91..334a017596 100755 --- a/board/common/overlay/etc/init.d/vars +++ b/board/common/overlay/etc/init.d/vars @@ -1,6 +1,6 @@ #!/bin/bash source /etc/version -board=$(cat /etc/board) board_sn=$(/etc/init.d/boardsn) +board_name=$(cat /etc/board) diff --git a/board/common/overlay/etc/inittab b/board/common/overlay/etc/inittab index 08afd810c3..f9c98a75cb 100644 --- a/board/common/overlay/etc/inittab +++ b/board/common/overlay/etc/inittab @@ -14,6 +14,7 @@ # process == program to run # Startup the system +::sysinit:/etc/init.d/mountsys ::sysinit:/etc/init.d/rcS # Put a getty on the serial port @@ -24,5 +25,6 @@ tty1::respawn:/sbin/getty -L tty1 115200 vt100 ::ctrlaltdel:/sbin/reboot # Stuff to do before rebooting -null::shutdown:/etc/init.d/rcK +::shutdown:/etc/init.d/rcK +::shutdown:/bin/umount -a -r diff --git a/board/common/overlay/etc/issue b/board/common/overlay/etc/issue index 29a6fbe6a9..b9d3c46ab7 100644 --- a/board/common/overlay/etc/issue +++ b/board/common/overlay/etc/issue @@ -1 +1 @@ -Welcome to motionEye! +Welcome to \n! diff --git a/board/common/overlay/etc/os.conf b/board/common/overlay/etc/os.conf index 1a62fb3894..a89e0973ba 100644 --- a/board/common/overlay/etc/os.conf +++ b/board/common/overlay/etc/os.conf @@ -1,2 +1,3 @@ os_debug="false" +os_prereleases="false" diff --git a/package/motioneye/extractl.py b/package/motioneye/extractl.py index ca810d2513..531a8254af 100644 --- a/package/motioneye/extractl.py +++ b/package/motioneye/extractl.py @@ -22,6 +22,7 @@ from config import additional_config MOTIONEYE_CONF = '/data/etc/motioneye.conf' +OS_CONF = '/data/etc/os.conf' DATE_CONF = '/data/etc/date.conf' @@ -40,12 +41,7 @@ def _get_date_settings(): if not line: continue - comment = False if line.startswith('#'): - line = line.strip('#') - comment = True - - if comment: continue try: @@ -95,6 +91,81 @@ def _set_date_settings(s): f.write('date_interval=%s\n' % s['dateInterval']) +def _get_os_settings(): + prereleases = False + + if os.path.exists(OS_CONF): + logging.debug('reading OS settings from %s' % OS_CONF) + + with open(OS_CONF) as f: + for line in f: + line = line.strip() + if not line: + continue + + if line.startswith('#'): + continue + + try: + name, value = line.split('=') + value = value.strip('"').strip("'") + + except: + continue + + if name == 'os_prereleases': + prereleases = value == 'true' + + s = { + 'prereleases': prereleases + } + + logging.debug('OS settings: prereleases=%(prereleases)s' % s) + + return s + + +def _set_os_settings(s): + s = dict(s) + + s.setdefault('prereleases', False) + + logging.debug('writing OS settings to %s: ' % OS_CONF + + 'prereleases=%(prereleases)s' % s) + + lines = [] + if os.path.exists(OS_CONF): + with open(OS_CONF) as f: + lines = f.readlines() + + for i, line in enumerate(lines): + line = line.strip() + if not line: + continue + + try: + name, _ = line.split(' ', 2) + + except: + continue + + name = name.replace('_', '-') + + if name == 'os_prereleases': + lines[i] = 'os_prereleases="%s"' % str(s.pop('prereleases')).lower() + + if 'prereleases' in s: + lines.append('os_prereleases="%s"' % str(s.pop('prereleases')).lower()) + + with open(OS_CONF, 'w') as f: + for line in lines: + if not line.strip(): + continue + if not line.endswith('\n'): + line += '\n' + f.write(line) + + def _get_motioneye_settings(): port = 80 motion_binary = '/usr/bin/motion' @@ -130,17 +201,14 @@ def _get_motioneye_settings(): elif name == 'mjpg-client-idle-timeout': motion_keep_alive = value == '0' - prereleases = os.path.exists('/data/etc/prereleases') - s = { 'port': port, 'motionBinary': motion_binary, 'motionKeepAlive': motion_keep_alive, - 'debug': debug, - 'prereleases': prereleases + 'debug': debug } - logging.debug('motioneye settings: port=%(port)s, motion_binary=%(motionBinary)s, motion_keep_alive=%(motionKeepAlive)s, debug=%(debug)s, prereleases=%(prereleases)s' % s) + logging.debug('motioneye settings: port=%(port)s, motion_binary=%(motionBinary)s, motion_keep_alive=%(motionKeepAlive)s, debug=%(debug)s' % s) return s @@ -150,11 +218,10 @@ def _set_motioneye_settings(s): s.setdefault('port', 80) s.setdefault('motionBinary', '/usr/bin/motion') s.setdefault('debug', False) - s.setdefault('prereleases', False) s.setdefault('motion_keep_alive', False) logging.debug('writing motioneye settings to %s: ' % MOTIONEYE_CONF + - 'port=%(port)s, motion_binary=%(motionBinary)s, debug=%(debug)s, prereleases=%(prereleases)s, motion_keep_alive=%(motionKeepAlive)s' % s) + 'port=%(port)s, motion_binary=%(motionBinary)s, debug=%(debug)s, motion_keep_alive=%(motionKeepAlive)s' % s) lines = [] if os.path.exists(MOTIONEYE_CONF): @@ -198,17 +265,6 @@ def _set_motioneye_settings(s): if 'motionKeepAlive' in s: lines.append('mjpg-client-idle-timeout %s' % [10, 0][s.pop('motionKeepAlive')]) - if s['prereleases']: - with open('/data/etc/prereleases', 'w'): - pass - - else: - try: - os.remove('/data/etc/prereleases') - - except: - pass - with open(MOTIONEYE_CONF, 'w') as f: for line in lines: if not line.strip(): @@ -217,6 +273,16 @@ def _set_motioneye_settings(s): line += '\n' f.write(line) + # also update debug in os.conf + if s['debug']: + cmd = "sed -r 's/os_debug=\"?false\"?/os_debug=\"true\"/' %s" % OS_CONF + + else: + cmd = "sed -r 's/os_debug=\"?true\"?/os_debug=\"false\"/' %s" % OS_CONF + + if os.system(cmd): + logging.error('failed to set debug flag in os.conf') + def _get_motion_log(): return 'motion.log'