-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloneProjectSource
More file actions
230 lines (209 loc) · 6.41 KB
/
cloneProjectSource
File metadata and controls
230 lines (209 loc) · 6.41 KB
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
229
230
#!/bin/sh
################################################################################
#
# cloneProject.sh
#
# morphed from the original renameXcodeProject.sh by Monte Ohrt (see below)
# by Rudi Farkas <rudi.farkas@gmail.com>
# version : 1.01
# date : 22 Jul 2011
#
# purpose : copy and rename an XCode project
#
# features (over and above those of renameXcodeProject.sh) :
#
# 1- makes the copied files writable before attempting to modify their content
#
# 2- works even if the new project name contains the old project name, for instance
# cloneProject.sh "MyStuff" "MyStuff2"
#
# installation :
#
# copy this file to a directory in your PATH, and make it executable with :
#
# chmod +x cloneProject.sh
#
# usage :
#
# cloneProject.sh <OldProjectName> <NewProjectName>
#
# example :
#
# cloneProject.sh MyStuff MyBetterStuf
#
# use at your own risk
# let me know if something does not work as advertized
#
################################################################################
################################################################################
#
# renameXcodeProject.sh
#
# author: Monte Ohrt <monte@ohrt.com>
# date: Jan 27, 2009
# version: 1.0
# http://www.phpinsider.com/xcode/renameXcodeProject.sh.txt
#
# This script will copy an xcode project to a new project directory name
# and replace/rename all files within to work as expected under the new name.
# Project names that contain characters other than alpha-numeric, spaces or
# underscores MAY not work properly with this script. Use at your own risk!
# Be CERTAIN to backup your project(s) before renaming.
#
# One simple rule:
#
# 1) The old project name cannot contain the new project name, so for instance,
# renaming "MyStuff" to "MyStuff2" will not work. If you really need to do
# this, rename the project to a temp name, then rename again.
#
# I have instructions for manually renaming an xcode project here:
#
# http://mohrt.blogspot.com/2008/12/renaming-xcode-project.html
#
#
# Installation:
#
# Copy (this) file "renameXcodeProject.sh" to your file system, and invoke:
#
# chmod 755 renameXcodeProject.sh
#
# to make it executable.
#
# usage:
#
# renameXcodeProject.sh <OldProjectName> <NewProjectName>
#
# example:
#
# ./renameXcodeProject.sh MyStuff MyNewStuff
#
################################################################################
OLDNAME=$1
NEWNAME=$2
# remove bad characters
OLDNAME=`echo "${OLDNAME}" | sed -e "s/[^a-zA-Z0-9_ -]//g"`
NEWNAME=`echo "${NEWNAME}" | sed -e "s/[^a-zA-Z0-9_ -]//g"`
echo ${OLDNAME}
echo ${NEWNAME}
TMPFILE=/tmp/xcodeRename.$$
TMPPROJNAME="D401CB997FCB4CB4AABFAC60E754C7B2"
if [ "$OLDNAME" = "" -o "$NEWNAME" = "" ]; then
echo "usage: $0 <OldProjectName> <NewProjectName>"
exit
fi
if [ ! -d "${OLDNAME}" ]; then
echo "ERROR: \"${OLDNAME}\" must be a directory"
exit
fi
# set new project directory
if [ -d "${NEWNAME}" ]; then
echo "ERROR: project directory \"${NEWNAME}\" exists. Terminating."
exit
fi
# does NEWNAME contain OLDNAME ?
echo "${NEWNAME}" | grep "${OLDNAME}" > /dev/null
if [ $? -eq 0 ]; then
# yes : set up names for the two-pass operation
FINALNAME="${NEWNAME}"
NEWNAME="401CB99D-7FCB-4CB4-AABF-AC60E754C7B2"
echo "Warning: New project name contains old project name. Project will be renamed in two passes."
else
# no : one pass operation is sufficient
FINALNAME=""
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"`
# copy project directory
echo copying project directory from "${OLDNAME}" to "${NEWNAME}"
cp -rp "${OLDNAME}" "${NEWNAME}"
# remove build directory
echo removing build directory from "${NEWNAME}"
rm -rf "${NEWNAME}/build"
# find text files, replace text
find "${NEWNAME}/." | while read currFile
do
# find files that are of type text
file "${currFile}" | grep "text" > /dev/null
if [ $? -eq 0 ]; then
# make sure it is writable
chmod +w "${currFile}"
# 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 replacing "${OLDNAMEUSCORE}" in "${currFile}"
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 replacing "${OLDNAME}" in "${currFile}"
sed -e "s/${OLDNAME}/${NEWNAME}/g" "${currFile}" > ${TMPFILE}
mv ${TMPFILE} "${currFile}"
cp /dev/null ${TMPFILE}
fi
fi
done
# rename directories with underscores
find "${NEWNAME}/." -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 "${NEWNAME}/." -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 "${NEWNAME}/." -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 "${NEWNAME}/." -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}
if [ "$FINALNAME" = "" ]; then
# this is the second pass : remove temp project directory
if [ "${OLDNAME}" = "${TMPPROJNAME}" ]; then
rm -rf "${TMPPROJNAME}"
fi
echo finished.
exit
else
echo
echo starting the second pass...
$0 "$NEWNAME" "$FINALNAME"
fi