mirror of
https://github.com/motioneye-project/motioneyeos.git
synced 2025-07-29 06:06:32 +00:00
Merge remote-tracking branch 'thingos/dev' into dev
This commit is contained in:
commit
bbefaee042
@ -1,7 +1,7 @@
|
|||||||
#
|
#
|
||||||
# Automatically generated make config: don't edit
|
# Automatically generated make config: don't edit
|
||||||
# Busybox version: 1.29.2
|
# Busybox version: 1.29.2
|
||||||
# Fri Jan 25 20:24:12 2019
|
# Fri Feb 1 22:19:53 2019
|
||||||
#
|
#
|
||||||
CONFIG_HAVE_DOT_CONFIG=y
|
CONFIG_HAVE_DOT_CONFIG=y
|
||||||
|
|
||||||
@ -384,9 +384,9 @@ CONFIG_RESET=y
|
|||||||
# CONFIG_RUN_PARTS is not set
|
# CONFIG_RUN_PARTS is not set
|
||||||
# CONFIG_FEATURE_RUN_PARTS_LONG_OPTIONS is not set
|
# CONFIG_FEATURE_RUN_PARTS_LONG_OPTIONS is not set
|
||||||
# CONFIG_FEATURE_RUN_PARTS_FANCY is not set
|
# CONFIG_FEATURE_RUN_PARTS_FANCY is not set
|
||||||
CONFIG_START_STOP_DAEMON=y
|
# CONFIG_START_STOP_DAEMON is not set
|
||||||
CONFIG_FEATURE_START_STOP_DAEMON_LONG_OPTIONS=y
|
# CONFIG_FEATURE_START_STOP_DAEMON_LONG_OPTIONS is not set
|
||||||
CONFIG_FEATURE_START_STOP_DAEMON_FANCY=y
|
# CONFIG_FEATURE_START_STOP_DAEMON_FANCY is not set
|
||||||
CONFIG_WHICH=y
|
CONFIG_WHICH=y
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -621,7 +621,7 @@ CONFIG_HWCLOCK=y
|
|||||||
# CONFIG_IPCS is not set
|
# CONFIG_IPCS is not set
|
||||||
# CONFIG_LAST is not set
|
# CONFIG_LAST is not set
|
||||||
# CONFIG_FEATURE_LAST_FANCY is not set
|
# CONFIG_FEATURE_LAST_FANCY is not set
|
||||||
# CONFIG_LOSETUP is not set
|
CONFIG_LOSETUP=y
|
||||||
# CONFIG_LSPCI is not set
|
# CONFIG_LSPCI is not set
|
||||||
CONFIG_LSUSB=y
|
CONFIG_LSUSB=y
|
||||||
# CONFIG_MDEV is not set
|
# CONFIG_MDEV is not set
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
DATA_OFFS="1024" # up to 1024MB reserved for boot + root
|
||||||
|
|
||||||
|
|
||||||
test -n "${OS_VERSION}" || source /etc/init.d/base
|
test -n "${OS_VERSION}" || source /etc/init.d/base
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
@ -23,7 +26,7 @@ case "$1" in
|
|||||||
test -b ${data_dev} && exit 0
|
test -b ${data_dev} && exit 0
|
||||||
|
|
||||||
msg_begin "Creating data partition"
|
msg_begin "Creating data partition"
|
||||||
data_start=$((1024 * 2048)) # up to 1024MB reserved for boot + root
|
data_start=$((DATA_OFFS * 2048))
|
||||||
echo -e "n
|
echo -e "n
|
||||||
p
|
p
|
||||||
3
|
3
|
||||||
|
47
board/common/overlay/etc/init.d/S02restorebackups
Executable file
47
board/common/overlay/etc/init.d/S02restorebackups
Executable file
@ -0,0 +1,47 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
BACKUPS_DIR="/boot"
|
||||||
|
BACKUP_PATTERN="backup-*.tar.gz"
|
||||||
|
DATA_DIR="/data"
|
||||||
|
|
||||||
|
|
||||||
|
test -n "${OS_VERSION}" || source /etc/init.d/base
|
||||||
|
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
if ! ls ${BACKUPS_DIR}/${BACKUP_PATTERN} &>/dev/null; then
|
||||||
|
exit; # no backups
|
||||||
|
fi
|
||||||
|
|
||||||
|
mount -o remount,rw /boot
|
||||||
|
|
||||||
|
for file in ${BACKUPS_DIR}/${BACKUP_PATTERN}; do
|
||||||
|
msg_begin "Restoring backup from $(basename ${file})"
|
||||||
|
tar -mxf ${file} -C ${DATA_DIR}
|
||||||
|
if [[ $? == 0 ]]; then
|
||||||
|
rm ${file}
|
||||||
|
msg_done
|
||||||
|
else
|
||||||
|
msg_fail
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# source os_conf again, as it might have changed after restore
|
||||||
|
test -f /etc/init.d/os_conf && source /etc/init.d/os_conf
|
||||||
|
if [[ "${OS_DEBUG}" != "true" ]]; then
|
||||||
|
mount -o remount,ro /boot
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
stop)
|
||||||
|
true
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {start}"
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit $?
|
||||||
|
|
@ -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|file> (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|file> (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"
|
||||||
@ -33,8 +33,12 @@ fi
|
|||||||
|
|
||||||
#### configuration ####
|
#### configuration ####
|
||||||
|
|
||||||
|
set -a
|
||||||
|
set -e
|
||||||
|
|
||||||
SYS_VERSION_FILE=/etc/version
|
SYS_VERSION_FILE=/etc/version
|
||||||
SYS_BOARD_FILE=/etc/board
|
SYS_BOARD_FILE=/etc/board
|
||||||
|
OS_CONF_FILE=/etc/init.d/os_conf
|
||||||
|
|
||||||
MIN_FREE_DISK=$((500*1024)) # 500 MB
|
MIN_FREE_DISK=$((500*1024)) # 500 MB
|
||||||
VER_FILE=version
|
VER_FILE=version
|
||||||
@ -58,11 +62,15 @@ XZCAT_PID_FILE=xzcat.pid
|
|||||||
DD_LOG_FILE=dd.log
|
DD_LOG_FILE=dd.log
|
||||||
DD_PID_FILE=dd.pid
|
DD_PID_FILE=dd.pid
|
||||||
|
|
||||||
|
source ${OS_CONF_FILE}
|
||||||
|
source ${SYS_VERSION_FILE}
|
||||||
|
|
||||||
|
|
||||||
#### disk & partition devices ####
|
#### disk & partition devices ####
|
||||||
|
|
||||||
BOOT_DEV=$(mount | grep /boot | cut -d ' ' -f 1)
|
BOOT_DEV=$(mount | grep /boot | cut -d ' ' -f 1)
|
||||||
ROOT_DEV=${BOOT_DEV:0:-1}2
|
ROOT_DEV=${BOOT_DEV:0:-1}2
|
||||||
|
DATA_DEV=${BOOT_DEV:0:-1}3
|
||||||
DISK_DEV=$(mount | grep /boot | cut -d ' ' -f 1)
|
DISK_DEV=$(mount | grep /boot | cut -d ' ' -f 1)
|
||||||
if [[ "${ROOT_DEV}" =~ ^([/a-z0-9]+)(p[0-9])$ ]]; then # e.g. /dev/mmcblk0p2
|
if [[ "${ROOT_DEV}" =~ ^([/a-z0-9]+)(p[0-9])$ ]]; then # e.g. /dev/mmcblk0p2
|
||||||
DISK_DEV=${BASH_REMATCH[1]}
|
DISK_DEV=${BASH_REMATCH[1]}
|
||||||
@ -77,8 +85,6 @@ fi
|
|||||||
#### versions ####
|
#### versions ####
|
||||||
|
|
||||||
function show_versions() {
|
function show_versions() {
|
||||||
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
|
||||||
|
|
||||||
@ -112,8 +118,6 @@ function show_versions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function show_current() {
|
function show_current() {
|
||||||
source ${SYS_VERSION_FILE}
|
|
||||||
|
|
||||||
echo ${OS_VERSION}
|
echo ${OS_VERSION}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,8 +148,6 @@ function do_download() {
|
|||||||
fi
|
fi
|
||||||
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
|
||||||
@ -208,6 +210,34 @@ function download_status() {
|
|||||||
|
|
||||||
#### extract ####
|
#### extract ####
|
||||||
|
|
||||||
|
function run_pre_upgrade() {
|
||||||
|
which losetup &>/dev/null || return 0
|
||||||
|
|
||||||
|
root_start=$(cat ${FW_DIR}/${ROOT_INFO_FILE} | cut -d ' ' -f 1)
|
||||||
|
tmp_mnt="/tmp/fwupdate_root"
|
||||||
|
loop="/dev/loop4"
|
||||||
|
pre_upgrade="${tmp_mnt}/usr/share/pre-upgrade/*"
|
||||||
|
|
||||||
|
mkdir -p ${tmp_mnt}
|
||||||
|
losetup -o $((root_start * 1024 * 1024)) ${loop} ${FW_DIR}/${FW_FILE_EXTR}
|
||||||
|
mount ${loop} ${tmp_mnt}
|
||||||
|
if [[ -d ${pre_upgrade} ]]; then
|
||||||
|
for script in ${pre_upgrade}/*.sh; do
|
||||||
|
echo "running pre-upgrade script $(basename ${script})"
|
||||||
|
if [[ -x ${script} ]] && ! ${script}; then
|
||||||
|
# non-zero exit status of pre-upgrade script indicates that
|
||||||
|
# the upgrade process must not be continued
|
||||||
|
|
||||||
|
echo "aborted by pre-upgrade script"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
umount ${tmp_mnt}
|
||||||
|
losetup -d ${loop}
|
||||||
|
}
|
||||||
|
|
||||||
function do_extract() {
|
function do_extract() {
|
||||||
echo "extracting..."
|
echo "extracting..."
|
||||||
|
|
||||||
@ -249,35 +279,9 @@ function do_extract() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# verify available partition space
|
|
||||||
|
|
||||||
fw_boot_info=$(fdisk --bytes -l -o device,start,end,size ${FW_DIR}/${FW_FILE_EXTR} | grep "${FW_FILE_EXTR}1")
|
|
||||||
fw_boot_info=(${fw_boot_info})
|
|
||||||
fw_boot_size=${fw_boot_info[3]}
|
|
||||||
|
|
||||||
fw_root_info=$(fdisk --bytes -l -o device,start,end,size ${FW_DIR}/${FW_FILE_EXTR} | grep "${FW_FILE_EXTR}2")
|
|
||||||
fw_root_info=(${fw_root_info})
|
|
||||||
fw_root_size=${fw_root_info[3]}
|
|
||||||
|
|
||||||
disk_boot_info=$(fdisk --bytes -l -o device,start,end,size ${DISK_DEV} | grep ${BOOT_DEV})
|
|
||||||
disk_boot_info=(${disk_boot_info})
|
|
||||||
disk_boot_size=${disk_boot_info[3]}
|
|
||||||
|
|
||||||
disk_root_info=$(fdisk --bytes -l -o device,start,end,size ${DISK_DEV} | grep ${ROOT_DEV})
|
|
||||||
disk_root_info=(${disk_root_info})
|
|
||||||
disk_root_size=${disk_root_info[3]}
|
|
||||||
|
|
||||||
if [[ ${disk_boot_size} -lt ${fw_boot_size} ]]; then
|
|
||||||
echo "not enough space on boot partition (${fw_boot_size} needed, ${disk_boot_size} available)" 1>&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ${disk_root_size} -lt ${fw_root_size} ]]; then
|
|
||||||
echo "not enough space on root partition (${fw_root_size} needed, ${disk_root_size} available)" 1>&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# TODO verify hash
|
# TODO verify hash
|
||||||
|
|
||||||
|
run_pre_upgrade
|
||||||
}
|
}
|
||||||
|
|
||||||
function extract_status() {
|
function extract_status() {
|
||||||
@ -303,18 +307,55 @@ function extract_status() {
|
|||||||
|
|
||||||
#### flash boot ####
|
#### flash boot ####
|
||||||
|
|
||||||
function flash_boot() {
|
function reallocate_boot_part() {
|
||||||
|
boot_info=$(fdisk --bytes -l -o device,start,end,size ${DISK_DEV} | grep "${BOOT_DEV}")
|
||||||
|
boot_info=(${boot_info})
|
||||||
|
|
||||||
|
root_info=$(fdisk --bytes -l -o device,start,end,size ${DISK_DEV} | grep "${ROOT_DEV}")
|
||||||
|
root_info=(${root_info})
|
||||||
|
|
||||||
|
fw_boot_info=$(fdisk --bytes -l -o device,start,end,size ${FW_DIR}/${FW_FILE_EXTR} | grep "${FW_FILE_EXTR}1")
|
||||||
|
fw_boot_info=(${fw_boot_info})
|
||||||
|
|
||||||
|
if [[ ${boot_info[1]} == ${fw_boot_info[1]} ]] &&
|
||||||
|
[[ ${boot_info[2]} == ${fw_boot_info[2]} ]]; then
|
||||||
|
|
||||||
|
return # all good
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "reallocating boot partition..."
|
||||||
|
|
||||||
|
# check overlapping with root partition
|
||||||
|
if [[ ${fw_boot_info[2]} -ge ${root_info[1]} ]]; then
|
||||||
|
echo "cannot reallocate boot partition: will overlap with root"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
fdisk -w auto ${DISK_DEV} >/dev/null <<END
|
||||||
|
d
|
||||||
|
1
|
||||||
|
n
|
||||||
|
p
|
||||||
|
1
|
||||||
|
${fw_boot_info[1]}
|
||||||
|
${fw_boot_info[2]}
|
||||||
|
w
|
||||||
|
END
|
||||||
|
sync
|
||||||
|
}
|
||||||
|
|
||||||
|
function do_flash_boot() {
|
||||||
echo "flashing boot..."
|
echo "flashing boot..."
|
||||||
|
|
||||||
rm -f ${FW_DIR}/${BOOT_READY_FILE}
|
rm -f ${FW_DIR}/${BOOT_READY_FILE}
|
||||||
|
|
||||||
set +e
|
|
||||||
board=$(cat ${SYS_BOARD_FILE})
|
board=$(cat ${SYS_BOARD_FILE})
|
||||||
|
|
||||||
cp -r /boot ${FW_DIR}/old_boot
|
cp -r /boot ${FW_DIR}/old_boot
|
||||||
umount /boot
|
umount /boot
|
||||||
trap flash_cleanup EXIT
|
trap flash_cleanup EXIT
|
||||||
|
|
||||||
|
# prevent unwanted reboots during upgrade
|
||||||
mount -o remount,rw /
|
mount -o remount,rw /
|
||||||
mv /sbin/reboot /sbin/reboot.bak
|
mv /sbin/reboot /sbin/reboot.bak
|
||||||
ln -s /bin/true /sbin/reboot
|
ln -s /bin/true /sbin/reboot
|
||||||
@ -330,6 +371,8 @@ function flash_boot() {
|
|||||||
root_size=$((${root_info[3]} / 1048576)) # in MB
|
root_size=$((${root_info[3]} / 1048576)) # in MB
|
||||||
|
|
||||||
echo ${root_start} ${root_size} > ${FW_DIR}/${ROOT_INFO_FILE}
|
echo ${root_start} ${root_size} > ${FW_DIR}/${ROOT_INFO_FILE}
|
||||||
|
|
||||||
|
reallocate_boot_part
|
||||||
|
|
||||||
dd if=${FW_DIR}/${FW_FILE_EXTR} skip=${boot_start} of=${BOOT_DEV} bs=1048576 count=${boot_size} &>${FW_DIR}/${DD_LOG_FILE} &
|
dd if=${FW_DIR}/${FW_FILE_EXTR} skip=${boot_start} of=${BOOT_DEV} bs=1048576 count=${boot_size} &>${FW_DIR}/${DD_LOG_FILE} &
|
||||||
pid=$!
|
pid=$!
|
||||||
@ -373,7 +416,51 @@ function flash_cleanup() {
|
|||||||
|
|
||||||
#### flash reboot ####
|
#### flash reboot ####
|
||||||
|
|
||||||
function flash_reboot() {
|
function reallocate_root_part() {
|
||||||
|
root_info=$(fdisk --bytes -l -o device,start,end,size ${DISK_DEV} | grep "${ROOT_DEV}")
|
||||||
|
root_info=(${root_info})
|
||||||
|
|
||||||
|
data_info=$(fdisk --bytes -l -o device,start,end,size ${DISK_DEV} | grep "${DATA_DEV}")
|
||||||
|
data_info=(${data_info})
|
||||||
|
|
||||||
|
fw_root_info=$(fdisk --bytes -l -o device,start,end,size ${FW_DIR}/${FW_FILE_EXTR} | grep "${FW_FILE_EXTR}2")
|
||||||
|
fw_root_info=(${fw_root_info})
|
||||||
|
|
||||||
|
if [[ ${root_info[1]} == ${fw_root_info[1]} ]] &&
|
||||||
|
[[ ${root_info[2]} == ${fw_root_info[2]} ]]; then
|
||||||
|
|
||||||
|
return # all good
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "reallocating root partition..."
|
||||||
|
|
||||||
|
# check overlapping with data partition
|
||||||
|
if [[ ${fw_root_info[2]} -ge ${data_info[1]} ]]; then
|
||||||
|
echo "cannot reallocate root partition: will overlap with data"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
fdisk -w auto ${DISK_DEV} >/dev/null <<END
|
||||||
|
d
|
||||||
|
2
|
||||||
|
n
|
||||||
|
p
|
||||||
|
2
|
||||||
|
${fw_root_info[1]}
|
||||||
|
${fw_root_info[2]}
|
||||||
|
w
|
||||||
|
END
|
||||||
|
sync
|
||||||
|
}
|
||||||
|
|
||||||
|
function do_flash_reboot() {
|
||||||
|
if [[ ! -f ${FW_DIR}/${ROOT_INFO_FILE} ]]; then
|
||||||
|
echo "extracted firmware not present"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
reallocate_root_part
|
||||||
|
|
||||||
echo "preparing for reboot..."
|
echo "preparing for reboot..."
|
||||||
|
|
||||||
board=$(cat ${SYS_BOARD_FILE})
|
board=$(cat ${SYS_BOARD_FILE})
|
||||||
@ -397,6 +484,15 @@ function flash_reboot() {
|
|||||||
|
|
||||||
#### status ####
|
#### status ####
|
||||||
|
|
||||||
|
function new_version() {
|
||||||
|
cat ${FW_DIR}/${VER_FILE}
|
||||||
|
}
|
||||||
|
|
||||||
|
function backup_conf() {
|
||||||
|
echo "backing up /data/etc..."
|
||||||
|
tar -acf /boot/backup-etc-${OS_VERSION}.tar.gz -C /data etc
|
||||||
|
}
|
||||||
|
|
||||||
function show_status() {
|
function show_status() {
|
||||||
status=$(flash_boot_status)
|
status=$(flash_boot_status)
|
||||||
if [ "${status}" == "running" ]; then
|
if [ "${status}" == "running" ]; then
|
||||||
@ -434,25 +530,20 @@ function show_status() {
|
|||||||
function do_upgrade() {
|
function do_upgrade() {
|
||||||
echo "upgrading to $1"
|
echo "upgrading to $1"
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
do_download "$1"
|
do_download "$1"
|
||||||
show_status
|
show_status
|
||||||
|
|
||||||
do_extract
|
do_extract
|
||||||
show_status
|
show_status
|
||||||
|
|
||||||
flash_boot
|
do_flash_boot
|
||||||
show_status
|
show_status
|
||||||
|
|
||||||
flash_reboot
|
do_flash_reboot
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function new_version() {
|
#### main ####
|
||||||
cat ${FW_DIR}/${VER_FILE}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
versions)
|
versions)
|
||||||
@ -480,12 +571,12 @@ case "$1" in
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
flashboot)
|
flashboot)
|
||||||
flash_boot
|
do_flash_boot
|
||||||
show_status
|
show_status
|
||||||
;;
|
;;
|
||||||
|
|
||||||
flashreboot)
|
flashreboot)
|
||||||
flash_reboot
|
do_flash_reboot
|
||||||
;;
|
;;
|
||||||
|
|
||||||
status)
|
status)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user