From 4fbdb4071c92c95bccfcbc923ec69477f70dad5c Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 1 Feb 2019 21:52:08 +0200 Subject: [PATCH 1/8] fwupdate: add cleanupgrade command --- board/common/overlay/etc/init.d/S00datapart | 5 +- board/common/overlay/sbin/fwupdate | 89 +++++++++++++++------ 2 files changed, 70 insertions(+), 24 deletions(-) diff --git a/board/common/overlay/etc/init.d/S00datapart b/board/common/overlay/etc/init.d/S00datapart index b1f25768eb..5c76f928fa 100755 --- a/board/common/overlay/etc/init.d/S00datapart +++ b/board/common/overlay/etc/init.d/S00datapart @@ -1,5 +1,8 @@ #!/bin/bash +DATA_OFFS="1024" # up to 1024MB reserved for boot + root + + test -n "${OS_VERSION}" || source /etc/init.d/base case "$1" in @@ -23,7 +26,7 @@ case "$1" in test -b ${data_dev} && exit 0 msg_begin "Creating data partition" - data_start=$((1024 * 2048)) # up to 1024MB reserved for boot + root + data_start=$((DATA_OFFS * 2048)) echo -e "n p 3 diff --git a/board/common/overlay/sbin/fwupdate b/board/common/overlay/sbin/fwupdate index 4e66f01bb5..2bdc879257 100755 --- a/board/common/overlay/sbin/fwupdate +++ b/board/common/overlay/sbin/fwupdate @@ -4,14 +4,15 @@ #### usage #### function exit_usage() { - echo "Usage: fwupdate versions [-j] (lists available versions, optionally outputting json)" - echo " fwupdate current (shows the current version" - echo " fwupdate download (downloads a firmware version)" - echo " fwupdate extract (extracts the downloaded firmware archive)" - echo " fwupdate flashboot (flashes the boot partition from extracted image)" - echo " fwupdate flashreboot (prepares for reboot + root partititon flash)" - echo " fwupdate status (shows the current firmware updating status; see below)" - echo " fwupdate upgrade (performs all the operations necessary for upgrading)" + echo "Usage: fwupdate versions [-j] (lists available versions, optionally outputting json)" + echo " fwupdate current (shows the current version" + echo " fwupdate download (downloads a firmware version)" + echo " fwupdate extract (extracts the downloaded firmware archive)" + echo " fwupdate flashboot (flashes the boot partition from extracted image)" + echo " fwupdate flashreboot (prepares for reboot + root partititon flash)" + echo " fwupdate status (shows the current firmware updating status; see below)" + echo " fwupdate upgrade (performs all the operations necessary for upgrading)" + echo " fwupdate cleanupgrade (same as upgrade, but remove data partition, preserving config files)" echo "" echo "Statuses:" echo " idle" @@ -35,6 +36,7 @@ fi SYS_VERSION_FILE=/etc/version SYS_BOARD_FILE=/etc/board +OS_CONF_FILE=/etc/init.d/os_conf MIN_FREE_DISK=$((500*1024)) # 500 MB VER_FILE=version @@ -58,6 +60,9 @@ XZCAT_PID_FILE=xzcat.pid DD_LOG_FILE=dd.log DD_PID_FILE=dd.pid +source ${OS_CONF_FILE} +source ${SYS_VERSION_FILE} + #### disk & partition devices #### @@ -77,8 +82,6 @@ fi #### versions #### function show_versions() { - source /etc/init.d/os_conf # we need this for the OS_ vars - board=$(cat ${SYS_BOARD_FILE}) show_json=$1 @@ -112,8 +115,6 @@ function show_versions() { } function show_current() { - source ${SYS_VERSION_FILE} - echo ${OS_VERSION} } @@ -144,8 +145,6 @@ function do_download() { fi fi - source /etc/init.d/os_conf # we need this for the OS_ vars - board=$(cat ${SYS_BOARD_FILE}) url=$1 version=$1 @@ -303,7 +302,7 @@ function extract_status() { #### flash boot #### -function flash_boot() { +function do_flash_boot() { echo "flashing boot..." rm -f ${FW_DIR}/${BOOT_READY_FILE} @@ -373,7 +372,7 @@ function flash_cleanup() { #### flash reboot #### -function flash_reboot() { +function do_flash_reboot() { echo "preparing for reboot..." board=$(cat ${SYS_BOARD_FILE}) @@ -397,6 +396,25 @@ function flash_reboot() { #### 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 remove_data_part() { + echo "removing data partition..." + fdisk ${DISK_DEV} >/dev/null < Date: Fri, 1 Feb 2019 23:14:03 +0200 Subject: [PATCH 2/8] fwupdate: add root partition relocation support --- board/common/overlay/sbin/fwupdate | 87 +++++++++++++++++++++++++++--- 1 file changed, 81 insertions(+), 6 deletions(-) diff --git a/board/common/overlay/sbin/fwupdate b/board/common/overlay/sbin/fwupdate index 2bdc879257..e249ff33e0 100755 --- a/board/common/overlay/sbin/fwupdate +++ b/board/common/overlay/sbin/fwupdate @@ -34,6 +34,8 @@ fi #### configuration #### +set -a + SYS_VERSION_FILE=/etc/version SYS_BOARD_FILE=/etc/board OS_CONF_FILE=/etc/init.d/os_conf @@ -68,6 +70,7 @@ source ${SYS_VERSION_FILE} BOOT_DEV=$(mount | grep /boot | cut -d ' ' -f 1) ROOT_DEV=${BOOT_DEV:0:-1}2 +DATA_DEV=${BOOT_DEV:0:-1}3 DISK_DEV=$(mount | grep /boot | cut -d ' ' -f 1) if [[ "${ROOT_DEV}" =~ ^([/a-z0-9]+)(p[0-9])$ ]]; then # e.g. /dev/mmcblk0p2 DISK_DEV=${BASH_REMATCH[1]} @@ -78,6 +81,8 @@ else exit 1 fi +set +a + #### versions #### @@ -250,19 +255,19 @@ function do_extract() { # 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=$(fdisk -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=$(fdisk -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=$(fdisk -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=$(fdisk -l -o device,start,end,size ${DISK_DEV} | grep ${ROOT_DEV}) disk_root_info=(${disk_root_info}) disk_root_size=${disk_root_info[3]} @@ -318,12 +323,12 @@ function do_flash_boot() { mv /sbin/reboot /sbin/reboot.bak ln -s /bin/true /sbin/reboot - boot_info=$(fdisk --bytes -l -o device,start,end,size ${FW_DIR}/${FW_FILE_EXTR} | grep "${FW_FILE_EXTR}1") + boot_info=$(fdisk -l -o device,start,end,size ${FW_DIR}/${FW_FILE_EXTR} | grep "${FW_FILE_EXTR}1") boot_info=(${boot_info}) boot_start=$((${boot_info[1]} / 2048)) # in MB boot_size=$((${boot_info[3]} / 1048576)) # in MB - root_info=$(fdisk --bytes -l -o device,start,end,size ${FW_DIR}/${FW_FILE_EXTR} | grep "${FW_FILE_EXTR}2") + root_info=$(fdisk -l -o device,start,end,size ${FW_DIR}/${FW_FILE_EXTR} | grep "${FW_FILE_EXTR}2") root_info=(${root_info}) root_start=$((${root_info[1]} / 2048)) # in MB root_size=$((${root_info[3]} / 1048576)) # in MB @@ -372,7 +377,77 @@ function flash_cleanup() { #### flash reboot #### +function run_pre_upgrade() { + 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 reallocate_root_part() { + root_info=$(fdisk -l -o device,start,end,size ${DISK_DEV} | grep "${ROOT_DEV}") + root_info=(${root_info}) + + data_info=$(fdisk -l -o device,start,end,size ${DISK_DEV} | grep "${DATA_DEV}") + data_info=(${data_info}) + + fw_root_info=$(fdisk -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 + + # 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 ${DISK_DEV} >/dev/null < Date: Fri, 1 Feb 2019 23:25:55 +0200 Subject: [PATCH 3/8] busybox: enable losetup --- board/common/busybox.config | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/board/common/busybox.config b/board/common/busybox.config index 1a3a02eda5..f70c01fc58 100644 --- a/board/common/busybox.config +++ b/board/common/busybox.config @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit # Busybox version: 1.29.2 -# Fri Jan 25 20:24:12 2019 +# Fri Feb 1 22:19:53 2019 # CONFIG_HAVE_DOT_CONFIG=y @@ -384,9 +384,9 @@ CONFIG_RESET=y # CONFIG_RUN_PARTS is not set # CONFIG_FEATURE_RUN_PARTS_LONG_OPTIONS is not set # CONFIG_FEATURE_RUN_PARTS_FANCY is not set -CONFIG_START_STOP_DAEMON=y -CONFIG_FEATURE_START_STOP_DAEMON_LONG_OPTIONS=y -CONFIG_FEATURE_START_STOP_DAEMON_FANCY=y +# CONFIG_START_STOP_DAEMON is not set +# CONFIG_FEATURE_START_STOP_DAEMON_LONG_OPTIONS is not set +# CONFIG_FEATURE_START_STOP_DAEMON_FANCY is not set CONFIG_WHICH=y # @@ -621,7 +621,7 @@ CONFIG_HWCLOCK=y # CONFIG_IPCS is not set # CONFIG_LAST is not set # CONFIG_FEATURE_LAST_FANCY is not set -# CONFIG_LOSETUP is not set +CONFIG_LOSETUP=y # CONFIG_LSPCI is not set CONFIG_LSUSB=y # CONFIG_MDEV is not set From 91389abbf23b280db6145505482cd9776a0a9a74 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 1 Feb 2019 23:36:18 +0200 Subject: [PATCH 4/8] fwupdate: add support for boot partition reallocation --- board/common/overlay/sbin/fwupdate | 79 +++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 22 deletions(-) diff --git a/board/common/overlay/sbin/fwupdate b/board/common/overlay/sbin/fwupdate index e249ff33e0..6ef83e5778 100755 --- a/board/common/overlay/sbin/fwupdate +++ b/board/common/overlay/sbin/fwupdate @@ -35,6 +35,7 @@ fi #### configuration #### set -a +set -e SYS_VERSION_FILE=/etc/version SYS_BOARD_FILE=/etc/board @@ -81,8 +82,6 @@ else exit 1 fi -set +a - #### versions #### @@ -255,19 +254,19 @@ function do_extract() { # verify available partition space - fw_boot_info=$(fdisk -l -o device,start,end,size ${FW_DIR}/${FW_FILE_EXTR} | grep "${FW_FILE_EXTR}1") + 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 -l -o device,start,end,size ${FW_DIR}/${FW_FILE_EXTR} | grep "${FW_FILE_EXTR}2") + 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 -l -o device,start,end,size ${DISK_DEV} | grep ${BOOT_DEV}) + 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 -l -o device,start,end,size ${DISK_DEV} | grep ${ROOT_DEV}) + 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]} @@ -307,33 +306,72 @@ function extract_status() { #### 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 < ${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} & pid=$! @@ -404,13 +442,13 @@ function run_pre_upgrade() { } function reallocate_root_part() { - root_info=$(fdisk -l -o device,start,end,size ${DISK_DEV} | grep "${ROOT_DEV}") + root_info=$(fdisk --bytes -l -o device,start,end,size ${DISK_DEV} | grep "${ROOT_DEV}") root_info=(${root_info}) - data_info=$(fdisk -l -o device,start,end,size ${DISK_DEV} | grep "${DATA_DEV}") + data_info=$(fdisk --bytes -l -o device,start,end,size ${DISK_DEV} | grep "${DATA_DEV}") data_info=(${data_info}) - fw_root_info=$(fdisk -l -o device,start,end,size ${FW_DIR}/${FW_FILE_EXTR} | grep "${FW_FILE_EXTR}2") + 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]} ]] && @@ -419,21 +457,22 @@ function reallocate_root_part() { 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 ${DISK_DEV} >/dev/null </dev/null < Date: Fri, 1 Feb 2019 23:39:43 +0200 Subject: [PATCH 5/8] fwupdate: run pre-upgrade after extract --- board/common/overlay/sbin/fwupdate | 57 ++++++++++++++++-------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/board/common/overlay/sbin/fwupdate b/board/common/overlay/sbin/fwupdate index 6ef83e5778..c60ed01e75 100755 --- a/board/common/overlay/sbin/fwupdate +++ b/board/common/overlay/sbin/fwupdate @@ -211,6 +211,34 @@ function download_status() { #### extract #### +function run_pre_upgrade() { + which losetup &>/dev/null || return + + 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() { echo "extracting..." @@ -281,6 +309,8 @@ function do_extract() { fi # TODO verify hash + + run_pre_upgrade } function extract_status() { @@ -415,32 +445,6 @@ function flash_cleanup() { #### flash reboot #### -function run_pre_upgrade() { - 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 reallocate_root_part() { root_info=$(fdisk --bytes -l -o device,start,end,size ${DISK_DEV} | grep "${ROOT_DEV}") root_info=(${root_info}) @@ -484,7 +488,6 @@ function do_flash_reboot() { return 1 fi - run_pre_upgrade reallocate_root_part echo "preparing for reboot..." From 902304808708d2cb83bdfde55e39e4873f7b9a60 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 1 Feb 2019 23:40:03 +0200 Subject: [PATCH 6/8] fwupdate: do not verify partition space after extract --- board/common/overlay/sbin/fwupdate | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/board/common/overlay/sbin/fwupdate b/board/common/overlay/sbin/fwupdate index c60ed01e75..9751ba5ce9 100755 --- a/board/common/overlay/sbin/fwupdate +++ b/board/common/overlay/sbin/fwupdate @@ -280,34 +280,6 @@ function do_extract() { exit 1 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 run_pre_upgrade From 89c7c36a23f94f770865fa166ef1fb2b0c54520b Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 1 Feb 2019 23:58:26 +0200 Subject: [PATCH 7/8] fwupdate: remove cleanupgrade command --- board/common/overlay/sbin/fwupdate | 39 +----------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/board/common/overlay/sbin/fwupdate b/board/common/overlay/sbin/fwupdate index 9751ba5ce9..d9097227eb 100755 --- a/board/common/overlay/sbin/fwupdate +++ b/board/common/overlay/sbin/fwupdate @@ -12,7 +12,6 @@ function exit_usage() { echo " fwupdate flashreboot (prepares for reboot + root partititon flash)" echo " fwupdate status (shows the current firmware updating status; see below)" echo " fwupdate upgrade (performs all the operations necessary for upgrading)" - echo " fwupdate cleanupgrade (same as upgrade, but remove data partition, preserving config files)" echo "" echo "Statuses:" echo " idle" @@ -212,7 +211,7 @@ function download_status() { #### extract #### function run_pre_upgrade() { - which losetup &>/dev/null || return + which losetup &>/dev/null || return 0 root_start=$(cat ${FW_DIR}/${ROOT_INFO_FILE} | cut -d ' ' -f 1) tmp_mnt="/tmp/fwupdate_root" @@ -494,16 +493,6 @@ function backup_conf() { tar -acf /boot/backup-etc-${OS_VERSION}.tar.gz -C /data etc } -function remove_data_part() { - echo "removing data partition..." - fdisk ${DISK_DEV} >/dev/null < Date: Sat, 2 Feb 2019 02:13:31 +0200 Subject: [PATCH 8/8] Add S02restorebackups --- .../overlay/etc/init.d/S02restorebackups | 47 +++++++++++++++++++ .../etc/init.d/{S02modules => S03modules} | 0 .../etc/init.d/{S03hostname => S04hostname} | 0 .../etc/init.d/{S04syslog => S05syslog} | 0 4 files changed, 47 insertions(+) create mode 100755 board/common/overlay/etc/init.d/S02restorebackups rename board/common/overlay/etc/init.d/{S02modules => S03modules} (100%) rename board/common/overlay/etc/init.d/{S03hostname => S04hostname} (100%) rename board/common/overlay/etc/init.d/{S04syslog => S05syslog} (100%) diff --git a/board/common/overlay/etc/init.d/S02restorebackups b/board/common/overlay/etc/init.d/S02restorebackups new file mode 100755 index 0000000000..fd5e733a4b --- /dev/null +++ b/board/common/overlay/etc/init.d/S02restorebackups @@ -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 $? + diff --git a/board/common/overlay/etc/init.d/S02modules b/board/common/overlay/etc/init.d/S03modules similarity index 100% rename from board/common/overlay/etc/init.d/S02modules rename to board/common/overlay/etc/init.d/S03modules diff --git a/board/common/overlay/etc/init.d/S03hostname b/board/common/overlay/etc/init.d/S04hostname similarity index 100% rename from board/common/overlay/etc/init.d/S03hostname rename to board/common/overlay/etc/init.d/S04hostname diff --git a/board/common/overlay/etc/init.d/S04syslog b/board/common/overlay/etc/init.d/S05syslog similarity index 100% rename from board/common/overlay/etc/init.d/S04syslog rename to board/common/overlay/etc/init.d/S05syslog