forked from RelistenNet/relisten-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·146 lines (128 loc) · 2.98 KB
/
setup.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
#!/bin/bash
function printProgress {
printf "\033[0;33m%-70s" "$1"
}
function printSuccess {
if [ -z "$1" ]; then
message="DONE"
else
message=$1
fi
printf "\033[0;32m[\033[1;32m $message \033[0;32m]\033[0m\n"
}
function printFailure {
if [ -z "$1" ]; then
message="ERROR"
else
message=$1
fi
printf "\033[0;32m[\033[1;31m $message \033[0;32m]\033[0m\n"
}
runCmd ()
{
if [ -z "$2" ]; then
return 1
fi
cmd=$1
title=$2
if [ -z "$3" ]; then
expect=0
else
expect=$3
fi
if [ -z "$4" ]; then
log=`mktemp -t scriptcommand`
shouldRemove=1
else
log=$4
shouldRemove=0
fi
retval=0
printProgress "$title"
printf "$cmd\n" > $log
$cmd >> $log 2>&1
result=$?
if [[ "$result" == "$expect" ]]; then
printSuccess
else
retval=1
printFailure
printf "Last 10 lines of output (full log is at $log):\n"
tail -n 10 $log
shouldRemove=0
fi
if [ $shouldRemove == "1" ]; then
rm $log
fi
if [ "$retval" != "0" ]; then
exit 1
fi
}
function checkAndClone {
projectName=$1
projectURL=$2
if [ -z $3 ]; then
projectBasePath=".."
else
projectBasePath=$3
fi
if [ ! -d "$projectBasePath/$1" ]; then
runCmd "git clone --quiet $2 $projectBasePath/$1" "Cloning $1"
else
printProgress "Checking $1"
printSuccess
fi
}
function usage {
printf "Use: $0 [-n] [-l path]\n"
printf "\t-n\tDon't install CocoaPods\n"
printf "\t-l\tClone development pods into a subdirectory\n"
}
shouldInstallPods=1
podBasePath=".."
while getopts "nhl:" o; do
case "${o}" in
n)
shouldInstallPods=0
;;
l)
podBasePath=${OPTARG}
mkdir -p $podBasePath
;;
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
# Belt and suspenders
is_ci=0
pod_command="pod"
if [[ ! -z ${CI} ]]; then
echo "Running under continuous integration"
podBasePath="CIPods"
pod_command="bundle exec pod"
is_ci=1
fi
checkAndClone BASSGaplessAudioPlayer https://github.com/alecgorge/gapless-audio-bass-ios.git $podBasePath
checkAndClone AGAudioPlayer https://github.com/alecgorge/AGAudioPlayer.git $podBasePath
if [[ $shouldInstallPods == 1 ]]; then
printProgress "Checking for CocoaPods"
command -v $pod_command >/dev/null 2>&1 || {
printFailure
echo >&2 "Cocoapods is not installed. Please install it from https://cocoapods.org and try again."
exit 1
}
printSuccess
if [[ $is_ci == 1 ]]; then
runCmd "$pod_command install --repo-update" "Installing pods"
else
runCmd "$pod_command install" "Installing pods"
fi
fi
printf "\n\n✅ Success! Open \033[0;33mRelisten.xcworkspace\033[0m to build the app.\n"
exit 0