Commit f6fa8672 authored by aTc's avatar aTc

Initial version

parents
#!/bin/bash
version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | tail -n 1)" == "$1"; }
check_exists() { if ! hash $1 2>/dev/null ; then echo $1 not found ; exit 1 ; fi ; }
if [ "$#" -ne 3 ] ; then echo "Usage: $0 : rootfs.tgz u-boot /dev/mmcblk1" ; exit 1 ; fi
if [ $(id -u) -ne 0 ] ; then echo "Must be run as root"; exit 0; fi
check_exists dd
check_exists sfdisk
check_exists mkfs.ext4
check_exists lsblk
check_exists id
UBOOT=$2
IMAGE=$1
DISK=$3
echo Image:$IMAGE Disk:$DISK U-Boot:$UBOOT
#if [ ! -d $UBOOT ] ; then echo "u-boot files not found"; exit 1; fi
if [ ! -f "${UBOOT}/MLO" ] || [ ! -f "${UBOOT}/u-boot.img" ] ; then echo "u-boot files not found"; exit 1; fi
if [ ! -f $IMAGE ] ; then echo "rootfs image $IMAGE not found."; exit 1; fi
lsblk $DISK
#if [[ $? != 0 ]] ; then echo Failed; exit 1; fi
echo "Installing to $DISK , make sure all partitions are unmounted"
read -p "Are you sure you want to continue? <y/N> " prompt
if ! [[ $prompt =~ [yY](es)* ]] ; then echo "Exiting.." ; exit 1 ; fi
#exit 0
if [[ $DISK == /dev/mmcblk* ]] ; then
PART=${DISK}p1
else
PART=${DISK}1
fi
echo "Clearing partition table"
dd if=/dev/zero of=${DISK} bs=1M count=10
if [[ $? != 0 ]] ; then echo Partitioning failed.; exit 1; fi
echo "Installing U-Boot"
dd if="$UBOOT/MLO" of=${DISK} count=1 seek=1 bs=128k
dd if="$UBOOT/u-boot.img" of=${DISK} count=2 seek=1 bs=384k
echo "Creating partition"
SFVER=$(sfdisk -v | awk '{print $4}')
echo Found sfdisk version: ${SFVER}
if version_gt $SFVER 2.26.0; then
echo "> 2.26.0"
sfdisk ${DISK} <<-__EOF__
1M,,0x83,*
__EOF__
else
echo "< 2.26.0"
sfdisk --in-order --Linux --unit M ${DISK} <<-__EOF__
1,,0x83,*
__EOF__
fi
if [[ $? != 0 ]] ; then echo Partitioning failed.; exit 1; fi
echo "Formatting partition"
mkfs.ext4 -O ^64bit ${PART} -L rootfs
if [[ $? != 0 ]] ; then echo Formatting failed.; exit 1; fi
mkdir rootfs
mount ${PART} ./rootfs
if [[ $? != 0 ]] ; then echo Mounting ${PART} failed.; exit 1; fi
echo "Installing rootfs"
if hash bar 2>/dev/null ; then
bar $IMAGE | tar --numeric-owner -xzf - -C rootfs
else
echo Install "bar" for progress bar
tar --numeric-owner -xzf $IMAGE -C rootfs
fi
if [[ $? != 0 ]] ; then echo Extracting $IMAGE failed.; umount ${PART} ; exit 1; fi
echo "Syncing"
sync
umount rootfs
rm rootfs -rf
echo "Done"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment