1#!/bin/bash 2# 3# Copy the Development build (as built by Xcode) of msdosfs.kext to one or 4# more test machines. It will unload the kext if previously loaded, 5# touch /System/Library/Extensions to invalidate the KEXT cache, manually 6# load the new KEXT, and copy the symbols back to the development machine 7# (in a directory named for the target machine). 8# 9# The target machine host names are passed as command line arguments. If 10# there are no command line arguments, but $MACHINE is set, then the target 11# host name is in $MACHINE. It is an error if there are no command line 12# arguments and $MACHINE is not set. 13# 14# This script doesn't currently handle the case where the KEXT cannot be 15# unloaded (usually because a volume is still mounted). It will just copy 16# the new KEXT over and fail to load it. 17# 18# Note that the kext gets copied to the current user's home directory 19# on the target machine. That way, if it panics, you can always reboot 20# and get the standard KEXT from /System/Library/Extensions. 21# 22# Also note that this script assumes it can SSH as root to the target 23# machine. In a default install, root has no password, and no SSH keys, 24# so SSH to root fails unless you give root a password or SSH keys. I prefer 25# to set up root's SSH authorized keys to be my user's keys, so my user 26# can SSH to root without any prompt. Here's how I do it: 27# 28# ~ $ sudo -s 29# Password: 30# ~ # cd ~root 31# ~root # mkdir .ssh 32# ~root # cp ~mark/.ssh/authorized_keys* .ssh 33# ~root # exit 34# ~ $ 35# 36 37configuration=Debug 38kext=msdosfs 39 40if [ "$1" = "-config" ]; then 41 configuration="$2" 42 shift 2 43fi 44 45if [ $# -eq 0 ]; then 46 if [ -z "$MACHINE" ]; then 47 echo 'No arguments, and $MACHINE not set!' 1>&2 48 exit 1 49 fi 50 set $MACHINE 51fi 52 53# 54# Determine the $BUILT_PRODUCTS_DIR for the given configuration 55# 56BUILT_PRODUCTS_DIR=$(xcodebuild -configuration $configuration -showBuildSettings 2>/dev/null | sed -n -E '1,$ s/[ \t]+BUILT_PRODUCTS_DIR = //p') 57 58for m 59do 60 ssh root@$m kextunload -b com.apple.filesystems.${kext} 61 scp -r "$BUILT_PRODUCTS_DIR/${kext}.kext" root@$m:"/var/tmp" 62 ssh root@$m chgrp -R wheel "/var/tmp/${kext}.kext" 63 ssh root@$m touch /System/Library/Extensions 64 ssh root@$m kextutil -c -s /tmp "/var/tmp/${kext}.kext" || exit 65 mkdir -p /tmp/$m 66 scp root@$m:/tmp/"com.apple.*.sym" /tmp/$m 67 rm -rf /tmp/$m/${kext}.kext{,.dSYM} 68 cp -r "$BUILT_PRODUCTS_DIR/${kext}.kext"{,.dSYM} /tmp/$m 69done 70