-
Notifications
You must be signed in to change notification settings - Fork 1
/
create.sh
executable file
·180 lines (127 loc) · 3.69 KB
/
create.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
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
#!/bin/sh
################################################################################
#
# HRMake.sh
#
# Author: Heverton Rodrigues <[email protected]>
# Date: 2016-08-03
# Version: 0.1
#
# Project Description
#
# One simple rule:
#
# Usage:
#
# sudo chmod +x create.sh
# ./create.sh and follow the steps
#
################################################################################
OLDNAME="HRPRODUCTNAME"
OLDBUNDLE="HRBUNDLEID"
OLDORGANIZATION="HRORGANIZATION"
NEWNAME="DEFAULTNAME"
BUNDLEID="DEFAULTBUNDLE"
ORGANIZATION="DEFAULTORGANIZATION"
echo "Set the project name"
read NAME
NEWNAME=$(echo "${NAME}" | sed -e "s/[^a-zA-Z0-9_-]//g")
echo "Set your organization"
read TMPORGANIZATION
ORGANIZATION=$(echo "${TMPORGANIZATION}" | sed -e "s/[^a-zA-Z0-9_-]//g")
TMPBUNDLEID="com.$ORGANIZATION.$NEWNAME"
echo "Your bundle ID will be: $TMPBUNDLEID, want to confirm?"
read -p "[Y/n]: " OPT
if [ "$OPT" == "n" ]; then
echo "Enter your customized bundle id"
read TMPBUNDLEID
fi
BUNDLEID=$(echo "${TMPBUNDLEID}" | sed -e "s/[^.a-zA-Z0-9_-]//g")
echo "${BUNDLEID}" | grep ".${NEWNAME}" > /dev/null
if [ $? -eq 0 ]; then
BUNDLEID=$(echo $BUNDLEID | sed -e "s/.$NEWNAME//g")
fi
if [[ $1 = "-v" ]]; then
tar -zxvf "projects/$OLDNAME.tar.gz"
else
tar -zxf "projects/$OLDNAME.tar.gz"
fi
#Validations
TMPFILE=/tmp/xcodeRename.$$
if [ -d "${NEWNAME}" -o "$NEWNAME" = "" ]; then
echo "Invalid Name"
exit
fi
echo "${NEWNAME}" | grep "${OLDNAME}" > /dev/null
if [ $? -eq 0 ]; then
echo "Invalid Name"
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
# copy project directory
echo "Creating Project ${NEWNAME}"
mv "${OLDNAME}" "${NEWNAME}"
#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
# Renaming Organization
grep "${OLDORGANIZATION}" "${currFile}" > /dev/null
if [ $? -eq 0 ]; then
sed -e "s/${OLDORGANIZATION}/${ORGANIZATION}/g" "${currFile}" > ${TMPFILE}
mv ${TMPFILE} "${currFile}" 2> /dev/null
cp /dev/null ${TMPFILE}
fi
# Renaming Bundle ID
grep "${OLDBUNDLE}" "${currFile}" > /dev/null
if [ $? -eq 0 ]; then
sed -e "s/${OLDBUNDLE}/${BUNDLEID}/g" "${currFile}" > ${TMPFILE}
mv ${TMPFILE} "${currFile}" 2> /dev/null
cp /dev/null ${TMPFILE}
fi
# Renaming Project Name
grep "${OLDNAME}" "${currFile}" > /dev/null
if [ $? -eq 0 ]; then
sed -e "s/${OLDNAME}/${NEWNAME}/g" "${currFile}" > ${TMPFILE}
mv ${TMPFILE} "${currFile}" 2> /dev/null
cp /dev/null ${TMPFILE}
fi
fi
done
# rename directories
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"`
mv "${currFile}" "${MOVETO}" 2> /dev/null
fi
done
# rename files
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"`
mv "${currFile}" "${MOVETO}" 2> /dev/null
fi
done
rm -f ${TMPFILE}
echo "Installing PODs"
cat <<EOT > $NEWNAME/Podfile
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
use_frameworks!
target '$NEWNAME' do
$(echo "pod 'Fabric'\n pod 'Crashlytics'\n pod 'Alamofire'")
end
EOT
echo $(cd $NEWNAME && pod install && git init && git add . && git commit -m "Initial Commit" && open "$NEWNAME.xcworkspace") > /dev/null
echo finished.