forked from peetonn/PTNSampleProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·152 lines (132 loc) · 4.01 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
147
148
149
150
151
152
#!/bin/sh
################################################################################
#
# setup
#
# author: Peter Gusev <[email protected]>
# date: Jan 25, 2013
# version: 1.0
#
# This script prepares workspace for new iOS app Xcode project.
# It does the following:
# - renames files/directories appropriately by new project name
# - configures project file for newly created project
# - clones submodules from remote servser (PTNArtifacts and OCMock libraries)
# - renames workspace
#
# Installation:
#
# chmod +x setup
#
# to make it executable.
#
# usage:
#
# setup <NewProjectName>
#
# examples:
#
# ./setup SuperProject
# ./setup "Super Project"
#
################################################################################
OLDNAME=PTNSampleProject
OLDWORKSPACE=PTNSample
NEWNAME=$1
# remove bad characters
NEWNAME=`echo "${NEWNAME}" | sed -e "s/[^a-zA-Z0-9_ -]//g"`
TMPFILE=/tmp/xcodeRename.$$
if [ "$NEWNAME" = "" ]; then
echo "usage: $0 <ProjectName>"
exit
fi
# be sure tmp file is writable
cp /dev/null ${TMPFILE}
if [ $? -ne 0 ]; then
echo "tmp file ${TMPFILE} is not writable. Terminating."
exit
fi
# create project name with unscores for spaces
OLDNAMEUSCORE=`echo "${OLDNAME}" | sed -e "s/ /_/g"`
NEWNAMEUSCORE=`echo "${NEWNAME}" | sed -e "s/ /_/g"`
echo renaming project...
#find text files, replace text
find "." | while read currFile
do
# find files that are of type text
file "${currFile}" | grep "text" > /dev/null
if [ $? -eq 0 -a "${currFile}" != "setup" ]; then
# see if old proj name with underscores is in the text
grep "${OLDNAMEUSCORE}" "${currFile}" > /dev/null
if [ $? -eq 0 ]; then
# replace the text with new proj name
#echo found "${OLDNAMEUSCORE}" in "${currFile}", replacing...
sed -e "s/${OLDNAMEUSCORE}/${NEWNAMEUSCORE}/g" "${currFile}" > ${TMPFILE}
mv ${TMPFILE} "${currFile}"
cp /dev/null ${TMPFILE}
fi
# see if old proj name is in the text
grep "${OLDNAME}" "${currFile}" > /dev/null
if [ $? -eq 0 ]; then
# replace the text with new proj name
#echo found "${OLDNAME}" in "${currFile}", replacing...
sed -e "s/${OLDNAME}/${NEWNAME}/g" "${currFile}" > ${TMPFILE}
mv ${TMPFILE} "${currFile}"
cp /dev/null ${TMPFILE}
fi
fi
done
# rename directories with underscores
find "." -maxdepth 1 -type dir | while read currFile
do
echo "${currFile}" | grep "${OLDNAMEUSCORE}" > /dev/null
if [ $? -eq 0 ]; then
MOVETO=`echo "${currFile}" | sed -e "s/${OLDNAMEUSCORE}/${NEWNAMEUSCORE}/g"`
#echo renaming "${currFile}" to "${MOVETO}"
mv "${currFile}" "${MOVETO}"
fi
done
# rename directories with spaces
find "." -maxdepth 1 -type dir | while read currFile
do
echo "${currFile}" | grep "${OLDNAME}" > /dev/null
if [ $? -eq 0 ]; then
MOVETO=`echo "${currFile}" | sed -e "s/${OLDNAME}/${NEWNAME}/g"`
#echo renaming "${currFile}" to "${MOVETO}"
mv "${currFile}" "${MOVETO}"
fi
done
# rename files with underscores
find "." -type file | while read currFile
do
echo "${currFile}" | grep "${OLDNAMEUSCORE}" > /dev/null
if [ $? -eq 0 ]; then
MOVETO=`echo "${currFile}" | sed -e "s/${OLDNAMEUSCORE}/${NEWNAMEUSCORE}/g"`
#echo renaming "${currFile}" to "${MOVETO}"
mv "${currFile}" "${MOVETO}"
fi
done
# rename files with spaces
find "." -type file | while read currFile
do
echo "${currFile}" | grep "${OLDNAME}" > /dev/null
if [ $? -eq 0 ]; then
MOVETO=`echo "${currFile}" | sed -e "s/${OLDNAME}/${NEWNAME}/g"`
#echo renaming "${currFile}" to "${MOVETO}"
mv "${currFile}" "${MOVETO}"
fi
done
rm -f ${TMPFILE}
echo renaming workspace...
mv "${OLDWORKSPACE}WS.xcworkspace" "${NEWNAMEUSCORE}WS.xcworkspace"
echo git submodules initialization...
git submodule init
git submodule update
echo removing git remote "origin"...
git remote rm origin
echo your workspace "${NEWNAMEUSCORE}WS" is ready for developing.
read -p "open Xcode?(y/n)[Y]?" REPLY
if [ "$REPLY" == "n" ]; then
exit 1
fi
open -a Xcode "${NEWNAMEUSCORE}WS.xcworkspace"