Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- read_input(){
- local MESSAGE="${1}"
- if [ -n "${MESSAGE}" ];then
- echo "${MESSAGE}"
- fi
- read INPUT
- }
- write_warning(){
- local MESSAGE=$1
- echo "WARNING: ${MESSAGE}"
- }
- write_error(){
- local MESSAGE=$1
- echo "ERROR: ${MESSAGE}"
- }
- plist_value() {
- echo "$1" | xpath "//key[.='$2']/following-sibling::*[1]/text()" 2> /dev/null
- }
- choose_install_device(){
- echo ""
- echo "#########################################################"
- echo "# #"
- echo "# OpenELEC Installer for Mac OS X #"
- echo "# #"
- echo "#########################################################"
- echo "# #"
- echo "# This will wipe ALL data off your chosen drive #"
- echo "# Please read the instructions and use carefully.. #"
- echo "# #"
- echo "#########################################################"
- echo ""
- echo "The following devices were found:"
- echo ""
- local devices=$(diskutil list -plist | xpath "//key[.='WholeDisks']/following-sibling::*[1]//string" 2>/dev/null | sed 's/\<string\>//g' | sed 's/\<\/string\>/ /g')
- echo "[Device] [Media name] [Total size]"
- for device in $devices; do
- local device_info=$(diskutil info -plist $device)
- local size=$(plist_value "$device_info" TotalSize)
- local mediaName=$(plist_value "$device_info" MediaName)
- echo "$device $mediaName $size bytes"
- done
- echo ""
- INPUT=""
- while [ -z "${INPUT}" ];do
- read_input "Please enter the install device (e.g. disk1): "
- echo ""
- done
- INSTALL_DEVICE="${INPUT}"
- }
- check_install_device(){
- diskutil list ${INSTALL_DEVICE} > /dev/null
- if [ $? == 0 ]; then
- diskutil list /dev/"${INSTALL_DEVICE}"
- else
- write_error "Device /dev/${INSTALL_DEVICE} appears to be invalid"
- echo ""
- exit 1
- fi
- echo ""
- write_warning "*** ALL DATA WILL BE WIPED FROM /dev/${INSTALL_DEVICE} ***"
- echo ""
- read -p "Are you sure you want to continue? " -n 1
- if [[ ! $REPLY =~ ^[Yy]$ ]];then
- echo ""
- echo ""
- echo "Goodbye!"
- echo ""
- exit 1
- fi
- }
- unmount_install_device_partitions(){
- diskutil unmountDisk /dev/${INSTALL_DEVICE} &> /dev/null
- }
- prepare_install_device(){
- echo ""
- echo ""
- echo "Creating OpenELEC Install Stick"
- echo ""
- diskutil eraseDisk MS-DOS INSTALL MBR /dev/${INSTALL_DEVICE} &> /dev/null
- diskutil unmountDisk /dev/${INSTALL_DEVICE} &> /dev/null
- curl -O http://chewitt.openelec.tv/osx_installstick_files.tar.gz &> /dev/null
- tar -xzvf osx_installstick_files.tar.gz &> /dev/null
- chmod 755 osx_installstick_files/*
- cat osx_installstick_files/mbr.bin > /dev/${INSTALL_DEVICE}
- osx_installstick_files/syslinux -f /dev/${INSTALL_DEVICE}s1 &> /dev/null
- }
- create_partitions(){
- diskutil unmountDisk /dev/${INSTALL_DEVICE} &> /dev/null
- fdisk -e /dev/${INSTALL_DEVICE} < osx_installstick_files/fdisk.input &> /dev/null
- }
- install_files(){
- diskutil mountDisk /dev/${INSTALL_DEVICE} &> /dev/null
- cp -a target/KERNEL /Volumes/INSTALL/
- cp -a target/SYSTEM /Volumes/INSTALL/
- cp -a sample.conf/syslinux_installer.cfg /Volumes/INSTALL/syslinux.cfg
- }
- final_cleanup(){
- diskutil unmountDisk /dev/${INSTALL_DEVICE} &> /dev/null
- fsck_msdos -y /dev/${INSTALL_DEVICE}s1 &> /dev/null
- echo "ALL DONE! ..it's now safe to remove your USB stick"
- echo ""
- }
- main(){
- if [ $UID != 0 ];then
- echo "This script *must* be run as root"
- exit 1
- fi
- choose_install_device
- check_install_device
- unmount_install_device_partitions
- prepare_install_device
- create_partitions
- install_files
- final_cleanup
- exit 0
- }
- main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement