-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_project.sh
47 lines (40 loc) · 1.67 KB
/
new_project.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
#! /usr/bin/env bash
main() {
gopath=`go env GOPATH`
if [ $? = 127 ]; then
echo "GOPATH not exists"
exit -1
fi
echo -e "New project will be create in ${gopath}/src/"
echo -ne "Enter your new project full name (eg. github.com/my_username/my_projname): "
read projname
# get template project
echo -e "Downloading the template..."
if !(curl https://codeload.github.com/axiaoxin-com/grpc-tpl/zip/main -o /tmp/grpc-tpl.zip && unzip /tmp/grpc-tpl.zip -d /tmp)
then
echo "Downloading failed."
exit -2
fi
echo -e "Generating the project..."
mv /tmp/grpc-tpl-main ${gopath}/src/${projname} && cd ${gopath}/src/${projname}
if [ `uname` = 'Darwin' ]; then
sed -i '' -e "s|github.com/axiaoxin-com/grpc-tpl|${projname}|g" `grep "grpc-tpl" --include "*.proto" --include ".travis.yml" --include "*.go" --include "go.*" -rl .`
else
sed -i "s|github.com/axiaoxin-com/grpc-tpl|${projname}|g" `grep "grpc-tpl" --include "*.proto" --include ".travis.yml" --include "*.go" --include "go.*" -rl .`
fi
if [ $? -ne 0 ]
then
echo -e "set project name failed."
exit -3
fi
echo -e "Create project ${projname} in ${gopath}/src succeed."
# init a git repo
echo -ne "Do you want to init a git repo[N/y]: "
read initgit
if [ "${initgit}" == "y" ] || [ "${initgit}" == "Y" ]; then
cd ${gopath}/src/${projname} && git init && git add . && git commit -m "init project with grpc-tpl"
cp ${gopath}/src/${projname}/misc/scripts/pre-push.githook ${gopath}/src/${projname}/.git/hooks/pre-push
chmod +x ${gopath}/src/${projname}/.git/hooks/pre-push
fi
}
main