]> git.stg.codes - stg.git/blob - functest/test.sh
Clone from local repo.
[stg.git] / functest / test.sh
1 #!/bin/sh
2
3 BASEPATH=$1
4
5 if [ "$BASEPATH" == "" ]
6 then
7     printf "Usage: $0 <path>\n"
8     exit -1
9 fi
10
11 if [ ! -d "$BASEPATH" ]
12 then
13     printf "Path '$BASEPATH' does not exist or not a directory.\n"
14     exit -1
15 fi
16
17 STGPATH="$BASEPATH/stg/projects/stargazer"
18
19 cp "stuff/stargazer-files.conf" "$STGPATH/stargazer.conf"
20 cp "stuff/rules" "$STGPATH/"
21 cp "stuff/OnConnect" "$STGPATH/"
22 cp "stuff/OnDisconnect" "$STGPATH/"
23 cp "stuff/OnChange" "$STGPATH/"
24 cp -R "stuff/db-stub" "$STGPATH/db"
25
26 sed -i "s|-STG-PATH-|$STGPATH|g" "$STGPATH/stargazer.conf"
27
28 LOGFILE=`pwd`"/"`date "+%Y-%m-%d-%H%M%S.console.log"`
29
30 cd "$STGPATH"
31
32 "$STGPATH/stargazer" "$STGPATH" >> "$LOGFILE" 2>&1 &
33
34 COUNT=""
35 while true
36 do
37     grep "Stg started successfully" "$STGPATH/stargazer.log" > /dev/null 2> /dev/null
38     if [ "$?" == "0" ]
39     then
40         break
41     fi
42     COUNT="$COUNT."
43     if [ "$COUNT" == "....." ]
44     then
45         printf "Failed to start stg in 5 sec.\n"
46         exit -1
47     fi
48     sleep 1
49 done
50
51 PID=`cat "$STGPATH/stargazer.pid"`
52 printf "Started with pid $PID\n"
53
54 SGCONFPATH="$BASEPATH/stg/projects/sgconf"
55
56 RES=`"$SGCONFPATH/sgconf" -s localhost -p 5555 -u admin -w 123456 --get-admins`
57
58 if [ "$?" != "0" ]
59 then
60     printf "Failed to get admins list. Result:\n$RES\n"
61     exit 0
62 fi
63
64 printf "Got admins list:\n"
65
66 LOGINS=""
67 OLDIFS=$IFS
68 IFS=$(printf "\n")
69 for LINE in $RES
70 do
71     printf -- "$LINE\n"
72     LOGIN=`echo $LINE | grep login`
73     if [ "$?" == "0" ]
74     then
75         LOGINS="$LOGINS\n"`echo $LOGIN | cut -d: -f2 | sed -e 's/^ *//' -e 's/ *$//'`
76     fi
77 done
78 IFS=$OLDIFS
79
80 printf "Logins:\n$LOGINS\n"
81
82 NUM=`echo $LOGINS | wc -l`
83
84 printf -- "--------\n$NUM\n\n"
85
86 printf "Stopping...\n"
87 kill $PID
88
89 COUNT=""
90 while true
91 do
92     grep "Stg stopped successfully" "$STGPATH/stargazer.log" > /dev/null 2> /dev/null
93     if [ "$?" == "0" ]
94     then
95         break
96     fi
97     COUNT="$COUNT."
98     if [ "$COUNT" == "....." ]
99     then
100         printf "Failed to stop stg in 5 sec.\n"
101         exit -1
102     fi
103     sleep 1
104 done
105
106 printf "Stopped.\n"