All pastes #918466 Raw Edit

Stuff

public text v1 · immutable
#918466 ·published 2008-02-26 03:15 UTC
rendered paste body
#!/bin/bash
#
# Usage: createPatchstick /dev/diskX

echo
echo "--- Generation of Apple TV Patchstick ---"
echo
echo " Created by Marook."
echo " Thanks to: MacTijn, Alan_Quatermain & ericIII"
echo " Leopard remake by joda"
echo
echo "-----------------------------------------"
echo

if [ "$USER" != "root" ]
then
	echo "You need to run this script as ROOT. Exiting..."
	echo
	exit 1
fi

if [ $# -ne 1 ]
then
		echo
		echo "Listing available disks:"
		diskutil list
		echo $'\a'
        echo "Please specify the disk to re-partition as argument one:"
        echo " ./createpatchstick /dev/diskX"
        echo
        echo " WARNING: The disk will be ERASED !!!"
        echo
        exit 1
fi


partition_disk() {
	echo
	echo " Partitioning $THEDISK:"
	diskutil partitionDisk $THEDISK 2 GPTFormat HFS+ Patchstick-root 80M HFS+ Patchstick 40M
	echo " Patitions done."
	#sleep 2
}

basic_folders() {
	echo "Creating System folders..."
	mkdir /Volumes/Patchstick-root/sbin /Volumes/Patchstick-root/etc /Volumes/Patchstick-root/dev /Volumes/Patchstick-root/OSBoot /Volumes/Patchstick-root/stuff
	mkdir -p /Volumes/Patchstick-root/usr/lib/system
	mkdir -p /Volumes/Patchstick-root/System/Library/Extensions
	mkdir -p /Volumes/Patchstick-root/System/Library/Frameworks
	ln -s /Volumes/Patchstick-root/sbin /Volumes/Patchstick-root/bin
	mkdir -p /Volumes/Patchstick-root/System/Library/Frameworks/OSXFrames/
	mkdir -p /Volumes/Patchstick-root/usr/libexec

}

copy_system() {
	echo "Copying System Extentions..."
	cp -R Files/System/Library/Extensions/{AppleACPIPlatform,AppleAPIC,AppleEFIRuntime,AppleFileSystemDriver,AppleFlashNVRAM,AppleHDA,AppleHPET,AppleIRController,AppleRTC,AppleSMBIOS,AppleSMC,AudioIPCDriver,BootCache,GeForce,IO80211Family,IOACPIFamily,IOATAFamily,IOAudioFamily,IOGraphicsFamily,IOHIDFamily,IONDRVSupport,IONetworkingFamily,IOPCIFamily,IOPlatformPluginFamily,IOSCSIArchitectureModelFamily,IOStorageFamily,IOUSBFamily,IOUSBMassStorageClass,NVDANV40Hal,NVDAResman,OSvKernDSPLib,System,AppleIntelCPUPowerManagement}.kext /Volumes/Patchstick-root/System/Library/Extensions/
	cp -R Files/System/Library/Frameworks/{CoreFoundation,IOKit}.framework /Volumes/Patchstick-root/System/Library/Frameworks
	cp Files/sbin/{bash,chmod,chown,bless,cp,mount,mount_hfs,mount_devfs,sleep,umount,sync,sh,ls,reboot} /Volumes/Patchstick-root/sbin/
	cp Files/usr/lib/{dyld,libSystem.B.dylib,libncurses.5.4.dylib,libgcc_s.1.dylib} /Volumes/Patchstick-root/usr/lib/
	cp Files/usr/lib/system/libmathCommon.A.dylib /Volumes/Patchstick-root/usr/lib/system/
}

copy_kernal() {
	echo "Copying System files..."
	cp root/mach_kernel /Volumes/Patchstick-root/
	cp root/com.apple.Boot.plist /Volumes/Patchstick-root/
	cp root/Info.plist /Volumes/Patchstick-root/System/Library/Extensions/AppleFileSystemDriver.kext/Contents/
	cp root/launchd /Volumes/Patchstick-root/sbin/launchd
	chmod 755 /Volumes/Patchstick-root/sbin/launchd
	cp Files/boot.efi /Volumes/Patchstick-root/
	
	echo "Adding Kerberos..."
	cp -p -R Files/System/Library/Frameworks/Kerberos.framework /Volumes/Patchstick-root/System/Library/Frameworks/OSXFrames/
}

copy_stuff() {
	echo "Copying Patchstick files..."
	
	cp -R Patchstick/* /Volumes/Patchstick/
}

disk_atv_mode() {
	echo "Changing Patchstick-root to Apple TV Mode..."
	START=$(gpt -r show $THEDISK | grep '1  GPT part' | awk '{print $1}')
	SIZE=$(gpt -r show $THEDISK | grep '1  GPT part' | awk '{print $2}')
	diskutil unmountDisk $THEDISK
	gpt remove -i 1 $THEDISK
	diskutil unmountDisk $THEDISK
	gpt add -b $START -s $SIZE -i 1 -t "5265636F-7665-11AA-AA11-00306543ECAC" $THEDISK
	diskutil unmountDisk $THEDISK
	echo
	echo "Your disk $THEDISK is now unmounted and ready to patch your AppleTV."
}


if [ $# = 1 ]
then

	read -p "Are you sure you want to partition disk $1? [yes|no]" sure
	echo
	
	THEDISK=$1
	export THEDISK
	
	case "$sure" in
     yes)
     	echo
     	partition_disk
     	basic_folders
     	copy_system
     	copy_kernal
     	copy_stuff
     	disk_atv_mode
		echo "Enjoy... :-)"
		echo
		;;

     *)
		echo "You selected No. Aborting..."
		exit
		;;
	esac   

fi