#!/bin/sh ################################################################################ # This file is part of OpenELEC - http://www.openelec.tv # Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv) # # This Program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This Program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with OpenELEC.tv; see the file COPYING. If not, write to # the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA. # http://www.gnu.org/copyleft/gpl.html ################################################################################ # usage: sudo ./create_sdcard # example: sudo ./create_sdcard /dev/sdb platform='linux' unamestr=`uname` if [[ "$unamestr" = 'Darwin' ]]; then platform='osx' fi if [ "$(id -u)" != "0" ]; then clear echo "#########################################################" echo "# please execute with 'sudo' or -DANGEROUS!!!- as root #" echo "# example: sudo ./create_sdcard #" echo "#########################################################" exit 1 fi if [ -z "$1" ]; then clear echo "#########################################################" echo "# please execute with your drive as option #" echo "# example: sudo ./create_sdcard /dev/sdb #" echo "# or: sudo ./create_sdcard /dev/mmcblk0 #" echo "#########################################################" exit 1 fi DISK="$1" if [ "$platform" = "osx" ]; then PART1="${DISK}s1" PART2="${DISK}s2" else if [ "$DISK" = "/dev/mmcblk0" ]; then PART1="${DISK}p1" PART2="${DISK}p2" else PART1="${DISK}1" PART2="${DISK}2" fi fi clear echo "#########################################################" echo "# #" echo "# OpenELEC.tv USB Installer #" echo "# #" echo "#########################################################" echo "# #" echo "# This will wipe any data off your chosen drive #" echo "# Please read the instructions and use very carefully.. #" echo "# #" echo "#########################################################" # check for some required tools # Mac dependencies if [ "$platform" == "osx" ]; then diskutil listFilesystems | grep "fuse-ext2" > /dev/null if [ "$?" -eq "1" ]; then clear echo "#########################################################" echo "# #" echo "# OpenELEC.tv missing depency - Installation will quit #" echo "# #" echo "# We couldn't find the 'fuse-ext2' filesystem #" echo "# on your system. #" echo "# Please install OSXFuse and fuse-ext2 from the #" echo "# following websites: #" echo "# - http://osxfuse.github.com/ #" echo "# - http://sourceforge.net/projects/fuse-ext2/ #" echo "# #" echo "#########################################################" exit 1 fi # Linux dependencies else # this is needed to partion the drive which parted > /dev/null if [ "$?" = "1" ]; then clear echo "#########################################################" echo "# #" echo "# OpenELEC.tv missing tool - Installation will quit #" echo "# #" echo "# We can't find the required tool \"parted\" #" echo "# on your system. #" echo "# Please install it via your package manager. #" echo "# #" echo "#########################################################" exit 1 fi # this is needed to format the drive which mkfs.vfat > /dev/null if [ "$?" = "1" ]; then clear echo "#########################################################" echo "# #" echo "# OpenELEC.tv missing tool - Installation will quit #" echo "# #" echo "# We can't find the required tool \"mkfs.vfat\" #" echo "# on your system. #" echo "# Please install it via your package manager. #" echo "# #" echo "#########################################################" exit 1 fi # this is needed to format the drive which mkfs.ext4 > /dev/null if [ "$?" = "1" ]; then clear echo "#########################################################" echo "# #" echo "# OpenELEC.tv missing tool - Installation will quit #" echo "# #" echo "# We can't find the required tool \"mkfs.ext4\" #" echo "# on your system. #" echo "# Please install it via your package manager. #" echo "# #" echo "#########################################################" exit 1 fi # this is needed to tell the kernel for partition changes which partprobe > /dev/null if [ "$?" = "1" ]; then clear echo "#########################################################" echo "# #" echo "# OpenELEC.tv missing tool - Installation will quit #" echo "# #" echo "# We can't find the required tool \"partprobe\" #" echo "# on your system. #" echo "# Please install it via your package manager. #" echo "# #" echo "#########################################################" exit 1 fi fi # this is needed to tell the kernel for partition changes if [ "$platform" == "osx" ]; then which md5 > /dev/null else which md5sum > /dev/null fi if [ "$?" = "1" ]; then clear echo "#########################################################" echo "# #" echo "# OpenELEC.tv missing tool - Installation will quit #" echo "# #" echo "# We can't find the required tool \"md5sum\" #" echo "# on your system. #" echo "# Please install it via your package manager. #" echo "# #" echo "#########################################################" exit 1 fi # check MD5 sums echo "checking MD5 sum..." md5sumFailed() { clear echo "#########################################################" echo "# #" echo "# OpenELEC.tv failed md5 check - Installation will quit #" echo "# #" echo "# Your original download was probably corrupt. #" echo "# Please visit www.openelec.tv and get another copy #" echo "# #" echo "#########################################################" exit 1 } if [ "$platform" == "osx" ]; then real=`md5 -r target/KERNEL | cut -c 1-32` expected=`cat target/KERNEL.md5 | cut -c 1-32` if [ "$real" != "$expected" ]; then md5sumFailed fi real=`md5 -r target/SYSTEM | cut -c 1-32` expected=`cat target/SYSTEM.md5 | cut -c 1-32` if [ "$real" != "$expected" ]; then md5sumFailed fi else md5sum -c target/KERNEL.md5 if [ "$?" = "1" ]; then md5sumFailed fi md5sum -c target/SYSTEM.md5 if [ "$?" = "1" ]; then md5sumFailed fi fi # (TODO) umount everything (if more than one partition) umount ${DISK}* if [ "$platform" == "osx" ]; then unmount_partition() { partition=$1 echo "unmounting partition $partition..." return_code=0 while [ "$return_code" == "0" ]; do sleep 1 diskutil unmount force 2>&1 $partition | grep failed return_code=$? done } # Formating echo "erasing $DISK and creating partitions..." diskutil partitionDisk $1 2 MBRFormat "MS-DOS FAT32" "DOS" 128M "fuse-ext2" "OPENELEC" R unmount_partition $PART1 unmount_partition $PART2 else # remove all partitions from the drive echo "writing new disklabel on $DISK (removing all partitions)..." parted -s "$DISK" mklabel msdos # create a single partition echo "creating partitions on $DISK..." parted -s "$DISK" unit cyl mkpart primary fat32 -- 0 16 parted -s "$DISK" unit cyl mkpart primary ext2 -- 16 -2 # make partition active (bootable) echo "marking partition active..." parted -s "$DISK" set 1 boot on # tell kernel we have a new partition table echo "telling kernel we have a new partition table..." partprobe "$DISK" # create filesystem echo "creating filesystem on $PART1..." mkfs.vfat "$PART1" -n System echo "creating filesystem on $PART2..." mkfs.ext4 "$PART2" -L Storage fi # mount partition echo "mounting partition $PART1 ..." if [ "$platform" == "osx" ]; then rm -rf /tmp/openelec_install mkdir -p /tmp/openelec_install mount -t msdos "$PART1" /tmp/openelec_install MOUNTPOINT=/tmp/openelec_install else if [ -d /dev/shm ]; then rm -rf /dev/shm/openelec_install mkdir -p /dev/shm/openelec_install mount "$PART1" /dev/shm/openelec_install MOUNTPOINT=/dev/shm/openelec_install else rm -rf /tmp/openelec_install mkdir -p /tmp/openelec_install mount "$PART1" /tmp/openelec_install MOUNTPOINT=/tmp/openelec_install fi fi # create bootloader configuration echo "creating bootloader configuration..." echo "boot=/dev/mmcblk0p1 disk=/dev/mmcblk0p2 ssh quiet" > $MOUNTPOINT/cmdline.txt # copy files echo "copying files to $MOUNTPOINT..." cp target/KERNEL $MOUNTPOINT/kernel.img cp target/SYSTEM $MOUNTPOINT cp 3rdparty/bootloader/* $MOUNTPOINT cp openelec.ico $MOUNTPOINT cp README.md $MOUNTPOINT # sync disk echo "syncing disk..." sync # unmount partition echo "unmounting partition $MOUNTPOINT ..." umount $MOUNTPOINT # cleaning echo "cleaning tempdir..." rmdir $MOUNTPOINT echo "...installation finished"