feature: 0.3.2 -> 0.3.3 upgrade (#1958)

* 0.3.2 -> 0.3.3 upgrade script

* fix upgrade

* integrated image

* fix rip-image

* no U option on older rsync

* permissions and cleanup

* fixes

* label fs

* fix progress reporting

* only create rootfs for lite upgrade

* shrink image after creating

* fix for `blue` partitions
This commit is contained in:
Aiden McClelland
2022-11-23 12:58:46 -07:00
parent b40be8c494
commit 0ecd920ad9
8 changed files with 208 additions and 121 deletions

View File

@@ -0,0 +1,47 @@
#!/bin/bash
set -e
function partition_for () {
if [[ "$1" =~ [0-9]+$ ]]; then
echo "$1p$2"
else
echo "$1$2"
fi
}
TARGET_NAME=lite-upgrade.img
TARGET_SIZE=7000000000
LOOPDEV=$(sudo losetup --show -fP raspios.img)
sudo cat `partition_for ${LOOPDEV} 2` > $TARGET_NAME
sudo losetup -d $LOOPDEV
truncate -s $TARGET_SIZE $TARGET_NAME
sudo e2fsck -f -y $TARGET_NAME
sudo resize2fs $TARGET_NAME
TMPDIR=$(mktemp -d)
mkdir $TMPDIR/target
mkdir $TMPDIR/source
sudo mount update.img $TMPDIR/source
sudo mount $TARGET_NAME $TMPDIR/target
sudo mkdir -p $TMPDIR/target/update
sudo rsync -acvAXH $TMPDIR/source/ $TMPDIR/target/update/
sudo cp ./build/raspberry-pi/033-upgrade.sh $TMPDIR/target/usr/local/bin/033-upgrade.sh
sudo cp ./build/raspberry-pi/033-upgrade.service $TMPDIR/target/etc/systemd/system/033-upgrade.service
sudo ln -s /etc/systemd/system/033-upgrade.service $TMPDIR/target/etc/systemd/system/multi-user.target.wants/033-upgrade.service
sudo cp ./build/raspberry-pi/nc-broadcast.service $TMPDIR/target/etc/systemd/system/nc-broadcast.service
sudo ln -s /etc/systemd/system/nc-broadcast.service $TMPDIR/target/etc/systemd/system/multi-user.target.wants/nc-broadcast.service
sudo umount $TMPDIR/target
sudo e2fsck -f -y $TARGET_NAME
sudo resize2fs -M $TARGET_NAME
BLOCK_INFO=$(sudo dumpe2fs $TARGET_NAME)
BLOCK_COUNT=$(echo "$BLOCK_INFO" | grep "Block count:" | sed 's/Block count:\s\+//g')
BLOCK_SIZE=$(echo "$BLOCK_INFO" | grep "Block size:" | sed 's/Block size:\s\+//g')
FS_SIZE=$[$BLOCK_COUNT*$BLOCK_SIZE]
truncate -s $FS_SIZE $TARGET_NAME