From 0d1384c9fd6ce92d7485ab1f01b3871d10960c41 Mon Sep 17 00:00:00 2001 From: Andre Pedro Date: Wed, 21 Nov 2018 02:01:12 +0100 Subject: [PATCH] Add pv util and fix autoupdate. --- buildopenfang.sh | 2 +- config/buildroot.config | 4 ++-- fs/etc/init.d/S40dafang | 10 +++++----- fs/opt/autoupdate.sh | 25 ++++++++++++++++++++----- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/buildopenfang.sh b/buildopenfang.sh index 6bed30e4..263df611 100755 --- a/buildopenfang.sh +++ b/buildopenfang.sh @@ -1,6 +1,6 @@ #!/bin/sh -TAG=rc04_01 +TAG=rc05_01 set -e diff --git a/config/buildroot.config b/config/buildroot.config index 60547f73..11c65b3c 100644 --- a/config/buildroot.config +++ b/config/buildroot.config @@ -1,6 +1,6 @@ # # Automatically generated file; DO NOT EDIT. -# Buildroot 2016.02-00007-g2ccb557 Configuration +# Buildroot 2016.02-00011-g71f6336 Configuration # BR2_HAVE_DOT_CONFIG=y @@ -457,7 +457,7 @@ BR2_PACKAGE_MEMSTAT=y # BR2_PACKAGE_NETPERF is not set # BR2_PACKAGE_OPROFILE is not set # BR2_PACKAGE_PAX_UTILS is not set -# BR2_PACKAGE_PV is not set +BR2_PACKAGE_PV=y # BR2_PACKAGE_RAMSMP is not set # BR2_PACKAGE_RAMSPEED is not set # BR2_PACKAGE_RT_TESTS is not set diff --git a/fs/etc/init.d/S40dafang b/fs/etc/init.d/S40dafang index 2fabe356..732539c9 100755 --- a/fs/etc/init.d/S40dafang +++ b/fs/etc/init.d/S40dafang @@ -20,26 +20,26 @@ start | "") mount -t jffs2 /dev/mtdblock9 /params # Detect other partitions available in the microSD - [[ -f "/dev/mmcblk0p2" ]] || { + [ -b "/dev/mmcblk0p2" ] && { mkdir -p /mnt/mmcblk0p2 mount /dev/mmcblk0p2 /mnt/mmcblk0p2 } - [[ -f "/dev/mmcblk0p3" ]] || { + [ -b "/dev/mmcblk0p3" ] && { mkdir -p /mnt/mmcblk0p3 mount /dev/mmcblk0p3 /mnt/mmcblk0p3 } - [[ -f "/dev/mmcblk0p4" ]] || { + [ -b "/dev/mmcblk0p4" ] && { mkdir -p /mnt/mmcblk0p4 mount /dev/mmcblk0p4 /mnt/mmcblk0p4 } - [[ -f "/dev/mmcblk0p5" ]] || { + [ -b "/dev/mmcblk0p5" ] && { mkdir -p /mnt/mmcblk0p5 mount /dev/mmcblk0p5 /mnt/mmcblk0p5 } # Try to find wpa_supplicant.conf in one of the available partitions PATH_TO_WPACONF=$(find /mnt -name "wpa_supplicant.conf") - [[ -z "$PATH_TO_WPACONF" ]] || { + [ -z "$PATH_TO_WPACONF" ] || { echo "Copying wpa_supplicant.conf ..." cp $PATH_TO_WPACONF /etc } diff --git a/fs/opt/autoupdate.sh b/fs/opt/autoupdate.sh index 13b38fdb..58c30741 100755 --- a/fs/opt/autoupdate.sh +++ b/fs/opt/autoupdate.sh @@ -9,9 +9,15 @@ ID= WORKING_DIR=/mnt/mmcblk0p2 update() { - xz -cd images-$ID.tar.xz | tar xvf - - [[ -d "/mnt/update" ]] || { mkdir /mnt/update; } + echo "Update is starting..." + + # check if there is enough memory available + [ $(free | head -3 | tail -1 | awk '{printf $4}') -gt 64000 ] || { echo "No free ram available! Try to disable HD mode first..."; exit 1; } + + xz -cd images-$ID.tar.xz | pv -s $(printf "%.0f\n" $(xz -l images-$ID.tar.xz | tail -n 1 | awk '{print $5}'))m | tar xvf - + + [ -d "/mnt/update" ] || { mkdir /mnt/update; } mount -t ext3 -o loop openfang-images/rootfs.ext2 /mnt/update @@ -30,7 +36,7 @@ version) --id=*) ID_NEW=$(echo "$1" | cut -d "=" -f 2) echo "$ID_NEW" - [[ ! -f "$WORKING_DIR/images-$ID_NEW.tar.xz" ]] || { + [ -f "$WORKING_DIR/images-$ID_NEW.tar.xz" ] && { cd $WORKING_DIR update exit 0 @@ -53,7 +59,7 @@ version) VERSION_=$(date -d "$VERSION" +%s) NEW_VER_=$(date -d "$NEW_VER" +%s) - if [[ "$VERSION_" -lt "$NEW_VER_" ]]; then + if [ "$VERSION_" -lt "$NEW_VER_" ]; then echo "***" echo "$VERSION ($VERSION_) will be updated to $NEW_VER ($NEW_VER_)" echo "***" @@ -67,15 +73,24 @@ version) echo "Current version is $date_b ($date_b_) and will be updated to $VERSION ($VERSION_)" echo "***" - [[ "$VERSION_" -le "$date_b_" ]] && { + [ "$VERSION_" -le "$date_b_" ] && { echo "nothing to do." exit 0 } + # check if there is a second partition + [ -d "$WORKING_DIR" ] || { echo "A second partition is not available to extract files!"; exit 1; } + + # check if there is 500mb free space available + [ $(df -k "$WORKING_DIR" | tail -n 1 | awk '{printf $4}') -gt 500000 ] || { echo "No space available!"; exit 1; } + cd $WORKING_DIR curl -L --insecure https://github.com/anmaped/openfang/releases/download/$TAG/images-$ID.tar.xz -o images-$ID.tar.xz + # check if file exists + [ -f "images-$ID.tar.xz" ] || { echo "Something wrong happen with the downloaded file."; exit 1; } + update ;;