| 1 |
#!/bin/bash |
|---|
| 2 |
# |
|---|
| 3 |
# Usage: createpatchstick /dev/diskX |
|---|
| 4 |
|
|---|
| 5 |
echo |
|---|
| 6 |
echo "--- Generation of Apple TV Patchstick ---" |
|---|
| 7 |
echo |
|---|
| 8 |
echo " Created by Marook." |
|---|
| 9 |
echo " Thanks to: MacTijn, Alan_Quatermain & ericIII" |
|---|
| 10 |
echo |
|---|
| 11 |
echo "-----------------------------------------" |
|---|
| 12 |
echo |
|---|
| 13 |
|
|---|
| 14 |
if [ "$USER" != "root" ] |
|---|
| 15 |
then |
|---|
| 16 |
echo "You need to run this script as ROOT. Exiting..." |
|---|
| 17 |
echo |
|---|
| 18 |
exit 1 |
|---|
| 19 |
fi |
|---|
| 20 |
|
|---|
| 21 |
if [ $# -ne 1 ] |
|---|
| 22 |
then |
|---|
| 23 |
echo |
|---|
| 24 |
echo "Listing available disks:" |
|---|
| 25 |
diskutil list |
|---|
| 26 |
echo $'\a' |
|---|
| 27 |
echo "Please specify the disk to re-partition as argument one:" |
|---|
| 28 |
echo " ./createpatchstick /dev/diskX" |
|---|
| 29 |
echo |
|---|
| 30 |
echo " WARNING: The disk will be ERASED !!!" |
|---|
| 31 |
echo |
|---|
| 32 |
exit 1 |
|---|
| 33 |
fi |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
partition_disk() { |
|---|
| 37 |
echo |
|---|
| 38 |
echo " Partitioning $THEDISK:" |
|---|
| 39 |
diskutil partitionDisk $THEDISK 2 GPTFormat HFS+ Patchstick-root 80M HFS+ Patchstick 40M |
|---|
| 40 |
echo " Patitions done." |
|---|
| 41 |
#sleep 2 |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
basic_folders() { |
|---|
| 45 |
echo "Creating System folders..." |
|---|
| 46 |
mkdir /Volumes/Patchstick-root/sbin /Volumes/Patchstick-root/etc /Volumes/Patchstick-root/dev /Volumes/Patchstick-root/OSBoot /Volumes/Patchstick-root/stuff |
|---|
| 47 |
mkdir -p /Volumes/Patchstick-root/usr/lib/system |
|---|
| 48 |
mkdir -p /Volumes/Patchstick-root/System/Library/Extensions |
|---|
| 49 |
mkdir -p /Volumes/Patchstick-root/System/Library/Frameworks |
|---|
| 50 |
ln -s /Volumes/Patchstick-root/sbin /Volumes/Patchstick-root/bin |
|---|
| 51 |
mkdir -p /Volumes/Patchstick-root/System/Library/Frameworks/OSXFrames/ |
|---|
| 52 |
mkdir -p /Volumes/Patchstick-root/usr/libexec |
|---|
| 53 |
|
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
copy_system() { |
|---|
| 57 |
echo "Copying System Extentions..." |
|---|
| 58 |
cp -R /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/ |
|---|
| 59 |
cp -R /System/Library/Frameworks/{CoreFoundation,IOKit}.framework /Volumes/Patchstick-root/System/Library/Frameworks |
|---|
| 60 |
cp /bin/bash /bin/chmod /usr/sbin/chown /usr/sbin/bless /bin/cp /sbin/mount /sbin/mount_hfs /sbin/mount_devfs /bin/sleep /sbin/umount /bin/sync /bin/sh /bin/ls /sbin/reboot /Volumes/Patchstick-root/sbin/ |
|---|
| 61 |
cp /usr/lib/dyld /usr/lib/libSystem.B.dylib /usr/lib/libncurses.5.4.dylib /usr/lib/libgcc_s.1.dylib /Volumes/Patchstick-root/usr/lib/ |
|---|
| 62 |
cp /usr/lib/system/libmathCommon.A.dylib /Volumes/Patchstick-root/usr/lib/system/ |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
copy_kernal() { |
|---|
| 66 |
echo "Copying System files..." |
|---|
| 67 |
cp root/mach_kernel /Volumes/Patchstick-root/ |
|---|
| 68 |
cp root/com.apple.Boot.plist /Volumes/Patchstick-root/ |
|---|
| 69 |
cp root/Info.plist /Volumes/Patchstick-root/System/Library/Extensions/AppleFileSystemDriver.kext/Contents/ |
|---|
| 70 |
cp root/launchd /Volumes/Patchstick-root/sbin/launchd |
|---|
| 71 |
chmod 755 /Volumes/Patchstick-root/sbin/launchd |
|---|
| 72 |
if [ -e /Volumes/OSBoot/System/Library/CoreServices/boot.efi ] |
|---|
| 73 |
then |
|---|
| 74 |
cp /Volumes/OSBoot/System/Library/CoreServices/boot.efi /Volumes/Patchstick-root/ |
|---|
| 75 |
else |
|---|
| 76 |
echo "boot.efi not found! Do you have a mounted OSBoot volume?" |
|---|
| 77 |
echo "Can't complete process. Exiting.." |
|---|
| 78 |
exit 1 |
|---|
| 79 |
fi |
|---|
| 80 |
|
|---|
| 81 |
echo "Adding Kerberos..." |
|---|
| 82 |
cp -p -R /System/Library/Frameworks/Kerberos.framework /Volumes/Patchstick-root/System/Library/Frameworks/OSXFrames/ |
|---|
| 83 |
#cp /usr/libexec/sshd-keygen-wrapper /Volumes/Patchstick-root/usr/libexec |
|---|
| 84 |
#sed -i"" -e 's;^exec;DYLD_FRAMEWORK_PATH="/System/Library/Frameworks/OSXFrames" exec;' /Volumes/Patchstick-root/usr/libexec/sshd-keygen-wrapper |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
copy_stuff() { |
|---|
| 88 |
echo "Copying Patchstick files..." |
|---|
| 89 |
|
|---|
| 90 |
cp -R Patchstick/* /Volumes/Patchstick/ |
|---|
| 91 |
#cp /usr/sbin/sshd /Volumes/Patchstick/ssh/ |
|---|
| 92 |
|
|---|
| 93 |
if [ -e /Library/QuickTime/Perian.component ] |
|---|
| 94 |
then |
|---|
| 95 |
echo " - Found Perian component. Adding it to the Patchstick..." |
|---|
| 96 |
#cp installer.d/perian /Volumes/Patchstick/installer.d/ |
|---|
| 97 |
ditto /Library/QuickTime/Perian.component /Volumes/Patchstick/perian/Perian.component |
|---|
| 98 |
elif |
|---|
| 99 |
echo " - Found Perian in your home directory. Grabbing it..." |
|---|
| 100 |
ditto $HOME/Library/QuickTime/Perian.component /Volumes/Patchstick/perian/Perian.component |
|---|
| 101 |
else |
|---|
| 102 |
echo " - Perian not found in /Library/QuickTime. Skipping..." |
|---|
| 103 |
#rm /Volumes/Patchstick/installer.d/perian |
|---|
| 104 |
fi |
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
disk_atv_mode() { |
|---|
| 112 |
echo "Changing Patchstick-root to Apple TV Mode..." |
|---|
| 113 |
#diskutil unmountDisk $THEDISK |
|---|
| 114 |
START=$(gpt -r show $THEDISK | grep '1 GPT part' | awk '{print $1}') |
|---|
| 115 |
SIZE=$(gpt -r show $THEDISK | grep '1 GPT part' | awk '{print $2}') |
|---|
| 116 |
diskutil unmountDisk $THEDISK |
|---|
| 117 |
gpt remove -i 1 $THEDISK |
|---|
| 118 |
diskutil unmountDisk $THEDISK |
|---|
| 119 |
gpt add -b $START -s $SIZE -i 1 -t "5265636F-7665-11AA-AA11-00306543ECAC" $THEDISK |
|---|
| 120 |
diskutil unmountDisk $THEDISK |
|---|
| 121 |
echo |
|---|
| 122 |
echo "Your disk $THEDISK is now unmounted and ready to patch your AppleTV." |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
if [ $# = 1 ] |
|---|
| 127 |
then |
|---|
| 128 |
|
|---|
| 129 |
read -p "Are you sure you want to partition disk $1? [yes|no]" sure |
|---|
| 130 |
echo |
|---|
| 131 |
|
|---|
| 132 |
THEDISK=$1 |
|---|
| 133 |
export THEDISK |
|---|
| 134 |
|
|---|
| 135 |
case "$sure" in |
|---|
| 136 |
yes) |
|---|
| 137 |
echo |
|---|
| 138 |
partition_disk |
|---|
| 139 |
basic_folders |
|---|
| 140 |
copy_system |
|---|
| 141 |
copy_kernal |
|---|
| 142 |
copy_stuff |
|---|
| 143 |
disk_atv_mode |
|---|
| 144 |
echo "Enjoy... :-)" |
|---|
| 145 |
echo |
|---|
| 146 |
;; |
|---|
| 147 |
|
|---|
| 148 |
*) |
|---|
| 149 |
echo "You selected No. Aborting..." |
|---|
| 150 |
exit |
|---|
| 151 |
;; |
|---|
| 152 |
esac |
|---|
| 153 |
|
|---|
| 154 |
fi |
|---|