-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcreate_project.sh
executable file
·67 lines (57 loc) · 2.98 KB
/
create_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ]
then
echo "Invalid arguments: ./create_project.sh PROJECT_NAME ORGANIZATION_NAME SERVICE_NAME SERVICE_PORT"
exit 1
fi
PROJECT_NAME=$1
ORGANIZATION_NAME=$2
SERVICE_NAME=$3
SERVICE_PORT=$4
TEMPLATE_DIR=template
SRC_DIR=/opt/singnet/go/src/$PROJECT_NAME
PROTO_DIR=$SRC_DIR/service_spec
PROTO_FILE=$PROTO_DIR/$PROJECT_NAME.proto
PROTO_SED_DIR=$(echo $PROJECT_NAME/service_spec | sed 's_/_\\/_g')
PROTO_SED_DIR_START=$(echo service_spec | sed 's_/_\\/_g')
SERVER_GO_FILE=$SRC_DIR/server.go
CLIENT_GO_FILE=$SRC_DIR/client.go
BUILD_SCRIPT_FILE=$SRC_DIR/build.sh
DAEMON_CONFIG_DIRNAME=config
DAEMON_CONFIG_FILENAME=snetd.config.json
DAEMON_CONFIG_DIR=$SRC_DIR/$DAEMON_CONFIG_DIRNAME
DAEMON_CONFIG_FILE=$DAEMON_CONFIG_DIR/$DAEMON_CONFIG_FILENAME
START_SERVICE_SCRIPT_FILE=$SRC_DIR/publishAndStartService.sh
CLIENT_TEST_SCRIPT_FILENAME=testServiceRequest.sh
CLIENT_TEST_SCRIPT_FILE=$SRC_DIR/$CLIENT_TEST_SCRIPT_FILENAME
TEMPLATE_PROTO=$TEMPLATE_DIR/proto.template.proto
TEMPLATE_BUILD_SCRIPT=$TEMPLATE_DIR/build.template.sh
TEMPLATE_SERVER=$TEMPLATE_DIR/server.template.go
TEMPLATE_CLIENT=$TEMPLATE_DIR/client.template.go
TEMPLATE_DAEMON_CONFIG_FILE=$TEMPLATE_DIR/daemonConfigFile.template.json
TEMPLATE_START_SERVICE_SCRIPT=$TEMPLATE_DIR/publishAndStartService.template.sh
TEMPLATE_CLIENT_TEST_SCRIPT=$TEMPLATE_DIR/testService.template.sh
PROJECT_TAG=__PROJECT__
SERVICE_PORT_TAG=__SERVICE_PORT__
SERVICE_NAME_TAG=__SERVICE_NAME__
ORGANIZATION_NAME_TAG=__ORGANIZATION_NAME__
PROTO_DIR_TAG=__PROTO_DIR__
DAEMON_CONFIG_FILE_TAG=__DAEMON_CONFIG_FILE__
TEST_SCRIPT_FILENAME_TAG=__TEST_SCRIPT_FILENAME__
if [ -d "$SRC_DIR" ] || [ -f $SRC_DIR ]; then
echo "ERROR: $SRC_DIR already exists"
exit 1
fi
mkdir -p $PROTO_DIR
mkdir -p $SRC_DIR
mkdir -p $DAEMON_CONFIG_DIR
cat $TEMPLATE_PROTO | sed "s/$PROJECT_TAG/$PROJECT_NAME/g" > $PROTO_FILE
cat $TEMPLATE_BUILD_SCRIPT > $BUILD_SCRIPT_FILE
cat $TEMPLATE_SERVER | sed "s/$PROJECT_TAG/$PROJECT_NAME/g" | sed "s/$SERVICE_PORT_TAG/$SERVICE_PORT/g" | sed "s/$PROTO_DIR_TAG/$PROTO_SED_DIR/g" > $SERVER_GO_FILE
cat $TEMPLATE_CLIENT | sed "s/$PROJECT_TAG/$PROJECT_NAME/g" | sed "s/$SERVICE_PORT_TAG/$SERVICE_PORT/g" | sed "s/$PROTO_DIR_TAG/$PROTO_SED_DIR/g" > $CLIENT_GO_FILE
cat $TEMPLATE_DAEMON_CONFIG_FILE | sed "s/$ORGANIZATION_NAME_TAG/$ORGANIZATION_NAME/g" | sed "s/$SERVICE_NAME_TAG/$SERVICE_NAME/g" | sed "s/$SERVICE_PORT_TAG/$SERVICE_PORT/g" > $DAEMON_CONFIG_FILE
cat $TEMPLATE_CLIENT_TEST_SCRIPT | sed "s/$ORGANIZATION_NAME_TAG/$ORGANIZATION_NAME/g" | sed "s/$SERVICE_NAME_TAG/$SERVICE_NAME/g" > $CLIENT_TEST_SCRIPT_FILE
cat $TEMPLATE_START_SERVICE_SCRIPT | sed "s/$ORGANIZATION_NAME_TAG/$ORGANIZATION_NAME/g" | sed "s/$SERVICE_NAME_TAG/$SERVICE_NAME/g" | sed "s/$PROTO_DIR_TAG/$PROTO_SED_DIR_START/g" | sed "s/$DAEMON_CONFIG_FILE_TAG/$DAEMON_CONFIG_DIRNAME\/$DAEMON_CONFIG_FILENAME/g" > $START_SERVICE_SCRIPT_FILE
chmod 755 $START_SERVICE_SCRIPT_FILE
chmod 755 $CLIENT_TEST_SCRIPT_FILE
chmod 755 $BUILD_SCRIPT_FILE