This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
run.sh
executable file
·95 lines (83 loc) · 2.45 KB
/
run.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
95
#!/bin/bash
if [ -f "stop.sh" ]; then
./stop.sh
fi
echo -e "\n> Update 'master' branch:"
git pull origin master
echo -e "< Already updated."
branchs=("core" "browser" "server")
for branch in ${branchs[@]}; do
outdir=PixelPet3D-$branch
if [ ! -d "$outdir" ]; then
echo -e "\n> Clone '$branch' branch:"
git clone git@github.com:zhengxiaoyao0716/PixelPet3D.git -b $branch $outdir
echo -e "< Cloned into '$outdir'."
else
echo -e "\n> Pull '$branch' branch:"
cd $outdir
git pull origin $branch
cd ..
echo -e "< Pull into '$outdir'."
fi
done
if [ -f "/bin/mintty.exe" ]; then
exit 0
fi
echo -e "\n> Build and run core-module from 'core' branch:"
cd PixelPet3D-core
make build
nohup ./out/PixelPet3D-core &
core_pid=$!
cd ..
echo -e "< Core-module runing, pid=$core_pid, logged to PixelPet3D-core/nohup.out."
echo -e "\n> Config and start server from 'server' branch:"
cd PixelPet3D-server
pip install -r requirements.txt -q
chmod u+x main.py
nohup ./main.py -u &
server_pid=$!
cd ..
echo -e "< Server started, pid=$server_pid, logged to PixelPet3D-server/nohup.out."
clean="#!/bin/bash\n"
clean=$clean"\n"
clean=$clean"echo -e \"\0134n> Stop and clean:\";\n"
clean=$clean"\n"
clean=$clean"core_pid=$core_pid\n"
clean=$clean"server_pid=$server_pid\n"
clean=$clean"\n"
clean=$clean"branchs=(\"core\" \"server\")\n"
clean=$clean"for branch in \${branchs[@]}; do\n"
clean=$clean"\tpidvar=\\\$\${branch}_pid\n"
clean=$clean"\tpid=\`eval echo \$pidvar\`\n"
clean=$clean"\tcwd=/proc/\$pid/cwd\n"
clean=$clean"\tif [ -d \"\$cwd\" ]; then\n"
clean=$clean"\t\tif [[ \`ls -l \$cwd | awk '{print \$11}'\` =~ \"PixelPet3D-\$branch\" ]]; then\n"
clean=$clean"\t\t\tkill \$pid\n"
clean=$clean"\t\t\techo -e \"* Killed \$branch branch, pid=\$pid.\"\n"
clean=$clean"\t\tfi\n"
clean=$clean"\tfi\n"
clean=$clean"done\n"
clean=$clean"\n"
clean=$clean"rm .pp3d-*.sock */nohup.out stop.sh -f\n"
clean=$clean"\n"
clean=$clean"echo -e \"< Finish.\0134n\""
echo -e $clean > stop.sh
chmod u+x stop.sh
while : ; do
sleep 0.1
echo -e ".\c"
if [ -f "PixelPet3D-core/nohup.out" ]; then
if [ -f "PixelPet3D-server/nohup.out" ]; then
break
fi
fi
done
echo -e ""
while getopts "dh" opt; do
case $opt in
d) exit 0;;
?) echo -e "* Use '-d' argument to run in background.";;
esac
done
trap "./stop.sh; exit 2" 1 2 3 15
tail -f PixelPet3D-core/nohup.out PixelPet3D-server/nohup.out