-
Notifications
You must be signed in to change notification settings - Fork 17
/
install.sh
executable file
·96 lines (81 loc) · 2.06 KB
/
install.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
#!/bin/bash +x
DB="pg"
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "$package - boilerplate for Golang"
echo " "
echo "$package [options]"
echo " "
echo "options:"
echo "-h, --help show brief help"
echo "-p PACKAGE specify the package. Eg. gautamrege/sample"
echo "-d DB specify the DB {mongo|pg}"
exit 0
;;
-p)
shift
if test $# -gt 0; then
PACKAGE=$1
else
echo "no package specified"
exit 1
fi
shift
;;
-d)
shift
if test $# -gt 0; then
DB=$1
else
echo "no DB specified"
exit 1
fi
if [ "$DB" != "pg" ] && [ "$DB" != "mongo" ]; then
echo "Unsupported database! Only 'mongo' or 'pg' supported currently."
exit 1
fi
shift
;;
*)
break
;;
esac
done
if [ "$PACKAGE" == "" ]; then
echo "Package is mandatory. Use -p <package name>."
exit 1
fi
# For the internal scripts, we need extra escape chars
PACKAGE_S=`echo $PACKAGE | sed -e 's/\//\\\\\//g'`
git clone [email protected]:joshsoftware/golang-boilerplate.git
rm -rf golang-boilerplate/.git
cp -r golang-boilerplate/* .
rm -rf golang-boilerplate
sed -i bkp s/joshsoftware\\\/golang-boilerplate/$PACKAGE_S/g *.go
sed -i bkp s/joshsoftware\\\/golang-boilerplate/$PACKAGE_S/g */*.go
# Cleanup the bkp files
find . -name *bkp | xargs -I{} rm {}
find ./. -name *bkp | xargs -I{} rm {}
if [ "$DB" == "mongo" ]; then
tail +3 db/mongo.go > db/mongo.go.tmp
mv db/mongo.go.tmp db/mongo.go
rm db/pg.go
mv db/user.go.mongo db/user.go
else
rm db/mongo.go db/user.go.mongo
fi
rm go.mod go.sum
go mod init $PACKAGE
BINARY=`echo $PACKAGE | sed -e 's/^.*\///g'`
echo $BINARY >> .gitignore
cp application.yml.default application.yml
echo
echo "*********** Service setup completed **************"
echo "Microservice: $PACKAGE"
echo "Database: $DB"
echo
echo "*** Please configure application.yml ***"
echo "Then run 'go build' to build your service."
echo "**************************************************"
echo