-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit
executable file
·163 lines (139 loc) · 4.63 KB
/
init
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
#!/bin/sh
# Adatped from: https://rudifa.wordpress.com/2011/07/23/clonexcodeproject-sh/
#NEWNAME=$1
iOSSwiftStarterPack="iOSSwiftStarterPack"
# Get new project name
read -p 'Enter new project name (default is iOSStarterPack): ' NEWNAME
## Check for default
if [ "$NEWNAME" = "" ]; then
NEWNAME="iOSStarterPack"
fi
# remove bad characters
iOSSwiftStarterPack=`echo "${iOSSwiftStarterPack}" | sed -e "s/[^a-zA-Z0-9_ -]//g"`
NEWNAME=`echo "${NEWNAME}" | sed -e "s/[^a-zA-Z0-9_ -]//g"`
echo ${iOSSwiftStarterPack}
echo ${NEWNAME}
TMPFILE=/tmp/xcodeRename.$$
TMPPROJNAME="D401CB997FCB4CB4AABFAC60E754C7B2"
if [ "$iOSSwiftStarterPack" = "" -o "$NEWNAME" = "" ]; then
echo "usage: $0 <OldProjectName> <NewProjectName>"
exit
fi
if [ ! -d "${iOSSwiftStarterPack}" ]; then
echo "ERROR: \"${iOSSwiftStarterPack}\" 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 iOSSwiftStarterPack ?
echo "${NEWNAME}" | grep "${iOSSwiftStarterPack}" > /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
iOSSwiftStarterPackUSCORE=`echo "${iOSSwiftStarterPack}" | sed -e "s/ /_/g"`
NEWNAMEUSCORE=`echo "${NEWNAME}" | sed -e "s/ /_/g"`
# copy project directory
echo copying project directory from "${iOSSwiftStarterPack}" to "${NEWNAME}"
cp -rp "${iOSSwiftStarterPack}" "${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 "${iOSSwiftStarterPackUSCORE}" "${currFile}" > /dev/null
if [ $? -eq 0 ]; then
# replace the text with new proj name
echo replacing "${iOSSwiftStarterPackUSCORE}" in "${currFile}"
sed -e "s/${iOSSwiftStarterPackUSCORE}/${NEWNAMEUSCORE}/g" "${currFile}" > ${TMPFILE}
mv ${TMPFILE} "${currFile}"
cp /dev/null ${TMPFILE}
fi
# see if old proj name is in the text
grep "${iOSSwiftStarterPack}" "${currFile}" > /dev/null
if [ $? -eq 0 ]; then
# replace the text with new proj name
echo replacing "${iOSSwiftStarterPack}" in "${currFile}"
sed -e "s/${iOSSwiftStarterPack}/${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 "${iOSSwiftStarterPackUSCORE}" > /dev/null
if [ $? -eq 0 ]; then
MOVETO=`echo "${currFile}" | sed -e "s/${iOSSwiftStarterPackUSCORE}/${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 "${iOSSwiftStarterPack}" > /dev/null
if [ $? -eq 0 ]; then
MOVETO=`echo "${currFile}" | sed -e "s/${iOSSwiftStarterPack}/${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 "${iOSSwiftStarterPackUSCORE}" > /dev/null
if [ $? -eq 0 ]; then
MOVETO=`echo "${currFile}" | sed -e "s/${iOSSwiftStarterPackUSCORE}/${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 "${iOSSwiftStarterPack}" > /dev/null
if [ $? -eq 0 ]; then
MOVETO=`echo "${currFile}" | sed -e "s/${iOSSwiftStarterPack}/${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 [ "${iOSSwiftStarterPack}" = "${TMPPROJNAME}" ]; then
rm -rf "${TMPPROJNAME}"
fi
echo finished.
# Remove template
rm -rf ${iOSSwiftStarterPack}
exit
else
echo
echo starting the second pass...
$0 "$NEWNAME" "$FINALNAME"
fi