1 #!/bin/bash 2 ############################################################################### 3 # Copyright 2015 Google Inc. 4 # 5 # Use of this source code is governed by a BSD-style license that can be 6 # found in the LICENSE file. 7 ############################################################################### 8 # 9 # ios_setup.sh: Sets environment variables used by other iOS scripts. 10 11 # File system location where we mount the ios devices. 12 if [[ -z "${IOS_MOUNT_POINT}" ]]; then 13 IOS_MOUNT_POINT="/tmp/mnt_iosdevice" 14 fi 15 16 # Location on the ios device where all data are stored. This is 17 # relative to the mount point. 18 IOS_DOCS_DIR="Documents" 19 20 # Directory with the Skia source. 21 SKIA_SRC_DIR=$(cd "${SCRIPT_DIR}/../../.."; pwd) 22 23 # Provisioning profile - this needs to be set up on the local machine. 24 PROVISIONING_PROFILE="" 25 26 # Code Signing identity - this needs to be set up on the local machine. 27 CODE_SIGN_IDENTITY="iPhone Developer" 28 29 IOS_RESULTS_DIR="results" 30 31 # Location of XCode build products. 32 if [[ -z "$XCODEBUILD" ]]; then 33 XCODEBUILD="${SKIA_SRC_DIR}/xcodebuild" 34 fi 35 36 ios_rm() { 37 local TARGET="$IOS_MOUNT_POINT/$IOS_DOCS_DIR/$1" 38 39 ios_mount 40 rm -rf "$TARGET" 41 ios_umount 42 } 43 44 ios_mkdir() { 45 local TARGET="$IOS_MOUNT_POINT/$IOS_DOCS_DIR/$1" 46 ios_mount 47 mkdir -p "$TARGET" 48 ios_umount 49 } 50 51 ios_cat() { 52 local TARGET="$IOS_MOUNT_POINT/$IOS_DOCS_DIR/$1" 53 >&2 echo "target: '${TARGET}''" 54 ios_mount 55 RET="$( cat ${TARGET} )" 56 ios_umount 57 >&2 echo "Result: '${RET}'" 58 echo -e "${RET}" 59 } 60 61 # ios_mount: mounts the iOS device for reading or writing. 62 ios_mount() { 63 # If this is already mounted we unmount it. 64 if $(mount | grep --quiet "$IOS_MOUNT_POINT"); then 65 >&2 echo "Device already mounted at: $IOS_MOUNT_POINT - Unmounting." 66 ios_umount || true 67 fi 68 69 # Ensure there is a mount directory. 70 if [[ ! -d "$IOS_MOUNT_POINT" ]]; then 71 mkdir -p $IOS_MOUNT_POINT 72 fi 73 ifuse --container $IOS_BUNDLE_ID $IOS_MOUNT_POINT 74 75 sleep 2 76 if [[ ! -d "${IOS_MOUNT_POINT}/${IOS_DOCS_DIR}" ]]; then 77 exit 1 78 fi 79 >&2 echo "Successfully mounted device." 80 #find $IOS_MOUNT_POINT 81 } 82 83 # ios_umount: unmounts the ios device. 84 ios_umount() { 85 sudo umount $IOS_MOUNT_POINT 86 sleep 1 87 } 88 89 # ios_restart: restarts the iOS device. 90 ios_restart() { 91 ios_umount || true 92 idevicediagnostics restart 93 } 94 95 # ios_pull(ios_src, host_dst): Copies the content of ios_src to host_dst. 96 # The path is relative to the 'Documents' folder on the device. 97 ios_pull() { 98 # read input params 99 local IOS_SRC="$IOS_MOUNT_POINT/$IOS_DOCS_DIR/$1" 100 local HOST_DST="$2" 101 102 ios_mount 103 if [[ -d "${HOST_DST}" ]]; then 104 cp -r "$IOS_SRC/." "$HOST_DST" 105 else 106 cp -r "$IOS_SRC" "$HOST_DST" 107 fi 108 ios_umount 109 } 110 111 # ios_push(host_src, ios_dst) 112 ios_push() { 113 # read input params 114 local HOST_SRC="$1" 115 local IOS_DST="$IOS_MOUNT_POINT/$IOS_DOCS_DIR/$2" 116 117 ios_mount 118 rm -rf $IOS_DST 119 mkdir -p "$(dirname $IOS_DST)" 120 cp -r -L "$HOST_SRC" "$IOS_DST" 121 ios_umount 122 } 123 124 ios_path_exists() { 125 local TARGET_PATH="$IOS_MOUNT_POINT/$IOS_DOCS_DIR/$1" 126 local RET=1 127 ios_mount 128 if [[ -e $TARGET_PATH ]]; then 129 RET=0 130 fi 131 ios_umount 132 return $RET 133 } 134 135 # ANDROID_LS=`$ADB $DEVICE_SERIAL shell ls -ld $ANDROID_DST` 136 # HOST_LS=`ls -ld $HOST_SRC` 137 # if [ "${ANDROID_LS:0:1}" == "d" -a "${HOST_LS:0:1}" == "-" ]; 138 # then 139 # ANDROID_DST="${ANDROID_DST}/$(basename ${HOST_SRC})" 140 # fi 141 142 143 # ANDROID_LS=`$ADB $DEVICE_SERIAL shell ls -ld $ANDROID_DST` 144 # if [ "${ANDROID_LS:0:1}" == "-" ]; then 145 # #get the MD5 for dst and src 146 # ANDROID_MD5=`$ADB $DEVICE_SERIAL shell md5 $ANDROID_DST` 147 # if [ $(uname) == "Darwin" ]; then 148 # HOST_MD5=`md5 -q $HOST_SRC` 149 # else 150 # HOST_MD5=`md5sum $HOST_SRC` 151 # fi 152 153 # if [ "${ANDROID_MD5:0:32}" != "${HOST_MD5:0:32}" ]; then 154 # echo -n "$ANDROID_DST " 155 # $ADB $DEVICE_SERIAL push $HOST_SRC $ANDROID_DST 156 # fi 157 # elif [ "${ANDROID_LS:0:1}" == "d" ]; then 158 # for FILE_ITEM in `ls $HOST_SRC`; do 159 # adb_push_if_needed "${HOST_SRC}/${FILE_ITEM}" "${ANDROID_DST}/${FILE_ITEM}" 160 # done 161 # else 162 # HOST_LS=`ls -ld $HOST_SRC` 163 # if [ "${HOST_LS:0:1}" == "d" ]; then 164 # $ADB $DEVICE_SERIAL shell mkdir -p $ANDROID_DST 165 # adb_push_if_needed $HOST_SRC $ANDROID_DST 166 # else 167 # echo -n "$ANDROID_DST " 168 # $ADB $DEVICE_SERIAL shell mkdir -p "$(dirname "$ANDROID_DST")" 169 # $ADB $DEVICE_SERIAL push $HOST_SRC $ANDROID_DST 170 # fi 171 # fi 172 # } 173 174 # setup_device "${DEVICE_ID}" 175