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 IOS_MOUNT_POINT="/tmp/mnt_iosdevice" 13 14 # Location on the ios device where all data are stored. This is 15 # relative to the mount point. 16 IOS_DOCS_DIR="Documents" 17 18 # Temporary location to assemble the app into an .ipa package. 19 IOS_PCKG_DIR="/tmp/ios_pckg" 20 21 # Directory with the Skia source. 22 SKIA_SRC_DIR=$(cd "${SCRIPT_DIR}/../../.."; pwd) 23 24 # Provisioning profile - this needs to be set up on the local machine. 25 PROVISIONING_PROFILE="" 26 27 # Code Signing identity - this needs to be set up on the local machine. 28 CODE_SIGN_IDENTITY="iPhone Developer" 29 30 IOS_BUNDLE_ID="com.google.iOSShell.`hostname | md5`" 31 32 IOS_RESULTS_DIR="results" 33 34 # BUILDTYPE is 'Debug' by default. 35 if [[ -z "$BUILDTYPE" ]]; then 36 BUILDTYPE="Debug" 37 fi 38 39 # Out dir is $SKIA_SRC_DIR/out by default. 40 if [[ -z "$SKIA_OUT" ]]; then 41 SKIA_OUT="$SKIA_SRC_DIR/out" 42 fi 43 44 ios_uninstall_app() { 45 ideviceinstaller -U "$IOS_BUNDLE_ID" 46 } 47 48 ios_install_app() { 49 rm -rf $IOS_PCKG_DIR 50 mkdir -p $IOS_PCKG_DIR/Payload # this directory must be named 'Payload' 51 cp -rf "${SKIA_SRC_DIR}/xcodebuild/${BUILDTYPE}-iphoneos/iOSShell.app" "${IOS_PCKG_DIR}/Payload/" 52 local RET_DIR=`pwd` 53 cd $IOS_PCKG_DIR 54 zip -r iOSShell.ipa Payload 55 ideviceinstaller -i ./iOSShell.ipa 56 cd $RET_DIR 57 } 58 59 ios_rm() { 60 local TARGET="$IOS_MOUNT_POINT/$IOS_DOCS_DIR/$1" 61 62 ios_mount 63 rm -rf "$TARGET" 64 ios_umount 65 } 66 67 ios_mkdir() { 68 local TARGET="$IOS_MOUNT_POINT/$IOS_DOCS_DIR/$1" 69 ios_mount 70 mkdir -p "$TARGET" 71 ios_umount 72 } 73 74 ios_cat() { 75 local TARGET="$IOS_MOUNT_POINT/$IOS_DOCS_DIR/$1" 76 ios_mount 77 RET="$(cat $TARGET)" 78 ios_umount 79 echo -e "$RET" 80 } 81 82 # ios_mount: mounts the iOS device for reading or writing. 83 ios_mount() { 84 # If this is already mounted we unmount it. 85 if $(mount | grep --quiet "$IOS_MOUNT_POINT"); then 86 >&2 echo "Device already mounted at: $IOS_MOUNT_POINT - Unmounting." 87 ios_umount || true 88 fi 89 90 # Ensure there is a mount directory. 91 if [[ ! -d "$IOS_MOUNT_POINT" ]]; then 92 mkdir -p $IOS_MOUNT_POINT 93 fi 94 ifuse --container $IOS_BUNDLE_ID $IOS_MOUNT_POINT 95 sleep 1 96 >&2 echo "Successfully mounted device." 97 } 98 99 # ios_umount: unmounts the ios device. 100 ios_umount() { 101 umount $IOS_MOUNT_POINT 102 sleep 1 103 } 104 105 # ios_restart: restarts the iOS device. 106 ios_restart() { 107 ios_umount || true 108 idevicediagnostics restart 109 } 110 111 # ios_pull(ios_src, host_dst): Copies the content of ios_src to host_dst. 112 # The path is relative to the 'Documents' folder on the device. 113 ios_pull() { 114 # read input params 115 local IOS_SRC="$IOS_MOUNT_POINT/$IOS_DOCS_DIR/$1" 116 local HOST_DST="$2" 117 118 ios_mount 119 if [[ -d "${HOST_DST}" ]]; then 120 cp -r "$IOS_SRC/" "$HOST_DST" 121 else 122 cp -r "$IOS_SRC" "$HOST_DST" 123 fi 124 ios_umount 125 } 126 127 # ios_push(host_src, ios_dst) 128 ios_push() { 129 # read input params 130 local HOST_SRC="$1" 131 local IOS_DST="$IOS_MOUNT_POINT/$IOS_DOCS_DIR/$2" 132 133 ios_mount 134 rm -rf $IOS_DST 135 mkdir -p "$(dirname $IOS_DST)" 136 cp -r "$HOST_SRC" "$IOS_DST" 137 ios_umount 138 } 139 140 ios_path_exists() { 141 local TARGET_PATH="$IOS_MOUNT_POINT/$IOS_DOCS_DIR/$1" 142 local RET=1 143 ios_mount 144 if [[ -e $TARGET_PATH ]]; then 145 RET=0 146 fi 147 ios_umount 148 return $RET 149 } 150 151 # ANDROID_LS=`$ADB $DEVICE_SERIAL shell ls -ld $ANDROID_DST` 152 # HOST_LS=`ls -ld $HOST_SRC` 153 # if [ "${ANDROID_LS:0:1}" == "d" -a "${HOST_LS:0:1}" == "-" ]; 154 # then 155 # ANDROID_DST="${ANDROID_DST}/$(basename ${HOST_SRC})" 156 # fi 157 158 159 # ANDROID_LS=`$ADB $DEVICE_SERIAL shell ls -ld $ANDROID_DST` 160 # if [ "${ANDROID_LS:0:1}" == "-" ]; then 161 # #get the MD5 for dst and src 162 # ANDROID_MD5=`$ADB $DEVICE_SERIAL shell md5 $ANDROID_DST` 163 # if [ $(uname) == "Darwin" ]; then 164 # HOST_MD5=`md5 -q $HOST_SRC` 165 # else 166 # HOST_MD5=`md5sum $HOST_SRC` 167 # fi 168 169 # if [ "${ANDROID_MD5:0:32}" != "${HOST_MD5:0:32}" ]; then 170 # echo -n "$ANDROID_DST " 171 # $ADB $DEVICE_SERIAL push $HOST_SRC $ANDROID_DST 172 # fi 173 # elif [ "${ANDROID_LS:0:1}" == "d" ]; then 174 # for FILE_ITEM in `ls $HOST_SRC`; do 175 # adb_push_if_needed "${HOST_SRC}/${FILE_ITEM}" "${ANDROID_DST}/${FILE_ITEM}" 176 # done 177 # else 178 # HOST_LS=`ls -ld $HOST_SRC` 179 # if [ "${HOST_LS:0:1}" == "d" ]; then 180 # $ADB $DEVICE_SERIAL shell mkdir -p $ANDROID_DST 181 # adb_push_if_needed $HOST_SRC $ANDROID_DST 182 # else 183 # echo -n "$ANDROID_DST " 184 # $ADB $DEVICE_SERIAL shell mkdir -p "$(dirname "$ANDROID_DST")" 185 # $ADB $DEVICE_SERIAL push $HOST_SRC $ANDROID_DST 186 # fi 187 # fi 188 # } 189 190 # setup_device "${DEVICE_ID}" 191