| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 | #!/usr/bin/env bash# This file is part of the OpenADK project. OpenADK is copyrighted# material, please see the LICENCE file in the top-level directory.if [ $(id -u) -ne 0 ];then	echo "Installation is only possible as root"	exit 1fifor tool in parted sfdisk mkfs.vfat mkfs.ext4;do	if ! which $tool >/dev/null; then		echo "Checking if $tool is installed... failed"		f=1	fidone[[ $f -eq 1 ]] && exit 1if [ -z $1 ];then	echo "Please give your SD card device as first parameter"	exit 1else	if [ -z $2 ];then		echo "Please give your install tar archive as second parameter"		exit 1	fi	if [ -f $2 ];then		echo "Installing $2 on $1"	else		echo "$2 is not a file, exiting"		exit 1	fi	if [ -b $1 ];then		echo "Using $1 as SD card disk for installation"		echo "WARNING: This will destroy all data on $1 - type Yes to continue!"		read y		if [ "$y" = "Yes" ];then			$sfdisk -l $1 2>&1 |grep 'No medium'			if [ $? -eq 0 ];then				echo "No medium found"				exit 1			else				echo "Starting with installation"			fi		else			echo "Exiting."			exit 1		fi	else		echo "Sorry $1 is not a block device"		exit 1	fifi	if [ $(mount | grep $1| wc -l) -ne 0 ];then	echo "Block device $1 is in use, please umount first"	exit 1fiecho "Wiping existing partitions"dd if=/dev/zero of=$1 bs=512 count=1 >/dev/null 2>&1syncecho "Create partition and filesystem for raspberry pi"rootpart=${1}2parted -s $1 mklabel msdossleep 2maxsize=$(env LC_ALL=C parted $1 -s unit cyl print |awk '/^Disk/ { print $3 }'|sed -e 's/cyl//')rootsize=$(($maxsize-34))datasize=$(($maxsize-2))parted -s $1 unit cyl mkpart primary fat32 -- 0 16parted -s $1 unit cyl mkpart primary ext2 -- 16 $rootsizeparted -s $1 unit cyl mkpart primary ext2 $rootsize $datasizeparted -s $1 unit cyl mkpart primary fat32 $datasize $maxsizeparted -s $1 set 1 boot onsfdisk --change-id $1 4 88sleep 2mkfs.vfat ${1}1mkfs.ext4 ${1}2mkfs.ext4 ${1}3syncsleep 2tmp=$(mktemp -d)mount -t ext4 ${rootpart} $tmpmkdir $tmp/bootmkdir $tmp/datamount -t ext4 ${1}3 $tmp/datamkdir $tmp/data/mpd $tmp/data/xbmcmount -t vfat ${1}1 $tmp/bootsleep 1echo "Extracting install archive"tar -C $tmp -xzpf $2 echo "Fixing permissions"chmod 1777 $tmp/tmpchmod 4755 $tmp/bin/busyboxecho "/dev/mmcblk0p3	/data	ext4	rw	0	0" >>$tmp/etc/fstabumount $tmp/dataumount $tmp/bootumount $tmpecho "Successfully installed."exit 0
 |