#!/bin/sh ################################################################################ # Copyright (C) 2009-2010 OpenELEC.tv # http://www.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_installstick # example: sudo ./create_installstick /dev/sdb if [ "$(id -u)" != "0" ]; then clear echo "#########################################################" echo "# please execute with 'sudo' or -DANGEROUS!!!- as root #" echo "# example: sudo ./create_installstick #" echo "#########################################################" exit 1 fi if [ -z "$1" ]; then clear echo "#########################################################" echo "# please execute with your drive as option #" echo "# example: sudo ./create_installstick /dev/sdb #" echo "#########################################################" exit 1 fi DISK="$1" PART="${DISK}1" 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 # this is needed to create a bootloader which syslinux > /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 \"syslinux\" #" echo "# on your system. #" echo "# Please install it via your package manager. #" echo "# #" echo "#########################################################" exit 1 fi # this is needed by syslinux which mcopy > /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 \"mcopy\" #" echo "# on your system. #" echo "# Please install it via your package manager. #" echo "# NOTE: Some distributions call this package #" echo "# \"mtools\". #" echo "# #" echo "#########################################################" exit 1 fi # 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 # 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 } md5sum -c target/KERNEL.md5 if [ "$?" = "1" ]; then md5sumFailed fi md5sum -c target/SYSTEM.md5 if [ "$?" = "1" ]; then md5sumFailed fi # (TODO) umount everything (if more than one partition) umount "$PART" # remove all partitions from the drive echo "writing new disklabel on $DISK (removing all partitions)..." dd if=/dev/zero of="$DISK" bs=4096 count=1024 parted -s "$DISK" mklabel msdos # create a single partition echo "creating a partition on $DISK..." parted -s "$DISK" unit cyl mkpart primary fat32 -- 0 -0 # 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 $PART..." mkfs.vfat "$PART" -n OpenELEC # install syslinux echo "installing syslinux to $PART..." syslinux -f "$PART" # mount partition echo "mounting partition $PART on /tmp/usb_install..." mkdir -p /tmp/usb_install mount "$PART" /tmp/usb_install # find UUID echo -n "finding partition UUID for $PART ..." UUID=`blkid $PART -s UUID -o value` echo "$UUID" # create bootloader configuration echo "creating bootloader configuration..." echo "DEFAULT linux" > /tmp/usb_install/syslinux.cfg echo "PROMPT 0" >> /tmp/usb_install/syslinux.cfg echo " " >> /tmp/usb_install/syslinux.cfg echo "LABEL linux" >> /tmp/usb_install/syslinux.cfg echo " KERNEL /KERNEL" >> /tmp/usb_install/syslinux.cfg echo " APPEND boot=UUID=$UUID installer quiet" >> /tmp/usb_install/syslinux.cfg # copy files echo "copying files to $PART..." cp target/KERNEL /tmp/usb_install cp target/KERNEL.md5 /tmp/usb_install cp target/SYSTEM /tmp/usb_install cp target/SYSTEM.md5 /tmp/usb_install cp Autorun.inf /tmp/usb_install cp openelec.ico /tmp/usb_install cp CHANGELOG /tmp/usb_install cp INSTALL /tmp/usb_install cp README.md /tmp/usb_install cp RELEASE /tmp/usb_install # sync disk echo "syncing disk..." sync # unmount partition echo "unmounting partition $PART..." umount "$PART" # write mbr echo "writing mbr..." if [ -f /usr/lib/syslinux/mbr.bin ]; then MBR="/usr/lib/syslinux/mbr.bin" # example: debian, ubuntu elif [ -f /usr/share/syslinux/mbr.bin ]; then MBR="/usr/share/syslinux/mbr.bin" # example: fedora else echo "Can't find syslinux's mbr.bin on Host OS" fi if [ -n "$MBR" ]; then cat "$MBR" > "$DISK" fi # syncing disk echo "syncing disk..." sync # cleaning echo "cleaning tempdir..." rmdir /tmp/usb_install echo "...installation finished"