-
Notifications
You must be signed in to change notification settings - Fork 4
/
install
executable file
·144 lines (115 loc) · 2.85 KB
/
install
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
#!/bin/bash
# Copyright (C) AlexWoo(Wu Jie) [email protected]
exec=`basename $0`
usage()
{
cat << END
usage: $exec [options]
options:
--help print this message
--prefix=InstallPath set installation prefix
--debug build with debug mode
--docker build docker image gortc development
END
}
docker_build()
{
docker build -t alexwoo/gortc ./
cp -f gortcdev /usr/local/bin/
}
install_service()
{
release=`cat /etc/redhat-release | awk '{print $4}' |awk -F '.' '{print $1}'`
if [ "$release" == '7' ];then
sed "s#\[InstallPath\]#$InstallPath#g" gortc.service > /lib/systemd/system/gortc.service
else
echo "Only support CentOS7"
exit 1
fi
}
create_user()
{
grep "^gortc" /etc/passwd >& /dev/null
if [ $? -ne 0 ];then
useradd gortc -M -r -s /sbin/nologin
fi
mkdir -p $InstallPath/logs
chown -R gortc:gortc $InstallPath
}
help=no
debug=no
docker=no
for option
do
case "$option" in
-*=*) value=`echo "$option" | sed -e 's/[-_a-zA-Z0-9]*=//'` ;;
*) value="" ;;
esac
case "$option" in
--help) help=yes ;;
--prefix=) InstallPath="!" ;;
--prefix=*) InstallPath="$value" ;;
--debug) debug=yes ;;
--docker) docker=yes ;;
*)
echo "$exec: error: invalid option \"$option\""
usage
exit 1
;;
esac
done
if [ $help = yes ];then
usage
exit 0
fi
if [ $docker = yes ];then
docker_build
exit 0
fi
case ".$InstallPath" in
.) InstallPath=/usr/local/gortc ;;
.!) InstallPath=/usr/local/gortc ;;
*) ;;
esac
OLDGOPATH="$GOPATH"
export GOPATH="$InstallPath"
# compile gortc
src=$InstallPath/src/gortc/
mkdir -p $InstallPath
cp -rf src $InstallPath
sed -i "s#RTCPATH = \".*\"#RTCPATH = \"$InstallPath\"#" $InstallPath/src/rtclib/base.go
cd $src
# get dependence
go get
# install
if [ $debug == 'yes' ];then
go install -ldflags=-w -gcflags "-N -l"
else
go install
fi
cd -
# compile rtest
src=$InstallPath/src/rtest/
cd $src
go install
cd -
mkdir -p $InstallPath/conf
mkdir -p $InstallPath/logs
mkdir -p $InstallPath/plugins
mkdir -p $InstallPath/certs
confs="gortc.ini .slps .apis"
for f in $confs
do
if [ ! -f $InstallPath/conf/$f ];then
install conf/$f $InstallPath/conf/$f -m 644
fi
done
bins="pcompile apim slpm rtcm"
for f in $bins
do
install bin/$f $InstallPath/bin/$f -m 755
sed -i "s#^path=.*#path=$InstallPath#" $InstallPath/bin/$f
done
export GOPATH="$OLDGOPATH"
create_user
install_service