Merge branch 'thingos-init-improvements' into thingos-next

This commit is contained in:
Calin Crisan 2019-01-12 13:53:56 +02:00
commit 014684880c
46 changed files with 436 additions and 444 deletions

View File

@ -28,7 +28,7 @@ GUARD_SIZE="10" # MB
DISK_SIZE=$((ROOT_START + ROOT_SIZE + GUARD_SIZE)) DISK_SIZE=$((ROOT_START + ROOT_SIZE + GUARD_SIZE))
COMMON_DIR=$(cd $IMG_DIR/../../../board/common; pwd) 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 # boot filesystem
msg "creating boot loop device" msg "creating boot loop device"
@ -73,19 +73,19 @@ tar -xpsf $ROOT_SRC -C $ROOT
if [ -f $ROOT/etc/version ]; then if [ -f $ROOT/etc/version ]; then
if [ -n "$THINGOS_NAME" ]; then if [ -n "$THINGOS_NAME" ]; then
msg "setting OS name to $THINGOS_NAME" 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 fi
if [ -n "$THINGOS_SHORT_NAME" ]; then if [ -n "$THINGOS_SHORT_NAME" ]; then
msg "setting OS short name to $THINGOS_SHORT_NAME" 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 fi
if [ -n "$THINGOS_PREFIX" ]; then if [ -n "$THINGOS_PREFIX" ]; then
msg "setting OS prefix to $THINGOS_PREFIX" 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 fi
if [ -n "$THINGOS_VERSION" ]; then if [ -n "$THINGOS_VERSION" ]; then
msg "setting OS version to $THINGOS_VERSION" 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
fi fi

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
test -n "$os_version" || source /etc/init.d/base test -n "$OS_VERSION" || source /etc/init.d/base
case "$1" in case "$1" in
start) start)

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
test -n "$os_version" || source /etc/init.d/base test -n "$OS_VERSION" || source /etc/init.d/base
mount_fs() { mount_fs() {
msg_begin "Mounting filesystems" msg_begin "Mounting filesystems"
@ -22,8 +22,8 @@ remount_rw() {
} }
mk_tty_login() { mk_tty_login() {
test -z "$os_tty_login" && os_tty_login=tty1 test -z "$OS_TTY_LOGIN" && OS_TTY_LOGIN=tty1
ln -sf /dev/$os_tty_login /dev/ttylogin ln -sf /dev/$OS_TTY_LOGIN /dev/ttylogin
} }
case "$1" in case "$1" in
@ -31,8 +31,8 @@ case "$1" in
mount_fs mount_fs
# we need to source conf again, now that /data is available # 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 test "$OS_DEBUG" == "true" && remount_rw
mk_tty_login mk_tty_login
;; ;;

View File

@ -1,20 +1,26 @@
#!/bin/bash #!/bin/bash
sys_modules_file="/etc/modules" SYS_MODULES_FILE="/etc/modules"
modules_file="/data/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 case "$1" in
start) start)
msg_begin "Loading kernel modules" msg_begin "Loading kernel modules"
if [[ -r $sys_modules_file ]]; then if [[ -r $SYS_MODULES_FILE ]]; then
cat $sys_modules_file | while read line; do test -n "$line" && /sbin/modprobe $line &>/dev/null; done cat $SYS_MODULES_FILE | while read line; do test -n "$line" && /sbin/modprobe $line &>/dev/null; done
fi fi
if [[ -r $modules_file ]]; then if [[ -r $BOOT_MODULES_FILE ]]; then
cat $modules_file | while read line; do test -n "$line" && /sbin/modprobe $line &>/dev/null; done 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 fi
msg_done msg_done

View File

@ -1,27 +1,22 @@
#!/bin/bash #!/bin/bash
sys_hostname_file="/etc/hostname" SYS_HOSTNAME_FILE="/etc/hostname"
boot_hostname_file="/boot/hostname" BOOT_HOSTNAME_FILE="/boot/hostname"
hostname_file="/data/etc/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 case "$1" in
start) start)
msg_begin "Setting hostname" msg_begin "Setting hostname"
if ! [[ -f $hostname_file ]]; then prepare_conf $HOSTNAME_FILE $SYS_HOSTNAME_FILE $BOOT_HOSTNAME_FILE
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
if [[ -f $hostname_file ]]; then if [[ -f $HOSTNAME_FILE ]]; then
hostname=$(cat $hostname_file) hostname=$(cat $HOSTNAME_FILE)
else else
hostname="$os_prefix-$board_sn" hostname="$OS_PREFIX-$BOARD_SN"
fi fi
/bin/hostname $hostname /bin/hostname $hostname

View File

@ -1,16 +1,17 @@
#!/bin/bash #!/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 case "$1" in
start) start)
msg_begin "Starting syslogd" msg_begin "Starting syslogd"
syslogd syslogd
test $? == 0 && msg_done || msg_fail 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 & dmesg -T -w >> $DMESG_LOG &
;; ;;
stop) stop)

View File

@ -1,10 +1,13 @@
#!/bin/bash #!/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() { start() {
msg_begin "Starting eudev" msg_begin "Starting eudev"

View File

