-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartandroidstudio.sh
executable file
·106 lines (94 loc) · 2.18 KB
/
startandroidstudio.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
#!/bin/bash
ASEXECCACHE=~/.asexeccache
SDKLOCCACHE=~/.sdklockcache
if [ $# -gt 0 ]
then
if [ $1 == "-r" ]
then
rm -f ${ASEXECCACHE} ${SDKLOCCACHE}
elif [ $1 == "-e" ]
then
echo export ANDROID_HOME=$(cat ${SDKLOCCACHE})
exit 0
else
echo "usage: $0 [-r]"
echo "options"
echo " -r remove cache files and search for executable and sdk again"
exit 1
fi
fi
function findandroidstudioexecutable
{
if [ -e '/Applications/Android Studio.app/Contents/MacOS/studio' ] # assume we are running on Mac OSX
then
ASEXEC=("/Applications/Android Studio.app/Contents/MacOS/studio")
else
ASEXEC=($(find ~ -name 'studio.sh'))
fi
# Check if found files are readable and executable
INDEX=0
for asexec in ${ASEXEC[@]}
do
if ! [ -x ${asexec} ] && [ -r ${asexec} ]
then
unset ASEXEC[${INDEX}]
fi
INDEX=$((INDEX+1))
done
if [ ${#ASEXEC[@]} -gt 1 ]
then
echo "Multiple executables found:"
INDEX=0
for asexec in ${ASEXEC[@]}
do
echo ${INDEX}: ${asexec}
INDEX=$((INDEX+1))
done
echo "Which executable should be started? (0-$((INDEX-1)))"
while read answer
do
if [ ${answer} -gt -1 ] && [ ${answer} -lt ${INDEX} ]
then
ASEXEC=${ASEXEC[${answer}]}
break
fi
done
else
ASEXEC=${ASEXEC[0]}
fi
echo ${ASEXEC} > ${ASEXECCACHE}
}
function findandroidsdk
{
SDKLOC=($(find ~ -name 'SDK Readme.txt' -exec dirname {} \;))
if [ ${#SDKLOC[@]} -eq 0 ]
then
echo "Error: no SDK found"
exit 1
fi
if [ ${#SDKLOC[@]} -gt 1 ]
then
echo "Multiple SDKs found:"
INDEX=0
for sdkloc in "${SDKLOC[@]}"
do
echo ${INDEX}: ${sdkloc}
INDEX=$((INDEX+1))
done
echo "Which SDK do you want to use? (0-$((INDEX-1)))"
while read answer
do
if [ ${answer} -gt -1 ] && [ ${answer} -lt ${INDEX} ]
then
SDKLOC=${SDKLOC[${answer}]}
break
fi
done
fi
echo ${SDKLOC} > ${SDKLOCCACHE}
}
[ -r ${ASEXECCACHE} ] || findandroidstudioexecutable
[ -r ${SDKLOCCACHE} ] || findandroidsdk
export ANDROID_HOME=$(cat ${SDKLOCCACHE})
echo Starting "$(cat ${ASEXECCACHE})"
exec "$(cat ${ASEXECCACHE})"