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