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