-
Notifications
You must be signed in to change notification settings - Fork 13
/
install
executable file
·228 lines (202 loc) · 5.99 KB
/
install
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/bash
#
# $1 - Path to iOS project
set -e
DEFAULT_CARTHAGE_VERSION="0.16.2"
DEFAULT_SWIFTLINT_VERSION="0.9.2"
DEFAULT_XCODE_VERSION="7.3"
generate_env_file ()
{
echo ""
echo "Do you want to generate .env file? [N/y]"
read generate_env_file
if [ "$generate_env_file" == "y" ]
then
while [ -z "$project_name" ]
do
echo ""
echo "Enter the project name:"
read project_name
done
echo ""
echo "Enter 'project' or 'workspace' depending on what you use [project]:"
read xcode_file
if [ "$xcode_file" == "workspace" ]
then
echo ""
echo "Enter the xcode workspace file name [$project_name.xcworkspace]:"
read xcode_workspace_file
if [ -z "$xcode_workspace_file" ]
then
xcode_workspace_file="$project_name.xcworkspace"
fi
else
echo ""
echo "Enter the xcode project file name [$project_name.xcodeproj]:"
read xcode_project_file
if [ -z "$xcode_project_file" ]
then
xcode_project_file="$project_name.xcodeproj"
fi
fi
echo ""
echo "What version of Xcode should we use? [$DEFAULT_XCODE_VERSION]"
read required_xcode_version
echo ""
echo "Do you want to install githooks when bootstrapping the project? [Y/n]"
read install_githooks
if [ "$install_githooks" != "n" ]
then
install_githooks="y"
fi
if [ -f $1/.swiftlint.yml ]
then
echo ""
echo "What version of swiftlint should we use? [$DEFAULT_SWIFTLINT_VERSION]"
read required_swiftlint_version
fi
if [ -f $1/Cartfile ] || [ -f $1/Cartfile.private ]
then
echo ""
echo "What version of Carthage should we use? [$DEFAULT_CARTHAGE_VERSION]"
read required_carthage_version
echo ""
echo "Do you want to use ssh to checkout dependencies with Carthage? [N/y]"
read use_ssh
echo ""
echo "Do you want to use submodules when checking out dependencies with Carthage? [N/y]"
read use_submodules
echo ""
echo "What platforms should Carthage build? Enter as a comma separated list [iOS]"
read carthage_platforms
fi
echo ""
echo "Do you want to define iOS destination value for xcodebuild? [N/y]:"
read override_ios_destination
if [ "$override_ios_destination" == "y" ]
then
echo ""
echo "iOS version [latest]:"
read ios_destination_version
echo ""
echo "iOS simulator name [iPhone 6]:"
read ios_destination_simulator_name
fi
echo ""
echo "Do you want to define OS X destination value for xcodebuild? [N/y]:"
read override_osx_destination
if [ "$override_osx_destination" == "y" ]
then
echo ""
echo "OSX arch [current]?:"
read osx_destination_arch
fi
if [ -z "$required_carthage_version" ]
then
required_carthage_version="$DEFAULT_CARTHAGE_VERSION"
fi
ios_destination_version=${ios_destination_version:-"latest"}
ios_destination_simulator_name=${ios_destination_simulator_name:-"iPhone 6"}
carthage_platforms=${carthage_platforms:-"iOS"}
echo "
REQUIRED_XCODE_VERSION=$required_xcode_version
REQUIRED_SWIFTLINT_VERSION=$required_swiftlint_version
REQUIRED_CARTHAGE_VERSION=$required_carthage_version
CARTHAGE_BUILD_PLATFORM=\${CARTHAGE_BUILD_PLATFORM:-\"$carthage_platforms\"}
CARTHAGE_NO_USE_BINARIES=\${CARTHAGE_NO_USE_BINARIES:-\"false\"}
LINT_PODSPEC=\${LINT_PODSPEC:-\"yes\"}
PROJECT_NAME=$project_name
XCODE_WORKSPACE=$xcode_workspace_file
XCODE_PROJECT=$xcode_project_file
IOS_DESTINATION_VERSION=\${IOS_DESTINATION_VERSION:-\"$ios_destination_version\"}
IOS_DESTINATION_SIMULATOR_NAME=\${IOS_DESTINATION_SIMULATOR_NAME:-\"$ios_destination_simulator_name\"}
OSX_DESTINATION_ARCH=\${OSX_DESTINATION_ARCH:-\"$osx_destination_arch\"}" > "$1/script/.env"
if [ "$use_ssh" == "y" ]
then
echo "USE_SSH=true" >> "$1/script/.env"
fi
if [ "$use_submodules" == "y" ]
then
echo "USE_SUBMODULES=true" >> "$1/script/.env"
fi
if [ "$install_githooks" == "y" ]
then
echo "INSTALL_GITHOOKS=true" >> "$1/script/.env"
fi
echo " → '$1/script/.env' successfully generated"
echo ""
cat "$1/script/.env"
echo ""
echo "Do you want to bootstrap the project? [Y/n]:"
read bootstrap_project
if [ "$bootstrap_project" != "n" ]
then
(cd $1 && script/bootstrap)
fi
else
echo " → Skipping generation of .env file"
echo ""
fi
}
commit_changes ()
{
echo " → Committing changes in '$1'"
echo ""
local current_directory=`pwd`
cd $1
git add .
git commit -m "Updates build scripts." > /dev/null
cd $current_directory
echo " ✔ Changes successfully commited"
echo ""
}
install_scripts()
{
# Need to check if the working directory is clean before Installing
# script. We use '|| echo false' to avoid the script to fail in case
# the path where the scripts are going to be installed is not under
# git version control
local can_commit_changes="$(cd $1; git status --porcelain || echo false)"
echo ""
echo " → Installing scripts into '$1/script'"
cp -r script $1
echo ""
echo " ✔ Scripts successfully installed"
echo ""
if [ ! -f "$1/script/.env" ]
then
generate_env_file $1
fi
if [ -z "$can_commit_changes" ]
then
if [ ! -z "$(cd $1; git status --porcelain || echo '')" ]
then
commit_changes $1
else
echo "Skipping commit for '$1'. Scripts were already up-to-date."
fi
else
echo "Cannot commit updated scripts for '$1'. Working directory is not clean."
fi
}
if [ -z "$1" ] && [ -f .installrc ]
then
while read path
do
if [ -f "$path/script/.env" ]
then
install_scripts $path
else
echo "Skipping installation for '$path'. First time installation must be done separatelly."
echo "Run the following:"
echo " ./install $path"
echo ""
fi
done < .installrc
elif [ -z "$1" ]
then
echo "You need to supply a path where to install the scripts or a '.installrc' file."
exit 1
else
install_scripts $1
fi