-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathios-mount.sh
executable file
·195 lines (188 loc) · 5.64 KB
/
ios-mount.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/bash
[[ $(tty) == "not a tty" ]] && gui=true || gui=false
if $gui ;
then
zenity_status_file="$(mktemp)"
zenity_pid_file="$(mktemp)"
fi
while true; do
old_msg=""
pair_status=""
pair_cmd="idevicepair validate"
while [ "$pair_status" != "0" ] ; do
pair_output="$($pair_cmd 2>&1)"
pair_status=$?
pair_cmd="idevicepair validate"
if [ "$pair_status" != "0" ] ; then
case "$pair_output" in
*"No device found"*)
msg="Please connect an iOS device..."
;;
*"Please enter the passcode on the device and retry"*)
msg="Please unlock the device..."
;;
*"Please accept the trust dialog on the screen of device"*)
msg="Please accept the trust prompt on the device..."
;;
*"the user denied the trust dialog"*)
msg="The trust prompt was denied, please disconnect and reconnect the device..."
;;
*"is not paired with this host"*)
msg="$old_msg"
if [ "$msg" = "" ] ; then
msg="Pairing device..."
fi
pair_cmd="idevicepair pair"
;;
*)
msg="Something went wrong pairing the device...\\nError message:\\n$pair_output"
;;
esac
if $gui ; then
zenity_pid="$(< "$zenity_pid_file")"
if [ "$zenity_pid" != "" ] ; then
ps -p $zenity_pid 2>&1 > /dev/null
exists=$?
else
exists=0
fi
else
exists=0
fi
if $gui ; then
zenity_status="$(< "$zenity_status_file")"
if [ "$zenity_status" != "" ] && [ "$zenity_status" != "0" ] ; then
exit
fi
fi
if [ "$old_msg" != "$msg" ] || [ "$exists" != "0" ] ; then
old_msg="$msg"
if $gui ; then
if [ "$exists" = "0" ] && [ "$zenity_pid" != "" ] ; then
kill $zenity_pid
fi
{
zenity --title "iOS-Mount" --error --no-wrap --text "$msg" &
zenity_pid=$!
echo $zenity_pid > "$zenity_pid_file"
wait $zenity_pid
echo $? > "$zenity_status_file"
} &
else
echo -e "$msg"
fi
fi
sleep 0.25
fi
done
if $gui && [ "$zenity_pid" != "" ] ; then
ps -p $zenity_pid 2>&1 > /dev/null
exists=$?
if [ "$exists" = "0" ] && [ "$zenity_pid" != "" ] ; then
kill $zenity_pid
fi
fi
unset apps
declare -A apps
while IFS=: read -r name identifier ; do
apps["$name"]="$identifier"
done <<< $(ifuse --list-apps | grep -v CFBundleIdentifier | awk -F '","' '{printf "%s:%s\n", substr($3, 1, length($3)-1), substr($1, 2)}' | sort)
unset options
declare -a options
options[0]="Filesystem (Photos and Media)"
while IFS='' read app ; do
options+=("$app")
done <<< $(for app in "${!apps[@]}" ; do echo "$app" ; done | sort)
if $gui ; then
choice=$(zenity --title "iOS-Mount" --list --width 250 --height 300 --hide-header --text "What should be mounted?" --column "" "${options[@]}")
if [ "$?" != "0" ] ; then
exit
fi
else
oldps3="$PS3"
PS3="Select option number: "
echo "Available apps:"
select choice in "${options[@]}" ; do break ; done
PS3="$oldps3"
fi
if [ "$choice" != "Filesystem (Photos and Media)" ] ; then
if [[ ! -v apps["$choice"] ]] ; then
echo "No option selected, exiting..."
exit 0
fi
fi
mountpoint="$HOME/iOS-Mount"
mkdir -p "$mountpoint" 2>&1 > /dev/null
ifuse_output="$(fusermount -u -z "$mountpoint" 2>&1)"
ifuse_status=$?
if [ "$ifuse_status" != "0" ] && [[ "$ifuse_output" != *"not found"* ]] ; then
msg="Something went wrong while preparing $mountpoint...\\nError message:\\n$ifuse_output"
if $gui ; then
zenity --title "iOS-Mount" --error --no-wrap --text "$msg"
if [ "$?" != "0" ] ; then
exit
fi
else
echo -e "$msg"
fi
continue
fi
if [ "$choice" = "Filesystem (Photos and Media)" ] ; then
ifuse_output="$(ifuse "$mountpoint" 2>&1)"
ifuse_status=$?
if [ "$ifuse_status" = "0" ] ; then
msg="Successfully mounted device filesystem on $mountpoint!"
else
msg="Something went wrong while mounting device filesystem on $mountpoint..."
fi
else
ifuse_output="$(ifuse --documents "${apps["$choice"]}" "$mountpoint" 2>&1)"
ifuse_status=$?
if [ "$ifuse_status" = "0" ] ; then
msg="Successfully mounted $choice on $mountpoint!"
else
msg="Something went wrong while mounting $choice on $mountpoint..."
fi
fi
if [ "$ifuse_status" = "0" ] ; then
if $gui ; then
xdg-open "$mountpoint"
zenity --title "iOS-Mount" --info --no-wrap --text "$msg\\nWhen you are done click below or close this window to unmount!" --ok-label "Unmount!"
else
echo -e "$msg\\nPress [ENTER] when you are done and want to unmount!"
read
fi
else
msg="$msg\\nError message:\\n$ifuse_output"
if $gui ; then
zenity --title "iOS-Mount" --error --no-wrap --text "$msg"
if [ "$?" != "0" ] ; then
exit
fi
else
echo -e "$msg"
fi
continue
fi
ifuse_output="$(fusermount -u -z "$mountpoint" 2>&1)"
ifuse_status=$?
if [ "$ifuse_status" = "0" ] ; then
msg="Successfully unmounted $mountpoint!"
if $gui ; then
zenity --title "iOS-Mount" --info --no-wrap --text "$msg"
else
echo -e "$msg"
fi
else
msg="Something went wrong while unmounting $mountpoint...\\nError message:\\n$ifuse_output"
if $gui ; then
zenity --title "iOS-Mount" --error --no-wrap --text "$msg"
if [ "$?" != "0" ] ; then
exit
fi
else
echo -e "$msg"
fi
continue
fi
done