mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
fix quick flash
This commit is contained in:
committed by
Aiden McClelland
parent
c68342ee10
commit
da0eecfad8
@@ -12,10 +12,42 @@ else
|
|||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! which pv > /dev/null; then
|
||||||
|
>&2 echo 'This script would like to use `pv` to show a progress indicator, but it is not installed.'
|
||||||
|
if which apt-get > /dev/null; then
|
||||||
|
read -p "Install? [y/N]" -n 1 -r
|
||||||
|
echo
|
||||||
|
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
|
||||||
|
sudo apt-get install pv
|
||||||
|
fi
|
||||||
|
elif which pacman > /dev/null; then
|
||||||
|
read -p "Install? [y/N]" -n 1 -r
|
||||||
|
echo
|
||||||
|
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
|
||||||
|
sudo pacman -S pv
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
>&2 echo 'This script does not recognize what package manager you have available on your system.'
|
||||||
|
>&2 echo 'Please go install the utility manually if you want progress reporting.'
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if ! test -e /dev/disk/by-label/green; then
|
if ! test -e /dev/disk/by-label/green; then
|
||||||
>&2 echo '`green` partition not found'
|
>&2 echo '`green` partition not found'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
export TARGET_PARTITION=$(readlink -f /dev/disk/by-label/green)
|
||||||
|
|
||||||
|
if [[ "$TARGET_PARTITION" =~ ^/dev/loop ]]; then
|
||||||
|
>&2 echo 'You are currently flashing onto a loop device.'
|
||||||
|
>&2 echo 'This is probably a mistake, and usually means you failed to detach a .img file.'
|
||||||
|
read -p "Continue anyway? [y/N]" -n 1 -r
|
||||||
|
if ! [[ "$REPLY" =~ ^[Yy]$ ]]; then
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
export SOURCE_DEVICE=$(sudo losetup --show -fP eos.img)
|
export SOURCE_DEVICE=$(sudo losetup --show -fP eos.img)
|
||||||
sudo e2fsck -f ${SOURCE_DEVICE}p3
|
sudo e2fsck -f ${SOURCE_DEVICE}p3
|
||||||
@@ -23,13 +55,19 @@ sudo resize2fs -M ${SOURCE_DEVICE}p3
|
|||||||
export BLOCK_INFO=$(sudo dumpe2fs ${SOURCE_DEVICE}p3)
|
export BLOCK_INFO=$(sudo dumpe2fs ${SOURCE_DEVICE}p3)
|
||||||
export BLOCK_COUNT=$(echo "$BLOCK_INFO" | grep "Block count:" | sed 's/Block count:\s\+//g')
|
export BLOCK_COUNT=$(echo "$BLOCK_INFO" | grep "Block count:" | sed 's/Block count:\s\+//g')
|
||||||
export BLOCK_SIZE=$(echo "$BLOCK_INFO" | grep "Block size:" | sed 's/Block size:\s\+//g')
|
export BLOCK_SIZE=$(echo "$BLOCK_INFO" | grep "Block size:" | sed 's/Block size:\s\+//g')
|
||||||
sudo dd if=${SOURCE_DEVICE}p3 of=/dev/disk/by-label/green count=$BLOCK_COUNT bs=$BLOCK_SIZE status=progress
|
export FS_SIZE=$[$BLOCK_COUNT*$BLOCK_SIZE]
|
||||||
|
echo "Flashing $FS_SIZE bytes to $TARGET_PARTITION"
|
||||||
|
if which pv > /dev/null; then
|
||||||
|
sudo cat ${SOURCE_DEVICE}p3 | head -c $FS_SIZE | pv -s $FS_SIZE | sudo dd of=${TARGET_PARTITION} bs=1M iflag=fullblock oflag=direct 2>/dev/null
|
||||||
|
else
|
||||||
|
sudo cat ${SOURCE_DEVICE}p3 | head -c $FS_SIZE | sudo dd of=${TARGET_PARTITION} bs=1M iflag=fullblock oflag=direct
|
||||||
|
fi
|
||||||
echo Verifying...
|
echo Verifying...
|
||||||
export INPUT_HASH=$(sudo dd if=${SOURCE_DEVICE}p3 count=$BLOCK_COUNT bs=$BLOCK_SIZE | sha256sum)
|
export INPUT_HASH=$(sudo cat ${SOURCE_DEVICE}p3 | head -c $FS_SIZE | sha256sum)
|
||||||
export OUTPUT_HASH=$(sudo dd if=/dev/disk/by-label/green count=$BLOCK_COUNT bs=$BLOCK_SIZE | sha256sum)
|
export OUTPUT_HASH=$(sudo cat ${TARGET_PARTITION} | head -c $FS_SIZE | sha256sum)
|
||||||
sudo losetup -d ${SOURCE_DEVICE}
|
sudo losetup -d ${SOURCE_DEVICE}
|
||||||
if ! [[ "$INPUT_HASH" == "$OUTPUT_HASH" ]]; then
|
if ! [[ "$INPUT_HASH" == "$OUTPUT_HASH" ]]; then
|
||||||
>&2 echo Verification Failed
|
>&2 echo Verification Failed
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo Quick Flash Successfull
|
echo "Verification Succeeded"
|
||||||
|
|||||||
Reference in New Issue
Block a user