@ -2,7 +2,7 @@
test -c /dev/watchdog || exit 0 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 case "$1" in
start) start)

View File

@ -1,19 +1,18 @@
#!/bin/bash #!/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) test -n "$OS_VERSION" || source /etc/init.d/base
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 "$hash" == "$sys_hash" && exit 0
test -d $post_upgrade_dir || exit 0 test -d $POST_UPGRADE_DIR || exit 0
function version_gt() { function version_gt() {
if [[ "$1" != "$2" ]] && [[ $(echo -e "$2\n$1" | sort -t . | head -n 1) == "$2" ]]; then if [[ "$1" != "$2" ]] && [[ $(echo -e "$2\n$1" | sort -t . | head -n 1) == "$2" ]]; then
@ -24,37 +23,24 @@ function version_gt() {
} }
function run_post_upgrade() { function run_post_upgrade() {
version="$(source $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)" 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 for v in $versions; do
if [[ -z "$version" ]] || version_gt $v $version; then if [[ -z "$version" ]] || version_gt $v $version; then
msg_begin "Post-upgrading to version $v" 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 test $? == 0 && msg_done || msg_fail
echo "$out" | logger -t post-upgrade echo "$out" | logger -t post-upgrade
fi fi
done 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 case "$1" in
start) start)
run_post_upgrade run_post_upgrade
cp $sys_version_file $version_file cp $SYS_VERSION_FILE $VERSION_FILE
update_os_conf
;; ;;
stop) stop)

View File

@ -1,15 +1,16 @@
#!/bin/bash #!/bin/bash
sys_btconf="/etc/bluetooth.conf" SYS_BTCONF="/etc/bluetooth.conf"
boot_btconf="/boot/bluetooth.conf" BOOT_BTCONF="/boot/bluetooth.conf"
btconf="/data/etc/bluetooth.conf" BTCONF="/data/etc/bluetooth.conf"
# dbus is currently only used by bluez # 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 -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() { start() {
mkdir -p /tmp/dbus mkdir -p /tmp/dbus

View File

