• 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
20ios_rm() {
21  local TARGET="$IOS_MOUNT_POINT/$IOS_DOCS_DIR/$1"
22
23  ios_mount
24  rm -rf "$TARGET"
25  ios_umount
26}
27
28ios_mkdir() {
29  local TARGET="$IOS_MOUNT_POINT/$IOS_DOCS_DIR/$1"
30  ios_mount
31  mkdir -p "$TARGET"
32  ios_umount
33}
34
35ios_cat() {
36  local TARGET="$IOS_MOUNT_POINT/$IOS_DOCS_DIR/$1"
37  >&2 echo "target: '${TARGET}''"
38  ios_mount
39  RET="$( cat ${TARGET} )"
40  ios_umount
41  >&2 echo "Result: '${RET}'"
42  echo -e "${RET}"
43}
44
45# ios_mount: mounts the iOS device for reading or writing.
46ios_mount() {
47  # If this is already mounted we unmount it.
48  if $(mount | grep --quiet "$IOS_MOUNT_POINT"); then
49    >&2 echo "Device already mounted at: $IOS_MOUNT_POINT - Unmounting."
50    ios_umount || true
51  fi
52
53  # Ensure there is a mount directory.
54  if [[ ! -d "$IOS_MOUNT_POINT" ]]; then
55    mkdir -p $IOS_MOUNT_POINT
56  fi
57  ifuse --container $IOS_BUNDLE_ID $IOS_MOUNT_POINT
58
59  sleep 2
60  if [[ ! -d "${IOS_MOUNT_POINT}/${IOS_DOCS_DIR}" ]]; then
61    exit 1
62  fi
63  >&2 echo "Successfully mounted device."
64  #find $IOS_MOUNT_POINT
65}
66
67# ios_umount: unmounts the ios device.
68ios_umount() {
69  sudo umount $IOS_MOUNT_POINT
70  sleep 1
71}
72
73# ios_restart: restarts the iOS device.
74ios_restart() {
75  ios_umount || true
76  idevicediagnostics restart
77}
78
79# ios_pull(ios_src, host_dst): Copies the content of ios_src to host_dst.
80# The path is relative to the 'Documents' folder on the device.
81ios_pull() {
82  # read input params
83  local IOS_SRC="$IOS_MOUNT_POINT/$IOS_DOCS_DIR/$1"
84  local HOST_DST="$2"
85
86  ios_mount
87  if [[ -d "${HOST_DST}" ]]; then
88    cp -r "$IOS_SRC/." "$HOST_DST"
89  else
90    cp -r "$IOS_SRC" "$HOST_DST"
91  fi
92  ios_umount
93}
94
95# ios_push(host_src, ios_dst)
96ios_push() {
97  # read input params
98  local HOST_SRC="$1"
99  local IOS_DST="$IOS_MOUNT_POINT/$IOS_DOCS_DIR/$2"
100
101  ios_mount
102  rm -rf $IOS_DST
103  mkdir -p "$(dirname $IOS_DST)"
104  cp -r -L "$HOST_SRC" "$IOS_DST"
105  ios_umount
106}
107
108ios_path_exists() {
109  local TARGET_PATH="$IOS_MOUNT_POINT/$IOS_DOCS_DIR/$1"
110  local RET=1
111  ios_mount
112  if [[ -e $TARGET_PATH ]]; then
113    RET=0
114  fi
115  ios_umount
116  return $RET
117}
118