]> git.stg.codes - stg.git/blob - functest/test.sh
921fa3f244eeda64e3b32cd70c55b7effce407ae
[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 GROUP=root
27 groups | grep root > /dev/null 2> /dev/null
28 if [ "$?" != "0" ]
29 then
30     groups | grep wheel > /dev/null 2> /dev/null
31     if [ "$?" != "0" ]
32     then
33         printf "Can't find neither 'root' nor 'wheel' group.\n"
34         exit -1
35     fi
36     GROUP=wheel
37 fi
38
39 sed -i "" "s|-STG-PATH-|$STGPATH|g" "$STGPATH/stargazer.conf"
40 sed -i "" "s|-STG-GROUP-|$GROUP|g" "$STGPATH/stargazer.conf"
41
42 CURPATH=`pwd`
43 LOGFILE="$CURPATH/"`date "+%Y-%m-%d-%H%M%S.console.log"`
44
45 cd "$STGPATH"
46
47 printf "Starting Stargazer... "
48
49 "$STGPATH/stargazer" "$STGPATH" >> "$LOGFILE" 2>&1 &
50
51 COUNT=""
52 while true
53 do
54     grep "Stg started successfully" "$STGPATH/stargazer.log" > /dev/null 2> /dev/null
55     if [ "$?" == "0" ]
56     then
57         break
58     fi
59     COUNT="$COUNT."
60     if [ "$COUNT" == "....." ]
61     then
62         printf "Failed to start stg in 5 sec.\n"
63         exit -1
64     fi
65     sleep 1
66 done
67
68 PID=`cat "$STGPATH/stargazer.pid"`
69 printf "Started with pid $PID\n"
70
71 printf "\nTesting admins:\n"
72 "$CURPATH/test_admins.sh" "$BASEPATH"
73 printf "\nTesting services:\n"
74 "$CURPATH/test_services.sh" "$BASEPATH"
75 printf "\n"
76
77 printf "Stopping... "
78 kill $PID
79
80 COUNT=""
81 while true
82 do
83     grep "Stg stopped successfully" "$STGPATH/stargazer.log" > /dev/null 2> /dev/null
84     if [ "$?" == "0" ]
85     then
86         break
87     fi
88     COUNT="$COUNT."
89     if [ "$COUNT" == "....." ]
90     then
91         printf "Failed to stop stg in 5 sec.\n"
92         exit -1
93     fi
94     sleep 1
95 done
96
97 printf "Stopped.\n"