@ -1,30 +1,25 @@
#!/bin/bash #!/bin/bash
sys_conf="/etc/hostapd.conf" SYS_CONF="/etc/hostapd.conf"
boot_conf="/boot/hostapd.conf" BOOT_CONF="/boot/hostapd.conf"
conf="/data/etc/hostapd.conf" CONF="/data/etc/hostapd.conf"
log="/var/log/hostapd.log" LOG="/var/log/hostapd.log"
prog="/usr/sbin/hostapd" PROG="/usr/sbin/hostapd"
watch_conf="/data/etc/watch.conf" WATCH_CONF="/data/etc/watch.conf"
link_watch=yes link_watch=yes
link_watch_timeout=20 link_watch_timeout=20
test -f $watch_conf && source $watch_conf
if ! [[ -f $conf ]]; then test -n "$OS_VERSION" || source /etc/init.d/base
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 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() { running() {
killall -0 hostapd &> /dev/null killall -0 hostapd &> /dev/null
@ -55,11 +50,11 @@ start() {
fi fi
done 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) module=$(basename $(readlink /sys/class/net/$iface/device/driver/module 2>/dev/null) 2>/dev/null)
iwconfig $iface power off &> /dev/null iwconfig $iface power off &> /dev/null
$prog $conf &> $log & $PROG $CONF &> $LOG &
if [[ "$link_watch" == "yes" ]]; then if [[ "$link_watch" == "yes" ]]; then
watch & watch &

View File

@ -1,49 +1,35 @@
#!/bin/bash #!/bin/bash
sys_conf="/etc/wpa_supplicant.conf" SYS_CONF="/etc/wpa_supplicant.conf"
boot_conf="/boot/wpa_supplicant.conf" BOOT_CONF="/boot/wpa_supplicant.conf"
conf="/data/etc/wpa_supplicant.conf" CONF="/data/etc/wpa_supplicant.conf"
log="/var/log/wpa_supplicant.log" LOG="/var/log/wpa_supplicant.log"
prog="/usr/sbin/wpa_supplicant" PROG="/usr/sbin/wpa_supplicant"
driver=nl80211,wext DRIVER=nl80211,wext
sys_watch_conf="/etc/watch.conf" SYS_WATCH_CONF="/etc/watch.conf"
boot_watch_conf="/boot/watch.conf" BOOT_WATCH_CONF="/boot/watch.conf"
watch_conf="/data/etc/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 prepare_conf $WATCH_CONF $SYS_WATCH_CONF $BOOT_WATCH_CONF
if [[ -f $boot_conf ]]; then source $WATCH_CONF
cp $boot_conf $conf
elif [[ -f $sys_conf ]]; then
cp $sys_conf $conf
fi
fi
test -f $conf || exit 0 prepare_conf $CONF $SYS_CONF $BOOT_CONF
test -f $CONF || exit 0
# we want only Unix newlines here ssid=$(cat $CONF | grep ssid | grep -v scan_ssid | cut -d '"' -f 2)
sed -i 's/\r//g' $conf
ssid=$(cat $conf | grep ssid | grep -v scan_ssid | cut -d '"' -f 2)
test -n "$ssid" || exit 0 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() { 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() { watch() {
@ -65,13 +51,13 @@ watch() {
} }
start() { start() {
test -n "$os_country" && iw reg set $os_country test -n "$OS_COUNTRY" && iw reg set $OS_COUNTRY
msg_begin "Starting wpa_supplicant" msg_begin "Starting wpa_supplicant"
# wait up to 5 seconds for interface # wait up to 5 seconds for interface
count=0 count=0
while ! ifconfig $os_wlan >/dev/null 2>&1; do while ! ifconfig $OS_WLAN >/dev/null 2>&1; do
sleep 1 sleep 1
count=$(($count + 1)) count=$(($count + 1))
if [[ $count -ge 5 ]]; then if [[ $count -ge 5 ]]; then
@ -80,11 +66,11 @@ start() {
fi fi
done 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 iwconfig $OS_WLAN power off &> /dev/null
iw $os_wlan set power_save 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 count=0
while true; do while true; do
sleep 1 sleep 1

View File

@ -1,33 +1,29 @@
#!/bin/bash #!/bin/bash
sys_conf="/etc/ppp/default" SYS_CONF="/etc/ppp/default"
boot_conf="/boot/ppp" BOOT_CONF="/boot/ppp"
conf="/data/etc/ppp" CONF="/data/etc/ppp"
prog="/usr/sbin/pppd" PROG="/usr/sbin/pppd"
provider="mobile" PROVIDER="mobile"
watch_conf="/data/etc/watch.conf" WATCH_CONF="/data/etc/watch.conf"
source $watch_conf
if ! [[ -d $conf ]]; then test -n "$OS_VERSION" || source /etc/init.d/base
if [[ -d $boot_conf ]]; then
cp -r $boot_conf $conf
elif [[ -d $sys_conf ]]; then
cp -r $sys_conf $conf
fi
fi
test -e $conf/modem || exit 0 prepare_conf $CONF $SYS_CONF $BOOT_CONF
test -e $conf/apn || exit 0
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() { connected() {
ifconfig | grep $os_ppp &>/dev/null && return 0 || return 1 ifconfig | grep $OS_PPP &>/dev/null && return 0 || return 1
} }
watch() { watch() {
@ -55,15 +51,15 @@ udev_trigger_add() {
} }
start() { start() {
test -e $conf/auth || touch $conf/auth test -e $CONF/auth || touch $CONF/auth
test -e $conf/extra || touch $conf/extra test -e $CONF/extra || touch $CONF/extra
test -e $conf/pin || touch $conf/pin test -e $CONF/pin || touch $CONF/pin
mknod /dev/ppp c 108 0 &>/dev/null mknod /dev/ppp c 108 0 &>/dev/null
msg_begin "Starting pppd" msg_begin "Starting pppd"
# wait for modem # wait for modem
modem=$(head -n 1 $conf/modem) modem=$(head -n 1 $CONF/modem)
if ! [[ -e /dev/$modem ]]; then if ! [[ -e /dev/$modem ]]; then
udev_trigger_add 4 & udev_trigger_add 4 &
fi fi
@ -83,7 +79,7 @@ start() {
return return
fi fi
$prog call $provider $PROG call $PROVIDER
count=0 count=0
while true; do while true; do
sleep 1 sleep 1

View File

@ -1,18 +1,14 @@
#!/bin/bash #!/bin/bash
sys_conf="/etc/bluetooth.conf" SYS_CONF="/etc/bluetooth.conf"
boot_conf="/boot/bluetooth.conf" BOOT_CONF="/boot/bluetooth.conf"
conf="/data/etc/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 hci=hci0
bluetoothd=/usr/libexec/bluetooth/bluetoothd bluetoothd=/usr/libexec/bluetooth/bluetoothd
@ -22,12 +18,11 @@ run_conf=/var/lib/bluetooth.conf
test -x $bluetoothd || exit 0 test -x $bluetoothd || exit 0
test -n "$os_version" || source /etc/init.d/base
configure() { configure() {
mkdir -p $run_data_dir mkdir -p $run_data_dir
ln -sf $run_data_dir $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 no specific name configured, use hostname
if ! grep -E 'Name\s*=' $run_conf &>/dev/null; then if ! grep -E 'Name\s*=' $run_conf &>/dev/null; then

View File

@ -1,33 +1,29 @@
#!/bin/bash #!/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 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() { watch_eth() {
count=0 count=0
while true; do while true; do
sleep 5 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 count=0
else else
if [[ $count -lt $link_watch_timeout ]]; then if [[ $count -lt $link_watch_timeout ]]; then
@ -66,31 +62,31 @@ start_lo() {
start_wlan() { start_wlan() {
msg_begin "Configuring wireless network" msg_begin "Configuring wireless network"
if ! ifconfig $os_wlan &>/dev/null; then if ! ifconfig $OS_WLAN &>/dev/null; then
msg_fail "no device" msg_fail "no device"
return 1 return 1
fi 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" msg_fail "no link"
return 1 return 1
fi fi
if [[ -n "$mtu" ]]; then if [[ -n "$mtu" ]]; then
ip link set mtu $mtu dev $os_wlan ip link set mtu $mtu dev $OS_WLAN
fi fi
if [[ -n "$static_ip" ]]; then if [[ -n "$static_ip" ]]; then
msg_done $static_ip msg_done $static_ip
ifconfig $os_wlan $static_ip up ifconfig $OS_WLAN $static_ip up
static_ip="" # won't be used again static_ip="" # won't be used again
else else
msg_done dhcp msg_done dhcp
dhclient -cf "$dh_conf" $os_wlan dhclient -cf "$DH_CONF" $OS_WLAN
fi fi
if [[ "$ip_watch" == "true" ]] && ip addr show dev $os_wlan | grep inet &>/dev/null; then if [[ "$ip_watch" == "true" ]] && ip addr show dev $OS_WLAN | grep inet &>/dev/null; then
watch_ip $os_wlan & watch_ip $OS_WLAN &
fi fi
} }
@ -100,7 +96,7 @@ start_eth() {
# wait for driver # wait for driver
w=3 w=3
count=0 count=0
while ! ifconfig $os_eth >/dev/null 2>&1; do while ! ifconfig $OS_ETH >/dev/null 2>&1; do
sleep 1 sleep 1
count=$(($count + 1)) count=$(($count + 1))
if [[ $count -ge $w ]]; then if [[ $count -ge $w ]]; then
@ -110,12 +106,12 @@ start_eth() {
done done
# bring it up # bring it up
ifconfig $os_eth up ifconfig $OS_ETH up
# wait for operstate # wait for operstate
w=3 w=3
count=0 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 sleep 1
count=$(($count + 1)) count=$(($count + 1))
if [[ $count -ge $w ]]; then if [[ $count -ge $w ]]; then
@ -125,36 +121,36 @@ start_eth() {
done done
# wait for link # wait for link
test "$link_watch" == "true" || link_nego_timeout=5 test "$link_watch" == "true" || LINK_NEGO_TIMEOUT=5
count=0 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 sleep 1
count=$(($count + 1)) count=$(($count + 1))
if [[ $count -ge $link_nego_timeout ]]; then if [[ $count -ge $LINK_NEGO_TIMEOUT ]]; then
msg_done "no link" msg_done "no link"
return 1 return 1
fi fi
done done
if [[ -n "$mtu" ]]; then if [[ -n "$mtu" ]]; then
ip link set mtu $mtu dev $os_eth ip link set mtu $mtu dev $OS_ETH
fi fi
if [[ -n "$static_ip" ]]; then if [[ -n "$static_ip" ]]; then
msg_done $static_ip msg_done $static_ip
ifconfig $os_eth $static_ip up ifconfig $OS_ETH $static_ip up
static_ip="" # won't be used again static_ip="" # won't be used again
else else
msg_done dhcp msg_done dhcp
dhclient -cf "$dh_conf" $os_eth dhclient -cf "$DH_CONF" $OS_ETH
fi fi
if [[ "$link_watch" == "true" ]]; then if [[ "$link_watch" == "true" ]]; then
watch_eth & watch_eth &
fi fi
if [[ "$ip_watch" == "true" ]] && ip addr show dev $os_eth | grep inet &>/dev/null; then if [[ "$ip_watch" == "true" ]] && ip addr show dev $OS_ETH | grep inet &>/dev/null; then
watch_ip $os_eth & watch_ip $OS_ETH &
fi fi
} }
@ -164,12 +160,12 @@ start() {
start_lo 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) 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 -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 wifi or ppp link ok, start eth in background
if [[ "$wlan_ok" == "ok" ]] || [[ "$ppp_ok" == "ok" ]]; then if [[ "$wlan_ok" == "ok" ]] || [[ "$ppp_ok" == "ok" ]]; then

View File

@ -1,29 +1,31 @@
#!/bin/bash #!/bin/bash
watch_conf="/data/etc/watch.conf" WATCH_CONF="/data/etc/watch.conf"
netwatch_retries=3 NETWATCH_RETRIES=3
netwatch_timeout=5 NETWATCH_TIMEOUT=5
netwatch_interval=20 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 exit 0
fi 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() { watch() {
count=0 count=0
netwatch_retries=$(($netwatch_retries - 1)) NETWATCH_RETRIES=$(($NETWATCH_RETRIES - 1))
while true; do while true; do
sleep $netwatch_interval sleep $NETWATCH_INTERVAL
if nc -z -w $netwatch_timeout $netwatch_host $netwatch_port </dev/null >/dev/null 2>&1; then if nc -z -w $NETWATCH_TIMEOUT $netwatch_host $netwatch_port </dev/null >/dev/null 2>&1; then
count=0 count=0
else else
if [[ $count -lt $netwatch_retries ]]; then if [[ $count -lt $NETWATCH_RETRIES ]]; then
logger -t netwatch -s "cannot connect to $netwatch_host:$netwatch_port" logger -t netwatch -s "cannot connect to $netwatch_host:$netwatch_port"
count=$(($count + 1)) count=$(($count + 1))
continue continue

View File

@ -1,25 +1,19 @@
#!/bin/bash #!/bin/bash
sys_conf="/etc/firewall.sh" SYS_CONF="/etc/firewall.sh"
boot_conf="/boot/firewall.sh" BOOT_CONF="/boot/firewall.sh"
conf="/data/etc/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() { start() {
msg_begin "Starting firewall" msg_begin "Starting firewall"
bash $conf bash $CONF
test $? == 0 && msg_done || msg_fail test $? == 0 && msg_done || msg_fail
} }

View File

@ -1,33 +1,28 @@
#!/bin/bash #!/bin/bash
sys_conf="/etc/dnsmasq.conf" SYS_CONF="/etc/dnsmasq.conf"
boot_conf="/boot/dnsmasq.conf" BOOT_CONF="/boot/dnsmasq.conf"
conf="/data/etc/dnsmasq.conf" CONF="/data/etc/dnsmasq.conf"
log="/var/log/dnsmasq.log" LOG="/var/log/dnsmasq.log"
prog="/usr/sbin/dnsmasq" 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() { start() {
msg_begin "Starting dnsmasq" msg_begin "Starting dnsmasq"
iface=$(cat $conf | grep interface | cut -d '=' -f 2) 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 ip=$(cat $CONF | grep range | cut -d '=' -f 2 | cut -d '.' -f 1,2,3).1
ifconfig $iface $ip ifconfig $iface $ip
$prog -C $conf --log-facility=$log $PROG -C $CONF --log-facility=$LOG
test $? == 0 && msg_done || msg_fail test $? == 0 && msg_done || msg_fail
} }

View File

@ -1,60 +1,49 @@
#!/bin/bash #!/bin/bash
# Date executable points to /bin/busybox\ date explicitly in the cases that date binary gets overwritten # 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" SYS_CONF="/etc/date.conf"
boot_conf="/boot/date.conf" BOOT_CONF="/boot/date.conf"
conf="/data/etc/date.conf" CONF="/data/etc/date.conf"
sys_ntp_conf="/etc/ntp.conf" SYS_NTP_CONF="/etc/ntp.conf"
boot_ntp_conf="/boot/ntp.conf" BOOT_NTP_CONF="/boot/ntp.conf"
ntp_conf="/data/etc/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 test -n "$OS_VERSION" || source /etc/init.d/base
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 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_timeout=10
date_method=http date_method=http
date_host="google.com" date_host="google.com"
date_interval="900" date_interval="900"
source $conf source $CONF
set_current_date_http() { 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: //') 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 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 $? return $?
} }
set_current_date_ntp() { 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() { start_http() {
msg_begin "Setting current date using http" msg_begin "Setting current date using http"
set_current_date_http || set_current_date_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" msg_begin "Starting http date updater"
while true; do while true; do
@ -67,23 +56,23 @@ start_http() {
start_ntp() { start_ntp() {
mkdir -p /var/lib/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 if [[ -n "$date_ntp_server" ]]; then
echo "server $date_ntp_server iburst" > $ntp_conf echo "server $date_ntp_server iburst" > $NTP_CONF
else else
cat $sys_ntp_conf | grep iburst > $ntp_conf cat $SYS_NTP_CONF | grep iburst > $NTP_CONF
fi fi
cat ${ntp_conf}.tmp >> $ntp_conf cat ${NTP_CONF}.tmp >> $NTP_CONF
rm ${ntp_conf}.tmp rm ${NTP_CONF}.tmp
msg_begin "Setting current date using ntp" msg_begin "Setting current date using ntp"
set_current_date_ntp || set_current_date_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" msg_begin "Starting ntpd"
ntpd -g -c $ntp_conf ntpd -g -c $NTP_CONF
test $? == 0 && msg_done || msg_fail test $? == 0 && msg_done || msg_fail
} }
@ -106,7 +95,7 @@ start() {
start_ntp start_ntp
fi 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() { stop() {

View File

@ -1,19 +1,19 @@
#!/bin/bash #!/bin/bash
sys_conf="/etc/crontabs" SYS_CONF="/etc/crontabs"
conf="/data/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() { start() {
msg_begin "Starting crond" msg_begin "Starting crond"
if [[ -d $sys_conf ]]; then if [[ -d $SYS_CONF ]]; then
/usr/sbin/crond -c $sys_conf /usr/sbin/crond -c $SYS_CONF
fi fi
mkdir -p $conf mkdir -p $CONF
/usr/sbin/crond -c $conf /usr/sbin/crond -c $CONF
test $? == 0 && msg_done || msg_fail test $? == 0 && msg_done || msg_fail
} }

View File

@ -1,12 +1,12 @@
#!/bin/bash #!/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() { start() {
msg_begin "Starting sshd" msg_begin "Starting sshd"
@ -22,7 +22,7 @@ start() {
echo "Welcome to $hostname!" > /var/cache/sshd_banner echo "Welcome to $hostname!" > /var/cache/sshd_banner
sync sync
/usr/sbin/sshd -f $conf /usr/sbin/sshd -f $CONF
test $? == 0 && msg_done || msg_fail test $? == 0 && msg_done || msg_fail
} }

View File

@ -1,15 +1,16 @@
#!/bin/bash #!/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 case "$1" in
start) start)
msg_begin "Executing user init script" msg_begin "Executing user init script"
/bin/bash $userinit_sh /bin/bash $USERINIT
test $? == 0 && msg_done || msg_fail test $? == 0 && msg_done || msg_fail
;; ;;

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
test -n "$os_version" || source /etc/init.d/base test -n "$OS_VERSION" || source /etc/init.d/base
msg_info() { msg_info() {
echo " # $1" echo " # $1"
@ -24,9 +24,9 @@ show_dns() {
case "$1" in case "$1" in
start) start)
show_iface_ip_addr $os_eth show_iface_ip_addr $OS_ETH
show_iface_ip_addr $os_wlan show_iface_ip_addr $OS_WLAN
show_iface_ip_addr $os_ppp show_iface_ip_addr $OS_PPP
show_gateway show_gateway
show_dns show_dns
;; ;;

42
board/common/overlay/etc/init.d/base Executable file → Normal file
View File

@ -1,13 +1,13 @@
#!/bin/bash
source /etc/version source /etc/version
board_sn=$(/etc/init.d/boardsn) BOARD_SN=$(/etc/init.d/boardsn)
board_name=$(cat /etc/board) 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 source /etc/init.d/panic
msg_begin() { msg_begin() {
echo -n " * $1: " echo -n " * $1: "
} }
@ -24,3 +24,37 @@ msg_background() {
test -n "$1" && echo $1 || echo "pending" 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
}

View File

@ -3,5 +3,5 @@
source /etc/init.d/panic source /etc/init.d/panic
# reset panic counter after a successful boot # reset panic counter after a successful boot
echo 0 > ${_PANIC_COUNTER_FILE} echo 0 > ${PANIC_COUNTER_FILE}

View File

@ -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

View File

@ -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

17
board/common/overlay/etc/init.d/panic Executable file → Normal file
View File

@ -1,20 +1,19 @@
#!/bin/bash
_PANIC_COUNTER_FILE="/var/lib/panic_counter" PANIC_COUNTER_FILE="/var/lib/panic_counter"
_PANIC_REBOOT_DELAY_FACTOR=10 PANIC_REBOOT_DELAY_FACTOR=10
_PANIC_REBOOT_DELAY_MAX=3600 # reboot at least once an hour in case of panic PANIC_REBOOT_DELAY_MAX=3600 # reboot at least once an hour in case of panic
panic_action() { panic_action() {
# read counter from file # 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 # 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)) delay=$((PANIC_REBOOT_DELAY_FACTOR * panic_counter))
if [[ "${delay}" -gt "${_PANIC_REBOOT_DELAY_MAX}" ]]; then if [[ "${delay}" -gt "${PANIC_REBOOT_DELAY_MAX}" ]]; then
delay=${_PANIC_REBOOT_DELAY_MAX} delay=${PANIC_REBOOT_DELAY_MAX}
fi fi
if [[ "${delay}" -gt 0 ]]; then if [[ "${delay}" -gt 0 ]]; then

View File

@ -5,7 +5,7 @@ pid_file=/tmp/rc.pid
source /etc/init.d/base 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, # stop all init scripts in /etc/init.d,
# executing them in reverse numerical order. # executing them in reverse numerical order.

View File

@ -6,7 +6,7 @@ pid_file=/tmp/rc.pid
source /etc/init.d/base 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, # start all init scripts in /etc/init.d,
# executing them in numerical order. # executing them in numerical order.

View File

@ -1,12 +1,12 @@
os_debug="false" OS_DEBUG="false"
os_prereleases="false" OS_PRERELEASES="false"
os_tty_login="tty1" OS_TTY_LOGIN="tty1"
os_eth="eth0" OS_ETH="eth0"
os_wlan="wlan0" OS_WLAN="wlan0"
os_ppp="ppp0" OS_PPP="ppp0"
os_networkless="false" OS_NETWORKLESS="false"
os_country="GB" OS_COUNTRY="GB"
os_firmware_method="github" OS_FIRMWARE_METHOD="github"
os_firmware_repo="ccrisan/motioneyeos" OS_FIRMWARE_REPO="ccrisan/motioneyeos"
os_firmware_username="" OS_FIRMWARE_USERNAME=""
os_firmware_password="" OS_FIRMWARE_PASSWORD=""

View File

@ -1,4 +1,4 @@
os_name="motionEyeOS" OS_NAME="motionEyeOS"
os_short_name="motioneyeos" OS_SHORT_NAME="motioneyeos"
os_prefix="meye" OS_PREFIX="meye"
os_version="unknown" OS_VERSION="unknown"

View File

@ -4,14 +4,14 @@
#### usage #### #### usage ####
function exit_usage() { function exit_usage() {
echo "Usage: fwupdate versions [-j] (lists available versions, optionally outputting json)" echo "Usage: fwupdate versions [-j] (lists available versions, optionally outputting json)"
echo " fwupdate current (shows the current version" echo " fwupdate current (shows the current version"
echo " fwupdate download <version|url> (downloads a firmware version)" echo " fwupdate download <version|url|file> (downloads a firmware version)"
echo " fwupdate extract (extracts the downloaded firmware archive)" echo " fwupdate extract (extracts the downloaded firmware archive)"
echo " fwupdate flashboot (flashes the boot partition from extracted image)" echo " fwupdate flashboot (flashes the boot partition from extracted image)"
echo " fwupdate flashreboot (prepares for reboot + root partititon flash)" echo " fwupdate flashreboot (prepares for reboot + root partititon flash)"
echo " fwupdate status (shows the current firmware updating status; see below)" echo " fwupdate status (shows the current firmware updating status; see below)"
echo " fwupdate upgrade <version|url> (performs all the operations necessary for upgrading)" echo " fwupdate upgrade <version|url|file> (performs all the operations necessary for upgrading)"
echo "" echo ""
echo "Statuses:" echo "Statuses:"
echo " idle" echo " idle"
@ -35,7 +35,6 @@ fi
SYS_VERSION_FILE=/etc/version SYS_VERSION_FILE=/etc/version
SYS_BOARD_FILE=/etc/board SYS_BOARD_FILE=/etc/board
OS_CONF=/data/etc/os.conf
MIN_FREE_DISK=$((500*1024)) # 500 MB MIN_FREE_DISK=$((500*1024)) # 500 MB
VER_FILE=version VER_FILE=version
@ -78,21 +77,22 @@ fi
#### versions #### #### versions ####
function show_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) board=$(cat $SYS_BOARD_FILE)
show_json=$1 show_json=$1
# the /usr/libexec/list-versions-* helpers return a table with the following format: # the /usr/libexec/list-versions-* helpers return a table with the following format:
# <version>|<prerelease>|<board>|<url>|<date> # <version>|<prerelease>|<board>|<url>|<date>
versions=$(FW_USERNAME=$os_firmware_username FW_PASSWORD=$os_firmware_password \ versions=$(FW_USERNAME=$OS_FIRMWARE_USERNAME FW_PASSWORD=$OS_FIRMWARE_PASSWORD \
/usr/libexec/list-versions-$os_firmware_method $os_firmware_repo) /usr/libexec/list-versions-$OS_FIRMWARE_METHOD $OS_FIRMWARE_REPO)
for version in ${versions[@]}; do for version in ${versions[@]}; do
OIFS=$IFS OIFS=$IFS
IFS="|" IFS="|"
varr=($version) varr=($version)
IFS=$OIFS IFS=$OIFS
if [ "$os_prereleases" == "false" ] && [ "${varr[1]}" == "true" ]; then if [ "$OS_PRERELEASES" == "false" ] && [ "${varr[1]}" == "true" ]; then
continue # skip prereleases continue # skip prereleases
fi fi
if [ "$board" != "${varr[2]}" ]; then if [ "$board" != "${varr[2]}" ]; then
@ -114,7 +114,7 @@ function show_versions() {
function show_current() { function show_current() {
source $SYS_VERSION_FILE source $SYS_VERSION_FILE
echo $os_version echo $OS_VERSION
} }
@ -123,11 +123,29 @@ function show_current() {
function do_download() { function do_download() {
echo "downloading..." echo "downloading..."
rm -f $FW_DIR/$FW_FILE_GZ $FW_DIR/$FW_FILE_XZ rm -rf $FW_DIR/*
rm -f $FW_DIR/$FW_FILE_EXTR mkdir -p $FW_DIR
rm -f $FW_DIR/$BOOT_READY_FILE
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) board=$(cat $SYS_BOARD_FILE)
url=$1 url=$1
version=$1 version=$1
@ -155,13 +173,11 @@ function do_download() {
outfile=$FW_DIR/$FW_FILE_XZ outfile=$FW_DIR/$FW_FILE_XZ
fi fi
rm -rf $FW_DIR/*
mkdir -p $FW_DIR
echo $version > $FW_DIR/$VER_FILE echo $version > $FW_DIR/$VER_FILE
curl_opts="-S -f -L" curl_opts="-S -f -L"
if [ -n "$os_firmware_username" ]; then if [ -n "$OS_FIRMWARE_USERNAME" ]; then
curl_opts+=" --user $os_firmware_username:$os_firmware_password" curl_opts+=" --user $OS_FIRMWARE_USERNAME:$OS_FIRMWARE_PASSWORD"
fi fi
curl $curl_opts -o $outfile "$url" &> $FW_DIR/$CURL_LOG_FILE & curl $curl_opts -o $outfile "$url" &> $FW_DIR/$CURL_LOG_FILE &

View File

@ -1,2 +1,2 @@
os_tty_login="ttyS0" OS_TTY_LOGIN="ttyS0"

View File

@ -1,2 +1,2 @@
os_tty_login="ttyS0" OS_TTY_LOGIN="ttyS0"

View File

@ -1,2 +1,2 @@
os_tty_login="ttyS0" OS_TTY_LOGIN="ttyS0"

View File

@ -1,2 +1,2 @@
os_tty_login="ttyS0" OS_TTY_LOGIN="ttyS0"

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
test -n "$os_version" || source /etc/init.d/base test -n "$OS_VERSION" || source /etc/init.d/base
case "$1" in case "$1" in
start) start)

View File

@ -1,18 +1,19 @@
#!/bin/bash #!/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" test -n "$OS_VERSION" || source /etc/init.d/base
govdir="/sys/devices/system/cpu/cpufreq/$gov"
configure() { configure() {
echo $gov > $cpufreqdir/scaling_governor echo $GOV > $CPUFREQDIR/scaling_governor
if [[ $gov == "ondemand" ]]; then if [[ $GOV == "ondemand" ]]; then
echo 50 > $govdir/up_threshold echo 50 > $GOVDIR/up_threshold
echo 100000 > $govdir/sampling_rate echo 100000 > $GOVDIR/sampling_rate
echo 50 > $govdir/sampling_down_factor echo 50 > $GOVDIR/sampling_down_factor
echo 1 > $govdir/io_is_busy echo 1 > $GOVDIR/io_is_busy
fi fi
} }

View File

@ -1,8 +1,9 @@
#!/bin/bash #!/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() { get_throttled_now() {
t=$(vcgencmd get_throttled | cut -d '=' -f 2) t=$(vcgencmd get_throttled | cut -d '=' -f 2)
@ -25,7 +26,7 @@ watch_now() {
logger -t throttlewatch -s "currently: $t" logger -t throttlewatch -s "currently: $t"
fi fi
sleep $check_interval sleep $CHECK_INTERVAL
done done
} }
@ -37,7 +38,7 @@ watch_since_boot() {
break break
fi fi
sleep $check_interval sleep $CHECK_INTERVAL
done done
} }

View File

@ -1,14 +1,15 @@
#!/bin/bash #!/bin/bash
sys_conf="/etc/bluetooth.conf" SYS_CONF="/etc/bluetooth.conf"
boot_conf="/boot/bluetooth.conf" BOOT_CONF="/boot/bluetooth.conf"
conf="/data/etc/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 -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() { function start() {
if [[ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ]] ; then if [[ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ]] ; then

View File

@ -1,18 +1,19 @@
#!/bin/bash #!/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" test -n "$OS_VERSION" || source /etc/init.d/base
govdir="/sys/devices/system/cpu/cpufreq/$gov"
configure() { configure() {
echo $gov > $cpufreqdir/scaling_governor echo $GOV > $CPUFREQDIR/scaling_governor
if [[ $gov == "ondemand" ]]; then if [[ $GOV == "ondemand" ]]; then
echo 50 > $govdir/up_threshold echo 50 > $GOVDIR/up_threshold
echo 100000 > $govdir/sampling_rate echo 100000 > $GOVDIR/sampling_rate
echo 50 > $govdir/sampling_down_factor echo 50 > $GOVDIR/sampling_down_factor
echo 1 > $govdir/io_is_busy echo 1 > $GOVDIR/io_is_busy
fi fi
} }

View File

@ -1,8 +1,9 @@
#!/bin/bash #!/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() { get_throttled_now() {
t=$(vcgencmd get_throttled | cut -d '=' -f 2) t=$(vcgencmd get_throttled | cut -d '=' -f 2)
@ -25,7 +26,7 @@ watch_now() {
logger -t throttlewatch -s "currently: $t" logger -t throttlewatch -s "currently: $t"
fi fi
sleep $check_interval sleep $CHECK_INTERVAL
done done
} }
@ -37,7 +38,7 @@ watch_since_boot() {
break break
fi fi
sleep $check_interval sleep $CHECK_INTERVAL
done done
} }

View File

@ -1,18 +1,19 @@
#!/bin/bash #!/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" test -n "$OS_VERSION" || source /etc/init.d/base
govdir="/sys/devices/system/cpu/cpufreq/$gov"
configure() { configure() {
echo $gov > $cpufreqdir/scaling_governor echo $GOV > $CPUFREQDIR/scaling_governor
if [[ $gov == "ondemand" ]]; then if [[ $GOV == "ondemand" ]]; then
echo 50 > $govdir/up_threshold echo 50 > $GOVDIR/up_threshold
echo 100000 > $govdir/sampling_rate echo 100000 > $GOVDIR/sampling_rate
echo 50 > $govdir/sampling_down_factor echo 50 > $GOVDIR/sampling_down_factor
echo 1 > $govdir/io_is_busy echo 1 > $GOVDIR/io_is_busy
fi fi
} }

View File

@ -1,8 +1,9 @@
#!/bin/bash #!/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() { get_throttled_now() {
t=$(vcgencmd get_throttled | cut -d '=' -f 2) t=$(vcgencmd get_throttled | cut -d '=' -f 2)
@ -25,7 +26,7 @@ watch_now() {
logger -t throttlewatch -s "currently: $t" logger -t throttlewatch -s "currently: $t"
fi fi
sleep $check_interval sleep $CHECK_INTERVAL
done done
} }
@ -37,7 +38,7 @@ watch_since_boot() {
break break
fi fi
sleep $check_interval sleep $CHECK_INTERVAL
done done
} }

View File

@ -1,12 +1,15 @@
#!/bin/bash #!/bin/bash
sys_conf="/etc/bluetooth.conf" SYS_CONF="/etc/bluetooth.conf"
boot_conf="/boot/bluetooth.conf" BOOT_CONF="/boot/bluetooth.conf"
conf="/data/etc/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() { function start() {
if [[ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ]] ; then if [[ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ]] ; then